diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-06-14 23:25:05 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-06-14 23:25:34 -0700 |
| commit | b12744d831c4158671fc22401590eaac00f7c141 (patch) | |
| tree | 203b80de68d89c7333172337f8def46ba11294d3 /core/scopes.nom | |
| parent | 49f1eb3d08caf7605046373b7b3a001f28aa8aab (diff) | |
Some cleanup and fixes. Simplifying a lot of code, and extending the
flexibility of scoping. Redesigned Object system too.
Diffstat (limited to 'core/scopes.nom')
| -rw-r--r-- | core/scopes.nom | 66 |
1 files changed, 21 insertions, 45 deletions
diff --git a/core/scopes.nom b/core/scopes.nom index 02ad73d..b5fdded 100644 --- a/core/scopes.nom +++ b/core/scopes.nom @@ -1,54 +1,30 @@ use "core/metaprogramming.nom" -use "core/text.nom" use "core/operators.nom" use "core/collections.nom" use "core/control_flow.nom" -compile [using %definitions %body, using %definitions do %body] to - %setup_lua <- - Lua ".." - local fell_through = false - local ok, ret = pcall(function() - \(%definitions as lua statements) - fell_through = true - end) - %body_lua <- - Lua ".." - local fell_through = false - local ok, ret = pcall(function() - \(%body as lua statements) - fell_through = true - end) - remove free vars (declare locals in %setup_lua) from %body_lua - %lua <- +compile [with local %locals %body, with local %locals do %body] to + %body_lua <- (%body as lua statements) + when %locals.type = ? + * "Dict" + %body_lua <- + Lua ".." + \(=lua "A_assign_1(\%locals, \%locals)") + \%body_lua + declare locals + (%.1 as lua id) for % in %locals + .. in %body_lua + * "List" + declare locals + (% as lua id) for % in %locals + .. in %body_lua + * "Var" + * "Action" + declare locals [%locals as lua id] in %body_lua + * else + barf "Unexpected local: \(%locals as nomsu)" + return Lua ".." do - local old_actions, old_compile_actions, old_arg_orders = ACTIONS, COMPILE_ACTIONS, ARG_ORDERS - ACTIONS = setmetatable({}, {__index=old_actions}) - COMPILE_ACTIONS = setmetatable({}, {__index=old_compile_actions}) - ARG_ORDERS = setmetatable({}, {__index=old_arg_orders}) - \%setup_lua - if not ok then - ACTIONS, COMPILE_ACTIONS, ARG_ORDERS = old_actions, old_compile_actions, old_arg_orders - error(ret, 0) - end - if not fell_through then - ACTIONS, COMPILE_ACTIONS, ARG_ORDERS = old_actions, old_compile_actions, old_arg_orders - return ret - end - getmetatable(ACTIONS).__newindex = old_actions - getmetatable(COMPILE_ACTIONS).__newindex = old_compile_actions - getmetatable(ARG_ORDERS).__newindex = old_arg_orders \%body_lua - ACTIONS, COMPILE_ACTIONS, ARG_ORDERS = old_actions, old_compile_actions, old_arg_orders - if not ok then - error(ret, 0) - end - if not fell_through then - return ret - end end - declare locals in %lua - return %lua - -parse [using %] as: using % (do nothing) |
