diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2017-12-09 15:34:52 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2017-12-09 15:34:52 -0800 |
| commit | 96441251c4bdbb2d9296866e6c84624ce85c2f45 (patch) | |
| tree | 7b390648a594517fb66735c9824a4f9d2cca3bb6 /nomsu.moon | |
| parent | 28b6bc188370fe3c20b26c483b48ab70673bd35b (diff) | |
Pretty much everything is working??
Diffstat (limited to 'nomsu.moon')
| -rwxr-xr-x | nomsu.moon | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -238,7 +238,7 @@ class NomsuCompiler aliases = {} @@def_number += 1 def = {:thunk, :src, :is_macro, aliases:{}, def_number:@@def_number, defs:@defs} - where_defs_go = (getmetatable(@defs) or {__newindex:@defs}).__newindex + where_defs_go = (getmetatable(@defs) or {}).__newindex or @defs for {stub, arg_names, escaped_args} in *signature assert stub, "NO STUB FOUND: #{repr signature}" if @debug then @writeln "#{colored.bright "DEFINING RULE:"} #{colored.underscore colored.magenta repr(stub)} #{colored.bright "WITH ARGS"} #{colored.dim repr(arg_names)}" @@ -261,7 +261,10 @@ class NomsuCompiler scoped: (thunk)=> old_defs = @defs - @defs = setmetatable({}, {__index:old_defs}) + new_defs = + ["#vars"]: setmetatable({}, {__index:@defs["#vars"]}) + ["#loaded_files"]: setmetatable({}, {__index:@defs["#loaded_files"]}) + @defs = setmetatable(new_defs, {__index:old_defs}) ok, ret1, ret2 = pcall thunk, @ @defs = old_defs if not ok then @error(ret1) @@ -825,15 +828,15 @@ end)]])\format(concat(lua_bits, "\n")) for bit in *code.value if type(bit) == "string" insert concat_parts, bit - elseif type(bit) == "table" and bit.type == "FunctionCall" and bit.src == "__src__" - insert concat_parts, repr(@defs["#macro_tree"].src) + elseif bit.src == '__src__' + insert concat_parts, repr(@dedent @defs["#macro_tree"].src) else expr, statement = @tree_to_lua bit, filename if statement @error "Cannot use [[#{bit.src}]] as a string interpolation value, since it's not an expression." insert concat_parts, expr return concat(concat_parts) - + -- Uses named local functions to help out callstack readability lua_code = (vars)=> lua = nomsu_string_as_lua(@, vars.code) |
