aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/compiler/expr.jvm.lux
diff options
context:
space:
mode:
Diffstat (limited to 'new-luxc/source/luxc/compiler/expr.jvm.lux')
-rw-r--r--new-luxc/source/luxc/compiler/expr.jvm.lux57
1 files changed, 42 insertions, 15 deletions
diff --git a/new-luxc/source/luxc/compiler/expr.jvm.lux b/new-luxc/source/luxc/compiler/expr.jvm.lux
index f0508c0d2..33a41541b 100644
--- a/new-luxc/source/luxc/compiler/expr.jvm.lux
+++ b/new-luxc/source/luxc/compiler/expr.jvm.lux
@@ -2,29 +2,56 @@
lux
(lux (control monad)
(data text/format)
- [macro #+ Monad<Lux> "Lux/" Monad<Lux>])
+ [macro #+ Monad<Lux> "Lux/" Monad<Lux>]
+ [host #+ jvm-import])
(luxc ["&" base]
- lang
+ (lang ["ls" synthesis])
["&;" analyser]
- ["&;" synthesizer]))
+ ["&;" synthesizer]
+ (compiler ["&;" common])))
-(type: #export JVM-Bytecode
- Void)
+(jvm-import #long java.lang.Object)
-(type: #export Compiled
- JVM-Bytecode)
+(jvm-import org.objectweb.asm.Opcodes)
+
+(jvm-import org.objectweb.asm.MethodVisitor
+ (visitLdcInsn [Object] void))
+
+(def: unit-value Text "\u0000unit\u0000")
+
+(def: (compiler-literal value)
+ (-> Top (Lux &common;Compiled))
+ (do Monad<Lux>
+ [visitor &common;get-visitor
+ #let [_ (MethodVisitor.visitLdcInsn [(:! java.lang.Object value)])]]
+ (wrap [])))
(def: (compile-synthesis synthesis)
- (-> Synthesis Compiled)
- (undefined))
+ (-> ls;Synthesis (Lux &common;Compiled))
+ (case synthesis
+ #ls;Unit
+ (compiler-literal &common;unit-value)
+
+ (^template [<tag>]
+ (<tag> value)
+ (compiler-literal value))
+ ([#ls;Bool]
+ [#ls;Nat]
+ [#ls;Int]
+ [#ls;Deg]
+ [#ls;Real]
+ [#ls;Char]
+ [#ls;Text])
+
+ _
+ (macro;fail "Unrecognized synthesis.")))
(def: (eval type code)
- Eval
+ &;Eval
(undefined))
(def: #export (compile input)
- (-> Code (Lux Compiled))
- (|> input
- (&analyser;analyse eval)
- (Lux/map &synthesizer;synthesize)
- (Lux/map compile-synthesis)))
+ (-> Code (Lux &common;Compiled))
+ (do Monad<Lux>
+ [analysis (&analyser;analyse eval input)]
+ (compile-synthesis (&synthesizer;synthesize analysis))))