diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-26 20:20:12 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-26 20:20:38 -0800 |
| commit | 90c56d31352a0eeccd382ef5921baf3af4971040 (patch) | |
| tree | 5167eafb5785c94b48458b18b0454222ca70c749 /lib/metaprogramming.nom | |
| parent | d5aa4e52983712f9f4c5b23528d0c2dab12b0b33 (diff) | |
Added a ton of tests for virtually all the functionality. Helped me find
and fix a lot of latent problems.
Diffstat (limited to 'lib/metaprogramming.nom')
| -rw-r--r-- | lib/metaprogramming.nom | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/metaprogramming.nom b/lib/metaprogramming.nom index f80c144..8f2bde9 100644 --- a/lib/metaprogramming.nom +++ b/lib/metaprogramming.nom @@ -136,10 +136,9 @@ immediately compile [repr %obj] to {expr:"repr(\(%obj as lua expr))"} compile [type of %obj] to {expr:"type(\(%obj as lua expr))"} -compile [nomsu] to {expr:"nomsu"} - -compile [nomsu's %key] to {expr:"nomsu[\(%key as lua expr)]"} -compile [nomsu %method %args] to {expr:"nomsu[\(%method as lua expr)](nomsu, unpack(\(%args as lua expr)))"} +immediately + compile [nomsu] to {expr:"nomsu"} + compile [%var as lua identifier] to {expr:"nomsu:var_to_lua_identifier(\(%var as lua expr))"} action [action %names metadata] =lua "ACTION_METADATA[ACTIONS[\%names]]" @@ -155,9 +154,10 @@ action [help %action] end # Compiler tools -parse [run %code] as: nomsu "run" [%code] -parse [enable debugging] as: lua> "nomsu.debug = true" -parse [disable debugging] as: lua> "nomsu.debug = false" +immediately + compile [run %code] to {expr: "nomsu:run(\(%code as lua expr), '\(!! code location !!)')"} + parse [enable debugging] as: lua> "nomsu.debug = true;" + parse [disable debugging] as: lua> "nomsu.debug = false;" immediately compile [say %message] to @@ -177,12 +177,20 @@ immediately # Error functions immediately - compile [barf!] to {statements:"error(nil, 0);"} + compile [barf] to {statements:"error(nil, 0);"} compile [barf %msg] to {statements:"error(\(%msg as lua expr), 0);"} - compile [assume %condition] to {..} - statements:"if not \(%condition as lua expr) then error('Assumption failed: '..\%condition:get_src(), 0); end" + compile [assume %condition] to + lua> "local \%assumption = 'Assumption failed: '..\%condition:get_src();" + return {..} + statements:".." + if not \(%condition as lua expr) then + error(\(repr %assumption), 0); + end compile [assume %condition or barf %msg] to {..} - statements:"if not \(%condition as lua expr) then error(\(%msg as lua expr), 0); end" + statements:".." + if not \(%condition as lua expr) then + error(\(%msg as lua expr), 0); + end # Literals immediately |
