aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lux/analyser/lux.clj4
-rw-r--r--src/lux/base.clj3
-rw-r--r--src/lux/compiler/lambda.clj68
3 files changed, 39 insertions, 36 deletions
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj
index c964058b2..59f3fbb1f 100644
--- a/src/lux/analyser/lux.clj
+++ b/src/lux/analyser/lux.clj
@@ -266,7 +266,9 @@
(matchv ::M/objects [_macro]
[["lux;Some" macro]]
(|do [macro-expansion #(-> macro (.apply ?args) (.apply %))]
- (&/flat-map% (partial analyse exo-type) macro-expansion))
+ (do (when (= "type`" ?name)
+ (prn 'macro-expansion (str ?module ";" ?name) (->> macro-expansion (&/|map &/show-ast) (&/|interpose " ") (&/fold str ""))))
+ (&/flat-map% (partial analyse exo-type) macro-expansion)))
[["lux;None" _]]
(fail (str "[Analyser Error] Macro has yet to be compiled: " (str ?module ";" ?name))))
diff --git a/src/lux/base.clj b/src/lux/base.clj
index 306c09b19..4b8045e8c 100644
--- a/src/lux/base.clj
+++ b/src/lux/base.clj
@@ -645,8 +645,7 @@
(|do [closure-name (|do [top get-top-local-env]
(return (->> top (get$ $INNER-CLOSURES) str)))]
(fn [state]
- (let [body* (with-scope closure-name
- body)]
+ (let [body* (with-scope closure-name body)]
(run-state body* (update$ $ENVS #(|cons (update$ $INNER-CLOSURES inc (|head %))
(|tail %))
state))))))
diff --git a/src/lux/compiler/lambda.clj b/src/lux/compiler/lambda.clj
index cfea13a73..276329a75 100644
--- a/src/lux/compiler/lambda.clj
+++ b/src/lux/compiler/lambda.clj
@@ -63,19 +63,19 @@
(&/with-writer (doto (.visitMethod class Opcodes/ACC_PUBLIC "impl" impl-signature nil nil)
(.visitCode))
(|do [*writer* &/get-writer
- :let [num-locals (&&/total-locals impl-body)
- $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))
- (->> (dotimes [idx num-locals])))
- (.visitLabel $start))]
- ret (compile impl-body)
- :let [_ (doto *writer*
- (.visitLabel $end)
- (.visitInsn Opcodes/ARETURN)
- (.visitMaxs 0 0)
- (.visitEnd))]]
+ :let [num-locals (&&/total-locals impl-body)
+ $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))
+ (->> (dotimes [idx num-locals])))
+ (.visitLabel $start))]
+ ret (compile impl-body)
+ :let [_ (doto *writer*
+ (.visitLabel $end)
+ (.visitInsn Opcodes/ARETURN)
+ (.visitMaxs 0 0)
+ (.visitEnd))]]
(return ret))))
(defn ^:private instance-closure [compile lambda-class closed-over init-signature]
@@ -121,7 +121,7 @@
;; :else
;; '???))
- (compile ?source))))))
+ (compile ?source))))))
:let [_ (.visitMethodInsn *writer* Opcodes/INVOKESPECIAL lambda-class "<init>" init-signature)]]
(return nil)))
@@ -129,23 +129,25 @@
(defn compile-lambda [compile ?scope ?env ?body]
;; (prn 'compile-lambda ?scope (&host/location ?scope) ?env)
(|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)]))
- (-> (doto (.visitField (+ Opcodes/ACC_PRIVATE Opcodes/ACC_FINAL) captured-name clo-field-sig nil nil)
- (.visitEnd))
- (->> (let [captured-name (str &&/closure-prefix ?captured-id)])
- (matchv ::M/objects [?name+?captured]
- [[?name [["captured" [_ ?captured-id ?source]] _]]])
- (doseq [?name+?captured (&/->seq ?env)
- ;; :let [_ (prn '?name+?captured (alength ?name+?captured))
- ;; _ (prn '?name+?captured (aget ?name+?captured 1 0))
- ;; _ (prn '?name+?captured (aget ?name+?captured 1 1 0 0))]
- ])))
- (add-lambda-apply lambda-class ?env)
- (add-lambda-<init> lambda-class ?env)
- )]
- _ (add-lambda-impl =class compile lambda-impl-signature ?body)
- :let [_ (.visitEnd =class)]
- _ (&&/save-class! lambda-class (.toByteArray =class))]
+ =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)]))
+ (-> (doto (.visitField (+ Opcodes/ACC_PRIVATE Opcodes/ACC_FINAL) captured-name clo-field-sig nil nil)
+ (.visitEnd))
+ (->> (let [captured-name (str &&/closure-prefix ?captured-id)])
+ (matchv ::M/objects [?name+?captured]
+ [[?name [["captured" [_ ?captured-id ?source]] _]]])
+ (doseq [?name+?captured (&/->seq ?env)
+ ;; :let [_ (prn '?name+?captured (alength ?name+?captured))
+ ;; _ (prn '?name+?captured (aget ?name+?captured 1 0))
+ ;; _ (prn '?name+?captured (aget ?name+?captured 1 1 0 0))]
+ ])))
+ (add-lambda-apply lambda-class ?env)
+ (add-lambda-<init> lambda-class ?env)
+ )]
+ _ (add-lambda-impl =class compile lambda-impl-signature ?body)
+ :let [_ (.visitEnd =class)
+ ;; _ (prn 'SAVING_LAMBDA lambda-class)
+ ]
+ _ (&&/save-class! lambda-class (.toByteArray =class))]
(instance-closure compile lambda-class ?env (lambda-<init>-signature ?env))))