aboutsummaryrefslogtreecommitdiff
path: root/lux-jvm/source/luxc/lang/translation/jvm/reference.lux
diff options
context:
space:
mode:
Diffstat (limited to 'lux-jvm/source/luxc/lang/translation/jvm/reference.lux')
-rw-r--r--lux-jvm/source/luxc/lang/translation/jvm/reference.lux65
1 files changed, 65 insertions, 0 deletions
diff --git a/lux-jvm/source/luxc/lang/translation/jvm/reference.lux b/lux-jvm/source/luxc/lang/translation/jvm/reference.lux
new file mode 100644
index 000000000..6bcf4a2e5
--- /dev/null
+++ b/lux-jvm/source/luxc/lang/translation/jvm/reference.lux
@@ -0,0 +1,65 @@
+(.module:
+ [lux #*
+ [abstract
+ [monad (#+ do)]]
+ [data
+ [text
+ ["%" format (#+ format)]]]
+ [target
+ [jvm
+ ["." type]]]
+ [tool
+ [compiler
+ ["." reference (#+ Register Variable)]
+ ["." phase ("operation@." monad)]
+ [meta
+ [archive (#+ Archive)]]
+ [language
+ [lux
+ ["." generation]]]]]]
+ [luxc
+ [lang
+ [host
+ [jvm (#+ Inst Operation)
+ ["_" inst]]]]]
+ ["." //
+ ["#." runtime]])
+
+(template [<name> <prefix>]
+ [(def: #export <name>
+ (-> Nat Text)
+ (|>> %.nat (format <prefix>)))]
+
+ [foreign-name "f"]
+ [partial-name "p"]
+ )
+
+(def: (foreign archive variable)
+ (-> Archive Register (Operation Inst))
+ (do {@ phase.monad}
+ [class-name (:: @ map //.class-name
+ (generation.context archive))]
+ (wrap (|>> (_.ALOAD 0)
+ (_.GETFIELD (type.class class-name (list))
+ (|> variable .nat foreign-name)
+ //.$Value)))))
+
+(def: local
+ (-> Register Inst)
+ (|>> _.ALOAD))
+
+(def: #export (variable archive variable)
+ (-> Archive Variable (Operation Inst))
+ (case variable
+ (#reference.Local variable)
+ (operation@wrap (local variable))
+
+ (#reference.Foreign variable)
+ (foreign archive variable)))
+
+(def: #export (constant archive name)
+ (-> Archive Name (Operation Inst))
+ (do {@ phase.monad}
+ [class-name (:: @ map //.class-name
+ (generation.remember archive name))]
+ (wrap (_.GETSTATIC (type.class class-name (list)) //.value-field //.$Value))))