diff --git a/LANGUAGE.md b/LANGUAGE.md index 88b1f73..ac0dcc7 100644 --- a/LANGUAGE.md +++ b/LANGUAGE.md @@ -248,7 +248,7 @@ Functions can return a value using a [return line](#lines-that-can-t-have-childr Functions always have the following variables defined in its namespace by default: `๐Ÿ‘๏ธ`: number, number of times the function was executed before -`๐Ÿ”–`: string, name of last reached checkpoint +`๐Ÿ”–`: funcion reference, last reached checkpoint. `nil` if no checkpoint reached. * `ยง`: checkpoint. Followed by an [identifier](#identifiers), then eventually an [alias](#aliases). Define a checkpoint. Also define a new namespace for its children. diff --git a/interpreter/expression.lua b/interpreter/expression.lua index a4e1e3e..dec1b05 100644 --- a/interpreter/expression.lua +++ b/interpreter/expression.lua @@ -437,11 +437,11 @@ local function eval(state, exp) else local e -- eval function from start - if paren_call or checkpoint.value == "" then + if paren_call or checkpoint.type == "nil" then ret, e = run(state, fn.child) -- resume at last checkpoint else - local expr, err = expression(checkpoint.value, state, fn.namespace) + local expr, err = expression(checkpoint.value[1], state, fn.namespace) if not expr then return expr, err end ret, e = eval(state, expr) end diff --git a/interpreter/interpreter.lua b/interpreter/interpreter.lua index 54d0621..3cb911f 100644 --- a/interpreter/interpreter.lua +++ b/interpreter/interpreter.lua @@ -116,8 +116,8 @@ run_line = function(state, line) value = reached.value + 1 }) set_variable(state, line.parent_function.namespace.."๐Ÿ”–", { - type = "string", - value = line.name + type = "function reference", + value = { line.name } }) merge_state(state) else @@ -167,11 +167,10 @@ run_block = function(state, block, resume_from_there, i, j) }) -- don't update checkpoint if an already more precise checkpoint is set -- (since we will go up the whole checkpoint hierarchy when resuming from a nested checkpoint) - local current_checkpoint = checkpoint.value - if not current_checkpoint:match("^"..escape(parent_line.name)) then + if checkpoint.type == "nil" or not checkpoint.value[1]:match("^"..escape(parent_line.name)) then set_variable(state, parent_line.parent_function.namespace.."๐Ÿ”–", { - type = "string", - value = parent_line.name + type = "function reference", + value = { parent_line.name } }) end merge_state(state) diff --git a/parser/preparser.lua b/parser/preparser.lua index 6f94b08..a64dad9 100644 --- a/parser/preparser.lua +++ b/parser/preparser.lua @@ -191,9 +191,9 @@ local function parse_line(line, state, namespace) -- define ๐Ÿ”– variable local checkpoint_alias = state.global_state.builtin_aliases["๐Ÿ”–"] if checkpoint_alias then - table.insert(line.children, 1, { content = (":๐Ÿ”–:%s=\"\""):format(checkpoint_alias), source = line.source }) + table.insert(line.children, 1, { content = (":๐Ÿ”–:%s=()"):format(checkpoint_alias), source = line.source }) else - table.insert(line.children, 1, { content = ":๐Ÿ”–=\"\"", source = line.source }) + table.insert(line.children, 1, { content = ":๐Ÿ”–=()", source = line.source }) end elseif r.type == "checkpoint" then -- define ๐Ÿ variable diff --git a/test/tests/checkpoint change.ans b/test/tests/checkpoint change.ans index 0ab8586..c49bf72 100644 --- a/test/tests/checkpoint change.ans +++ b/test/tests/checkpoint change.ans @@ -29,5 +29,5 @@ From q again: ~ f Go to p again by setting checkpoint manually: -~ f.checkpoint := "p" +~ f.checkpoint := &f.p ~ f