mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 12:50:55 +00:00
improve debug mode
This commit is contained in:
parent
ff2aaabd93
commit
a262c09219
@ -1,6 +1,6 @@
|
||||
package gay.pizza.pork.execution
|
||||
|
||||
class InternalNativeProvider(val quiet: Boolean = false) : NativeProvider {
|
||||
class InternalNativeProvider(val quiet: Boolean = false, val debug: Boolean = false) : NativeProvider {
|
||||
private val functions = mutableMapOf(
|
||||
"print" to NativeFunction(::printValues),
|
||||
"println" to NativeFunction(::printLine),
|
||||
@ -39,13 +39,26 @@ class InternalNativeProvider(val quiet: Boolean = false) : NativeProvider {
|
||||
|
||||
private fun printValues(arguments: ArgumentList): Any {
|
||||
if (quiet || arguments.isEmpty()) return None
|
||||
print(arguments.at<List<*>>(0).joinToString(" ") { it.toString() })
|
||||
val string = arguments.at<List<*>>(0).joinToString(" ") { it.toString() }
|
||||
if (debug) {
|
||||
print(" internal: native print: ${string.replace("\n", "\\n")}")
|
||||
return None
|
||||
}
|
||||
print(string)
|
||||
return None
|
||||
}
|
||||
|
||||
private fun printLine(arguments: ArgumentList): Any {
|
||||
if (quiet) return None
|
||||
println(arguments.at<List<*>>(0).joinToString(" ") { it.toString() })
|
||||
val string = arguments.at<List<*>>(0).joinToString(" ") { it.toString() }
|
||||
if (debug) {
|
||||
val lines = string.split("\n")
|
||||
for (line in lines) {
|
||||
println(" internal: native println: $line")
|
||||
}
|
||||
return None
|
||||
}
|
||||
println(string)
|
||||
return Unit
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package gay.pizza.pork.minimal
|
||||
|
||||
import gay.pizza.dough.fs.PlatformFsProvider
|
||||
import gay.pizza.pork.ast.gen.Symbol
|
||||
import gay.pizza.pork.evaluator.Scope
|
||||
import gay.pizza.pork.execution.ExecutionOptions
|
||||
import gay.pizza.pork.execution.InternalNativeProvider
|
||||
import gay.pizza.pork.execution.NativeRegistry
|
||||
@ -16,7 +15,7 @@ fun main(args: Array<String>) {
|
||||
val path = PlatformFsProvider.resolve(args[0])
|
||||
val tool = FileTool(path)
|
||||
val nativeRegistry = NativeRegistry()
|
||||
nativeRegistry.add("internal", InternalNativeProvider(quiet = false))
|
||||
nativeRegistry.add("internal", InternalNativeProvider(quiet = false, debug = false))
|
||||
val main = tool.createExecutionContext(
|
||||
ExecutionType.Evaluator,
|
||||
Symbol("main"),
|
||||
|
@ -32,7 +32,7 @@ class RunCommand : CliktCommand("run") {
|
||||
override fun run() {
|
||||
val tool = FileTool(PlatformFsProvider.resolve(path))
|
||||
val nativeRegistry = NativeRegistry()
|
||||
nativeRegistry.add("internal", InternalNativeProvider(quiet = quiet))
|
||||
nativeRegistry.add("internal", InternalNativeProvider(quiet = quiet, debug = debug))
|
||||
nativeRegistry.add("java", JavaNativeProvider())
|
||||
nativeRegistry.add("ffi", FfiNativeProvider())
|
||||
val main = tool.createExecutionContext(executionType, Symbol("main"), ExecutionOptions(
|
||||
|
@ -25,7 +25,8 @@ class InternalMachine(val world: CompiledWorld, val nativeRegistry: NativeRegist
|
||||
val (op, handler) = inlined[inst.toInt()]
|
||||
if (debug) {
|
||||
val frame = frame(inst)
|
||||
println("vm: step: in ${frame?.symbolInfo?.commonSymbolIdentity ?: "unknown"}: $inst ${op.code}${if (op.args.isEmpty()) "" else " " + op.args.joinToString(" ")}")
|
||||
println("vm: step: in slab ${frame?.symbolInfo?.slab ?: "unknown"}: symbol ${frame?.symbolInfo?.symbol ?: "unknown"}: $inst ${op.code}${if (op.args.isEmpty()) "" else " " + op.args.joinToString(" ")}")
|
||||
println("vm: step: stack: ${stack}")
|
||||
}
|
||||
|
||||
handler.handle(this, op)
|
||||
|
Loading…
Reference in New Issue
Block a user