diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-17 14:36:44 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-17 14:36:55 -0700 |
| commit | 26d0de8299c7568152f479320444833b4d30d0eb (patch) | |
| tree | 995feed96145619477a0b3547eb97e2f80521cdb /core | |
| parent | 54fc7fc4404c02df2c38a7ae121e61e9b8bca78c (diff) | |
Partially working, at least for metaprogramming.nom
Diffstat (limited to 'core')
| -rw-r--r-- | core/control_flow.nom | 28 | ||||
| -rw-r--r-- | core/metaprogramming.nom | 5 |
2 files changed, 16 insertions, 17 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: |
