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

Add Struct:get_strict

This commit is contained in:
Étienne Fildadut 2024-01-09 17:23:26 +01:00
parent 5d000e2fec
commit 95d69dfa2c
3 changed files with 16 additions and 10 deletions

View file

@ -157,16 +157,14 @@ local Environment = ast.abstract.Runtime {
-- returns nil if undefined
_lookup = function(self, state, identifier)
local _cache = self._lookup_cache
local var
if not _cache:has(state, identifier) then
local var = _cache:get_strict(state, identifier)
if not var then
if self.variables:has(state, identifier) then
var = self.variables:get(state, identifier)
elseif self.parent then
var = self.parent:_lookup(state, identifier)
end
if var then _cache:set(state, identifier, var) end
else
var = _cache:get(state, identifier)
end
if var and not var:undefined(state) then
return var
@ -177,8 +175,8 @@ local Environment = ast.abstract.Runtime {
_lookup_in_current = function(self, state, symbol)
local identifier = symbol:to_identifier()
local _cache = self._lookup_cache_current
local var
if not _cache:has(state, identifier) then
local var = _cache:get_strict(state, identifier)
if not var then
local name = symbol.string
if self.variables:has(state, identifier) then
var = self.variables:get(state, identifier)
@ -188,8 +186,6 @@ local Environment = ast.abstract.Runtime {
end
end
if var then _cache:set(state, identifier, var) end
else
var = _cache:get(state, identifier)
end
if var and not var:undefined(state) then
return var

View file

@ -109,11 +109,17 @@ Struct = ast.abstract.Runtime {
end,
get = function(self, key)
local v = self:get_strict(key)
if v ~= nil then
return v
else
return Nil:new()
end
end,
get_strict = function(self, key)
local hash = key:hash()
if self.table[hash] then
return self.table[hash][2]
else
return Nil:new()
end
end,
has = function(self, key)

View file

@ -41,6 +41,10 @@ Table = ast.abstract.Runtime {
return self.branched:get(state)
end,
get_strict = function(self, state, key)
local s = self.branched:get(state)
return s:get_strict(key)
end,
get = function(self, state, key)
local s = self.branched:get(state)
return s:get(key)