diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/metaprogramming.nom | 2 | ||||
| -rw-r--r-- | core/operators.nom | 16 | ||||
| -rw-r--r-- | core/scopes.nom | 39 |
3 files changed, 9 insertions, 48 deletions
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom index 165a814..fe97527 100644 --- a/core/metaprogramming.nom +++ b/core/metaprogramming.nom @@ -118,7 +118,7 @@ lua> "\ test: (foo %x) means "outer" - with local [(foo %)'s meaning]: + with {((foo %)'s meaning)}: (foo %x) means: %y = (%x + 1) return %y diff --git a/core/operators.nom b/core/operators.nom index a7cb116..2f79b8f 100644 --- a/core/operators.nom +++ b/core/operators.nom @@ -99,7 +99,8 @@ test: test: [%x, %y] = [1, 2] - with {%z: nil, %x: 999}: + with {%z, %x: 999}: + assume %z == (nil) %z = 999 assume (%z == 999) or barf "'with' failed." assume (%x == 999) or barf "'with' assignment failed." @@ -113,20 +114,19 @@ test: local vars = {} for i, item in ipairs(\%assignments) do local \%target, \%value = item[1], item[2] - if not \%target.type == "Var" then - error("Invalid target for 'with' assignment: "..tostring(\%target)) - end local target_lua = \(%target as lua) - local value_lua = \(%value as lua) + if not target_lua:text():is_lua_id() then + compile_error_at(\%target, "Invalid target for 'with' scope assignment.", + "This should be either a variable or an action's meaning.") + end + local value_lua = \%value and \(%value as lua) or "nil" if i > 1 then lhs:append(", ") rhs:append(", ") end lhs:append(target_lua) rhs:append(value_lua) - if \%target.type == "Var" then - vars[i] = target_lua:text() - end + vars[i] = target_lua:text() end \%lua:remove_free_vars(vars) \%lua:prepend("local ", lhs, " = ", rhs, ";\\n")" diff --git a/core/scopes.nom b/core/scopes.nom deleted file mode 100644 index 009728b..0000000 --- a/core/scopes.nom +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env nomsu -V4.10.12.7 -# - This file contains definitions pertaining to variable scoping - -use "core/metaprogramming.nom" -use "core/operators.nom" -use "core/collections.nom" -use "core/control_flow.nom" - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -test: - %x = "outer" - with local %x: - %x = "inner" - assume (%x == "inner") - assume (%x == "outer") - externally (foo) means "outer foo" - with local [(foo)'s meaning]: - externally (foo) means "inner foo" - 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") |
