diff options
author | Eduardo Julian | 2015-04-26 01:35:53 -0400 |
---|---|---|
committer | Eduardo Julian | 2015-04-26 01:35:53 -0400 |
commit | 411543f0c331bdfa23dc11988a326ba4a9c44a20 (patch) | |
tree | e11e15649e1066c589572d84e05881a0711c957d /src | |
parent | 8aa12467162bc0a0303ad62ac86d70cd0bbb782c (diff) |
- Macros are no longer declared. Instead, they are automatically detected.
Diffstat (limited to 'src')
-rw-r--r-- | src/lux/analyser.clj | 5 | ||||
-rw-r--r-- | src/lux/analyser/lux.clj | 14 | ||||
-rw-r--r-- | src/lux/type.clj | 92 |
3 files changed, 95 insertions, 16 deletions
diff --git a/src/lux/analyser.clj b/src/lux/analyser.clj index e85123032..2704f77ce 100644 --- a/src/lux/analyser.clj +++ b/src/lux/analyser.clj @@ -91,11 +91,6 @@ ;; (prn "if" (&/show-ast ?value))) (&&lux/analyse-def analyse ?name ?value)) - [["lux;Meta" [meta ["lux;Form" ["lux;Cons" [["lux;Meta" [_ ["lux;Symbol" ["" "declare-macro'"]]]] - ["lux;Cons" [["lux;Meta" [_ ["lux;Symbol" ?ident]]] - ["lux;Nil" _]]]]]]]]] - (&&lux/analyse-declare-macro ?ident) - [["lux;Meta" [meta ["lux;Form" ["lux;Cons" [["lux;Meta" [_ ["lux;Symbol" ["" "import'"]]]] ["lux;Cons" [["lux;Meta" [_ ["lux;Text" ?path]]] ["lux;Nil" _]]]]]]]]] diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj index 28b25a492..3bba07b39 100644 --- a/src/lux/analyser/lux.clj +++ b/src/lux/analyser/lux.clj @@ -285,21 +285,13 @@ :let [_ (prn 'analyse-def/TYPE ?name (&type/show-type =value-type)) _ (println)] _ (&&def/define module-name ?name =value-type) + _ (if (&type/type= &type/Macro =value-type) + (&&def/declare-macro module-name ?name) + (return nil)) ;; :let [_ (prn 'analyse-def/_3)] ] (return (&/|list (&/V "Statement" (&/V "def" (&/T ?name =value))))))))) -(defn analyse-declare-macro [ident] - (|do [current-module &/get-module-name - ;; :let [_ (prn 'analyse-declare-macro/current-module current-module)] - [?module ?name] (&&/resolved-ident* ident) - ;; :let [_ (prn 'analyse-declare-macro '[?module ?name] [?module ?name])] - ] - (if (= ?module current-module) - (|do [_ (&&def/declare-macro ?module ?name)] - (return (&/|list))) - (fail "Can't declare macros from foreign modules.")))) - (defn analyse-import [analyse exo-type ?path] (return (&/|list))) diff --git a/src/lux/type.clj b/src/lux/type.clj index cd7d5be1e..82a405977 100644 --- a/src/lux/type.clj +++ b/src/lux/type.clj @@ -44,6 +44,98 @@ )))) $Void)))) +(defn fAll [name arg body] + (&/V "lux;AllT" (&/T (&/V "lux;None" nil) name arg body))) + +(def Bindings + (fAll "Bindings" "k" + (fAll "" "v" + (&/V "lux;RecordT" (&/|list (&/T "lux;counter" Int) + (&/T "lux;mappings" (&/V "lux;AppT" (&/T List + (&/V "lux;TupleT" (&/|list (&/V "lux;BoundT" "k") + (&/V "lux;BoundT" "v"))))))))))) + +(def Env + (let [bindings (&/V "lux;AppT" (&/T (&/V "lux;AppT" (&/T Bindings (&/V "lux;BoundT" "k"))) + (&/V "lux;BoundT" "v")))] + (fAll "Env" "k" + (fAll "" "v" + (&/V "lux;RecordT" + (&/|list (&/T "lux;name" Text) + (&/T "lux;inner-closures" Int) + (&/T "lux;locals" bindings) + (&/T "lux;closure" bindings) + )))))) + +(def Cursor + (&/V "lux;TupleT" (&/|list Text Int Int))) + +(def Meta + (fAll "Meta" "m" + (fAll "" "v" + (&/V "lux;VariantT" (&/|list (&/T "lux;Meta" (&/V "lux;TupleT" (&/|list (&/V "lux;BoundT" "m") + (&/V "lux;BoundT" "v"))))))))) + +(def Reader + (&/V "lux;AppT" (&/T List + (&/V "lux;AppT" (&/T (&/V "lux;AppT" (&/T Meta Cursor)) + Text))))) + +(def HostState + (&/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 CompilerState + (&/V "lux;RecordT" + (&/|list (&/T "lux;source" (&/V "lux;AppT" (&/T Maybe Reader))) + (&/T "lux;modules" (&/V "lux;AppT" (&/T List $Void))) + (&/T "lux;module-aliases" (&/V "lux;AppT" (&/T List $Void))) + (&/T "lux;envs" (&/V "lux;AppT" (&/T List + (&/V "lux;AppT" (&/T (&/V "lux;AppT" (&/T Env Text)) + $Void))))) + (&/T "lux;types" (&/V "lux;AppT" (&/T (&/V "lux;AppT" (&/T Bindings Int)) Type))) + (&/T "lux;host" HostState)))) + +(def Syntax* + (let [Syntax* (&/V "lux;AppT" (&/T (&/V "lux;BoundT" "w") + (&/V "lux;AppT" (&/T (&/V "lux;BoundT" "Syntax'") + (&/V "lux;BoundT" "w"))))) + Syntax*List (&/V "lux;AppT" (&/T List Syntax*)) + Ident (&/V "lux;TupleT" (&/|list Text Text))] + (fAll "Syntax'" "w" + (&/V "lux;VariantT" (&/|list (&/T "lux;Bool" Bool) + (&/T "lux;Int" Int) + (&/T "lux;Real" Real) + (&/T "lux;Char" Char) + (&/T "lux;Text" Text) + (&/T "lux;Symbol" Ident) + (&/T "lux;Tag" Ident) + (&/T "lux;Form" Syntax*List) + (&/T "lux;Tuple" Syntax*List) + (&/T "lux;Record" (&/V "lux;AppT" (&/T List (&/V "lux;TupleT" (&/|list Text Syntax*)))))) + )))) + +(def Syntax + (let [w (&/V "lux;AppT" (&/T Meta Cursor))] + (&/V "lux;AppT" (&/T w (&/V "lux;AppT" (&/T Syntax* w)))))) + +(def Either + (fAll "_" "l" + (fAll "" "r" + (&/V "lux;VariantT" (&/|list (&/T "lux;Left" (&/V "lux;BoundT" "l")) + (&/T "lux;Right" (&/V "lux;BoundT" "r"))))))) + +(def Macro + (let [SyntaxList (&/V "lux;AppT" (&/T List Syntax))] + (&/V "lux;LambdaT" (&/T SyntaxList + (&/V "lux;LambdaT" (&/T CompilerState + (&/V "lux;AppT" (&/T (&/V "lux;AppT" (&/T Either Text)) + (&/V "lux;TupleT" (&/|list CompilerState + SyntaxList)))))))) + )) + (defn bound? [id] (fn [state] (if-let [type* (->> state (&/get$ &/$TYPES) (&/get$ &/$MAPPINGS) (&/|get id))] |