aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/jvm/eval.jvm.lux
diff options
context:
space:
mode:
authorEduardo Julian2018-01-08 21:40:06 -0400
committerEduardo Julian2018-01-08 21:40:06 -0400
commit9eaaaf953ba7ce1eeb805603f4e113aa15f5178f (patch)
treeef134eecc8a5767a997fce0637cd64e0ebcee6b1 /new-luxc/source/luxc/lang/translation/jvm/eval.jvm.lux
parentf523bc14d43286348aeb200bd0554812dc6ef28d (diff)
- Moved all translation code under the JVM path (in preparation for porting the JS back-end).
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/jvm/eval.jvm.lux')
-rw-r--r--new-luxc/source/luxc/lang/translation/jvm/eval.jvm.lux46
1 files changed, 46 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/lang/translation/jvm/eval.jvm.lux b/new-luxc/source/luxc/lang/translation/jvm/eval.jvm.lux
new file mode 100644
index 000000000..c326895a2
--- /dev/null
+++ b/new-luxc/source/luxc/lang/translation/jvm/eval.jvm.lux
@@ -0,0 +1,46 @@
+(.module:
+ lux
+ (lux (control monad)
+ (data [text]
+ text/format)
+ [macro]
+ [host #+ do-to])
+ (luxc ["&" lang]
+ (lang (host ["$" jvm]
+ (jvm ["$t" type]
+ ["$d" def]
+ ["$i" inst]))
+ ["la" analysis]
+ ["ls" synthesis]))
+ (// [".T" common]))
+
+(host.import java/lang/reflect/Field
+ (get [Object] Object))
+
+(host.import (java/lang/Class a)
+ (getField [String] Field))
+
+(def: #export (eval valueI)
+ (-> $.Inst (Meta Top))
+ (do macro.Monad<Meta>
+ [current-module macro.current-module-name
+ class-name (:: @ map %code (macro.gensym (format current-module "/eval")))
+ #let [store-name (text.replace-all "/" "." class-name)
+ bytecode ($d.class #$.V1_6
+ #$.Public $.noneC
+ class-name
+ (list) ["java.lang.Object" (list)]
+ (list)
+ (|>> ($d.field #$.Public ($_ $.++F $.finalF $.staticF)
+ commonT.value-field commonT.$Object)
+ ($d.method #$.Public ($_ $.++M $.staticM $.strictM)
+ "<clinit>"
+ ($t.method (list) #.None (list))
+ (|>> valueI
+ ($i.PUTSTATIC store-name commonT.value-field commonT.$Object)
+ $i.RETURN))))]
+ _ (commonT.store-class store-name bytecode)
+ class (commonT.load-class store-name)]
+ (wrap (|> class
+ (Class::getField [commonT.value-field])
+ (Field::get (host.null))))))