From ade7a4c39860afcdab7c47da6eb100dcb3ed7da5 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 8 Jul 2019 13:40:52 +0200 Subject: [PATCH] restructuring vm --- compiler/src/prog8/CompilerMain.kt | 9 +++++---- compiler/src/prog8/compiler/Compiler.kt | 2 +- compiler/src/prog8/compiler/intermediate/Instruction.kt | 2 +- compiler/src/prog8/compiler/target/c64/AsmGen.kt | 4 ++-- .../src/prog8/{optimizing => optimizer}/CallGraph.kt | 2 +- .../{optimizing => optimizer}/ConstExprEvaluator.kt | 2 +- .../prog8/{optimizing => optimizer}/ConstantFolding.kt | 2 +- .../src/prog8/{optimizing => optimizer}/Extensions.kt | 2 +- .../{optimizing => optimizer}/SimplifyExpressions.kt | 2 +- .../{optimizing => optimizer}/StatementOptimizer.kt | 2 +- compiler/src/prog8/{ => vm}/astvm/AstVm.kt | 2 +- compiler/src/prog8/{ => vm}/astvm/BuiltinFunctions.kt | 2 +- compiler/src/prog8/{ => vm}/astvm/CallStack.kt | 2 +- compiler/src/prog8/{ => vm}/astvm/Expressions.kt | 2 +- compiler/src/prog8/{ => vm}/astvm/Memory.kt | 2 +- compiler/src/prog8/{ => vm}/astvm/ScreenDialog.kt | 8 ++++---- compiler/src/prog8/{ => vm}/astvm/VariablesCreator.kt | 2 +- .../src/prog8/{StackVmMain.kt => vm/stackvm/Main.kt} | 6 +++--- compiler/src/prog8/{ => vm}/stackvm/Program.kt | 2 +- compiler/src/prog8/{ => vm}/stackvm/StackVm.kt | 6 +++--- compiler/test/StackVMOpcodeTests.kt | 5 +++-- 21 files changed, 35 insertions(+), 33 deletions(-) rename compiler/src/prog8/{optimizing => optimizer}/CallGraph.kt (99%) rename compiler/src/prog8/{optimizing => optimizer}/ConstExprEvaluator.kt (99%) rename compiler/src/prog8/{optimizing => optimizer}/ConstantFolding.kt (99%) rename compiler/src/prog8/{optimizing => optimizer}/Extensions.kt (98%) rename compiler/src/prog8/{optimizing => optimizer}/SimplifyExpressions.kt (99%) rename compiler/src/prog8/{optimizing => optimizer}/StatementOptimizer.kt (99%) rename compiler/src/prog8/{ => vm}/astvm/AstVm.kt (99%) rename compiler/src/prog8/{ => vm}/astvm/BuiltinFunctions.kt (99%) rename compiler/src/prog8/{ => vm}/astvm/CallStack.kt (92%) rename compiler/src/prog8/{ => vm}/astvm/Expressions.kt (99%) rename compiler/src/prog8/{ => vm}/astvm/Memory.kt (99%) rename compiler/src/prog8/{ => vm}/astvm/ScreenDialog.kt (96%) rename compiler/src/prog8/{ => vm}/astvm/VariablesCreator.kt (99%) rename compiler/src/prog8/{StackVmMain.kt => vm/stackvm/Main.kt} (92%) rename compiler/src/prog8/{ => vm}/stackvm/Program.kt (99%) rename compiler/src/prog8/{ => vm}/stackvm/StackVm.kt (99%) diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index f25963683..6ebd82678 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -7,17 +7,18 @@ import prog8.ast.base.checkRecursion import prog8.ast.base.checkValid import prog8.ast.base.reorderStatements import prog8.ast.statements.Directive -import prog8.astvm.AstVm +import prog8.vm.astvm.AstVm import prog8.compiler.* import prog8.compiler.target.c64.AsmGen import prog8.compiler.target.c64.C64Zeropage -import prog8.optimizing.constantFold -import prog8.optimizing.optimizeStatements -import prog8.optimizing.simplifyExpressions +import prog8.optimizer.constantFold +import prog8.optimizer.optimizeStatements +import prog8.optimizer.simplifyExpressions import prog8.parser.ParsingFailedError import prog8.parser.importLibraryModule import prog8.parser.importModule import prog8.parser.moduleName +import prog8.vm.stackvm.stackVmMain import java.io.File import java.io.PrintStream import java.lang.Exception diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index cbc4cca40..473d4a2f6 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -11,7 +11,7 @@ import prog8.compiler.intermediate.Opcode import prog8.compiler.intermediate.branchOpcodes import prog8.functions.BuiltinFunctions import prog8.parser.tryGetEmbeddedResource -import prog8.stackvm.Syscall +import prog8.vm.stackvm.Syscall import java.io.File import java.nio.file.Path import java.util.* diff --git a/compiler/src/prog8/compiler/intermediate/Instruction.kt b/compiler/src/prog8/compiler/intermediate/Instruction.kt index c646d641d..a18acc175 100644 --- a/compiler/src/prog8/compiler/intermediate/Instruction.kt +++ b/compiler/src/prog8/compiler/intermediate/Instruction.kt @@ -1,7 +1,7 @@ package prog8.compiler.intermediate import prog8.compiler.RuntimeValue -import prog8.stackvm.Syscall +import prog8.vm.stackvm.Syscall open class Instruction(val opcode: Opcode, val arg: RuntimeValue? = null, diff --git a/compiler/src/prog8/compiler/target/c64/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/AsmGen.kt index 1a60630d4..260487aef 100644 --- a/compiler/src/prog8/compiler/target/c64/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/AsmGen.kt @@ -10,8 +10,8 @@ import prog8.ast.base.printWarning import prog8.compiler.RuntimeValue import prog8.compiler.* import prog8.compiler.intermediate.* -import prog8.stackvm.Syscall -import prog8.stackvm.syscallsForStackVm +import prog8.vm.stackvm.Syscall +import prog8.vm.stackvm.syscallsForStackVm import java.io.File import java.util.* import kotlin.math.abs diff --git a/compiler/src/prog8/optimizing/CallGraph.kt b/compiler/src/prog8/optimizer/CallGraph.kt similarity index 99% rename from compiler/src/prog8/optimizing/CallGraph.kt rename to compiler/src/prog8/optimizer/CallGraph.kt index e229255ba..459a49190 100644 --- a/compiler/src/prog8/optimizing/CallGraph.kt +++ b/compiler/src/prog8/optimizer/CallGraph.kt @@ -1,4 +1,4 @@ -package prog8.optimizing +package prog8.optimizer import prog8.ast.* import prog8.ast.base.ParentSentinel diff --git a/compiler/src/prog8/optimizing/ConstExprEvaluator.kt b/compiler/src/prog8/optimizer/ConstExprEvaluator.kt similarity index 99% rename from compiler/src/prog8/optimizing/ConstExprEvaluator.kt rename to compiler/src/prog8/optimizer/ConstExprEvaluator.kt index 52df3f12f..435ba9fdb 100644 --- a/compiler/src/prog8/optimizing/ConstExprEvaluator.kt +++ b/compiler/src/prog8/optimizer/ConstExprEvaluator.kt @@ -1,4 +1,4 @@ -package prog8.optimizing +package prog8.optimizer import prog8.ast.* import prog8.ast.base.DataType diff --git a/compiler/src/prog8/optimizing/ConstantFolding.kt b/compiler/src/prog8/optimizer/ConstantFolding.kt similarity index 99% rename from compiler/src/prog8/optimizing/ConstantFolding.kt rename to compiler/src/prog8/optimizer/ConstantFolding.kt index 926345753..8070fff8f 100644 --- a/compiler/src/prog8/optimizing/ConstantFolding.kt +++ b/compiler/src/prog8/optimizer/ConstantFolding.kt @@ -1,4 +1,4 @@ -package prog8.optimizing +package prog8.optimizer import prog8.ast.* import prog8.ast.base.* diff --git a/compiler/src/prog8/optimizing/Extensions.kt b/compiler/src/prog8/optimizer/Extensions.kt similarity index 98% rename from compiler/src/prog8/optimizing/Extensions.kt rename to compiler/src/prog8/optimizer/Extensions.kt index 5dc952085..2a1ed5c11 100644 --- a/compiler/src/prog8/optimizing/Extensions.kt +++ b/compiler/src/prog8/optimizer/Extensions.kt @@ -1,4 +1,4 @@ -package prog8.optimizing +package prog8.optimizer import prog8.ast.* import prog8.ast.base.AstException diff --git a/compiler/src/prog8/optimizing/SimplifyExpressions.kt b/compiler/src/prog8/optimizer/SimplifyExpressions.kt similarity index 99% rename from compiler/src/prog8/optimizing/SimplifyExpressions.kt rename to compiler/src/prog8/optimizer/SimplifyExpressions.kt index e38b74979..e0fa77f6d 100644 --- a/compiler/src/prog8/optimizing/SimplifyExpressions.kt +++ b/compiler/src/prog8/optimizer/SimplifyExpressions.kt @@ -1,4 +1,4 @@ -package prog8.optimizing +package prog8.optimizer import prog8.ast.* import prog8.ast.base.AstException diff --git a/compiler/src/prog8/optimizing/StatementOptimizer.kt b/compiler/src/prog8/optimizer/StatementOptimizer.kt similarity index 99% rename from compiler/src/prog8/optimizing/StatementOptimizer.kt rename to compiler/src/prog8/optimizer/StatementOptimizer.kt index f62885984..f9715063f 100644 --- a/compiler/src/prog8/optimizing/StatementOptimizer.kt +++ b/compiler/src/prog8/optimizer/StatementOptimizer.kt @@ -1,4 +1,4 @@ -package prog8.optimizing +package prog8.optimizer import prog8.ast.* import prog8.ast.base.* diff --git a/compiler/src/prog8/astvm/AstVm.kt b/compiler/src/prog8/vm/astvm/AstVm.kt similarity index 99% rename from compiler/src/prog8/astvm/AstVm.kt rename to compiler/src/prog8/vm/astvm/AstVm.kt index aa1b55fb5..6e3f64f70 100644 --- a/compiler/src/prog8/astvm/AstVm.kt +++ b/compiler/src/prog8/vm/astvm/AstVm.kt @@ -1,4 +1,4 @@ -package prog8.astvm +package prog8.vm.astvm import prog8.ast.* import prog8.ast.base.* diff --git a/compiler/src/prog8/astvm/BuiltinFunctions.kt b/compiler/src/prog8/vm/astvm/BuiltinFunctions.kt similarity index 99% rename from compiler/src/prog8/astvm/BuiltinFunctions.kt rename to compiler/src/prog8/vm/astvm/BuiltinFunctions.kt index c51263d21..e9376cefd 100644 --- a/compiler/src/prog8/astvm/BuiltinFunctions.kt +++ b/compiler/src/prog8/vm/astvm/BuiltinFunctions.kt @@ -1,4 +1,4 @@ -package prog8.astvm +package prog8.vm.astvm import prog8.ast.base.DataType import prog8.compiler.RuntimeValue diff --git a/compiler/src/prog8/astvm/CallStack.kt b/compiler/src/prog8/vm/astvm/CallStack.kt similarity index 92% rename from compiler/src/prog8/astvm/CallStack.kt rename to compiler/src/prog8/vm/astvm/CallStack.kt index 195e714e1..603c46d11 100644 --- a/compiler/src/prog8/astvm/CallStack.kt +++ b/compiler/src/prog8/vm/astvm/CallStack.kt @@ -1,4 +1,4 @@ -package prog8.astvm +package prog8.vm.astvm import prog8.ast.INameScope import java.util.* diff --git a/compiler/src/prog8/astvm/Expressions.kt b/compiler/src/prog8/vm/astvm/Expressions.kt similarity index 99% rename from compiler/src/prog8/astvm/Expressions.kt rename to compiler/src/prog8/vm/astvm/Expressions.kt index f39f63d58..b8a320d8b 100644 --- a/compiler/src/prog8/astvm/Expressions.kt +++ b/compiler/src/prog8/vm/astvm/Expressions.kt @@ -1,4 +1,4 @@ -package prog8.astvm +package prog8.vm.astvm import prog8.ast.* import prog8.ast.base.ArrayElementTypes diff --git a/compiler/src/prog8/astvm/Memory.kt b/compiler/src/prog8/vm/astvm/Memory.kt similarity index 99% rename from compiler/src/prog8/astvm/Memory.kt rename to compiler/src/prog8/vm/astvm/Memory.kt index 1b2c64f26..ca1d8ff4c 100644 --- a/compiler/src/prog8/astvm/Memory.kt +++ b/compiler/src/prog8/vm/astvm/Memory.kt @@ -1,4 +1,4 @@ -package prog8.astvm +package prog8.vm.astvm import prog8.compiler.target.c64.Mflpt5 import prog8.compiler.target.c64.Petscii diff --git a/compiler/src/prog8/astvm/ScreenDialog.kt b/compiler/src/prog8/vm/astvm/ScreenDialog.kt similarity index 96% rename from compiler/src/prog8/astvm/ScreenDialog.kt rename to compiler/src/prog8/vm/astvm/ScreenDialog.kt index 9c5ad1ae7..003940266 100644 --- a/compiler/src/prog8/astvm/ScreenDialog.kt +++ b/compiler/src/prog8/vm/astvm/ScreenDialog.kt @@ -1,4 +1,4 @@ -package prog8.astvm +package prog8.vm.astvm import prog8.compiler.target.c64.Charset import prog8.compiler.target.c64.Colors @@ -79,7 +79,7 @@ class BitmapScreenPanel : KeyListener, JPanel() { for(sc in Petscii.encodeScreencode(text, lowercase)) { setChar(cursorX, cursorY, sc, color) cursorX++ - if(cursorX>=(SCREENWIDTH/8)) { + if(cursorX>=(SCREENWIDTH /8)) { cursorY++ cursorX=0 } @@ -149,11 +149,11 @@ class ScreenDialog(title: String) : JFrame(title) { // the borders (top, left, right, bottom) val borderTop = JPanel().apply { - preferredSize = Dimension(BitmapScreenPanel.SCALING * (BitmapScreenPanel.SCREENWIDTH+2*borderWidth), BitmapScreenPanel.SCALING * borderWidth) + preferredSize = Dimension(BitmapScreenPanel.SCALING * (BitmapScreenPanel.SCREENWIDTH +2*borderWidth), BitmapScreenPanel.SCALING * borderWidth) background = Colors.palette[14] } val borderBottom = JPanel().apply { - preferredSize =Dimension(BitmapScreenPanel.SCALING * (BitmapScreenPanel.SCREENWIDTH+2*borderWidth), BitmapScreenPanel.SCALING * borderWidth) + preferredSize =Dimension(BitmapScreenPanel.SCALING * (BitmapScreenPanel.SCREENWIDTH +2*borderWidth), BitmapScreenPanel.SCALING * borderWidth) background = Colors.palette[14] } val borderLeft = JPanel().apply { diff --git a/compiler/src/prog8/astvm/VariablesCreator.kt b/compiler/src/prog8/vm/astvm/VariablesCreator.kt similarity index 99% rename from compiler/src/prog8/astvm/VariablesCreator.kt rename to compiler/src/prog8/vm/astvm/VariablesCreator.kt index 626990079..2e0caccd7 100644 --- a/compiler/src/prog8/astvm/VariablesCreator.kt +++ b/compiler/src/prog8/vm/astvm/VariablesCreator.kt @@ -1,4 +1,4 @@ -package prog8.astvm +package prog8.vm.astvm import prog8.ast.* import prog8.ast.base.* diff --git a/compiler/src/prog8/StackVmMain.kt b/compiler/src/prog8/vm/stackvm/Main.kt similarity index 92% rename from compiler/src/prog8/StackVmMain.kt rename to compiler/src/prog8/vm/stackvm/Main.kt index 99e46111b..754a8773a 100644 --- a/compiler/src/prog8/StackVmMain.kt +++ b/compiler/src/prog8/vm/stackvm/Main.kt @@ -1,7 +1,7 @@ -package prog8 +package prog8.vm.stackvm -import prog8.astvm.ScreenDialog -import prog8.stackvm.* +import prog8.printSoftwareHeader +import prog8.vm.astvm.ScreenDialog import java.awt.EventQueue import javax.swing.Timer import kotlin.system.exitProcess diff --git a/compiler/src/prog8/stackvm/Program.kt b/compiler/src/prog8/vm/stackvm/Program.kt similarity index 99% rename from compiler/src/prog8/stackvm/Program.kt rename to compiler/src/prog8/vm/stackvm/Program.kt index 975dd0bde..084bda8cf 100644 --- a/compiler/src/prog8/stackvm/Program.kt +++ b/compiler/src/prog8/vm/stackvm/Program.kt @@ -1,4 +1,4 @@ -package prog8.stackvm +package prog8.vm.stackvm import prog8.ast.antlr.unescape import prog8.ast.base.* diff --git a/compiler/src/prog8/stackvm/StackVm.kt b/compiler/src/prog8/vm/stackvm/StackVm.kt similarity index 99% rename from compiler/src/prog8/stackvm/StackVm.kt rename to compiler/src/prog8/vm/stackvm/StackVm.kt index 2af784110..a8f5c2843 100644 --- a/compiler/src/prog8/stackvm/StackVm.kt +++ b/compiler/src/prog8/vm/stackvm/StackVm.kt @@ -1,12 +1,12 @@ -package prog8.stackvm +package prog8.vm.stackvm import prog8.ast.base.DataType import prog8.ast.base.IterableDatatypes import prog8.ast.base.NumericDatatypes import prog8.ast.base.Register import prog8.ast.base.initvarsSubName -import prog8.astvm.BitmapScreenPanel -import prog8.astvm.Memory +import prog8.vm.astvm.BitmapScreenPanel +import prog8.vm.astvm.Memory import prog8.compiler.RuntimeValue import prog8.compiler.HeapValues import prog8.compiler.IntegerOrAddressOf diff --git a/compiler/test/StackVMOpcodeTests.kt b/compiler/test/StackVMOpcodeTests.kt index c17cb44d1..b79af12d9 100644 --- a/compiler/test/StackVMOpcodeTests.kt +++ b/compiler/test/StackVMOpcodeTests.kt @@ -12,7 +12,7 @@ import prog8.compiler.RuntimeValue import prog8.compiler.HeapValues import prog8.compiler.intermediate.Instruction import prog8.compiler.intermediate.Opcode -import prog8.stackvm.* +import prog8.vm.stackvm.* import kotlin.test.* @@ -60,7 +60,8 @@ class TestStackVmOpcodes { labels: Map?=null, mem: Map>?=null) : Program { val heap = HeapValues() - return Program("test", ins, vars ?: mapOf(), memoryPointers ?: mapOf(), labels ?: mapOf(), mem ?: mapOf(), heap) + return Program("test", ins, vars ?: mapOf(), memoryPointers ?: mapOf(), labels ?: mapOf(), mem + ?: mapOf(), heap) } @Test