diff options
author | Eduardo Julian | 2017-06-12 21:14:55 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-06-12 21:14:55 -0400 |
commit | 9cd2927a4f6175784e081d6b512d3e900c8069e7 (patch) | |
tree | d1fe512bc84ea1e3a50ad86eeb3265771edd23c6 /new-luxc/source/luxc/compiler | |
parent | c50667a431a5ca67328a230f0c59956dc6ff43fa (diff) |
- Renamed the "compilation" phase as the "generation" phase.
- Implemented compilation of primitives.
- Implemented compilation of structures.
Diffstat (limited to '')
-rw-r--r-- | new-luxc/source/luxc/compiler/common.jvm.lux | 65 | ||||
-rw-r--r-- | new-luxc/source/luxc/compiler/expr.jvm.lux | 62 | ||||
-rw-r--r-- | new-luxc/source/luxc/compiler/runtime.jvm.lux | 11 | ||||
-rw-r--r-- | new-luxc/source/luxc/generator.lux (renamed from new-luxc/source/luxc/compiler.lux) | 70 | ||||
-rw-r--r-- | new-luxc/source/luxc/generator/base.jvm.lux (renamed from new-luxc/source/luxc/compiler/base.jvm.lux) | 0 | ||||
-rw-r--r-- | new-luxc/source/luxc/generator/statement.jvm.lux (renamed from new-luxc/source/luxc/compiler/statement.jvm.lux) | 0 |
6 files changed, 3 insertions, 205 deletions
diff --git a/new-luxc/source/luxc/compiler/common.jvm.lux b/new-luxc/source/luxc/compiler/common.jvm.lux deleted file mode 100644 index bd5487ef6..000000000 --- a/new-luxc/source/luxc/compiler/common.jvm.lux +++ /dev/null @@ -1,65 +0,0 @@ -(;module: - lux - (lux (concurrency ["A" atom]) - (data ["R" result] - (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) - (-> (Maybe MethodVisitor) Compiler Compiler) - (update@ #;host - (function [host] - (|> host - (:! Host) - (set@ #visitor ?visitor) - (:! Void))) - compiler)) - -(def: #export get-visitor - (Lux MethodVisitor) - (function [compiler] - (case (visitor::get compiler) - #;None - (#R;Error "No visitor has been set.") - - (#;Some visitor) - (#R;Success [compiler visitor])))) - -(def: #export (with-visitor visitor body) - (All [a] (-> MethodVisitor (Lux a) (Lux a))) - (function [compiler] - (case (macro;run' (visitor::put (#;Some visitor) compiler) body) - (#R;Error error) - (#R;Error error) - - (#R;Success [compiler' output]) - (#R;Success [(visitor::put (visitor::get compiler) compiler') - output])))) diff --git a/new-luxc/source/luxc/compiler/expr.jvm.lux b/new-luxc/source/luxc/compiler/expr.jvm.lux deleted file mode 100644 index b2e4923c4..000000000 --- a/new-luxc/source/luxc/compiler/expr.jvm.lux +++ /dev/null @@ -1,62 +0,0 @@ -(;module: - lux - (lux (control monad) - (data text/format) - [macro #+ Monad<Lux> "Lux/" Monad<Lux>] - [host #+ jvm-import]) - (luxc ["&" base] - (lang ["la" analysis] - ["ls" synthesis]) - ["&;" analyser] - ["&;" synthesizer] - (compiler ["&;" common]))) - -(jvm-import #long java.lang.Object) - -(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) - (-> 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 - (undefined)) - -(def: analyse - &;Analyser - (&analyser;analyser eval)) - -(def: #export (compile input) - (-> Code (Lux &common;Compiled)) - (do Monad<Lux> - [analysis (analyse input)] - (compile-synthesis (&synthesizer;synthesize analysis)))) diff --git a/new-luxc/source/luxc/compiler/runtime.jvm.lux b/new-luxc/source/luxc/compiler/runtime.jvm.lux deleted file mode 100644 index 16e072194..000000000 --- a/new-luxc/source/luxc/compiler/runtime.jvm.lux +++ /dev/null @@ -1,11 +0,0 @@ -(;module: - lux - (lux (control monad) - (concurrency ["P" promise "P/" Monad<Promise>]) - (data text/format - ["R" result])) - (luxc ["&" base])) - -(def: #export (compile-runtime compiler) - (-> Compiler (P;Promise (R;Result Compiler))) - (P/wrap (#R;Success compiler))) diff --git a/new-luxc/source/luxc/compiler.lux b/new-luxc/source/luxc/generator.lux index 55fe3c738..d095023ff 100644 --- a/new-luxc/source/luxc/compiler.lux +++ b/new-luxc/source/luxc/generator.lux @@ -15,6 +15,7 @@ ["&;" io] ["&;" module] ["&;" parser] + ["&;" host] (compiler ["&&;" runtime] ["&&;" statement] ["&&;" common]) @@ -109,69 +110,6 @@ (jvm-import org.objectweb.asm.MethodVisitor) -(jvm-import java.lang.reflect.AccessibleObject - (setAccessible [boolean] void)) - -(jvm-import java.lang.reflect.Method - (invoke [Object (Array Object)] #try Object)) - -(jvm-import (java.lang.Class a) - (getDeclaredMethod [String (Array (Class Object))] #try Method)) - -(jvm-import java.lang.Object - (getClass [] (Class Object))) - -(jvm-import java.lang.Integer - (#static TYPE (Class Integer))) - -(jvm-import java.lang.ClassLoader) - -(def: ClassLoader::defineClass - Method - (case (Class.getDeclaredMethod ["defineClass" - (|> (array (Class Object) +4) - (array-store +0 (:! (Class Object) (class-for String))) - (array-store +1 (Object.getClass [] (array byte +0))) - (array-store +2 (:! (Class Object) Integer.TYPE)) - (array-store +3 (:! (Class Object) Integer.TYPE)))] - (class-for java.lang.ClassLoader)) - (#R;Success method) - (do-to method - (AccessibleObject.setAccessible [true])) - - (#R;Error error) - (error! error))) - -(def: (memory-class-loader store) - (-> &&common;Class-Store ClassLoader) - (object ClassLoader [] - [] - (ClassLoader (findClass [class-name String]) void - (case (|> store A;get io;run (D;get class-name)) - (#;Some bytecode) - (case (Method.invoke [(:! Object _jvm_this) - (array;from-list (list (:! Object class-name) - (:! Object bytecode) - (:! Object (l2i 0)) - (:! Object (l2i (nat-to-int (array-length bytecode))))))] - ClassLoader::defineClass) - (#R;Success output) - [] - - (#R;Error error) - (error! error)) - - _ - (error! (format "Unknown class: " class-name)))))) - -(def: (init-host _) - (-> Top &&common;Host) - (let [store (: &&common;Class-Store - (A;atom (D;new text;Hash<Text>)))] - {#&&common;visitor #;None - #&&common;loader (memory-class-loader store) - #&&common;store store})) - (def: init-cursor Cursor ["" +0 +0]) (def: init-type-context @@ -180,11 +118,9 @@ #;var-counter +0 #;var-bindings (list)}) -(def: compiler-version Text "0.6.0") - (def: init-compiler-info Compiler-Info - {#;compiler-version compiler-version + {#;compiler-version &;compiler-version #;compiler-mode #;Build}) (def: (init-compiler host) @@ -214,7 +150,7 @@ (def: #export (compile-program program target sources) (-> &;Path &;Path (List &;Path) (P;Promise Unit)) (do P;Monad<Promise> - [#let [compiler (init-compiler (init-host []))] + [#let [compiler (init-compiler (&host;init-host []))] compiler (or-crash! (&&runtime;compile-runtime compiler)) compiler (or-crash! (compile-module sources prelude compiler)) compiler (or-crash! (compile-module sources program compiler)) diff --git a/new-luxc/source/luxc/compiler/base.jvm.lux b/new-luxc/source/luxc/generator/base.jvm.lux index 01a97aec4..01a97aec4 100644 --- a/new-luxc/source/luxc/compiler/base.jvm.lux +++ b/new-luxc/source/luxc/generator/base.jvm.lux diff --git a/new-luxc/source/luxc/compiler/statement.jvm.lux b/new-luxc/source/luxc/generator/statement.jvm.lux index 96263181f..96263181f 100644 --- a/new-luxc/source/luxc/compiler/statement.jvm.lux +++ b/new-luxc/source/luxc/generator/statement.jvm.lux |