From 0f0fb2256a46a8808794d7d4746d112278da3730 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 10 Jan 2019 16:33:37 -0800 Subject: Major overhaul of how modules and environments work, along with some steamlining and tweaks to the makefile. Version bump: 6.14.13.8 --- core/control_flow.nom | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'core/control_flow.nom') diff --git a/core/control_flow.nom b/core/control_flow.nom index 5c90bcc..b0c4f27 100644 --- a/core/control_flow.nom +++ b/core/control_flow.nom @@ -3,8 +3,8 @@ This file contains compile-time actions that define basic control flow structures like "if" statements and loops. -use "core/metaprogramming.nom" -use "core/operators.nom" +use "core/metaprogramming" +use "core/operators" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -464,29 +464,26 @@ test: assume (sorted $flat) == [1, 2, 3, 4, 5, 6] # Recurion control flow +(recurse $v on $x) compiles to + Lua "table.insert(_stack_\($v as lua expr), \($x as lua expr))" (for $var in recursive $structure $body) compiles to: - with local compile actions: - define mangler - (recurse $v on $x) compiles to - Lua "table.insert(\(mangle "stack \($v.1)"), \($x as lua expr))" - - $lua = - Lua (" - do - local \(mangle "stack \($var.1)") = List{\($structure as lua expr)} - while #\(mangle "stack \($var.1)") > 0 do - \($var as lua expr) = table.remove(\(mangle "stack \($var.1)"), 1) - \($body as lua) - ") - - if ($body has subtree \(do next)): - $lua, add "\n ::continue::" - - if ($body has subtree \(do next $var)): - $lua, add "\n \(\(---next $var ---) as lua)" - - $lua, add "\n end -- Recursive loop" - if ($body has subtree \(stop $var)): - $lua, add "\n \(\(---stop $var ---) as lua)" - $lua, add "\nend -- Recursive scope" - return $lua + $lua = + Lua (" + do + local _stack_\($var as lua expr) = List{\($structure as lua expr)} + while #_stack_\($var as lua expr) > 0 do + \($var as lua expr) = table.remove(_stack_\($var as lua expr), 1) + \($body as lua) + ") + + if ($body has subtree \(do next)): + $lua, add "\n ::continue::" + + if ($body has subtree \(do next $var)): + $lua, add "\n \(\(---next $var ---) as lua)" + + $lua, add "\n end -- Recursive loop" + if ($body has subtree \(stop $var)): + $lua, add "\n \(\(---stop $var ---) as lua)" + $lua, add "\nend -- Recursive scope" + return $lua -- cgit v1.2.3