diff options
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/jvm/reference.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/jvm/reference.lux | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/translation/jvm/reference.lux b/new-luxc/source/luxc/lang/translation/jvm/reference.lux new file mode 100644 index 000000000..c821a9de2 --- /dev/null +++ b/new-luxc/source/luxc/lang/translation/jvm/reference.lux @@ -0,0 +1,57 @@ +(.module: + [lux #* + [abstract + [monad (#+ do)]] + [data + [text + format]] + [tool + [compiler + ["." name] + ["." reference (#+ Register Variable)] + ["." phase ("operation/." monad) + ["." generation]]]]] + [luxc + [lang + [host + [jvm (#+ Inst Operation) + ["$t" type] + ["_" inst]]]]] + ["." //]) + +(template [<name> <prefix>] + [(def: #export (<name> idx) + (-> Nat Text) + (|> idx %n (format <prefix>)))] + + [foreign-name "f"] + [partial-name "p"] + ) + +(def: (foreign variable) + (-> Register (Operation Inst)) + (do phase.monad + [function-class generation.context] + (wrap (|>> (_.ALOAD 0) + (_.GETFIELD function-class + (|> variable .nat foreign-name) + //.$Object))))) + +(def: local + (-> Register (Operation Inst)) + (|>> _.ALOAD operation/wrap)) + +(def: #export (variable variable) + (-> Variable (Operation Inst)) + (case variable + (#reference.Local variable) + (local variable) + + (#reference.Foreign variable) + (foreign variable))) + +(def: #export (constant name) + (-> Name (Operation Inst)) + (do phase.monad + [bytecode-name (generation.remember name)] + (operation/wrap (_.GETSTATIC bytecode-name //.value-field //.$Object)))) |