From 79f2b2d51b8210d0a2bc81344ea82b4e5cbc7429 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 15 Sep 2015 00:59:45 -0400 Subject: - The Macro type now flows from lux.lux into the compiler, to achieve a perfect match without having the write the type in 2 places. - Made the "Host" type fully opaque to avoid letting users manipulate instances. --- source/lux.lux | 23 +---- src/lux/analyser/module.clj | 2 + src/lux/base.clj | 7 ++ src/lux/type.clj | 207 ++------------------------------------------ 4 files changed, 17 insertions(+), 222 deletions(-) diff --git a/source/lux.lux b/source/lux.lux index 4571529a0..e155af794 100644 --- a/source/lux.lux +++ b/source/lux.lux @@ -77,6 +77,7 @@ ## (#LambdaT Type Type) ## (#BoundT Int) ## (#VarT Int) +## (#ExT Int) ## (#UnivQ (List Type) Type) ## (#ExQ (List Type) Type) ## (#AppT Type Type) @@ -272,24 +273,6 @@ Text])]))) (_lux_export Source) -## (deftype Host -## (& #writer (^ org.objectweb.asm.ClassWriter) -## #loader (^ java.net.URLClassLoader) -## #classes (^ clojure.lang.Atom) -## #catching (List Text))) -(_lux_def Host - (#NamedT ["lux" "Host"] - (#TupleT (#Cons [## "lux;writer" - (#DataT "org.objectweb.asm.ClassWriter" #Nil) - (#Cons [## "lux;loader" - (#DataT "java.lang.ClassLoader" #Nil) - (#Cons [## "lux;classes" - (#DataT "clojure.lang.Atom" #Nil) - (#Cons [## "lux;catching" - (#AppT List Text) - #Nil])])])])))) -(_lux_declare-tags [#writer #loader #classes] Host) - ## (deftype (DefData' m) ## (| (#TypeD Type) ## (#ValueD (, Type Unit)) @@ -371,7 +354,7 @@ ## #expected Type ## #seed Int ## #eval? Bool -## #host Host +## #host Void ## )) (_lux_def Compiler (#NamedT ["lux" "Compiler"] @@ -396,7 +379,7 @@ (#Cons ## "lux;eval?" Bool (#Cons ## "lux;host" - Host + Void #Nil))))))))))) Void))) (_lux_export Compiler) diff --git a/src/lux/analyser/module.clj b/src/lux/analyser/module.clj index deb6be69e..63ba9b741 100644 --- a/src/lux/analyser/module.clj +++ b/src/lux/analyser/module.clj @@ -62,6 +62,8 @@ (defn define [module name def-data type] ;; (prn 'define module name (aget def-data 0) (&type/show-type type)) (fn [state] + (when (and (= "Macro" name) (= "lux" module)) + (&type/set-macro-type! (aget def-data 1))) (|case (&/get$ &/$envs state) (&/$Cons ?env (&/$Nil)) (return* (->> state diff --git a/src/lux/base.clj b/src/lux/base.clj index 0e164f5d2..e57cb0957 100644 --- a/src/lux/base.clj +++ b/src/lux/base.clj @@ -600,6 +600,13 @@ (do (prn 'memory-class-loader/store class-name (keys @store)) (throw (IllegalStateException. (str "[Class Loader] Unknown class: " class-name))))))))) + +;; (deftype Host +;; (& #writer (^ org.objectweb.asm.ClassWriter) +;; #loader (^ java.net.URLClassLoader) +;; #classes (^ clojure.lang.Atom) +;; #catching (List Text) +;; #module-states (List (, Text ModuleState)))) (defn host [_] (let [store (atom {})] (T ;; "lux;writer" diff --git a/src/lux/type.clj b/src/lux/type.clj index d6275651e..bc28dbde0 100644 --- a/src/lux/type.clj +++ b/src/lux/type.clj @@ -114,208 +114,11 @@ ))) $Void)))) -(def Bindings - (Named$ (&/T "lux" "Bindings") - (Univ$ empty-env - (Univ$ empty-env - (Tuple$ (&/|list - ;; "lux;counter" - Int - ;; "lux;mappings" - (App$ List - (Tuple$ (&/|list (Bound$ 2) - (Bound$ 0)))))))))) - -(def Env - (Named$ (&/T "lux" "Env") - (let [bindings (App$ (App$ Bindings (Bound$ 2)) - (Bound$ 0))] - (Univ$ empty-env - (Univ$ empty-env - (Tuple$ - (&/|list - ;; "lux;name" - Text - ;; "lux;inner-closures" - Int - ;; "lux;locals" - bindings - ;; "lux;closure" - bindings - ))))))) - -(def Cursor - (Named$ (&/T "lux" "Cursor") - (Tuple$ (&/|list Text Int Int)))) - -(def Meta - (Named$ (&/T "lux" "Meta") - (Univ$ empty-env - (Univ$ empty-env - (Tuple$ (&/|list (Bound$ 2) - (Bound$ 0))))))) - -(def AST* - (Named$ (&/T "lux" "AST'") - (let [AST* (App$ (Bound$ 0) - (App$ (Bound$ 1) - (Bound$ 0))) - AST*List (App$ List AST*)] - (Univ$ empty-env - (Variant$ (&/|list - ;; &/$BoolS - Bool - ;; &/$IntS - Int - ;; &/$RealS - Real - ;; &/$CharS - Char - ;; &/$TextS - Text - ;; &/$SymbolS - Ident - ;; &/$TagS - Ident - ;; &/$FormS - AST*List - ;; &/$TupleS - AST*List - ;; &/$RecordS - (App$ List (Tuple$ (&/|list AST* AST*)))) - ))))) - -(def AST - (Named$ (&/T "lux" "AST") - (let [w (App$ Meta Cursor)] - (App$ w (App$ AST* w))))) - -(def ^:private ASTList (App$ List AST)) - -(def Either - (Named$ (&/T "lux" "Either") - (Univ$ empty-env - (Univ$ empty-env - (Variant$ (&/|list - ;; &/$Left - (Bound$ 2) - ;; &/$Right - (Bound$ 0))))))) - -(def StateE - (Univ$ empty-env - (Univ$ empty-env - (Lambda$ (Bound$ 2) - (App$ (App$ Either Text) - (Tuple$ (&/|list (Bound$ 2) - (Bound$ 0)))))))) - -(def Source - (Named$ (&/T "lux" "Source") - (App$ List - (App$ (App$ Meta Cursor) - Text)))) - -(def Host - (Named$ (&/T "lux" "Host") - (Tuple$ - (&/|list - ;; "lux;writer" - (Data$ "org.objectweb.asm.ClassWriter" &/Nil$) - ;; "lux;loader" - (Data$ "java.lang.ClassLoader" &/Nil$) - ;; "lux;classes" - (Data$ "clojure.lang.Atom" &/Nil$) - ;; "lux;catching" - (App$ List Text) - )))) - -(def DefData* - (Univ$ empty-env - (Variant$ (&/|list - ;; "lux;ValueD" - (Tuple$ (&/|list Type Unit)) - ;; "lux;TypeD" - Type - ;; "lux;MacroD" - (Bound$ 0) - ;; "lux;AliasD" - Ident - )))) - -(def LuxVar - (Named$ (&/T "lux" "LuxVar") - (Variant$ (&/|list - ;; "lux;Local" - Int - ;; "lux;Global" - Ident)))) - -(def $Module - (Univ$ empty-env - (Tuple$ - (&/|list - ;; "lux;module-aliases" - (App$ List (Tuple$ (&/|list Text Text))) - ;; "lux;defs" - (App$ List - (Tuple$ (&/|list Text - (Tuple$ (&/|list Bool - (App$ DefData* - (Lambda$ ASTList - (App$ (App$ StateE (Bound$ 0)) - ASTList)))))))) - ;; "lux;imports" - (App$ List Text) - ;; "lux;tags" - ;; (List (, Text (, Int (List Ident) Type))) - (App$ List - (Tuple$ (&/|list Text - (Tuple$ (&/|list Int - (App$ List Ident) - Type))))) - ;; "lux;types" - ;; (List (, Text (, (List Ident) Type))) - (App$ List - (Tuple$ (&/|list Text - (Tuple$ (&/|list (App$ List Ident) - Type))))) - )))) - -(def $Compiler - (Named$ (&/T "lux" "Compiler") - (App$ (Univ$ empty-env - (Tuple$ - (&/|list - ;; "lux;source" - Source - ;; "lux;cursor" - Cursor - ;; "lux;modules" - (App$ List (Tuple$ (&/|list Text - (App$ $Module (App$ (Bound$ 1) (Bound$ 0)))))) - ;; "lux;envs" - (App$ List - (App$ (App$ Env Text) - (Tuple$ (&/|list LuxVar Type)))) - ;; "lux;types" - (App$ (App$ Bindings Int) Type) - ;; "lux;expected" - Type - ;; "lux;seed" - Int - ;; "lux;eval?" - Bool - ;; "lux;host" - Host - ))) - $Void))) - -(def Macro - (Named$ (&/T "lux" "Macro") - (Lambda$ ASTList - (App$ (App$ StateE $Compiler) - ASTList)))) +(def Macro) + +(defn set-macro-type! [type] + (def Macro type) + nil) (defn bound? [id] (fn [state] -- cgit v1.2.3