aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/compiler/common.jvm.lux
diff options
context:
space:
mode:
authorEduardo Julian2017-05-09 17:48:27 -0400
committerEduardo Julian2017-05-09 17:48:27 -0400
commitdd5220e13b03c8f85972feac535a34ef64525222 (patch)
tree2ac08a118eaa63f11c2397a08eaca74d199f2d1e /new-luxc/source/luxc/compiler/common.jvm.lux
parent7b74c1258f345d576b0c798303b0ed28f1734368 (diff)
- Added tests for some kinds of analysis.
- WIP: Porting more code.
Diffstat (limited to 'new-luxc/source/luxc/compiler/common.jvm.lux')
-rw-r--r--new-luxc/source/luxc/compiler/common.jvm.lux65
1 files changed, 65 insertions, 0 deletions
diff --git a/new-luxc/source/luxc/compiler/common.jvm.lux b/new-luxc/source/luxc/compiler/common.jvm.lux
new file mode 100644
index 000000000..d7abc1ff1
--- /dev/null
+++ b/new-luxc/source/luxc/compiler/common.jvm.lux
@@ -0,0 +1,65 @@
+(;module:
+ lux
+ (lux (concurrency ["A" atom])
+ (data ["E" error]
+ (coll ["D" dict]))
+ [macro]
+ [host #+ jvm-import]))
+
+## [Host]
+(jvm-import org.objectweb.asm.MethodVisitor
+ (visitLdcInsn [Object] void))
+
+(jvm-import java.lang.ClassLoader)
+
+## [Types]
+(type: #export Compiled
+ Unit)
+
+(type: #export Blob host;Byte-Array)
+
+(type: #export Class-Store (A;Atom (D;Dict Text Blob)))
+
+(type: #export Host
+ {#visitor (Maybe MethodVisitor)
+ #loader ClassLoader
+ #store Class-Store})
+
+(def: #export unit-value Text "\u0000unit\u0000")
+
+(def: (visitor::get compiler)
+ (-> Compiler (Maybe MethodVisitor))
+ (|> (get@ #;host compiler)
+ (:! Host)
+ (get@ #visitor)))
+
+(def: (visitor::put visitor compiler)
+ (-> MethodVisitor Compiler Compiler)
+ (update@ #;host
+ (function [host]
+ (|> host
+ (:! Host)
+ (set@ #visitor (#;Some visitor))
+ (:! Void)))
+ compiler))
+
+(def: #export get-visitor
+ (Lux MethodVisitor)
+ (function [compiler]
+ (case (visitor::get compiler)
+ #;None
+ (#E;Error "No visitor has been set.")
+
+ (#;Some visitor)
+ (#E;Success [compiler visitor]))))
+
+(def: #export (with-visitor visitor body)
+ (All [a] (-> MethodVisitor (Lux a) (Lux a)))
+ (function [compiler]
+ (case (macro;run' (visitor::put visitor compiler) body)
+ (#E;Error error)
+ (#E;Error error)
+
+ (#E;Success [compiler' output])
+ (#E;Success [(visitor::put (visitor::get compiler) compiler')
+ output]))))