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

Replace persistent variable system

Previous system linked the variable name with the saved value, meaning the variable could not be renamed or moved outside the global scope.

Instead we propose to store all persistent values in a global table, identifying each by a key. To still allow nice manipulation with identifiers, the alias syntax replace the persistent syntax for symbols - an aliases symbol will act as if a function call was used in place of the identifier when it appear.
This commit is contained in:
Étienne Fildadut 2023-12-27 21:25:14 +01:00
parent 56ed6c912b
commit e71bff9562
13 changed files with 169 additions and 58 deletions

View file

@ -30,12 +30,16 @@ local Definition = ast.abstract.Node {
end
local symbol = self.symbol:eval(state)
local val = self.expression:eval(state)
if Overloadable:issub(val) then
state.scope:define_overloadable(symbol, val)
if symbol.alias then
state.scope:define_alias(symbol, self.expression)
else
state.scope:define(symbol, val)
local val = self.expression:eval(state)
if Overloadable:issub(val) then
state.scope:define_overloadable(symbol, val)
else
state.scope:define(symbol, val)
end
end
return Nil:new()
@ -46,7 +50,9 @@ local Definition = ast.abstract.Node {
symbol:prepare(state)
val:prepare(state)
if Overloadable:issub(val) then
if self.symbol.alias then
state.scope:define(symbol:with{ alias = false }, val) -- disable alias to avoid call in Identifier:_prepare
elseif Overloadable:issub(val) then
state.scope:define_overloadable(symbol, val)
else
state.scope:define(symbol, val)