From dd9f6f634d676c7db510eb912c1eca23caa612c8 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 5 Aug 2020 12:50:00 +0900 Subject: [PATCH] minor fixups --- Videotron2K.md | 8 ++-- src/net/torvald/tsvm/vdc/Videotron2K.kt | 53 +++++++++++++++++++------ 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/Videotron2K.md b/Videotron2K.md index 6714cbc..bb941f3 100644 --- a/Videotron2K.md +++ b/Videotron2K.md @@ -38,12 +38,12 @@ SCENE initialise ; if next line is not there, it goes to the first non-@ line END SCENE -SCENE 0 ; indexed scene +SCENE_0 ; indexed scene 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 END SCENE -SCENE 1 ; indexed scene +SCENE_1 ; indexed scene 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 END SCENE @@ -52,8 +52,8 @@ SCENE anim @ define cnt 2 ; definition of the local constant @ mov c1 0 perform c1 ; accessing the indexed scene - inc c1 ; slightly inefficient way to make comparision - cmp c1 cnt r1 ; slightly inefficient way to make comparision + inc c1 ; slightly inefficient way to make comparison + cmp c1 cnt r1 ; slightly inefficient way to make comparison exitzr r1 END SCENE diff --git a/src/net/torvald/tsvm/vdc/Videotron2K.kt b/src/net/torvald/tsvm/vdc/Videotron2K.kt index b4472d3..42ccf58 100644 --- a/src/net/torvald/tsvm/vdc/Videotron2K.kt +++ b/src/net/torvald/tsvm/vdc/Videotron2K.kt @@ -92,11 +92,15 @@ class Videotron2K(var gpu: GraphicsAdapter?) { private var regs = UnsafeHelper.allocate(16 * 8) private var internalMem = UnsafeHelper.allocate(16384) + /* Compile-time variables */ private var scenes = HashMap>() // Long can have either SCENE_PREFIX- or INDEXED_SCENE_PREFIX-prefixed value private var varIdTable = HashMap() // String is always uppercase, Long always has VARIABLE_PREFIX added - private var sceneIdTable = HashMap() // String is always uppercase, Long always has SCENE_PREFIX added + //private var sceneIdTable = HashMap() // 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. + /* Run-time variables */ + private var variableMap = HashMap() // VarId, Integer-value + private val reComment = Regex(""";[^\n]*""") private val reTokenizer = Regex(""" +""") private val reGeneralReg = Regex("""[rR][0-9]""") @@ -106,6 +110,37 @@ class Videotron2K(var gpu: GraphicsAdapter?) { private val rng = HQRNG() 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) { + 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 { + scenes.clear() + varIdTable.clear() + //sceneIdTable.clear() val rootStatements = ArrayList() val sceneStatements = ArrayList() @@ -155,16 +190,7 @@ class Videotron2K(var gpu: GraphicsAdapter?) { } } - - if (debugPrint) { - scenes.forEach { id, statements -> - println("SCENE #${id and 0xFFFFFFFFL}") - statements.forEach { println(" $it") } - println("END SCENE\n") - } - - rootStatements.forEach { println(it) } - } + return rootStatements } 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) } return VT2Statement( + lnum, if (isInit) StatementPrefix.INIT else StatementPrefix.NONE, cmd, args.toLongArray() @@ -220,9 +247,9 @@ class Videotron2K(var gpu: GraphicsAdapter?) { 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 { - 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 {