diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lux.clj | 3 | ||||
-rw-r--r-- | src/lux/analyser.clj | 12 | ||||
-rw-r--r-- | src/lux/analyser/base.clj | 8 | ||||
-rw-r--r-- | src/lux/analyser/env.clj | 2 | ||||
-rw-r--r-- | src/lux/analyser/host.clj | 44 | ||||
-rw-r--r-- | src/lux/analyser/lambda.clj | 14 | ||||
-rw-r--r-- | src/lux/analyser/lux.clj | 92 | ||||
-rw-r--r-- | src/lux/analyser/module.clj | 2 | ||||
-rw-r--r-- | src/lux/compiler.clj | 30 | ||||
-rw-r--r-- | src/lux/compiler/base.clj | 2 | ||||
-rw-r--r-- | src/lux/compiler/lambda.clj | 18 |
11 files changed, 104 insertions, 123 deletions
diff --git a/src/lux.clj b/src/lux.clj index 103c15565..83353f7e9 100644 --- a/src/lux.clj +++ b/src/lux.clj @@ -14,9 +14,6 @@ ;; Finish total-locals - ;; TODO: Change &type/check to it returns a tuple with the new expected & actual types - ;; TODO: Stop passing-along the exo-types and instead pass-along endo-types where possible - (time (&compiler/compile-all (&/|list "lux"))) (System/gc) (time (&compiler/compile-all (&/|list "lux" "test2"))) diff --git a/src/lux/analyser.clj b/src/lux/analyser.clj index 938f6df2f..31b665c49 100644 --- a/src/lux/analyser.clj +++ b/src/lux/analyser.clj @@ -38,23 +38,23 @@ ;; Standard special forms [["lux;Meta" [meta ["lux;Bool" ?value]]]] (|do [_ (&type/check exo-type &type/Bool)] - (return (&/|list (&/V "Expression" (&/T (&/V "bool" ?value) exo-type))))) + (return (&/|list (&/T (&/V "bool" ?value) exo-type)))) [["lux;Meta" [meta ["lux;Int" ?value]]]] (|do [_ (&type/check exo-type &type/Int)] - (return (&/|list (&/V "Expression" (&/T (&/V "int" ?value) exo-type))))) + (return (&/|list (&/T (&/V "int" ?value) exo-type)))) [["lux;Meta" [meta ["lux;Real" ?value]]]] (|do [_ (&type/check exo-type &type/Real)] - (return (&/|list (&/V "Expression" (&/T (&/V "real" ?value) exo-type))))) + (return (&/|list (&/T (&/V "real" ?value) exo-type)))) [["lux;Meta" [meta ["lux;Char" ?value]]]] (|do [_ (&type/check exo-type &type/Char)] - (return (&/|list (&/V "Expression" (&/T (&/V "char" ?value) exo-type))))) + (return (&/|list (&/T (&/V "char" ?value) exo-type)))) [["lux;Meta" [meta ["lux;Text" ?value]]]] (|do [_ (&type/check exo-type &type/Text)] - (return (&/|list (&/V "Expression" (&/T (&/V "text" ?value) exo-type))))) + (return (&/|list (&/T (&/V "text" ?value) exo-type)))) [["lux;Meta" [meta ["lux;Tuple" ?elems]]]] (&&lux/analyse-tuple analyse exo-type ?elems) @@ -66,7 +66,7 @@ (&&lux/analyse-variant analyse exo-type ?ident (_meta (&/V "lux;Tuple" (|list)))) [["lux;Meta" [meta ["lux;Symbol" ["" "jvm-null"]]]]] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-null" nil) (&/V "lux;DataT" "null"))))) + (return (&/|list (&/T (&/V "jvm-null" nil) (&/V "lux;DataT" "null")))) [["lux;Meta" [meta ["lux;Symbol" ?ident]]]] (&&lux/analyse-symbol analyse exo-type ?ident) diff --git a/src/lux/analyser/base.clj b/src/lux/analyser/base.clj index 1653a4fa1..9913da4ae 100644 --- a/src/lux/analyser/base.clj +++ b/src/lux/analyser/base.clj @@ -9,12 +9,8 @@ ;; (prn 'expr-type syntax+) ;; (prn 'expr-type (aget syntax+ 0)) (matchv ::M/objects [syntax+] - [["Expression" [_ type]]] - (do ;; (prn 'expr-type (&type/show-type type)) - (return type)) - - [["Statement" _]] - (fail (str "[Analyser Error] Can't retrieve the type of a statement: " (pr-str syntax+))))) + [[_ type]] + (return type))) (defn analyse-1 [analyse exo-type elem] (|do [output (analyse exo-type elem)] diff --git a/src/lux/analyser/env.clj b/src/lux/analyser/env.clj index 52743879d..af0052c3d 100644 --- a/src/lux/analyser/env.clj +++ b/src/lux/analyser/env.clj @@ -18,7 +18,7 @@ (let [bound-unit (&/V "local" (->> (&/|head stack) (&/get$ &/$LOCALS) (&/get$ &/$COUNTER)))] (&/|cons (->> (&/|head stack) (&/update$ &/$LOCALS #(&/update$ &/$COUNTER inc %)) - (&/update$ &/$LOCALS #(&/update$ &/$MAPPINGS (fn [m] (&/|put name (&/V "Expression" (&/T bound-unit type)) m)) %))) + (&/update$ &/$LOCALS #(&/update$ &/$MAPPINGS (fn [m] (&/|put name (&/T bound-unit type) m)) %))) (&/|tail stack)))) state))] (matchv ::M/objects [=return] diff --git a/src/lux/analyser/host.clj b/src/lux/analyser/host.clj index 466058f4e..1b1947b35 100644 --- a/src/lux/analyser/host.clj +++ b/src/lux/analyser/host.clj @@ -25,7 +25,7 @@ (defn <name> [analyse ?x ?y] (|do [=x (&&/analyse-1 analyse input-type ?x) =y (&&/analyse-1 analyse input-type ?y)] - (return (&/|list (&/V "Expression" (&/T (&/V <output-tag> (&/T =x =y)) output-type))))))) + (return (&/|list (&/T (&/V <output-tag> (&/T =x =y)) output-type)))))) analyse-jvm-iadd "jvm-iadd" "java.lang.Integer" "java.lang.Integer" analyse-jvm-isub "jvm-isub" "java.lang.Integer" "java.lang.Integer" @@ -70,13 +70,13 @@ =type (&host/lookup-static-field =class ?field) ;; :let [_ (prn 'analyse-jvm-getstatic/=type =type)] ] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-getstatic" (&/T =class ?field)) =type)))))) + (return (&/|list (&/T (&/V "jvm-getstatic" (&/T =class ?field)) =type))))) (defn analyse-jvm-getfield [analyse ?class ?field ?object] (|do [=class (&host/full-class-name ?class) =type (&host/lookup-static-field =class ?field) =object (&&/analyse-1 analyse ?object)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-getfield" (&/T =class ?field =object)) =type)))))) + (return (&/|list (&/T (&/V "jvm-getfield" (&/T =class ?field =object)) =type))))) (defn analyse-jvm-putstatic [analyse ?class ?field ?value] (|do [=class (&host/full-class-name ?class) @@ -84,21 +84,21 @@ =type (&host/lookup-static-field =class ?field) ;; :let [_ (prn 'analyse-jvm-getstatic/=type =type)] =value (&&/analyse-1 analyse ?value)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-putstatic" (&/T =class ?field =value)) =type)))))) + (return (&/|list (&/T (&/V "jvm-putstatic" (&/T =class ?field =value)) =type))))) (defn analyse-jvm-putfield [analyse ?class ?field ?object ?value] (|do [=class (&host/full-class-name ?class) =type (&host/lookup-static-field =class ?field) =object (&&/analyse-1 analyse ?object) =value (&&/analyse-1 analyse ?value)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-putfield" (&/T =class ?field =object =value)) =type)))))) + (return (&/|list (&/T (&/V "jvm-putfield" (&/T =class ?field =object =value)) =type))))) (defn analyse-jvm-invokestatic [analyse ?class ?method ?classes ?args] (|do [=class (&host/full-class-name ?class) =classes (&/map% &host/extract-jvm-param ?classes) =return (&host/lookup-static-method =class ?method =classes) =args (&/flat-map% analyse ?args)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-invokestatic" (&/T =class ?method =classes =args)) =return)))))) + (return (&/|list (&/T (&/V "jvm-invokestatic" (&/T =class ?method =classes =args)) =return))))) (do-template [<name> <tag>] (defn <name> [analyse ?class ?method ?classes ?object ?args] @@ -117,7 +117,7 @@ (&/zip2 =classes ?args)) ;; :let [_ (prn 'analyse-jvm-invokevirtual/=args =args)] ] - (return (&/|list (&/V "Expression" (&/T (&/V <tag> (&/T =class ?method =classes =object =args)) =return)))))) + (return (&/|list (&/T (&/V <tag> (&/T =class ?method =classes =object =args)) =return))))) analyse-jvm-invokevirtual "jvm-invokevirtual" analyse-jvm-invokeinterface "jvm-invokeinterface" @@ -126,29 +126,29 @@ (defn analyse-jvm-null? [analyse ?object] (|do [=object (&&/analyse-1 analyse ?object)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-null?" =object) (&/V "lux;DataT" "java.lang.Boolean"))))))) + (return (&/|list (&/T (&/V "jvm-null?" =object) (&/V "lux;DataT" "java.lang.Boolean")))))) (defn analyse-jvm-new [analyse ?class ?classes ?args] (|do [=class (&host/full-class-name ?class) =classes (&/map% &host/extract-jvm-param ?classes) =args (&/flat-map% analyse ?args)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-new" (&/T =class =classes =args)) (&/V "lux;DataT" =class))))))) + (return (&/|list (&/T (&/V "jvm-new" (&/T =class =classes =args)) (&/V "lux;DataT" =class)))))) (defn analyse-jvm-new-array [analyse ?class ?length] (|do [=class (&host/full-class-name ?class)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-new-array" (&/T =class ?length)) (&/V "array" (&/T (&/V "lux;DataT" =class) - (&/V "lux;Nil" nil))))))))) + (return (&/|list (&/T (&/V "jvm-new-array" (&/T =class ?length)) (&/V "array" (&/T (&/V "lux;DataT" =class) + (&/V "lux;Nil" nil)))))))) (defn analyse-jvm-aastore [analyse ?array ?idx ?elem] (|do [=array (&&/analyse-1 analyse &type/$Void ?array) =elem (&&/analyse-1 analyse &type/$Void ?elem) =array-type (&&/expr-type =array)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-aastore" (&/T =array ?idx =elem)) =array-type)))))) + (return (&/|list (&/T (&/V "jvm-aastore" (&/T =array ?idx =elem)) =array-type))))) (defn analyse-jvm-aaload [analyse ?array ?idx] (|do [=array (&&/analyse-1 analyse ?array) =array-type (&&/expr-type =array)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-aaload" (&/T =array ?idx)) =array-type)))))) + (return (&/|list (&/T (&/V "jvm-aaload" (&/T =array ?idx)) =array-type))))) (defn analyse-jvm-class [analyse ?name ?super-class ?fields] (|do [?fields (&/map% (fn [?field] @@ -165,7 +165,7 @@ [field {:access :public :type class}]))] $module &/get-module-name] - (return (&/|list (&/V "Statement" (&/V "jvm-class" (&/T $module ?name ?super-class =fields {}))))))) + (return (&/|list (&/V "jvm-class" (&/T $module ?name ?super-class =fields {})))))) (defn analyse-jvm-interface [analyse ?name ?members] ;; (prn 'analyse-jvm-interface ?name ?members) @@ -191,7 +191,7 @@ [method {:access :public :type [inputs output]}]))] $module &/get-module-name] - (return (&/|list (&/V "Statement" (&/V "jvm-interface" (&/T $module ?name =methods))))))) + (return (&/|list (&/V "jvm-interface" (&/T $module ?name =methods)))))) (defn analyse-jvm-try [analyse ?body [?catches ?finally]] (|do [=body (&&/analyse-1 analyse ?body) @@ -202,24 +202,24 @@ ?catches) =finally (&&/analyse-1 analyse ?finally) =body-type (&&/expr-type =body)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-try" (&/T =body =catches =finally)) =body-type)))))) + (return (&/|list (&/T (&/V "jvm-try" (&/T =body =catches =finally)) =body-type))))) (defn analyse-jvm-throw [analyse ?ex] (|do [=ex (&&/analyse-1 analyse ?ex)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-throw" =ex) &type/$Void)))))) + (return (&/|list (&/T (&/V "jvm-throw" =ex) &type/$Void))))) (defn analyse-jvm-monitorenter [analyse ?monitor] (|do [=monitor (&&/analyse-1 analyse ?monitor)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-monitorenter" =monitor) (&/V "lux;TupleT" (&/V "lux;Nil" nil)))))))) + (return (&/|list (&/T (&/V "jvm-monitorenter" =monitor) (&/V "lux;TupleT" (&/V "lux;Nil" nil))))))) (defn analyse-jvm-monitorexit [analyse ?monitor] (|do [=monitor (&&/analyse-1 analyse ?monitor)] - (return (&/|list (&/V "Expression" (&/T (&/V "jvm-monitorexit" =monitor) (&/V "lux;TupleT" (&/V "lux;Nil" nil)))))))) + (return (&/|list (&/T (&/V "jvm-monitorexit" =monitor) (&/V "lux;TupleT" (&/V "lux;Nil" nil))))))) (do-template [<name> <tag> <from-class> <to-class>] (defn <name> [analyse ?value] (|do [=value (&&/analyse-1 analyse ?value)] - (return (&/|list (&/V "Expression" (&/T (&/V <tag> =value) (&/V "lux;DataT" <to-class>))))))) + (return (&/|list (&/T (&/V <tag> =value) (&/V "lux;DataT" <to-class>)))))) analyse-jvm-d2f "jvm-d2f" "java.lang.Double" "java.lang.Float" analyse-jvm-d2i "jvm-d2i" "java.lang.Double" "java.lang.Integer" @@ -244,7 +244,7 @@ (do-template [<name> <tag> <from-class> <to-class>] (defn <name> [analyse ?value] (|do [=value (&&/analyse-1 analyse ?value)] - (return (&/|list (&/V "Expression" (&/T (&/V <tag> =value) (&/V "lux;DataT" <to-class>))))))) + (return (&/|list (&/T (&/V <tag> =value) (&/V "lux;DataT" <to-class>)))))) analyse-jvm-iand "jvm-iand" "java.lang.Integer" "java.lang.Integer" analyse-jvm-ior "jvm-ior" "java.lang.Integer" "java.lang.Integer" @@ -261,4 +261,4 @@ (defn analyse-jvm-program [analyse ?args ?body] (|do [=body (&&env/with-local ?args (&/V "lux;AppT" (&/T &type/List &type/Text)) (&&/analyse-1 analyse ?body))] - (return (&/|list (&/V "Statement" (&/V "jvm-program" =body)))))) + (return (&/|list (&/V "jvm-program" =body))))) diff --git a/src/lux/analyser/lambda.clj b/src/lux/analyser/lambda.clj index 59df63b20..859f47e56 100644 --- a/src/lux/analyser/lambda.clj +++ b/src/lux/analyser/lambda.clj @@ -27,14 +27,14 @@ ;; register ;; (->> frame (&/get$ &/$CLOSURE) (&/get$ &/$COUNTER))) (matchv ::M/objects [register] - [["Expression" [_ register-type]]] - (|let [register* (&/V "Expression" (&/T (&/V "captured" (&/T scope - (->> frame (&/get$ &/$CLOSURE) (&/get$ &/$COUNTER)) - register)) - register-type)) + [[_ register-type]] + (|let [register* (&/T (&/V "captured" (&/T scope + (->> frame (&/get$ &/$CLOSURE) (&/get$ &/$COUNTER)) + register)) + register-type) [?module ?name] ident full-name (str ?module ";" ?name)] (&/T register* (&/update$ &/$CLOSURE #(->> % - (&/update$ &/$COUNTER inc) - (&/update$ &/$MAPPINGS (fn [mps] (&/|put full-name register* mps)))) + (&/update$ &/$COUNTER inc) + (&/update$ &/$MAPPINGS (fn [mps] (&/|put full-name register* mps)))) frame))))) diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj index 191a16235..b868312d3 100644 --- a/src/lux/analyser/lux.clj +++ b/src/lux/analyser/lux.clj @@ -18,9 +18,9 @@ ;; (prn 'analyse-1+ (aget $var 1) (&/show-ast ?token)) (|do [=expr (&&/analyse-1 analyse $var ?token)] (matchv ::M/objects [=expr] - [["Expression" [?item ?type]]] + [[?item ?type]] (|do [=type (&type/clean $var ?type)] - (return (&/V "Expression" (&/T ?item =type)))) + (return (&/T ?item =type))) ))))) ;; [Exports] @@ -35,8 +35,8 @@ (|let [[elem-t elem] ve] (&&/analyse-1 analyse elem-t elem))) (&/zip2 ?members ?elems))] - (return (&/|list (&/V "Expression" (&/T (&/V "tuple" =elems) - exo-type))))) + (return (&/|list (&/T (&/V "tuple" =elems) + exo-type)))) [["lux;AllT" _]] (&type/with-var @@ -69,8 +69,8 @@ =value (&&/analyse-1 analyse vtype ?value) ;; :let [_ (prn 'GOT_VALUE =value)] ] - (return (&/|list (&/V "Expression" (&/T (&/V "variant" (&/T ?tag =value)) - exo-type))))) + (return (&/|list (&/T (&/V "variant" (&/T ?tag =value)) + exo-type)))) (fail (str "[Analyser Error] There is no case " ?tag " for variant type " (&type/show-type exo-type*))))) [["lux;AllT" _]] @@ -110,7 +110,7 @@ [_] (fail "[Analyser Error] Wrong syntax for records. Odd elements must be tags."))) ?elems)] - (return (&/|list (&/V "Expression" (&/T (&/V "record" =slots) (&/V "lux;RecordT" exo-type))))))) + (return (&/|list (&/T (&/V "record" =slots) (&/V "lux;RecordT" exo-type)))))) (defn ^:private show-frame [frame] (str "{{" (->> frame (&/get$ &/$LOCALS) (&/get$ &/$MAPPINGS) @@ -150,16 +150,16 @@ (&type/check exo-type endo-type)) ;; :let [_ (println "Type-checked:" exo-type endo-type)] ] - (return (&/|list (&/V "Expression" (&/T (&/V "global" (&/T (if (= "" ?module) module-name ?module) - ?name)) - endo-type))))) + (return (&/|list (&/T (&/V "global" (&/T (if (= "" ?module) module-name ?module) + ?name)) + endo-type)))) state) [["lux;Cons" [?genv ["lux;Nil" _]]]] (if-let [global (->> ?genv (&/get$ &/$LOCALS) (&/get$ &/$MAPPINGS) (&/|get local-ident))] (do ;; (prn 'GOT_GLOBAL local-ident) (matchv ::M/objects [global] - [["Expression" [["global" [?module* ?name*]] _]]] + [[["global" [?module* ?name*]] _]] (&/run-state (|do [$def (&&module/find-def ?module* ?name*) ;; :let [_ (println "Found def:" ?module* ?name*)] endo-type (matchv ::M/objects [$def] @@ -178,8 +178,8 @@ (&type/check exo-type endo-type)) ;; :let [_ (println "Type-checked:" exo-type endo-type)] ] - (return (&/|list (&/V "Expression" (&/T (&/V "global" (&/T ?module* ?name*)) - endo-type))))) + (return (&/|list (&/T (&/V "global" (&/T ?module* ?name*)) + endo-type)))) state) [_] @@ -210,14 +210,11 @@ ;; (prn 'analyse-apply* (&/->seq (&/|map &/show-ast ?args))) ;; (prn 'analyse-apply*/exo-type (&type/show-type exo-type)) (matchv ::M/objects [=fn] - [["Statement" _]] - (fail "[Analyser Error] Can't apply a statement!") - - [["Expression" [?fun-expr ?fun-type]]] + [[?fun-expr ?fun-type]] (matchv ::M/objects [?args] [["lux;Nil" _]] (|do [_ (&type/check exo-type ?fun-type)] - (return (&/|list =fn))) + (return =fn)) [["lux;Cons" [?arg ?args*]]] (|do [?fun-type* (&type/actual-type ?fun-type)] @@ -226,22 +223,22 @@ (&type/with-var (fn [$var] (|do [type* (&type/apply-type ?fun-type* $var) - output (analyse-apply* analyse exo-type (&/V "Expression" (&/T ?fun-expr type*)) ?args)] + output (analyse-apply* analyse exo-type (&/T ?fun-expr type*) ?args)] (matchv ::M/objects [output] - [["lux;Cons" [["Expression" [?expr* ?type*]] ["lux;Nil" _]]]] + [[?expr* ?type*]] (|do [type** (&type/clean $var ?type*)] - (return (&/|list (&/V "Expression" (&/T ?expr* type**))))) + (return (&/T ?expr* type**))) [_] (assert false (prn-str 'analyse-apply*/output (aget output 0))))))) [["lux;LambdaT" [?input-t ?output-t]]] ;; (|do [=arg (&&/analyse-1 analyse ?input-t ?arg)] - ;; (return (&/|list (&/V "Expression" (&/T (&/V "apply" (&/T =fn =arg)) - ;; ?output-t))))) + ;; (return (&/T (&/V "apply" (&/T =fn =arg)) + ;; ?output-t))) (|do [=arg (&&/analyse-1 analyse ?input-t ?arg)] - (analyse-apply* analyse exo-type (&/V "Expression" (&/T (&/V "apply" (&/T =fn =arg)) - ?output-t)) + (analyse-apply* analyse exo-type (&/T (&/V "apply" (&/T =fn =arg)) + ?output-t) ?args*)) [_] @@ -252,7 +249,7 @@ ;; (prn 'analyse-apply1 (aget =fn 0)) (|do [loader &/loader] (matchv ::M/objects [=fn] - [["Expression" [=fn-form =fn-type]]] + [[=fn-form =fn-type]] (do ;; (prn 'analyse-apply2 (aget =fn-form 0)) (matchv ::M/objects [=fn-form] [["global" [?module ?name]]] @@ -268,14 +265,13 @@ (fail (str "[Analyser Error] Macro has yet to be compiled: " (str ?module ";" ?name)))) [_] - (analyse-apply* analyse exo-type =fn ?args))) + (|do [output (analyse-apply* analyse exo-type =fn ?args)] + (return (&/|list output))))) [_] - (analyse-apply* analyse exo-type =fn ?args))) - - [_] - (fail "[Analyser Error] Can't call a statement!")) - )) + (|do [output (analyse-apply* analyse exo-type =fn ?args)] + (return (&/|list output))))) + ))) (defn analyse-case [analyse exo-type ?value ?branches] ;; (prn 'analyse-case 'exo-type (&type/show-type exo-type) (&/show-ast ?value)) @@ -288,8 +284,8 @@ =match (&&case/analyse-branches analyse exo-type =value-type (&/|as-pairs ?branches)) ;; :let [_ (prn 'analyse-case/GOT_MATCH)] ] - (return (&/|list (&/V "Expression" (&/T (&/V "case" (&/T =value =match)) - exo-type)))))) + (return (&/|list (&/T (&/V "case" (&/T =value =match)) + exo-type))))) (defn analyse-lambda* [analyse exo-type ?self ?arg ?body] ;; (prn 'analyse-lambda ?self ?arg ?body) @@ -298,7 +294,7 @@ (|do [[=scope =captured =body] (&&lambda/with-lambda ?self exo-type ?arg ?arg-t (&&/analyse-1 analyse ?return-t ?body))] - (return (&/V "Expression" (&/T (&/V "lambda" (&/T =scope =captured =body)) exo-type)))) + (return (&/T (&/V "lambda" (&/T =scope =captured =body)) exo-type))) [_] (fail (str "[Analyser Error] Functions require function types: " @@ -323,19 +319,19 @@ (matchv ::M/objects [dtype] [["lux;BoundT" _]] (matchv ::M/objects [output] - [["Expression" [_expr _]]] + [[_expr _]] ;; (|do [_ (&type/set-var ?id (&/V "lux;BoundT" _arg))] - ;; (return (&/V "Expression" (&/T _expr exo-type)))) - (return (&/V "Expression" (&/T _expr exo-type))) + ;; (return (&/T _expr exo-type))) + (return (&/T _expr exo-type)) ) [_] (fail (str "[Analyser Error] Can't use type-var in any type-specific way inside polymorphic functions: " ?id ":" _arg " " (&type/show-type dtype))))) (matchv ::M/objects [output] - [["Expression" [_expr _]]] + [[_expr _]] ;; (|do [_ (&type/set-var ?id (&/V "lux;BoundT" _arg))] - ;; (return (&/V "Expression" (&/T _expr exo-type)))) - (return (&/V "Expression" (&/T _expr exo-type))) + ;; (return (&/T _expr exo-type))) + (return (&/T _expr exo-type)) ))))))) [_] @@ -358,7 +354,7 @@ ;; (|do [dtype (&type/deref ?id)] ;; (fail (str "[Analyser Error] Can't use type-var in any type-specific way inside polymorphic functions: " ?id ":" _arg " " (&type/show-type dtype)))) ;; (return output))))))) - + ;; [_] ;; (|do [exo-type* (&type/actual-type exo-type)] ;; (analyse-lambda* analyse exo-type* ?self ?arg ?body)) @@ -391,7 +387,7 @@ _ (&&module/define module-name ?name def-data) ;; :let [_ (prn 'analyse-def/_3)] ] - (return (&/|list (&/V "Statement" (&/V "def" (&/T ?name =value def-data))))))))) + (return (&/|list (&/V "def" (&/T ?name =value def-data)))))))) (defn analyse-declare-macro [analyse ?name] (|do [module-name &/get-module-name @@ -400,7 +396,7 @@ (defn analyse-declare-macro [analyse ?name] (|do [module-name &/get-module-name] - (return (&/|list (&/V "Statement" (&/V "declare-macro" (&/T module-name ?name))))))) + (return (&/|list (&/V "declare-macro" (&/T module-name ?name)))))) (defn analyse-import [analyse exo-type ?path] (return (&/|list))) @@ -420,13 +416,13 @@ ;; :let [_ (println "analyse-check#5")] ] (matchv ::M/objects [=value] - [["Expression" [?expr ?expr-type]]] - (return (&/|list (&/V "Expression" (&/T ?expr ==type))))))) + [[?expr ?expr-type]] + (return (&/|list (&/T ?expr ==type)))))) (defn analyse-coerce [analyse eval! exo-type ?type ?value] (|do [=type (&&/analyse-1 analyse &type/Type ?type) ==type (eval! =type) =value (&&/analyse-1 analyse ==type ?value)] (matchv ::M/objects [=value] - [["Expression" [?expr ?expr-type]]] - (return (&/|list (&/V "Expression" (&/T ?expr ==type))))))) + [[?expr ?expr-type]] + (return (&/|list (&/T ?expr ==type)))))) diff --git a/src/lux/analyser/module.clj b/src/lux/analyser/module.clj index 6f82d9b6f..b9a92c120 100644 --- a/src/lux/analyser/module.clj +++ b/src/lux/analyser/module.clj @@ -21,7 +21,7 @@ (&/set$ &/$ENVS (&/|list (&/update$ &/$LOCALS (fn [locals] (&/update$ &/$MAPPINGS (fn [mappings] (&/|put (str "" &/+name-separator+ name) - (&/V "Expression" (&/T (&/V "global" (&/T module name)) &type/$Void)) + (&/T (&/V "global" (&/T module name)) &type/$Void) mappings)) locals)) ?env)))) diff --git a/src/lux/compiler.clj b/src/lux/compiler.clj index e6879f4da..4f8ed727f 100644 --- a/src/lux/compiler.clj +++ b/src/lux/compiler.clj @@ -31,7 +31,7 @@ (defn ^:private compile-expression [syntax] ;; (prn 'compile-expression (aget syntax 0)) (matchv ::M/objects [syntax] - [["Expression" [?form ?type]]] + [[?form ?type]] (do ;; (prn 'compile-expression2 (aget ?form 0)) (matchv ::M/objects [?form] [["bool" ?value]] @@ -305,30 +305,22 @@ [["jvm-program" ?body]] (&&host/compile-jvm-program compile-expression ?type ?body) )) - - [_] - (fail "[Compiler Error] Can't compile statements as expressions."))) + )) (defn ^:private compile-statement [syntax] ;; (prn 'compile-statement syntax) (matchv ::M/objects [syntax] - [["Statement" ?form]] - (do ;; (prn 'compile-statement (aget syntax 0) (aget ?form 0)) - (matchv ::M/objects [?form] - [["def" [?name ?body ?def-data]]] - (&&lux/compile-def compile-expression ?name ?body ?def-data) - - [["declare-macro" [?module ?name]]] - (&&lux/compile-declare-macro compile-expression ?module ?name) - - [["jvm-interface" [?package ?name ?methods]]] - (&&host/compile-jvm-interface compile-expression ?package ?name ?methods) + [["def" [?name ?body ?def-data]]] + (&&lux/compile-def compile-expression ?name ?body ?def-data) - [["jvm-class" [?package ?name ?super-class ?fields ?methods]]] - (&&host/compile-jvm-class compile-expression ?package ?name ?super-class ?fields ?methods))) + [["declare-macro" [?module ?name]]] + (&&lux/compile-declare-macro compile-expression ?module ?name) + + [["jvm-interface" [?package ?name ?methods]]] + (&&host/compile-jvm-interface compile-expression ?package ?name ?methods) - [_] - (fail "[Compiler Error] Can't compile expressions as top-level forms."))) + [["jvm-class" [?package ?name ?super-class ?fields ?methods]]] + (&&host/compile-jvm-class compile-expression ?package ?name ?super-class ?fields ?methods))) (defn ^:private eval! [expr] ;; (prn 'eval! (aget expr 0)) diff --git a/src/lux/compiler/base.clj b/src/lux/compiler/base.clj index 7a75917d0..1023e086e 100644 --- a/src/lux/compiler/base.clj +++ b/src/lux/compiler/base.clj @@ -34,7 +34,7 @@ (defn total-locals [expr] ;; (prn 'total-locals1 (aget expr 0)) (matchv ::M/objects [expr] - [["Expression" [?struct ?type]]] + [[?struct ?type]] (do ;; (prn 'total-locals2 (aget ?struct 0)) (matchv ::M/objects [?struct] [["case" [?variant ?base-register ?num-registers ?branches]]] diff --git a/src/lux/compiler/lambda.clj b/src/lux/compiler/lambda.clj index f13578653..cfea13a73 100644 --- a/src/lux/compiler/lambda.clj +++ b/src/lux/compiler/lambda.clj @@ -43,7 +43,7 @@ ;; _ (prn 'add-lambda-<init> class-name ?captured-id) ]) (matchv ::M/objects [?name+?captured] - [[?name ["Expression" [["captured" [_ ?captured-id ?source]] _]]]]) + [[?name [["captured" [_ ?captured-id ?source]] _]]]) (doseq [?name+?captured (&/->seq env)]))) (.visitInsn Opcodes/RETURN) (.visitMaxs 0 0) @@ -86,32 +86,32 @@ (.visitInsn Opcodes/DUP)) ;; _ (prn 'closed-over/pre ;; (&/->seq (&/|map #(matchv ::M/objects [(&/|second %1)] - ;; [["Expression" [["captured" [_ ?cid _]] _]]] + ;; [[["captured" [_ ?cid _]] _]] ;; ?cid) ;; closed-over))) ;; _ (prn 'closed-over/post ;; (->> closed-over ;; &/->seq ;; (sort #(matchv ::M/objects [(&/|second %1) (&/|second %2)] - ;; [["Expression" [["captured" [_ ?cid1 _]] _]] - ;; ["Expression" [["captured" [_ ?cid2 _]] _]]] + ;; [[["captured" [_ ?cid1 _]] _] + ;; [["captured" [_ ?cid2 _]] _]] ;; (< ?cid1 ?cid2))) ;; &/->list ;; (&/|map #(matchv ::M/objects [(&/|second %1)] - ;; [["Expression" [["captured" [_ ?cid _]] _]]] + ;; [[["captured" [_ ?cid _]] _]] ;; ?cid)) ;; &/->seq)) ] _ (->> closed-over &/->seq (sort #(matchv ::M/objects [(&/|second %1) (&/|second %2)] - [["Expression" [["captured" [_ ?cid1 _]] _]] - ["Expression" [["captured" [_ ?cid2 _]] _]]] + [[["captured" [_ ?cid1 _]] _] + [["captured" [_ ?cid2 _]] _]] (< ?cid1 ?cid2))) &/->list (&/map% (fn [?name+?captured] (matchv ::M/objects [?name+?captured] - [[?name ["Expression" [["captured" [_ _ ?source]] _]]]] + [[?name [["captured" [_ _ ?source]] _]]] (do ;; (prn '?source (aget ?source 1 0 0) ;; (cond (= "captured" (aget ?source 1 0 0)) ;; ["captured" (aget ?source 1 0 1 1)] @@ -136,7 +136,7 @@ (.visitEnd)) (->> (let [captured-name (str &&/closure-prefix ?captured-id)]) (matchv ::M/objects [?name+?captured] - [[?name ["Expression" [["captured" [_ ?captured-id ?source]] _]]]]) + [[?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)) |