mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 00:59:31 +00:00
Add Struct:get_strict
This commit is contained in:
parent
5d000e2fec
commit
95d69dfa2c
3 changed files with 16 additions and 10 deletions
|
|
@ -157,16 +157,14 @@ local Environment = ast.abstract.Runtime {
|
||||||
-- returns nil if undefined
|
-- returns nil if undefined
|
||||||
_lookup = function(self, state, identifier)
|
_lookup = function(self, state, identifier)
|
||||||
local _cache = self._lookup_cache
|
local _cache = self._lookup_cache
|
||||||
local var
|
local var = _cache:get_strict(state, identifier)
|
||||||
if not _cache:has(state, identifier) then
|
if not var then
|
||||||
if self.variables:has(state, identifier) then
|
if self.variables:has(state, identifier) then
|
||||||
var = self.variables:get(state, identifier)
|
var = self.variables:get(state, identifier)
|
||||||
elseif self.parent then
|
elseif self.parent then
|
||||||
var = self.parent:_lookup(state, identifier)
|
var = self.parent:_lookup(state, identifier)
|
||||||
end
|
end
|
||||||
if var then _cache:set(state, identifier, var) end
|
if var then _cache:set(state, identifier, var) end
|
||||||
else
|
|
||||||
var = _cache:get(state, identifier)
|
|
||||||
end
|
end
|
||||||
if var and not var:undefined(state) then
|
if var and not var:undefined(state) then
|
||||||
return var
|
return var
|
||||||
|
|
@ -177,8 +175,8 @@ local Environment = ast.abstract.Runtime {
|
||||||
_lookup_in_current = function(self, state, symbol)
|
_lookup_in_current = function(self, state, symbol)
|
||||||
local identifier = symbol:to_identifier()
|
local identifier = symbol:to_identifier()
|
||||||
local _cache = self._lookup_cache_current
|
local _cache = self._lookup_cache_current
|
||||||
local var
|
local var = _cache:get_strict(state, identifier)
|
||||||
if not _cache:has(state, identifier) then
|
if not var then
|
||||||
local name = symbol.string
|
local name = symbol.string
|
||||||
if self.variables:has(state, identifier) then
|
if self.variables:has(state, identifier) then
|
||||||
var = self.variables:get(state, identifier)
|
var = self.variables:get(state, identifier)
|
||||||
|
|
@ -188,8 +186,6 @@ local Environment = ast.abstract.Runtime {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if var then _cache:set(state, identifier, var) end
|
if var then _cache:set(state, identifier, var) end
|
||||||
else
|
|
||||||
var = _cache:get(state, identifier)
|
|
||||||
end
|
end
|
||||||
if var and not var:undefined(state) then
|
if var and not var:undefined(state) then
|
||||||
return var
|
return var
|
||||||
|
|
|
||||||
|
|
@ -109,11 +109,17 @@ Struct = ast.abstract.Runtime {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
get = function(self, key)
|
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()
|
local hash = key:hash()
|
||||||
if self.table[hash] then
|
if self.table[hash] then
|
||||||
return self.table[hash][2]
|
return self.table[hash][2]
|
||||||
else
|
|
||||||
return Nil:new()
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
has = function(self, key)
|
has = function(self, key)
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,10 @@ Table = ast.abstract.Runtime {
|
||||||
return self.branched:get(state)
|
return self.branched:get(state)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
get_strict = function(self, state, key)
|
||||||
|
local s = self.branched:get(state)
|
||||||
|
return s:get_strict(key)
|
||||||
|
end,
|
||||||
get = function(self, state, key)
|
get = function(self, state, key)
|
||||||
local s = self.branched:get(state)
|
local s = self.branched:get(state)
|
||||||
return s:get(key)
|
return s:get(key)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue