summaryrefslogtreecommitdiff
path: root/src/LispExecutionContext.kt
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-08-11 02:26:00 +0200
committernea <nea@nea.moe>2023-08-11 02:26:00 +0200
commit69f8367389c9d6f60ca594053d9d470e5a8ec999 (patch)
tree4fe2d341ca9ec9b8aaa0ec5cb18c53bf63265844 /src/LispExecutionContext.kt
parent912c9918d9a5afbfb023b650bed6e2754f030d5e (diff)
downloadnealisp-69f8367389c9d6f60ca594053d9d470e5a8ec999.tar.gz
nealisp-69f8367389c9d6f60ca594053d9d470e5a8ec999.tar.bz2
nealisp-69f8367389c9d6f60ca594053d9d470e5a8ec999.zip
Add output capture and more test reports
Diffstat (limited to 'src/LispExecutionContext.kt')
-rw-r--r--src/LispExecutionContext.kt20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/LispExecutionContext.kt b/src/LispExecutionContext.kt
index 9c2d9f8..6398cc4 100644
--- a/src/LispExecutionContext.kt
+++ b/src/LispExecutionContext.kt
@@ -7,12 +7,6 @@ class LispExecutionContext() {
val unloadedModules = mutableMapOf<String, LispAst.Program>()
val modules = mutableMapOf<String, Map<String, LispData>>()
- fun reportError(name: String, position: HasLispPosition): LispData.LispNil {
- println("Error: $name ${position.position}")
- return LispData.LispNil
- }
-
-
fun genBindings(): StackFrame {
return StackFrame(rootStackFrame)
}
@@ -36,8 +30,10 @@ class LispExecutionContext() {
isWhitelist: Boolean = false
): TestFramework.TestSuite {
val testSuite = TestFramework.setup(stackFrame, name, testList, isWhitelist)
+ val output = OutputCapture.captureOutput(stackFrame)
executeProgram(stackFrame, program)
testSuite.isTesting = false
+ testSuite.otherOutput = output.asString
return testSuite
}
@@ -54,7 +50,7 @@ class LispExecutionContext() {
if (exports == null) {
val module = unloadedModules[moduleName]
if (module == null) {
- reportError("Could not find module $moduleName", position)
+ into.reportError("Could not find module $moduleName", position)
return
}
exports = realizeModule(moduleName)
@@ -70,7 +66,7 @@ class LispExecutionContext() {
stackFrame.setValueLocal("export", LispData.externalRawCall("export") { context, callsite, stackFrame, args ->
args.forEach { name ->
if (name !is LispAst.Reference) {
- context.reportError("Invalid export", name)
+ stackFrame.reportError("Invalid export", name)
return@forEach
}
map[name.label] = context.resolveValue(stackFrame, name)
@@ -94,7 +90,7 @@ class LispExecutionContext() {
when (node) {
is LispAst.Parenthesis -> {
val first = node.items.firstOrNull()
- ?: return reportError("Cannot execute empty parenthesis ()", node)
+ ?: return stackFrame.reportError("Cannot execute empty parenthesis ()", node)
val rest = node.items.drop(1)
return when (val resolvedValue = resolveValue(stackFrame, first)) {
@@ -102,12 +98,12 @@ class LispExecutionContext() {
resolvedValue.execute(this, node, stackFrame, rest)
}
- else -> reportError("Cannot evaluate expression of type $resolvedValue", node)
+ else -> stackFrame.reportError("Cannot evaluate expression of type $resolvedValue", node)
}
}
- else -> return reportError("Expected invocation", node)
+ else -> return stackFrame.reportError("Expected invocation", node)
}
}
@@ -116,7 +112,7 @@ class LispExecutionContext() {
is LispAst.Atom -> LispData.Atom(node.label)
is LispAst.Parenthesis -> executeLisp(stackFrame, node)
is LispAst.Reference -> stackFrame.resolveReference(node.label)
- ?: reportError("Could not resolve variable ${node.label}", node)
+ ?: stackFrame.reportError("Could not resolve variable ${node.label}", node)
is LispAst.NumberLiteral -> LispData.LispNumber(node.numberValue)
is LispAst.StringLiteral -> LispData.LispString(node.parsedString)