nomsu/core/scopes.nom

46 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env nomsu -V3.6.5.6
#
This file contains definitions pertaining to variable scoping
2018-05-10 22:51:08 -07:00
use "core/metaprogramming.nom"
use "core/operators.nom"
use "core/collections.nom"
use "core/control_flow.nom"
2018-07-22 16:13:33 -07:00
test:
%x = "outer"
with local %x:
%x = "inner"
assume (%x == "inner")
2018-07-22 16:13:33 -07:00
assume (%x == "outer")
action [foo] "outer foo"
with local [action (foo)]:
action [foo] "inner foo"
assume ((foo) == "inner foo")
2018-07-22 16:13:33 -07:00
assume ((foo) == "outer foo")
compile [with local %locals %body, with local %locals do %body] to:
%body_lua = (%body as lua statements)
if %locals.type is:
"Dict":
%body_lua = (..)
Lua ".."
\(compile as (<- %locals))
\%body_lua
%body_lua::declare locals ("\(%.1 as lua)" for % in %locals)
"List":
%body_lua::declare locals ("\(% as lua)" for % in %locals)
"Var" "Action":
%body_lua::declare locals ["\(%locals as lua)"]
else:
compile error at %locals.source "Unexpected locals: %s"
return (..)
Lua ".."
do
\%body_lua
end