diff --git a/anselme/ast/Environment.lua b/anselme/ast/Environment.lua index 7465331..cd338de 100644 --- a/anselme/ast/Environment.lua +++ b/anselme/ast/Environment.lua @@ -68,7 +68,7 @@ local Environment = ast.abstract.Runtime { variables = nil, -- Table of { {identifier} = variable metadata, ... } partial = nil, -- { [name string] = true, ... } - undefine = nil, -- { [name string] = true, ... } + undefine = nil, -- { [name string] = true, ... } - variable present here will not be looked up in parent env export = nil, -- bool init = function(self, state, parent, partial_names, is_export) @@ -186,16 +186,6 @@ local Environment = ast.abstract.Runtime { return self:_get_variable(state, identifier):set(state, val) end, - -- returns a list {[symbol]=val,...} of all exported variables (evaluated) in the current strict layer - -- TODO currently unused - list_exported = function(self, state) - assert(self.export, "not an export scope layer") - local r = {} - for _, vm in self.variables:iter(state) do - r[vm.symbol] = vm:get(state) - end - return r - end, -- return the depth of the environmenet, i.e. the number of parents depth = function(self) local d = 0 diff --git a/anselme/ast/PartialScope.lua b/anselme/ast/PartialScope.lua index d1517a9..48f6aa7 100644 --- a/anselme/ast/PartialScope.lua +++ b/anselme/ast/PartialScope.lua @@ -9,6 +9,7 @@ local unpack = table.unpack or unpack local PartialScope PartialScope = ast.abstract.Node { type = "partial scope", + hide_in_stacktrace = true, expression = nil, definitions = nil, -- {[sym]=value,...} diff --git a/anselme/ast/Quote.lua b/anselme/ast/Quote.lua index b7c9d36..68130e4 100644 --- a/anselme/ast/Quote.lua +++ b/anselme/ast/Quote.lua @@ -10,6 +10,7 @@ local ast = require("anselme.ast") local Quote Quote = ast.abstract.Node { type = "quote", + hide_in_stacktrace = true, expression = nil, diff --git a/anselme/ast/ReturnBoundary.lua b/anselme/ast/ReturnBoundary.lua index 2740b44..c3e4540 100644 --- a/anselme/ast/ReturnBoundary.lua +++ b/anselme/ast/ReturnBoundary.lua @@ -5,6 +5,7 @@ local Return local ReturnBoundary = ast.abstract.Node { type = "return boundary", + hide_in_stacktrace = true, expression = nil, diff --git a/anselme/ast/Translatable.lua b/anselme/ast/Translatable.lua index c4d6505..55744e8 100644 --- a/anselme/ast/Translatable.lua +++ b/anselme/ast/Translatable.lua @@ -7,6 +7,7 @@ local translation_manager local Translatable = ast.abstract.Node { type = "translatable", + hide_in_stacktrace = true, expression = nil, diff --git a/anselme/ast/abstract/Node.lua b/anselme/ast/abstract/Node.lua index 39abd75..870a304 100644 --- a/anselme/ast/abstract/Node.lua +++ b/anselme/ast/abstract/Node.lua @@ -27,8 +27,12 @@ local function cutoff_text(str) return str end local function format_error(state, node, message) - local ctx = cutoff_text(node:format(state)) -- get some context code around error - return fmt("%{red}%s%{reset}\n\t↳ from %{underline}%s%{reset} in %s: %{dim}%s", message, node.source, node.type, ctx) + if node.hide_in_stacktrace then + return message + else + local ctx = cutoff_text(node:format(state)) -- get some context code around error + return fmt("%{red}%s%{reset}\n\t↳ from %{underline}%s%{reset} in %s: %{dim}%s", message, node.source, node.type, ctx) + end end -- traverse helpers @@ -58,6 +62,7 @@ Node = class { type = "node", source = "?", mutable = false, + hide_in_stacktrace = false, -- abstract class -- must be redefined diff --git a/test/results/checkpoint merging mutable value.ans b/test/results/checkpoint merging mutable value.ans index 2ab75df..735d602 100644 --- a/test/results/checkpoint merging mutable value.ans +++ b/test/results/checkpoint merging mutable value.ans @@ -9,6 +9,8 @@ | {}"1,2,3,4,5: " {}"*[1, 2, 3, 4, 5]" {}"" | --- error --- cancel merge + ↳ from test/tests/checkpoint merging mutable value.ans:24:6 in call: error("cancel merge") + ↳ from ? in block: :l = *[1, 2]… --# post run check #-- --- text --- | {}"1,2,3,4: " {}"*[1, 2, 3, 4]" {}"" | diff --git a/test/results/checkpoint merging variable.ans b/test/results/checkpoint merging variable.ans index e222db9..5522ad8 100644 --- a/test/results/checkpoint merging variable.ans +++ b/test/results/checkpoint merging variable.ans @@ -9,6 +9,8 @@ | {}"4: " {}"4" {}"" | --- error --- cancel merge + ↳ from test/tests/checkpoint merging variable.ans:24:6 in call: error("cancel merge") + ↳ from ? in block: :l = 1… --# post run check #-- --- text --- | {}"3: " {}"3" {}"" | diff --git a/test/results/closure define nested.ans b/test/results/closure define nested.ans index 4cbb41e..ea16e38 100644 --- a/test/results/closure define nested.ans +++ b/test/results/closure define nested.ans @@ -2,6 +2,9 @@ --- text --- | {}"" {}"42" {}"" | --- error --- -no variable "y" defined in closure +no variable "y" defined in closure + ↳ from test/tests/closure define nested.ans:12:4 in call: f . "y" + ↳ from test/tests/closure define nested.ans:12:1 in text interpolation: | {f . "y"} | + ↳ from ? in block: :f = ($() _)… --# saved #-- {} \ No newline at end of file diff --git a/test/results/constant variable.ans b/test/results/constant variable.ans index 560257c..53dc1fc 100644 --- a/test/results/constant variable.ans +++ b/test/results/constant variable.ans @@ -1,5 +1,7 @@ --# run #-- --- error --- trying to change the value of constant a + ↳ from test/tests/constant variable.ans:5:3 in assignment: a = 52 + ↳ from ? in block: ::a = 3… --# saved #-- {} \ No newline at end of file diff --git a/test/results/constrained variable assignement.ans b/test/results/constrained variable assignement.ans index 293289e..8944dc7 100644 --- a/test/results/constrained variable assignement.ans +++ b/test/results/constrained variable assignement.ans @@ -5,5 +5,7 @@ | {}"" {}"type(\"kg\", 12)" {}"" | --- error --- type check failure for weigh; 32 does not satisfy $(x) type(x) == t + ↳ from test/tests/constrained variable assignement.ans:9:7 in assignment: weigh = 32 + ↳ from ? in block: :weigh::is("kg") = type(5, "kg")… --# saved #-- {} \ No newline at end of file diff --git a/test/results/define override function.ans b/test/results/define override function.ans index c14fab4..b548d21 100644 --- a/test/results/define override function.ans +++ b/test/results/define override function.ans @@ -1,5 +1,7 @@ --# run #-- --- error --- a is already defined in the current scope + ↳ from test/tests/define override function.ans:4:4 in definition: :a = 2 + ↳ from ? in block: :a = ($() _)… --# saved #-- {} \ No newline at end of file diff --git a/test/results/define override variable.ans b/test/results/define override variable.ans index 93efbc7..e47d85f 100644 --- a/test/results/define override variable.ans +++ b/test/results/define override variable.ans @@ -1,5 +1,7 @@ --# run #-- --- error --- -can't add an overload variant to non-overloadable variable a defined in the same scope +can't add an overload variant to non-overloadable variable a defined in the same scope + ↳ from test/tests/define override variable.ans:3:1 in definition: :a = ($() _) + ↳ from ? in block: :a = 2… --# saved #-- {} \ No newline at end of file diff --git a/test/results/define override.ans b/test/results/define override.ans index c14fab4..770be88 100644 --- a/test/results/define override.ans +++ b/test/results/define override.ans @@ -1,5 +1,7 @@ --# run #-- --- error --- a is already defined in the current scope + ↳ from test/tests/define override.ans:3:4 in definition: :a = 2 + ↳ from ? in block: :a = 5… --# saved #-- {} \ No newline at end of file diff --git a/test/results/exported variable nested.ans b/test/results/exported variable nested.ans index 4b7972c..900b8f1 100644 --- a/test/results/exported variable nested.ans +++ b/test/results/exported variable nested.ans @@ -5,6 +5,9 @@ --- text --- | {}"" {}"42" {}"" | --- error --- -identifier "z" is undefined in branch cf017f8a-7c86-4871-109af-6658231331e6 +identifier "z" is undefined in branch cf017f8a-7c86-4871-109af-6658231331e6 + ↳ from test/tests/exported variable nested.ans:12:3 in identifier: z + ↳ from test/tests/exported variable nested.ans:12:1 in text interpolation: | {z} | + ↳ from ? in block: :f = ($() _)… --# saved #-- {} \ No newline at end of file diff --git a/test/results/function args arity check fail.ans b/test/results/function args arity check fail.ans index 599327d..dea819f 100644 --- a/test/results/function args arity check fail.ans +++ b/test/results/function args arity check fail.ans @@ -1,5 +1,7 @@ --# run #-- --- error --- can't call function $(a, b) _: expected 2 arguments, received 1 + ↳ from test/tests/function args arity check fail.ans:4:2 in call: f("ok") + ↳ from ? in block: :f = ($(a, b) _)… --# saved #-- {} \ No newline at end of file diff --git a/test/results/function conflict.ans b/test/results/function conflict.ans index 1cf0b97..3b84880 100644 --- a/test/results/function conflict.ans +++ b/test/results/function conflict.ans @@ -1,5 +1,7 @@ --# run #-- --- error --- a function with parameters (a, b) is already defined in the overload + ↳ from test/tests/function conflict.ans:5:1 in definition: :f = ($(a, b) 0) + ↳ from ? in block: :f = ($(a, b) 0)… --# saved #-- {} \ No newline at end of file diff --git a/test/results/function custom type dispatch error.ans b/test/results/function custom type dispatch error.ans index a2a89f9..0f10730 100644 --- a/test/results/function custom type dispatch error.ans +++ b/test/results/function custom type dispatch error.ans @@ -7,5 +7,7 @@ can't call overload overload<($(name::($(x) type(x) == t)) _), ($(name::($(x) type(x) == t)) _)>: no function match (type("nope", 5)), possible functions were: • (name::($(x) type(x) == t)): type check failure for parameter name in function (name::($(x) type(x) == t)) • (name::($(x) type(x) == t)): type check failure for parameter name in function (name::($(x) type(x) == t)) + ↳ from test/tests/function custom type dispatch error.ans:14:2 in call: a(type(5, "nope")) + ↳ from ? in block: :french name = "french name"… --# saved #-- {} \ No newline at end of file diff --git a/test/results/function scope wrong.ans b/test/results/function scope wrong.ans index f425648..2d30e80 100644 --- a/test/results/function scope wrong.ans +++ b/test/results/function scope wrong.ans @@ -1,5 +1,8 @@ --# run #-- --- error --- -identifier "b" is undefined in branch cf017f8a-7c86-4871-109af-6658231331e6 +identifier "b" is undefined in branch cf017f8a-7c86-4871-109af-6658231331e6 + ↳ from test/tests/function scope wrong.ans:4:7 in identifier: b + ↳ from test/tests/function scope wrong.ans:4:1 in text interpolation: | a: {b} | + ↳ from ? in block: :a = ($() _)… --# saved #-- {} \ No newline at end of file diff --git a/test/results/function separate variable from variants.ans b/test/results/function separate variable from variants.ans index 8a0b487..9b36243 100644 --- a/test/results/function separate variable from variants.ans +++ b/test/results/function separate variable from variants.ans @@ -1,11 +1,14 @@ --# run #-- --- error --- -can't call overload overload<($(s::($(x) type(x) == t), k::($(x) )) = val; _), ($(s::($(x) type(x) == t), k::($(x) )) = val; _), ($(s::($(x) type(x) == t), k::($(x) )) _), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) )>: no function match (overload<($(b) _), ($(x) _), ($() _)>, "a"), possible functions were: +can't call overload overload<($(s::($(x) type(x) == t), k::($(x) )) = val; _), ($(s::($(x) type(x) == t), k::($(x) )) = val; _), ($(s::($(x) type(x) == t), k::($(x) )) _), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) = v; ), ($(c::($(x) ), s::($(x) )) )>: no function match (overload<($(b) _), ($(x) _), ($() _)>, "a"), possible functions were: • (s::($(x) type(x) == t), k::($(x) )) = val: expected 3 arguments, received 2 • (s::($(x) type(x) == t), k::($(x) )) = val: expected 3 arguments, received 2 • (s::($(x) type(x) == t), k::($(x) )): type check failure for parameter s in function (s::($(x) type(x) == t), k::($(x) )) • (c::($(x) ), s::($(x) )) = v: expected 3 arguments, received 2 • (c::($(x) ), s::($(x) )) = v: expected 3 arguments, received 2 • (c::($(x) ), s::($(x) )): type check failure for parameter c in function (c::($(x) ), s::($(x) )) + ↳ from test/tests/function separate variable from variants.ans:10:4 in call: f . "a" + ↳ from test/tests/function separate variable from variants.ans:10:1 in text interpolation: | {f . "a"} = 2 | + ↳ from ? in block: :f = ($() _)… --# saved #-- {} \ No newline at end of file diff --git a/test/results/function type dispatch ambigous.ans b/test/results/function type dispatch ambigous.ans index 506fb21..8d6a596 100644 --- a/test/results/function type dispatch ambigous.ans +++ b/test/results/function type dispatch ambigous.ans @@ -3,5 +3,7 @@ can't call overload overload<($(a::($(x) )) _), ($(x::($(x) )) _)>: more than one function match (5), matching functions were at least (specificity 1.3): • (x::($(x) )) • (a::($(x) )) + ↳ from test/tests/function type dispatch ambigous.ans:7:3 in call: fn(5) + ↳ from ? in block: :fn = ($(x::number) _)… --# saved #-- {} \ No newline at end of file diff --git a/test/results/list assignement.ans b/test/results/list assignement.ans index b1f2aca..327cc09 100644 --- a/test/results/list assignement.ans +++ b/test/results/list assignement.ans @@ -11,5 +11,7 @@ | {}"" {}"*[3, 12, 99]" {}"" | --- error --- list index out of bounds + ↳ from test/tests/list assignement.ans:21:6 in call: x(5) = 0 + ↳ from ? in block: :x = *[1, 2]… --# saved #-- {} \ No newline at end of file diff --git a/test/results/list index.ans b/test/results/list index.ans index 5e113e0..95a2604 100644 --- a/test/results/list index.ans +++ b/test/results/list index.ans @@ -8,6 +8,9 @@ --- text --- | {}"" {}"3" {}" == " {}"3" {}"" | --- error --- -tuple index out of bounds +tuple index out of bounds + ↳ from test/tests/list index.ans:11:4 in call: x(-4) + ↳ from test/tests/list index.ans:11:1 in text interpolation: | {x(-4)} | + ↳ from ? in block: :x = [1, 2, 3]… --# saved #-- {} \ No newline at end of file diff --git a/test/results/merge nested mutable error bis.ans b/test/results/merge nested mutable error bis.ans index aa1b66b..c6501ca 100644 --- a/test/results/merge nested mutable error bis.ans +++ b/test/results/merge nested mutable error bis.ans @@ -1,6 +1,19 @@ --# run #-- --- error --- -abort +abort + ↳ from test/tests/merge nested mutable error bis.ans:14:7 in call: error("abort") + ↳ from test/tests/merge nested mutable error bis.ans:3:1 in block: insert(a, b)… + ↳ from test/tests/merge nested mutable error bis.ans:3:18 in call: _ + ↳ from script.ans:30:6 in call: fn! + ↳ from script.ans:28:3 in block: resumed from = ()… + ↳ from script.ans:28:7 in call: else! + ↳ from script.ans:24:2 in block: if(fn . "current checkpoint")… + ↳ from script.ans:24:9 in call: _ + ↳ from script.ans:38:9 in call: value(s)! + ↳ from script.ans:37:1 in block: value(s)! + ↳ from script.ans:37:20 in call: _ + ↳ from test/tests/merge nested mutable error bis.ans:19:2 in call: f! + ↳ from ? in block: :a = *[1]… --# post run check #-- --- text --- | {}"[1,[2,3]]: " {}"*[1, *[2, 3]]" {}"" | diff --git a/test/results/merge nested mutable error.ans b/test/results/merge nested mutable error.ans index aa1b66b..71120a5 100644 --- a/test/results/merge nested mutable error.ans +++ b/test/results/merge nested mutable error.ans @@ -1,6 +1,19 @@ --# run #-- --- error --- -abort +abort + ↳ from test/tests/merge nested mutable error.ans:14:7 in call: error("abort") + ↳ from test/tests/merge nested mutable error.ans:3:1 in block: insert(a, b)… + ↳ from test/tests/merge nested mutable error.ans:3:18 in call: _ + ↳ from script.ans:30:6 in call: fn! + ↳ from script.ans:28:3 in block: resumed from = ()… + ↳ from script.ans:28:7 in call: else! + ↳ from script.ans:24:2 in block: if(fn . "current checkpoint")… + ↳ from script.ans:24:9 in call: _ + ↳ from script.ans:38:9 in call: value(s)! + ↳ from script.ans:37:1 in block: value(s)! + ↳ from script.ans:37:20 in call: _ + ↳ from test/tests/merge nested mutable error.ans:19:2 in call: f! + ↳ from ? in block: :a = *[1]… --# post run check #-- --- text --- | {}"[1,[2,3]]: " {}"*[1, *[2, 3]]" {}"" | diff --git a/test/results/scope checkpoint mutable bis error.ans b/test/results/scope checkpoint mutable bis error.ans index cdc95da..b93352d 100644 --- a/test/results/scope checkpoint mutable bis error.ans +++ b/test/results/scope checkpoint mutable bis error.ans @@ -14,7 +14,17 @@ --- text --- | {}"CHECK 2" | --- error --- -t +t + ↳ from test/tests/scope checkpoint mutable bis error.ans:32:7 in call: error("t") + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:8 in call: _ + ↳ from test/tests/scope checkpoint mutable bis error.ans:19:4 in call: f(t) + ↳ from test/tests/scope checkpoint mutable bis error.ans:15:2 in block: | REC |… + ↳ from test/tests/scope checkpoint mutable bis error.ans:15:4 in call: if(n < 1) + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable bis error.ans:7:8 in call: _ + ↳ from test/tests/scope checkpoint mutable bis error.ans:41:2 in call: f(l) + ↳ from ? in block: :x = *[99]… --# post run check #-- --- text --- | {}"AFTER ERROR" | diff --git a/test/results/scope checkpoint mutable error.ans b/test/results/scope checkpoint mutable error.ans index 36816ef..9d4edd4 100644 --- a/test/results/scope checkpoint mutable error.ans +++ b/test/results/scope checkpoint mutable error.ans @@ -10,7 +10,17 @@ --- text --- | {}"CHECK" | --- error --- -t +t + ↳ from test/tests/scope checkpoint mutable error.ans:23:7 in call: error("t") + ↳ from test/tests/scope checkpoint mutable error.ans:5:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable error.ans:5:8 in call: _ + ↳ from test/tests/scope checkpoint mutable error.ans:17:4 in call: f(t) + ↳ from test/tests/scope checkpoint mutable error.ans:13:2 in block: | REC |… + ↳ from test/tests/scope checkpoint mutable error.ans:13:4 in call: if(n < 1) + ↳ from test/tests/scope checkpoint mutable error.ans:5:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable error.ans:5:8 in call: _ + ↳ from test/tests/scope checkpoint mutable error.ans:32:2 in call: f(l) + ↳ from ? in block: :l = *[1]… --# post run check #-- --- text --- | {}"AFTER ERROR" | diff --git a/test/results/scope checkpoint mutable ter error.ans b/test/results/scope checkpoint mutable ter error.ans index 12723bc..c32ccd2 100644 --- a/test/results/scope checkpoint mutable ter error.ans +++ b/test/results/scope checkpoint mutable ter error.ans @@ -14,7 +14,17 @@ --- text --- | {}"CHECK 2" | --- error --- -t +t + ↳ from test/tests/scope checkpoint mutable ter error.ans:34:7 in call: error("t") + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:8 in call: _ + ↳ from test/tests/scope checkpoint mutable ter error.ans:19:4 in call: f(t) + ↳ from test/tests/scope checkpoint mutable ter error.ans:15:2 in block: | REC |… + ↳ from test/tests/scope checkpoint mutable ter error.ans:15:4 in call: if(n < 1) + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:1 in block: insert(t, len(l) + 1)… + ↳ from test/tests/scope checkpoint mutable ter error.ans:7:8 in call: _ + ↳ from test/tests/scope checkpoint mutable ter error.ans:43:2 in call: f(l) + ↳ from ? in block: :x = *[99]… --# post run check #-- --- text --- | {}"AFTER ERROR" | diff --git a/test/results/symbol alias constant.ans b/test/results/symbol alias constant.ans index d8394d9..f311b8f 100644 --- a/test/results/symbol alias constant.ans +++ b/test/results/symbol alias constant.ans @@ -6,5 +6,7 @@ | {}"d=" {}"2" {}" (2)" | --- error --- trying to change the value of constant d + ↳ from test/tests/symbol alias constant.ans:12:3 in assignment: d = 5 + ↳ from ? in block: :l = *[1, 2, 3]… --# saved #-- {} \ No newline at end of file diff --git a/test/run.lua b/test/run.lua index f33c313..3645bb3 100644 --- a/test/run.lua +++ b/test/run.lua @@ -47,8 +47,6 @@ local function run_loop(run_state, out) elseif e == "return" then table.insert(out, data:format(run_state)) run_state:merge() - elseif e == "error" then - table.insert(out, (tostring(data):gsub("\n%s*↳[^\n]*", ""))) -- traceback change every day and a half due to AST changes. TODO: only keep ast layers relevant for the user else table.insert(out, tostring(data)) end