diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lux/base.clj | 14 | ||||
-rw-r--r-- | src/lux/compiler.clj | 42 | ||||
-rw-r--r-- | src/lux/compiler/lambda.clj | 4 | ||||
-rw-r--r-- | src/lux/lexer.clj | 30 | ||||
-rw-r--r-- | src/lux/type.clj | 2 |
5 files changed, 42 insertions, 50 deletions
diff --git a/src/lux/base.clj b/src/lux/base.clj index 5292faffa..9ea255132 100644 --- a/src/lux/base.clj +++ b/src/lux/base.clj @@ -15,9 +15,8 @@ (def $NAME 3) ;; Host -(def $EVAL-CTOR 0) -(def $LOADER 1) -(def $WRITER 2) +(def $LOADER 0) +(def $WRITER 1) ;; CompilerState (def $ENVS 0) @@ -441,9 +440,7 @@ )) (defn host [_] - (R ;; "lux;eval-ctor" - 0 - ;; "lux;loader" + (R ;; "lux;loader" (-> (java.io.File. "./output/") .toURL vector into-array java.net.URLClassLoader.) ;; "lux;writer" (V "lux;None" nil))) @@ -465,11 +462,6 @@ +init-bindings+ )) -(def get-eval-ctor - (fn [state] - (return* (update$ $HOST #(update$ $EVAL-CTOR inc %) state) - (get$ $EVAL-CTOR (get$ $HOST state))))) - (def get-writer (fn [state] (let [writer* (->> state (get$ $HOST) (get$ $WRITER))] diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj index 209e29626..40bb3a710 100644 --- a/src/lux/compiler.clj +++ b/src/lux/compiler.clj @@ -315,27 +315,27 @@ (&&host/compile-jvm-class compile-expression ?package ?name ?super-class ?fields ?methods))) (defn ^:private eval! [expr] - (|do [eval-ctor &/get-eval-ctor - :let [class-name (str eval-ctor) - =class (doto (new ClassWriter ClassWriter/COMPUTE_MAXS) - (.visit Opcodes/V1_5 (+ Opcodes/ACC_PUBLIC Opcodes/ACC_SUPER) - class-name nil "java/lang/Object" nil) - (-> (.visitField (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC) "_eval" "Ljava/lang/Object;" nil nil) - (doto (.visitEnd))))] - _ (&/with-writer (.visitMethod =class Opcodes/ACC_PUBLIC "<clinit>" "()V" nil nil) - (|do [^MethodVisitor *writer* &/get-writer - :let [_ (.visitCode *writer*)] - _ (compile-expression expr) - :let [_ (doto *writer* - (.visitFieldInsn Opcodes/PUTSTATIC class-name "_eval" "Ljava/lang/Object;") - (.visitInsn Opcodes/RETURN) - (.visitMaxs 0 0) - (.visitEnd))]] - (return nil))) - :let [bytecode (.toByteArray (doto =class - .visitEnd))] - _ (&&/save-class! class-name bytecode) - loader &/loader] + (|do [id &/gen-id + :let [class-name (str id) + =class (doto (new ClassWriter ClassWriter/COMPUTE_MAXS) + (.visit Opcodes/V1_5 (+ Opcodes/ACC_PUBLIC Opcodes/ACC_SUPER) + class-name nil "java/lang/Object" nil) + (-> (.visitField (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_STATIC) "_eval" "Ljava/lang/Object;" nil nil) + (doto (.visitEnd))))] + _ (&/with-writer (.visitMethod =class Opcodes/ACC_PUBLIC "<clinit>" "()V" nil nil) + (|do [^MethodVisitor *writer* &/get-writer + :let [_ (.visitCode *writer*)] + _ (compile-expression expr) + :let [_ (doto *writer* + (.visitFieldInsn Opcodes/PUTSTATIC class-name "_eval" "Ljava/lang/Object;") + (.visitInsn Opcodes/RETURN) + (.visitMaxs 0 0) + (.visitEnd))]] + (return nil))) + :let [bytecode (.toByteArray (doto =class + .visitEnd))] + _ (&&/save-class! class-name bytecode) + loader &/loader] (-> (.loadClass ^ClassLoader loader class-name) (.getField "_eval") (.get nil) diff --git a/src/lux/compiler/lambda.clj b/src/lux/compiler/lambda.clj index 65c7e58aa..625599617 100644 --- a/src/lux/compiler/lambda.clj +++ b/src/lux/compiler/lambda.clj @@ -63,7 +63,7 @@ $start (new Label) $end (new Label) _ (doto *writer* - (-> (.visitLocalVariable (str &&/local-prefix idx) (&host/->java-sig (&/V "lux;DataT" "java.lang.Object")) nil $start $end (+ 2 idx)) + (-> (.visitLocalVariable (str &&/local-prefix idx) "Ljava/lang/Object;" nil $start $end (+ 2 idx)) (->> (dotimes [idx num-locals]))) (.visitLabel $start))] ret (compile impl-body) @@ -92,7 +92,7 @@ (|do [:let [lambda-class (&host/location ?scope) =class (doto (new ClassWriter ClassWriter/COMPUTE_MAXS) (.visit Opcodes/V1_5 (+ Opcodes/ACC_PUBLIC Opcodes/ACC_FINAL Opcodes/ACC_SUPER) - lambda-class nil "java/lang/Object" (into-array [(&host/->class &host/function-class)])) + lambda-class nil "java/lang/Object" (into-array ["lux/Function"])) (-> (doto (.visitField (+ Opcodes/ACC_PRIVATE Opcodes/ACC_FINAL) captured-name clo-field-sig nil nil) (.visitEnd)) (->> (let [captured-name (str &&/closure-prefix ?captured-id)]) diff --git a/src/lux/lexer.clj b/src/lux/lexer.clj index f94a3d058..31258bc4b 100644 --- a/src/lux/lexer.clj +++ b/src/lux/lexer.clj @@ -36,18 +36,18 @@ (def ^:private lex-single-line-comment (|do [[_ [meta _]] (&reader/read-text "##") - [_ [_ comment]] (&reader/read-regex #"^(.*)$")] + [_ [_ comment]] (&reader/read-regex #"^(.*)$")] (return (&/V "lux;Meta" (&/T meta (&/V "Comment" comment)))))) (defn ^:private lex-multi-line-comment [_] (|do [_ (&reader/read-text "#(") - [meta comment] (&/try-all% (&/|list (|do [[_ [meta comment]] (&reader/read-regex #"(?is)^((?!#\().)*?(?=\)#)")] - (return comment)) - (|do [[_ [meta pre]] (&reader/read-regex #"(?is)^(.+?(?=#\())") - [_ inner] (lex-multi-line-comment nil) - [_ [_ post]] (&reader/read-regex #"(?is)^(.+?(?=\)#))")] - (return (str pre "#(" inner ")#" post))))) - _ (&reader/read-text ")#")] + [meta comment] (&/try-all% (&/|list (|do [[_ [meta comment]] (&reader/read-regex #"(?is)^((?!#\().)*?(?=\)#)")] + (return comment)) + (|do [[_ [meta pre]] (&reader/read-regex #"(?is)^(.+?(?=#\())") + [_ inner] (lex-multi-line-comment nil) + [_ [_ post]] (&reader/read-regex #"(?is)^(.+?(?=\)#))")] + (return (str pre "#(" inner ")#" post))))) + _ (&reader/read-text ")#")] (return (&/V "lux;Meta" (&/T meta (&/V "Comment" comment)))))) (def ^:private lex-comment @@ -65,17 +65,17 @@ (def ^:private lex-char (|do [[_ [meta _]] (&reader/read-text "#\"") - token (&/try-all% (&/|list (|do [[_ [_ escaped]] (&reader/read-regex #"^(\\.)")] - (escape-char escaped)) - (|do [[_ [_ char]] (&reader/read-regex #"^(.)")] - (return char)))) - _ (&reader/read-text "\"")] + token (&/try-all% (&/|list (|do [[_ [_ escaped]] (&reader/read-regex #"^(\\.)")] + (escape-char escaped)) + (|do [[_ [_ char]] (&reader/read-regex #"^(.)")] + (return char)))) + _ (&reader/read-text "\"")] (return (&/V "lux;Meta" (&/T meta (&/V "Char" token)))))) (def ^:private lex-text (|do [[_ [meta _]] (&reader/read-text "\"") - token (lex-text-body nil) - _ (&reader/read-text "\"")] + token (lex-text-body nil) + _ (&reader/read-text "\"")] (return (&/V "lux;Meta" (&/T meta (&/V "Text" token)))))) (def ^:private lex-ident diff --git a/src/lux/type.clj b/src/lux/type.clj index 2e9e85092..b2ea0ff0d 100644 --- a/src/lux/type.clj +++ b/src/lux/type.clj @@ -126,7 +126,7 @@ (&/V "lux;RecordT" (&/|list (&/T "lux;writer" (&/V "lux;DataT" "org.objectweb.asm.ClassWriter")) (&/T "lux;loader" (&/V "lux;DataT" "java.lang.ClassLoader")) - (&/T "lux;eval-ctor" Int)))) + ))) (def DefData* (fAll "DefData'" "" |