global: a working virtual machine for some of the use cases. APIs and validation still WIP.

This commit is contained in:
2023-11-21 22:18:05 -08:00
parent 0a2d029c5c
commit 6211ad4ff1
53 changed files with 434 additions and 182 deletions

View File

@ -6,7 +6,6 @@ import gay.pizza.dough.fs.PlatformFsProvider
import gay.pizza.pork.ast.gen.Symbol
import gay.pizza.pork.compiler.Compiler
import gay.pizza.pork.minimal.FileTool
import gay.pizza.pork.vm.VirtualMachine
class CompileCommand : CliktCommand(help = "Compile Pork to Bytecode", name = "compile") {
val path by argument("file")
@ -32,7 +31,5 @@ class CompileCommand : CliktCommand(help = "Compile Pork to Bytecode", name = "c
println(" ${symbol.offset + index.toUInt()} ${op}${annotation}")
}
}
val vm = VirtualMachine(compiledWorld)
vm.execute()
}
}

View File

@ -2,33 +2,33 @@ package gay.pizza.pork.tool
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.enum
import gay.pizza.dough.fs.PlatformFsProvider
import gay.pizza.pork.evaluator.*
import gay.pizza.pork.ast.gen.Symbol
import gay.pizza.pork.execution.InternalNativeProvider
import gay.pizza.pork.execution.NativeRegistry
import gay.pizza.pork.minimal.ExecutionType
import gay.pizza.pork.minimal.FileTool
class RunCommand : CliktCommand(help = "Run Program", name = "run") {
val loop by option("--loop", help = "Loop Program").flag()
val measure by option("--measure", help = "Measure Time").flag()
val quiet by option("--quiet", help = "Silence Prints").flag()
val dumpScope by option("--dump-scope", help = "Dump Scope").flag()
val executionType by option("--execution-type", "-E")
.enum<ExecutionType> { it.id }
.default(ExecutionType.VirtualMachine)
val path by argument("file")
override fun run() {
val tool = FileTool(PlatformFsProvider.resolve(path))
val main = tool.loadMainFunctionStandard(quiet = quiet)
if (dumpScope) {
val functionContext = main as FunctionContext
val internalScope = functionContext.slabContext.internalScope
internalScope.crawlScopePath { key, path ->
println("[scope] $key [${path.joinToString(" -> ")}]")
}
}
val nativeRegistry = NativeRegistry()
nativeRegistry.add("internal", InternalNativeProvider(quiet = quiet))
val main = tool.createExecutionContext(executionType, Symbol("main"), nativeRegistry)
maybeLoopAndMeasure(loop, measure) {
main.call(emptyList(), CallStack())
main.execute()
}
}
}