diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index 820873e11..bb8453b80 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -4,17 +4,20 @@ import kotlinx.cli.* import prog8.ast.base.AstException import prog8.code.core.CbmPrgLauncherType import prog8.code.target.* +import prog8.code.target.virtual.VirtualMachineDefinition import prog8.compiler.CompilationResult import prog8.compiler.CompilerArguments import prog8.compiler.compileProgram import java.io.File import java.nio.file.FileSystems import java.nio.file.Path +import java.nio.file.Paths import java.nio.file.StandardWatchEventKinds import java.time.LocalDateTime import kotlin.system.exitProcess + fun main(args: Array) { val buildVersion = object {}.javaClass.getResource("/version.txt")?.readText()?.trim() println("\nProg8 compiler v$buildVersion by Irmen de Jong (irmen@razorvine.net)") @@ -46,6 +49,7 @@ private fun compileMain(args: Array): Boolean { val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler (one of '${C64Target.NAME}', '${C128Target.NAME}', '${Cx16Target.NAME}', '${AtariTarget.NAME}', '${VMTarget.NAME}')") .default(C64Target.NAME) val sourceDirs by cli.option(ArgType.String, fullName="srcdirs", description = "list of extra paths, separated with ${File.pathSeparator}, to search in for imported modules").multiple().delimiter(File.pathSeparator) + val startVm by cli.option(ArgType.Boolean, fullName = "vm", description = "load and run a p8-virt listing in the VM instead") val moduleFiles by cli.argument(ArgType.String, fullName = "modules", description = "main module file(s) to compile").multiple(999) try { @@ -76,6 +80,10 @@ private fun compileMain(args: Array): Boolean { return false } + if(startVm==true) { + return runVm(moduleFiles.first()) + } + if(watchMode==true) { val watchservice = FileSystems.getDefault().newWatchService() val allImportedFiles = mutableSetOf() @@ -184,3 +192,14 @@ private fun compileMain(args: Array): Boolean { return true } + +fun runVm(listingFilename: String): Boolean { + val name = + if(listingFilename.endsWith(".p8virt")) + listingFilename.substring(0, listingFilename.length-7) + else + listingFilename + val vmdef = VirtualMachineDefinition() + vmdef.launchEmulator(0, Paths.get(name)) + return true +} diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 6a6372189..017e3d5c0 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,6 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- add -vm option to load an existing p8virt file directly in the virtual machine - pipe operator: allow non-unary function calls in the pipe that specify the other argument(s) in the calls. - writeAssembly(): make it possible to actually get rid of the VarDecl nodes by fixing the rest of the code mentioned there. - allow "xxx" * constexpr (where constexpr is not a number literal), now gives expression error not same type