diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-07 18:03:37 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-07 18:03:37 -0800 |
| commit | c92e5fbc81e57ada43f2c17792e500da5b708bee (patch) | |
| tree | 8f89f2c0ab21de3fe6110c84ee980e0920d18fb4 /lib/control_flow.nom | |
| parent | b1c6354464ab2c9f8f09217815a11317cc068cec (diff) | |
Some overhaul of binary operators so that arbitrary math patterns work
fine.
Diffstat (limited to 'lib/control_flow.nom')
| -rw-r--r-- | lib/control_flow.nom | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/control_flow.nom b/lib/control_flow.nom index 2ac6cff..72a2ad1 100644 --- a/lib/control_flow.nom +++ b/lib/control_flow.nom @@ -7,10 +7,11 @@ compile [if %condition %if_body] to code: ".." if \(%condition as lua) then \(%if_body as lua statements) end --end if -compile [unless %condition %body] to code: ".." - if not (\(%condition as lua)) then - \(%body as lua statements) - end --end if +parse [unless %condition %unless_body] as: if (not %condition) %unless_body +parse [if %x == %y %if_body] as: if (%x == %y) %if_body +parse [if %x != %y %if_body] as: if (%x != %y) %if_body +parse [unless %x == %y %if_body] as: if (%x != %y) %if_body +parse [unless %x != %y %if_body] as: if (%x == %y) %if_body compile [if %condition %if_body else %else_body, unless %condition %else_body else %if_body] to code: ".." if \(%condition as lua) then @@ -18,6 +19,10 @@ compile [if %condition %if_body else %else_body, unless %condition %else_body el else \(%else_body as lua statements) end --end if +parse [if %x == %y %if_body else %else_body] as: if (%x == %y) %if_body else %else_body +parse [if %x != %y %if_body else %else_body] as: if (%x != %y) %if_body else %else_body +parse [unless %x == %y %if_body else %else_body] as: if (%x != %y) %if_body else %else_body +parse [unless %x != %y %if_body else %else_body] as: if (%x == %y) %if_body else %else_body # Return compile [return] to code: "do return; end" @@ -60,6 +65,10 @@ compile [repeat while %condition %body] to code: return %code parse [repeat %body] as: repeat while (true) %body parse [repeat until %condition %body] as: repeat while (not %condition) %body +parse [repeat while %x == %y %body] as: repeat while (%x == %y) %body +parse [repeat while %x != %y %body] as: repeat while (%x != %y) %body +parse [repeat until %x == %y %body] as: repeat while (%x != %y) %body +parse [repeat until %x != %y %body] as: repeat while (%x == %y) %body # For loop control flow: compile [stop for-loop] to code: "goto stop_for;" |
