mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 21:00:56 +00:00
improve debug mode
This commit is contained in:
parent
ff2aaabd93
commit
a262c09219
@ -1,6 +1,6 @@
|
|||||||
package gay.pizza.pork.execution
|
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(
|
private val functions = mutableMapOf(
|
||||||
"print" to NativeFunction(::printValues),
|
"print" to NativeFunction(::printValues),
|
||||||
"println" to NativeFunction(::printLine),
|
"println" to NativeFunction(::printLine),
|
||||||
@ -39,13 +39,26 @@ class InternalNativeProvider(val quiet: Boolean = false) : NativeProvider {
|
|||||||
|
|
||||||
private fun printValues(arguments: ArgumentList): Any {
|
private fun printValues(arguments: ArgumentList): Any {
|
||||||
if (quiet || arguments.isEmpty()) return None
|
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
|
return None
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun printLine(arguments: ArgumentList): Any {
|
private fun printLine(arguments: ArgumentList): Any {
|
||||||
if (quiet) return None
|
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
|
return Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package gay.pizza.pork.minimal
|
|||||||
|
|
||||||
import gay.pizza.dough.fs.PlatformFsProvider
|
import gay.pizza.dough.fs.PlatformFsProvider
|
||||||
import gay.pizza.pork.ast.gen.Symbol
|
import gay.pizza.pork.ast.gen.Symbol
|
||||||
import gay.pizza.pork.evaluator.Scope
|
|
||||||
import gay.pizza.pork.execution.ExecutionOptions
|
import gay.pizza.pork.execution.ExecutionOptions
|
||||||
import gay.pizza.pork.execution.InternalNativeProvider
|
import gay.pizza.pork.execution.InternalNativeProvider
|
||||||
import gay.pizza.pork.execution.NativeRegistry
|
import gay.pizza.pork.execution.NativeRegistry
|
||||||
@ -16,7 +15,7 @@ fun main(args: Array<String>) {
|
|||||||
val path = PlatformFsProvider.resolve(args[0])
|
val path = PlatformFsProvider.resolve(args[0])
|
||||||
val tool = FileTool(path)
|
val tool = FileTool(path)
|
||||||
val nativeRegistry = NativeRegistry()
|
val nativeRegistry = NativeRegistry()
|
||||||
nativeRegistry.add("internal", InternalNativeProvider(quiet = false))
|
nativeRegistry.add("internal", InternalNativeProvider(quiet = false, debug = false))
|
||||||
val main = tool.createExecutionContext(
|
val main = tool.createExecutionContext(
|
||||||
ExecutionType.Evaluator,
|
ExecutionType.Evaluator,
|
||||||
Symbol("main"),
|
Symbol("main"),
|
||||||
|
@ -32,7 +32,7 @@ class RunCommand : CliktCommand("run") {
|
|||||||
override fun run() {
|
override fun run() {
|
||||||
val tool = FileTool(PlatformFsProvider.resolve(path))
|
val tool = FileTool(PlatformFsProvider.resolve(path))
|
||||||
val nativeRegistry = NativeRegistry()
|
val nativeRegistry = NativeRegistry()
|
||||||
nativeRegistry.add("internal", InternalNativeProvider(quiet = quiet))
|
nativeRegistry.add("internal", InternalNativeProvider(quiet = quiet, debug = debug))
|
||||||
nativeRegistry.add("java", JavaNativeProvider())
|
nativeRegistry.add("java", JavaNativeProvider())
|
||||||
nativeRegistry.add("ffi", FfiNativeProvider())
|
nativeRegistry.add("ffi", FfiNativeProvider())
|
||||||
val main = tool.createExecutionContext(executionType, Symbol("main"), ExecutionOptions(
|
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()]
|
val (op, handler) = inlined[inst.toInt()]
|
||||||
if (debug) {
|
if (debug) {
|
||||||
val frame = frame(inst)
|
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)
|
handler.handle(this, op)
|
||||||
|
Loading…
Reference in New Issue
Block a user