2018-09-14 19:17:09 -07:00
|
|
|
#!/usr/bin/env nomsu -V4.8.8.6
|
2018-07-15 19:41:22 -07:00
|
|
|
#
|
|
|
|
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-20 20:27:15 -07:00
|
|
|
|
2018-07-22 16:13:33 -07:00
|
|
|
test:
|
|
|
|
%x = "outer"
|
|
|
|
with local %x:
|
|
|
|
%x = "inner"
|
|
|
|
assume (%x == "inner")
|
2018-07-23 14:40:20 -07:00
|
|
|
|
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-23 14:40:20 -07:00
|
|
|
|
2018-07-22 16:13:33 -07:00
|
|
|
assume ((foo) == "outer foo")
|
2018-07-17 23:08:13 -07:00
|
|
|
compile [with local %locals %body, with local %locals do %body] to:
|
2018-07-18 01:27:56 -07:00
|
|
|
%body_lua = (%body as lua statements)
|
2018-07-18 17:55:29 -07:00
|
|
|
if %locals.type is:
|
|
|
|
"Dict":
|
2018-07-18 01:27:56 -07:00
|
|
|
%body_lua = (..)
|
2018-09-14 19:17:09 -07:00
|
|
|
Lua "\
|
|
|
|
..\(compile as (<- %locals))
|
|
|
|
\%body_lua"
|
2018-07-18 01:27:56 -07:00
|
|
|
|
2018-08-29 15:09:35 -07:00
|
|
|
%body_lua::declare locals ("\(%.1 as lua)" for % in %locals)
|
2018-07-17 23:08:13 -07:00
|
|
|
|
2018-07-20 20:27:15 -07:00
|
|
|
"List":
|
2018-08-29 15:09:35 -07:00
|
|
|
%body_lua::declare locals ("\(% as lua)" for % in %locals)
|
2018-07-20 20:27:15 -07:00
|
|
|
"Var" "Action":
|
2018-08-29 15:09:35 -07:00
|
|
|
%body_lua::declare locals ["\(%locals as lua)"]
|
2018-07-20 20:27:15 -07:00
|
|
|
else:
|
2018-09-16 17:38:19 -07:00
|
|
|
compile error at %locals "Unexpected local value"
|
2018-07-17 23:08:13 -07:00
|
|
|
|
|
|
|
return (..)
|
2018-09-14 19:17:09 -07:00
|
|
|
Lua "\
|
|
|
|
..do
|
2018-07-20 20:27:15 -07:00
|
|
|
\%body_lua
|
2018-09-14 19:17:09 -07:00
|
|
|
end"
|