From 7de8f8cd63710827dc597b5f7d2191393ff43a76 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Tue, 5 Sep 2023 01:02:13 -0700 Subject: [PATCH] Prepare for benchmarking and profiling. --- .../kotlin/gay/pizza/pork/tool/AttributeCommand.kt | 2 +- .../main/kotlin/gay/pizza/pork/tool/RunCommand.kt | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tool/src/main/kotlin/gay/pizza/pork/tool/AttributeCommand.kt b/tool/src/main/kotlin/gay/pizza/pork/tool/AttributeCommand.kt index 16ba5ac..cf6338f 100644 --- a/tool/src/main/kotlin/gay/pizza/pork/tool/AttributeCommand.kt +++ b/tool/src/main/kotlin/gay/pizza/pork/tool/AttributeCommand.kt @@ -16,7 +16,7 @@ class AttributeCommand : CliktCommand(help = "Attribute AST", name = "attribute" val coalescer = NodeCoalescer { node -> val tokens = attribution.assembleTokens(node) - println("node ${node.toString().replace("\n", "^")}") + println("node ${node.type.name}") for (token in tokens) { println("token $token") } diff --git a/tool/src/main/kotlin/gay/pizza/pork/tool/RunCommand.kt b/tool/src/main/kotlin/gay/pizza/pork/tool/RunCommand.kt index 5195e76..406ee16 100644 --- a/tool/src/main/kotlin/gay/pizza/pork/tool/RunCommand.kt +++ b/tool/src/main/kotlin/gay/pizza/pork/tool/RunCommand.kt @@ -2,14 +2,27 @@ 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.flag +import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.types.path import gay.pizza.pork.evaluator.CallableFunction import gay.pizza.pork.evaluator.Scope class RunCommand : CliktCommand(help = "Run Program", name = "run") { + val loop by option("--loop", help = "Loop Program").flag() val path by argument("file").path(mustExist = true, canBeDir = false) override fun run() { + if (loop) { + while (true) { + runProgramOnce() + } + } else { + runProgramOnce() + } + } + + private fun runProgramOnce() { val tool = FileTool(path) val scope = Scope() scope.define("println", CallableFunction { arguments ->