2018-11-11 15:50:46 -08:00
|
|
|
#!/usr/bin/env nomsu -V4.10.12.7
|
2018-07-15 19:41:22 -07:00
|
|
|
#
|
|
|
|
This file contains definitions pertaining to variable scoping
|
2018-11-11 15:50:46 -08:00
|
|
|
|
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-11-08 15:23:22 -08:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2018-07-22 16:13:33 -07:00
|
|
|
test:
|
|
|
|
%x = "outer"
|
|
|
|
with local %x:
|
|
|
|
%x = "inner"
|
|
|
|
assume (%x == "inner")
|
|
|
|
assume (%x == "outer")
|
2018-10-30 23:42:04 -07:00
|
|
|
externally (foo) means "outer foo"
|
2018-10-31 15:05:17 -07:00
|
|
|
with local [(foo)'s meaning]:
|
2018-10-30 23:42:04 -07:00
|
|
|
externally (foo) means "inner foo"
|
2018-07-22 16:13:33 -07:00
|
|
|
assume ((foo) == "inner foo")
|
|
|
|
assume ((foo) == "outer foo")
|
2018-11-11 15:50:46 -08:00
|
|
|
|
2018-10-30 23:42:04 -07:00
|
|
|
[with local %locals %body, with local %locals do %body] all compile to:
|
2018-11-09 14:48:23 -08:00
|
|
|
%body_lua = (%body as lua)
|
2018-07-18 17:55:29 -07:00
|
|
|
if %locals.type is:
|
|
|
|
"Dict":
|
2018-11-11 15:50:46 -08:00
|
|
|
%body_lua = (Lua "\(what (<- %locals) compiles to)\n\%body_lua")
|
|
|
|
%body_lua::declare locals [: for % in %locals: add "\(%.1 as lua)"]
|
2018-07-17 23:08:13 -07:00
|
|
|
|
2018-07-20 20:27:15 -07:00
|
|
|
"List":
|
2018-11-11 15:50:46 -08:00
|
|
|
%body_lua::declare locals [: for % in %locals: add "\(% as lua)"]
|
|
|
|
|
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-11-11 15:50:46 -08:00
|
|
|
|
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-11-11 15:50:46 -08:00
|
|
|
return (Lua "do\n \%body_lua\nend")
|