1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

🔖 is now a function reference

This commit is contained in:
Étienne Fildadut 2022-01-14 21:40:08 +01:00
parent fd07db83f2
commit 5a61573cdb
5 changed files with 11 additions and 12 deletions

View file

@ -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.

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -29,5 +29,5 @@ From q again:
~ f
Go to p again by setting checkpoint manually:
~ f.checkpoint := "p"
~ f.checkpoint := &f.p
~ f