nomsu/core/scopes.nom

40 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env nomsu -V4.10.12.7
#
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")
assume (%x == "outer")
externally (foo) means "outer foo"
2018-10-31 15:05:17 -07:00
with local [(foo)'s meaning]:
externally (foo) means "inner foo"
2018-07-22 16:13:33 -07:00
assume ((foo) == "inner foo")
assume ((foo) == "outer foo")
[with local %locals %body, with local %locals do %body] all compile to:
%body_lua = (%body as lua)
if %locals.type is:
"Dict":
%body_lua = (Lua "\(what (<- %locals) compiles to)\n\%body_lua")
%body_lua::declare locals [: for % in %locals: add "\(%.1 as lua)"]
"List":
%body_lua::declare locals [: for % in %locals: add "\(% as lua)"]
"Var" "Action":
%body_lua::declare locals ["\(%locals as lua)"]
else:
compile error at %locals "Unexpected local value"
return (Lua "do\n \%body_lua\nend")