diff options
author | Eduardo Julian | 2017-11-01 00:51:45 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-11-01 00:51:45 -0400 |
commit | 012f6bd41e527479dddbccbdab10daa78fd9a0fd (patch) | |
tree | 621f344a09acd52736f343d94582b3f1a2f0c5f9 /new-luxc/source/luxc/lang/translation/expression.jvm.lux | |
parent | 71d7a4c7206155e09f3e1e1d8699561ea6967382 (diff) |
- Re-organized code-generation, and re-named it "translation".
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/expression.jvm.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/expression.jvm.lux | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/translation/expression.jvm.lux b/new-luxc/source/luxc/lang/translation/expression.jvm.lux new file mode 100644 index 000000000..af66d4994 --- /dev/null +++ b/new-luxc/source/luxc/lang/translation/expression.jvm.lux @@ -0,0 +1,76 @@ +(;module: + lux + (lux (control monad + ["ex" exception #+ exception:] + ["p" parser]) + (data ["e" error] + text/format) + [meta] + (meta ["s" syntax])) + (luxc ["&" base] + (host ["$" jvm]) + (lang ["ls" synthesis] + (translation [";T" common] + [";T" primitive] + [";T" structure] + [";T" eval] + [";T" procedure] + [";T" function] + [";T" reference] + [";T" case]) + [";L" variable #+ Variable Register]))) + +(exception: #export Unrecognized-Synthesis) + +(def: #export (generate synthesis) + (-> ls;Synthesis (Meta $;Inst)) + (case synthesis + (^code []) + primitiveT;generate-unit + + (^code [(~ singleton)]) + (generate singleton) + + (^template [<tag> <generator>] + [_ (<tag> value)] + (<generator> value)) + ([#;Bool primitiveT;generate-bool] + [#;Nat primitiveT;generate-nat] + [#;Int primitiveT;generate-int] + [#;Deg primitiveT;generate-deg] + [#;Frac primitiveT;generate-frac] + [#;Text primitiveT;generate-text]) + + (^code ((~ [_ (#;Nat tag)]) (~ [_ (#;Bool last?)]) (~ valueS))) + (structureT;generate-variant generate tag last? valueS) + + (^code [(~@ members)]) + (structureT;generate-tuple generate members) + + (^ [_ (#;Form (list [_ (#;Int var)]))]) + (if (variableL;captured? var) + (referenceT;generate-captured var) + (referenceT;generate-variable var)) + + [_ (#;Symbol definition)] + (referenceT;generate-definition definition) + + (^code ("lux let" (~ [_ (#;Nat register)]) (~ inputS) (~ exprS))) + (caseT;generate-let generate register inputS exprS) + + (^code ("lux case" (~ inputS) (~ pathPS))) + (caseT;generate-case generate inputS pathPS) + + (^multi (^code ("lux function" (~ [_ (#;Nat arity)]) [(~@ environment)] (~ bodyS))) + [(s;run environment (p;some s;int)) (#e;Success environment)]) + (functionT;generate-function generate environment arity bodyS) + + (^code ("lux call" (~ functionS) (~@ argsS))) + (functionT;generate-call generate functionS argsS) + + (^code ((~ [_ (#;Text procedure)]) (~@ argsS))) + (procedureT;generate-procedure generate procedure argsS) + + _ + (&;throw Unrecognized-Synthesis (%code synthesis)) + )) |