From 57f89f16e95749e4ee4ad98a4e3d7a7908fb9a2f Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 8 Mar 2015 12:44:42 -0400 Subject: - The implementation of monadic macros is finally finished. --- src/lux.clj | 1 - src/lux/analyser/lux.clj | 10 +++------- src/lux/compiler/lux.clj | 2 +- src/lux/macro.clj | 19 +++++++++++-------- 4 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/lux.clj b/src/lux.clj index ce843d0cd..888618de6 100644 --- a/src/lux.clj +++ b/src/lux.clj @@ -3,7 +3,6 @@ :reload-all)) (comment - ;; TODO: Make macros monadic. ;; TODO: Finish type system. ;; TODO: Re-implement compiler in language. ;; TODO: Adding metadata to global vars. diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj index 570048dcd..75b6f375a 100644 --- a/src/lux/analyser/lux.clj +++ b/src/lux/analyser/lux.clj @@ -60,13 +60,9 @@ [::&&/global ?module ?name] (exec [macro? (&&def/macro? ?module ?name)] (if macro? - (let [macro-class (&host/location (list ?module ?name)) - [macro-expansion state*] (¯o/expand loader macro-class ?args) - ;; _ (prn 'macro-expansion) - ;; _ (doseq [ast macro-expansion] - ;; (prn '=> ast)) - ] - (mapcat-m analyse macro-expansion)) + (let [macro-class (&host/location (list ?module ?name))] + (exec [macro-expansion (¯o/expand loader macro-class ?args)] + (mapcat-m analyse macro-expansion))) (exec [=args (mapcat-m analyse ?args)] (return (list [::&&/Expression [::&&/call =fn =args] &type/+dont-care-type+]))))) diff --git a/src/lux/compiler/lux.clj b/src/lux/compiler/lux.clj index f85d2f7a5..7e9e55b23 100644 --- a/src/lux/compiler/lux.clj +++ b/src/lux/compiler/lux.clj @@ -87,7 +87,7 @@ (return nil))) (defn compile-captured [compile *type* ?scope ?captured-id ?source] - (prn 'compile-captured ?scope ?captured-id) + ;; (prn 'compile-captured ?scope ?captured-id) (exec [*writer* &/get-writer :let [_ (doto *writer* (.visitVarInsn Opcodes/ALOAD 0) diff --git a/src/lux/macro.clj b/src/lux/macro.clj index 071f95691..9f42d6402 100644 --- a/src/lux/macro.clj +++ b/src/lux/macro.clj @@ -1,6 +1,7 @@ (ns lux.macro (:require [clojure.core.match :refer [match]] - [lux.parser :as &parser])) + (lux [base :as & :refer [fail* return*]] + [parser :as &parser]))) ;; [Utils] (defn ^:private ->lux+ [->lux loader xs] @@ -63,10 +64,12 @@ ;; [Resources] (defn expand [loader macro-class tokens] - (let [output (-> (.loadClass loader macro-class) - (.getField "_datum") - (.get nil) - (.apply (->lux+ ->lux loader tokens)) - (.apply nil))] - [(->clojure+ ->clojure (aget output 0)) - (aget output 1)])) + (fn [state] + (let [output (-> (.loadClass loader macro-class) + (.getField "_datum") + (.get nil) + (.apply (->lux+ ->lux loader tokens)) + (.apply state))] + (case (aget output 0) + "Ok" (return* (aget output 1 0) (->clojure+ ->clojure (aget output 1 1))) + "Error" (fail* (aget output 1)))))) -- cgit v1.2.3