aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-04-17 14:36:44 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-04-17 14:36:55 -0700
commit26d0de8299c7568152f479320444833b4d30d0eb (patch)
tree995feed96145619477a0b3547eb97e2f80521cdb
parent54fc7fc4404c02df2c38a7ae121e61e9b8bca78c (diff)
Partially working, at least for metaprogramming.nom
-rw-r--r--core/control_flow.nom28
-rw-r--r--core/metaprogramming.nom5
-rw-r--r--nomsu.lua2
-rwxr-xr-xnomsu.moon3
-rw-r--r--nomsu_tree.moon8
5 files changed, 24 insertions, 22 deletions
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 5a3a775..9b4217f 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -89,14 +89,14 @@ immediately:
compile [repeat while %condition %body] to
%lua <-: Lua "while \(%condition as lua expr) do"
if %body has subtree % where:
- (%.type = "FunctionCall") and ((%'s stub) is "do next repeat")
+ (%.type = "Action") and ((%'s stub) is "do next repeat")
..:
%lua +<- "\n::continue_repeat::;"
%lua +<- "\n"
%lua +<- (%body as lua statements)
%lua +<- "\nend --while-loop"
if %body has subtree % where:
- (%.type = "FunctionCall") and ((%'s stub) is "stop repeating")
+ (%.type = "Action") and ((%'s stub) is "stop repeating")
..:
%lua <- ".."
do -- scope of "stop repeating" label
@@ -112,11 +112,11 @@ immediately:
..to:
%lua <-: Lua "for i=1,\(%n as lua expr) do"
if %body has subtree % where
- (%.type = "FunctionCall") and ((%'s stub) is "do next repeat")
+ (%.type = "Action") and ((%'s stub) is "do next repeat")
..: %lua +<- "\n::continue_repeat::;"
%lua +<- "\n\(%body as lua statements)\nend --numeric for-loop"
if %body has subtree % where:
- (%.type = "FunctionCall") and ((%'s stub) is "stop repeating")
+ (%.type = "Action") and ((%'s stub) is "stop repeating")
..:
%lua <-:
Lua ".."
@@ -145,14 +145,14 @@ immediately:
Lua ".."
for \(%var as lua expr)=\(%start as lua expr),\(%n as lua expr) do
if %body has subtree % where:
- (%.type = "FunctionCall") and
+ (%.type = "Action") and
((%'s stub) is "do next %") and
%.value.3.value is %var.value
..: %lua write code "\n::continue_\(%var as lua identifier)::;"
%lua write code "\n\(%body as lua statements)\nend --numeric for-loop"
if %body has subtree % where:
- (%.type = "FunctionCall") and:
+ (%.type = "Action") and:
((%'s stub) is "stop %") and:
%.value.2.value is %var.value
..:
@@ -179,13 +179,13 @@ immediately:
assume (%var.type is "Var") or barf "Loop expected variable, not: \(%var's source code)"
%lua <-: Lua "for i,\(%var as lua identifier) in ipairs(\(%iterable as lua expr)) do"
if %body has subtree % where:
- (%.type = "FunctionCall") and
+ (%.type = "Action") and
((%'s stub) is "do next %") and
%.value.3.value is %var.value
..: %lua +<- (Lua "\n::continue_\(%var as lua identifier)::;")
%lua +<- (Lua "\n\(%body as lua statements)\nend --foreach-loop")
if %body has subtree % where:
- (%.type = "FunctionCall") and
+ (%.type = "Action") and
((%'s stub) is "stop %") and
%.value.2.value is %var.value
..:
@@ -207,13 +207,13 @@ immediately:
assume (%value.type is "Var") or barf "Loop expected variable, not: \(%value's source code)"
%lua <- (Lua "for \(%key as lua identifier),\(%value as lua identifier) in pairs(\(%iterable as lua expr)) do")
if %body has subtree % where:
- (%.type = "FunctionCall") and
+ (%.type = "Action") and
((%'s stub) is "do next %") and
%.value.3.value is %key.value
..: %lua +<- (Lua "\n::continue_\(%key as lua identifier)::;")
if %body has subtree % where:
- (%.type = "FunctionCall") and
+ (%.type = "Action") and
((%'s stub) is "do next %") and
%.value.3.value is %value.value
..: %lua +<- (Lua "\n::continue_\(%value as lua identifier)::;")
@@ -221,13 +221,13 @@ immediately:
%stop_labels <- ""
if %body has subtree % where:
- (%.type = "FunctionCall") and
+ (%.type = "Action") and
((%'s stub) is "stop %") and
%.value.2.value is %key.value
..: %stop_labels +<- "\n::stop_\(%key as lua identifier)::;"
if %body has subtree % where:
- (%.type = "FunctionCall") and
+ (%.type = "Action") and
((%'s stub) is "stop %") and
%.value.2.value is %value.value
..: %stop_labels +<- "\n::stop_\(%value as lua identifier)::;"
@@ -249,7 +249,7 @@ immediately:
%is_first <- (yes)
%seen_else <- (no)
for %func_call in %body.value:
- assume (%func_call.type is "FunctionCall") or barf ".."
+ assume (%func_call.type is "Action") or barf ".."
Invalid format for 'when' statement. Only '*' blocks are allowed.
with {..}
%tokens: %func_call.value
@@ -303,7 +303,7 @@ immediately:
%is_first <- (yes)
%seen_else <- (no)
for %func_call in %body.value:
- assume (%func_call.type is "FunctionCall") or barf ".."
+ assume (%func_call.type is "Action") or barf ".."
Invalid format for 'when' statement. Only '*' blocks are allowed.
%tokens <- %func_call.value
with {%star:%tokens.1, %condition:%tokens.2, %action:%tokens.3}:
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 9c7f166..870754b 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -171,7 +171,6 @@ immediately:
immediately:
compile [say %message] to:
lua> ".."
- local tree = nomsu.compilestack[#nomsu.compilestack];
if \%message.type == "Text" then
return Lua(tree.source, "print(", \(%message as lua expr), ");");
else
@@ -182,8 +181,8 @@ immediately:
compile [source] to: Lua value (=lua "tree.source") "tree.source"
immediately:
- action [Lua %]: Lua (=lua "nomsu.compilestack[#nomsu.compilestack]") %
- action [Lua value %]: Lua value (=lua "nomsu.compilestack[#nomsu.compilestack]") %
+ action [Lua %]: Lua (=lua "tree.source") %
+ action [Lua value %]: Lua value (=lua "tree.source") %
# Return
immediately:
diff --git a/nomsu.lua b/nomsu.lua
index 5e6698e..70e9fd6 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -1292,7 +1292,7 @@ if arg and debug_getinfo(2).func ~= require then
return line_table
end
})
- debug.getinfo = function(thread, f, what)
+ debug.getinfoXXXXXX = function(thread, f, what)
if what == nil then
f, what, thread = thread, f, nil
end
diff --git a/nomsu.moon b/nomsu.moon
index 21263ac..2f04817 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -37,6 +37,7 @@ debug_getinfo = debug.getinfo
-- Maybe do some sort of lazy definitions of actions that defer until they're used in code
-- Add a ((%x foo %y) where {x:"asdf", y:"fdsa"}) compile-time action for substitution
-- Allow plain text backslash like: "\n" in longstrings without requiring "\\n"
+-- Maybe support some kind of regex action definitions like "foo %first (and %next)*"?
export FILE_CACHE
FILE_CACHE = setmetatable {}, {
@@ -892,7 +893,7 @@ if arg and debug_getinfo(2).func != require
return line_table
}
- debug.getinfo = (thread,f,what)->
+ debug.getinfoXXXXXX = (thread,f,what)->
if what == nil
f,what,thread = thread,f,nil
if type(f) == 'number' then f += 1 -- Account for this wrapper function
diff --git a/nomsu_tree.moon b/nomsu_tree.moon
index 3162bf8..9b00d85 100644
--- a/nomsu_tree.moon
+++ b/nomsu_tree.moon
@@ -65,7 +65,7 @@ Tree "Block",
lua\append line_lua
return lua
-math_patt = re.compile [[ "%" (" " [*/^+-] " %")+ ]]
+math_expression = re.compile [[ "%" (" " [*/^+-] " %")+ ]]
Tree "Action",
as_lua: (nomsu)=>
stub = @get_stub!
@@ -77,10 +77,12 @@ Tree "Action",
if metadata.arg_orders
new_args = [args[p-1] for p in *metadata.arg_orders[stub]]
args = new_args
- return action(Lua(@source), unpack(args))
+ -- Force Lua to avoid tail call optimization for debugging purposes
+ ret = action(Lua(@source), unpack(args))
+ return ret
lua = Lua.Value(@source)
- if not metadata and math_patt\match(stub)
+ if not metadata and math_expression\match(stub)
-- This is a bit of a hack, but this code handles arbitrarily complex
-- math expressions like 2*x + 3^2 without having to define a single
-- action for every possibility.