minor fixups

This commit is contained in:
minjaesong
2020-08-05 12:50:00 +09:00
parent 95a9555031
commit dd9f6f634d
2 changed files with 44 additions and 17 deletions

View File

@@ -38,12 +38,12 @@ SCENE initialise
; if next line is not there, it goes to the first non-@ line ; if next line is not there, it goes to the first non-@ line
END SCENE END SCENE
SCENE 0 ; indexed scene SCENE_0 ; indexed scene
goto 100 100 ; moves pixel cursor to (x,y) = (100,100) goto 100 100 ; moves pixel cursor to (x,y) = (100,100)
plot 1 54 231 7 82 64 22 5 ; writes following bytes into the framebuffer plot 1 54 231 7 82 64 22 5 ; writes following bytes into the framebuffer
END SCENE END SCENE
SCENE 1 ; indexed scene SCENE_1 ; indexed scene
goto 100 102 ; moves pixel cursor to (x,y) = (100,102) goto 100 102 ; moves pixel cursor to (x,y) = (100,102)
plot 231 1 54 17 182 62 2 35 ; writes following bytes into the framebuffer plot 231 1 54 17 182 62 2 35 ; writes following bytes into the framebuffer
END SCENE END SCENE
@@ -52,8 +52,8 @@ SCENE anim
@ define cnt 2 ; definition of the local constant @ define cnt 2 ; definition of the local constant
@ mov c1 0 @ mov c1 0
perform c1 ; accessing the indexed scene perform c1 ; accessing the indexed scene
inc c1 ; slightly inefficient way to make comparision inc c1 ; slightly inefficient way to make comparison
cmp c1 cnt r1 ; slightly inefficient way to make comparision cmp c1 cnt r1 ; slightly inefficient way to make comparison
exitzr r1 exitzr r1
END SCENE END SCENE

View File

@@ -92,11 +92,15 @@ class Videotron2K(var gpu: GraphicsAdapter?) {
private var regs = UnsafeHelper.allocate(16 * 8) private var regs = UnsafeHelper.allocate(16 * 8)
private var internalMem = UnsafeHelper.allocate(16384) private var internalMem = UnsafeHelper.allocate(16384)
/* Compile-time variables */
private var scenes = HashMap<Long, Array<VT2Statement>>() // Long can have either SCENE_PREFIX- or INDEXED_SCENE_PREFIX-prefixed value private var scenes = HashMap<Long, Array<VT2Statement>>() // Long can have either SCENE_PREFIX- or INDEXED_SCENE_PREFIX-prefixed value
private var varIdTable = HashMap<String, Long>() // String is always uppercase, Long always has VARIABLE_PREFIX added private var varIdTable = HashMap<String, Long>() // String is always uppercase, Long always has VARIABLE_PREFIX added
private var sceneIdTable = HashMap<String, Long>() // String is always uppercase, Long always has SCENE_PREFIX added //private var sceneIdTable = HashMap<String, Long>() // String is always uppercase, Long always has SCENE_PREFIX added
private var currentScene: Long? = null // if it's named_scene, VARIABLE_PREFIX is added; indexed_scene does not. private var currentScene: Long? = null // if it's named_scene, VARIABLE_PREFIX is added; indexed_scene does not.
/* Run-time variables */
private var variableMap = HashMap<Long, Int>() // VarId, Integer-value
private val reComment = Regex(""";[^\n]*""") private val reComment = Regex(""";[^\n]*""")
private val reTokenizer = Regex(""" +""") private val reTokenizer = Regex(""" +""")
private val reGeneralReg = Regex("""[rR][0-9]""") private val reGeneralReg = Regex("""[rR][0-9]""")
@@ -106,6 +110,37 @@ class Videotron2K(var gpu: GraphicsAdapter?) {
private val rng = HQRNG() private val rng = HQRNG()
fun eval(command: String) { fun eval(command: String) {
val rootStatements = parseCommands(command)
if (debugPrint) {
scenes.forEach { id, statements ->
println("SCENE #${id and 0xFFFFFFFFL}")
statements.forEach { println("$it") }
println("END SCENE\n")
}
rootStatements.forEach { println(it) }
}
}
private fun execute(rootStatements: ArrayList<VT2Statement>) {
variableMap.clear()
rootStatements.forEach {
}
}
/**
* Clobbers scenes, varIdTable, sceneIdTable and temporary variable sceneIdTable
*
* @return root statements; scene statements are stored in 'scenes'
*/
private fun parseCommands(command: String): ArrayList<VT2Statement> {
scenes.clear()
varIdTable.clear()
//sceneIdTable.clear()
val rootStatements = ArrayList<VT2Statement>() val rootStatements = ArrayList<VT2Statement>()
val sceneStatements = ArrayList<VT2Statement>() val sceneStatements = ArrayList<VT2Statement>()
@@ -155,16 +190,7 @@ class Videotron2K(var gpu: GraphicsAdapter?) {
} }
} }
return rootStatements
if (debugPrint) {
scenes.forEach { id, statements ->
println("SCENE #${id and 0xFFFFFFFFL}")
statements.forEach { println(" $it") }
println("END SCENE\n")
}
rootStatements.forEach { println(it) }
}
} }
private fun translateLine(lnum: Int, line: String): VT2Statement { private fun translateLine(lnum: Int, line: String): VT2Statement {
@@ -180,6 +206,7 @@ class Videotron2K(var gpu: GraphicsAdapter?) {
val args = tokens.subList(1 + isInit.toInt(), tokens.size).map { parseArgString(cmdstr, lnum, it) } val args = tokens.subList(1 + isInit.toInt(), tokens.size).map { parseArgString(cmdstr, lnum, it) }
return VT2Statement( return VT2Statement(
lnum,
if (isInit) StatementPrefix.INIT else StatementPrefix.NONE, if (isInit) StatementPrefix.INIT else StatementPrefix.NONE,
cmd, cmd,
args.toLongArray() args.toLongArray()
@@ -220,9 +247,9 @@ class Videotron2K(var gpu: GraphicsAdapter?) {
private fun hasVar(name: String) = (varIdTable.containsKey(name.toUpperCase())) private fun hasVar(name: String) = (varIdTable.containsKey(name.toUpperCase()))
private class VT2Statement(val prefix: Int = StatementPrefix.NONE, val command: Int, val args: LongArray) { private class VT2Statement(val lnum: Int, val prefix: Int = StatementPrefix.NONE, val command: Int, val args: LongArray) {
override fun toString(): String { override fun toString(): String {
return StatementPrefix.toString(prefix) + " " + Command.reverseDict[command] + " " + (args.map { argsToString(it) }) return "L ${lnum.toString().padEnd(5, ' ')}" + StatementPrefix.toString(prefix) + " " + Command.reverseDict[command] + " " + (args.map { argsToString(it) })
} }
private fun argsToString(i: Long): String { private fun argsToString(i: Long): String {