diff options
author | Eduardo Julian | 2018-03-06 01:07:43 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-03-06 01:07:43 -0400 |
commit | 38bd6f35d81705ab0c04c85601ac5b236b62605a (patch) | |
tree | 4c2fd4f6369067965017aeea18ba68b1f658344d /new-luxc/source/luxc/lang/translation/lua/procedure/host.jvm.lux | |
parent | 9bf491a18e4b772505c3767cf0249eb24f0a822b (diff) |
- Initial Lua backend implementation.
Diffstat (limited to '')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/lua/procedure/host.jvm.lux | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/translation/lua/procedure/host.jvm.lux b/new-luxc/source/luxc/lang/translation/lua/procedure/host.jvm.lux new file mode 100644 index 000000000..85af96ec9 --- /dev/null +++ b/new-luxc/source/luxc/lang/translation/lua/procedure/host.jvm.lux @@ -0,0 +1,87 @@ +(.module: + lux + (lux (control [monad #+ do]) + (data [text] + text/format + (coll [list "list/" Functor<List>] + [dict #+ Dict])) + [macro "macro/" Monad<Meta>]) + (luxc ["&" lang] + (lang ["la" analysis] + ["ls" synthesis] + (host [lua #+ Lua Expression Statement]))) + [///] + (/// [".T" runtime]) + (// ["@" common])) + +(do-template [<name> <lua>] + [(def: (<name> _) @.Nullary <lua>)] + + [lua//nil "nil"] + [lua//table "{}"] + ) + +(def: (lua//global proc translate inputs) + (-> Text @.Proc) + (case inputs + (^ (list [_ (#.Text name)])) + (do macro.Monad<Meta> + [] + (wrap name)) + + _ + (&.throw @.Wrong-Syntax (@.wrong-syntax proc inputs)))) + +(def: (lua//call proc translate inputs) + (-> Text @.Proc) + (case inputs + (^ (list& functionS argsS+)) + (do macro.Monad<Meta> + [functionO (translate functionS) + argsO+ (monad.map @ translate argsS+)] + (wrap (lua.apply functionO argsO+))) + + _ + (&.throw @.Wrong-Syntax (@.wrong-syntax proc inputs)))) + +(def: lua-procs + @.Bundle + (|> (dict.new text.Hash<Text>) + (@.install "nil" (@.nullary lua//nil)) + (@.install "table" (@.nullary lua//table)) + (@.install "global" lua//global) + (@.install "call" lua//call))) + +(def: (table//call proc translate inputs) + (-> Text @.Proc) + (case inputs + (^ (list& tableS [_ (#.Text field)] argsS+)) + (do macro.Monad<Meta> + [tableO (translate tableS) + argsO+ (monad.map @ translate argsS+)] + (wrap (lua.method field tableO argsO+))) + + _ + (&.throw @.Wrong-Syntax (@.wrong-syntax proc inputs)))) + +(def: (table//get [fieldO tableO]) + @.Binary + (runtimeT.lua//get tableO fieldO)) + +(def: (table//set [fieldO valueO tableO]) + @.Trinary + (runtimeT.lua//set tableO fieldO valueO)) + +(def: table-procs + @.Bundle + (<| (@.prefix "table") + (|> (dict.new text.Hash<Text>) + (@.install "call" table//call) + (@.install "get" (@.binary table//get)) + (@.install "set" (@.trinary table//set))))) + +(def: #export procedures + @.Bundle + (<| (@.prefix "lua") + (|> lua-procs + (dict.merge table-procs)))) |