Renamed def->define_action and defmacro->define_macro

This commit is contained in:
Bruce Hill 2018-01-11 01:57:52 -08:00
parent 82cc997ddf
commit 199161a438
3 changed files with 19 additions and 19 deletions

View File

@ -20,7 +20,7 @@ immediately:
# Macro to make macros:
immediately:
lua> ".."
nomsu:defmacro("compile %macro_def to %body", \(__line_no__), function(nomsu, \%macro_def, \%body)
nomsu:define_macro("compile %macro_def to %body", \(__line_no__), function(nomsu, \%macro_def, \%body)
nomsu:assert(\%macro_def.type == "List",
"Invalid type for compile definition signature. Expected List, but got: "..tostring(\%macro_def.type));
nomsu:assert(\%body.type == "Block",
@ -34,14 +34,14 @@ immediately:
%s
end
local function macro_wrapper(...) return {expr=macro(...)}; end
nomsu:defmacro(%s, %s, macro_wrapper, %s);
nomsu:define_macro(%s, %s, macro_wrapper, %s);
end]]):format(args, body_lua, signature, nomsu:repr(\%macro_def:get_line_no()),
nomsu:repr(("compile %s\\n..to code %s"):format(\%macro_def.src, \%body.src)));
return {statements=lua};
end, \(__src__ 1));
lua> ".."
nomsu:defmacro("compile %macro_def to code %body", \(__line_no__), function(nomsu, \%macro_def, \%body)
nomsu:define_macro("compile %macro_def to code %body", \(__line_no__), function(nomsu, \%macro_def, \%body)
nomsu:assert(\%macro_def.type == "List",
"Invalid type for compile definition signature. Expected List, but got: "..tostring(\%macro_def.type));
nomsu:assert(\%body.type == "Block",
@ -55,7 +55,7 @@ immediately:
%s
end
local function macro_wrapper(...) return {statements=macro(...)}; end
nomsu:defmacro(%s, %s, macro_wrapper, %s);
nomsu:define_macro(%s, %s, macro_wrapper, %s);
end]]):format(args, body_lua, signature, nomsu:repr(\%macro_def:get_line_no()),
nomsu:repr(("compile %s\\n..to code %s"):format(\%macro_def.src, \%body.src)));
return {statements=lua};
@ -74,7 +74,7 @@ immediately:
body_lua = body_lua.statements or ("return "..body_lua.expr..";");
local src = nomsu:dedent(nomsu:source_code(0));
local def_lua = ([[
nomsu:def(%s, \(__line_no__), function(%s)
nomsu:define_action(%s, \(__line_no__), function(%s)
%s
end, %s);]]):format(signature, args, body_lua, nomsu:repr(src));
return def_lua;
@ -82,7 +82,7 @@ immediately:
# Macro to make nomsu macros:
immediately:
lua> ".."
nomsu:defmacro("parse %shorthand as %longhand", \(__line_no__), (function(nomsu, \%shorthand, \%longhand)
nomsu:define_macro("parse %shorthand as %longhand", \(__line_no__), (function(nomsu, \%shorthand, \%longhand)
nomsu:assert(\%shorthand.type == "List",
"Invalid type for parse definition signature. Expected List, but got: "..tostring(\%shorthand.type));
nomsu:assert(\%longhand.type == "Block",
@ -98,7 +98,7 @@ immediately:
for i, a in ipairs(arg_names) do replacements[i] = "["..nomsu:repr(a).."]=_"..nomsu:var_to_lua_identifier(a); end
replacements = "{"..table.concat(replacements, ", ").."}";
local lua_code = ([[
nomsu:defmacro(%s, %s, (function(%s)
nomsu:define_macro(%s, %s, (function(%s)
local template = nomsu:parse(%s, %s);
local replacement = nomsu:replaced_vars(template, %s);
return nomsu:tree_to_lua(replacement);

View File

@ -113,7 +113,7 @@ lua> ".."
};
for name,code in pairs(colors) do
local escape = "\\"\\\\27["..tostring(code).."m\\""
nomsu:defmacro(name, \(__line_no__), function() return escape end, "");
nomsu:define_macro(name, \(__line_no__), function() return escape end, "");
end
end

View File

@ -171,7 +171,7 @@ class NomsuCompiler
@write_err(...)
@write_err("\n")
def: (signature, line_no, fn, src, is_macro=false)=>
define_action: (signature, line_no, fn, src, is_macro=false)=>
if type(signature) == 'string'
signature = @get_stubs {signature}
elseif type(signature) == 'table' and type(signature[1]) == 'string'
@ -204,8 +204,8 @@ class NomsuCompiler
stub_def = setmetatable({:stub, :arg_names, :arg_positions}, {__index:def})
rawset(where_defs_go, stub, stub_def)
defmacro: (signature, line_no, fn, src)=>
@def(signature, line_no, fn, src, true)
define_macro: (signature, line_no, fn, src)=>
@define_action(signature, line_no, fn, src, true)
serialize_defs: (scope=nil, after=nil)=>
after or= @core_defs or 0
@ -793,38 +793,38 @@ end]]\format(lua_code))
insert concat_parts, lua.expr
return concat(concat_parts)
@defmacro "do %block", "nomsu.moon", (_block)=>
@define_macro "do %block", "nomsu.moon", (_block)=>
make_line = (lua)-> lua.expr and (lua.expr..";") or lua.statements
if _block.type == "Block"
return @tree_to_lua(_block)
else
return expr:"#{@tree_to_lua _block}(nomsu)"
@defmacro "immediately %block", "nomsu.moon", (_block)=>
@define_macro "immediately %block", "nomsu.moon", (_block)=>
lua = @tree_to_lua(_block)
lua_code = lua.statements or (lua.expr..";")
lua_code = "-- Immediately:\n"..lua_code
@run_lua(lua_code)
return statements:lua_code
@defmacro "lua> %code", "nomsu.moon", (_code)=>
@define_macro "lua> %code", "nomsu.moon", (_code)=>
lua = nomsu_string_as_lua(@, _code)
return statements:lua
@defmacro "=lua %code", "nomsu.moon", (_code)=>
@define_macro "=lua %code", "nomsu.moon", (_code)=>
lua = nomsu_string_as_lua(@, _code)
return expr:lua
@defmacro "__line_no__", "nomsu.moon", ()=>
@define_macro "__line_no__", "nomsu.moon", ()=>
expr: repr(@compilestack[#@compilestack]\get_line_no!)
@defmacro "__src__ %level", "nomsu.moon", (_level)=>
@define_macro "__src__ %level", "nomsu.moon", (_level)=>
expr: repr(@source_code(@tree_to_value(_level)))
@def "run file %filename", "nomsu.moon", (_filename)=>
@define_action "run file %filename", "nomsu.moon", (_filename)=>
@run_file(_filename)
@defmacro "require %filename", "nomsu.moon", (_filename)=>
@define_macro "require %filename", "nomsu.moon", (_filename)=>
filename = @tree_to_value(_filename)
@require_file(filename)
return statements:"nomsu:require_file(#{repr filename});"