aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/lux.lux126
-rw-r--r--source/lux/data/text.lux3
-rw-r--r--source/lux/math.lux2
-rw-r--r--source/lux/meta/lux.lux69
-rw-r--r--source/lux/meta/syntax.lux11
-rw-r--r--src/lux/analyser.clj7
-rw-r--r--src/lux/analyser/base.clj4
-rw-r--r--src/lux/analyser/host.clj10
-rw-r--r--src/lux/analyser/lux.clj66
-rw-r--r--src/lux/compiler/lux.clj4
-rw-r--r--src/lux/type.clj12
11 files changed, 167 insertions, 147 deletions
diff --git a/source/lux.lux b/source/lux.lux
index 76ca9517f..c1e7b0046 100644
--- a/source/lux.lux
+++ b/source/lux.lux
@@ -305,7 +305,6 @@
Ident
#Nil))))))))
(_lux_export DefData')
-(_lux_declare-tags [#ValueD #TypeD #MacroD #AliasD] DefData')
## (deftype LuxVar
## (| (#Local Int)
@@ -409,6 +408,12 @@
ASTList))))
(_lux_export Macro)
+(_lux_def DefData
+ (#NamedT ["lux" "DefData"]
+ (#AppT DefData' Macro)))
+(_lux_export DefData)
+(_lux_declare-tags [#ValueD #TypeD #MacroD #AliasD] DefData)
+
## Base functions & macros
## (def _cursor
## Cursor
@@ -925,13 +930,12 @@
(reverse tokens)))))))
(defmacro' (lambda' tokens)
- (let'' [name tokens'] (_lux_: (, Text ($' List AST))
- (_lux_case tokens
- (#Cons [[_ (#SymbolS ["" name])] tokens'])
- [name tokens']
+ (let'' [name tokens'] (_lux_case tokens
+ (#Cons [[_ (#SymbolS ["" name])] tokens'])
+ [name tokens']
- _
- ["" tokens]))
+ _
+ ["" tokens])
(_lux_case tokens'
(#Cons [[_ (#TupleS args)] (#Cons [body #Nil])])
(_lux_case args
@@ -1277,7 +1281,7 @@
(def''' (untemplate replace? subst token)
(-> Bool Text AST ($' Lux AST))
- (_lux_case (_lux_: (, Bool AST) [replace? token])
+ (_lux_case [replace? token]
[_ [_ (#BoolS value)]]
(return (wrap-meta (form$ (@list (tag$ ["lux" "BoolS"]) (bool$ value)))))
@@ -1470,9 +1474,8 @@
(defmacro' #export (do-template tokens)
(_lux_case tokens
(#Cons [[_ (#TupleS bindings)] (#Cons [[_ (#TupleS templates)] data])])
- (_lux_case (_lux_: (, ($' Maybe ($' List Text)) ($' Maybe ($' List ($' List AST))))
- [(map% Maybe/Monad get-name bindings)
- (map% Maybe/Monad tuple->list data)])
+ (_lux_case [(map% Maybe/Monad get-name bindings)
+ (map% Maybe/Monad tuple->list data)]
[(#Some bindings') (#Some data')]
(let' [apply (_lux_: (-> RepEnv ($' List AST))
(lambda' [env] (map (apply-template env) templates)))]
@@ -1553,7 +1556,7 @@
[$module (get module modules)
gdef (let' [{#module-aliases _ #defs bindings #imports _ #tags tags #types types} (_lux_: ($' Module Compiler) $module)]
(get name bindings))]
- (_lux_case (_lux_: (, Bool ($' DefData' Macro)) gdef)
+ (_lux_case (_lux_: (, Bool DefData) gdef)
[exported? (#MacroD macro')]
(if exported?
(#Some macro')
@@ -1801,20 +1804,18 @@
(fail "Wrong syntax for Rec")))
(defmacro' #export (deftype tokens)
- (let' [[export? tokens'] (: (, Bool (List AST))
- (_lux_case tokens
- (#Cons [_ (#TagS "" "export")] tokens')
- [true tokens']
-
- _
- [false tokens]))
- [rec? tokens'] (: (, Bool (List AST))
- (_lux_case tokens'
- (#Cons [_ (#TagS "" "rec")] tokens')
+ (let' [[export? tokens'] (_lux_case tokens
+ (#Cons [_ (#TagS "" "export")] tokens')
[true tokens']
_
- [false tokens']))
+ [false tokens])
+ [rec? tokens'] (_lux_case tokens'
+ (#Cons [_ (#TagS "" "rec")] tokens')
+ [true tokens']
+
+ _
+ [false tokens'])
parts (: (Maybe (, Text (List AST) AST))
(_lux_case tokens'
(#Cons [_ (#SymbolS "" name)] (#Cons type #Nil))
@@ -1885,13 +1886,12 @@
(fail "Wrong syntax for exec")))
(defmacro' (def' tokens)
- (let' [[export? tokens'] (: (, Bool (List AST))
- (_lux_case tokens
- (#Cons [_ (#TagS "" "export")] tokens')
- [true tokens']
+ (let' [[export? tokens'] (_lux_case tokens
+ (#Cons [_ (#TagS "" "export")] tokens')
+ [true tokens']
- _
- [false tokens]))
+ _
+ [false tokens])
parts (: (Maybe (, AST (List AST) (Maybe AST) AST))
(_lux_case tokens'
(#Cons [_ (#FormS (#Cons name args))] (#Cons type (#Cons body #Nil)))
@@ -2097,13 +2097,12 @@
(fail "Wrong syntax for lambda")))
(defmacro' #export (def tokens)
- (let [[export? tokens'] (: (, Bool (List AST))
- (case tokens
- (#Cons [_ (#TagS "" "export")] tokens')
- [true tokens']
+ (let [[export? tokens'] (case tokens
+ (#Cons [_ (#TagS "" "export")] tokens')
+ [true tokens']
- _
- [false tokens]))
+ _
+ [false tokens])
parts (: (Maybe (, AST (List AST) (Maybe AST) AST))
(case tokens'
(\ (@list [_ (#FormS (#Cons name args))] type body))
@@ -2145,13 +2144,12 @@
(fail "Wrong syntax for def"))))
(defmacro' #export (defmacro tokens)
- (let [[exported? tokens] (: (, Bool (List AST))
- (case tokens
- (\ (@list& [_ (#TagS ["" "export"])] tokens'))
- [true tokens']
+ (let [[exported? tokens] (case tokens
+ (\ (@list& [_ (#TagS ["" "export"])] tokens'))
+ [true tokens']
- _
- [false tokens]))
+ _
+ [false tokens])
name+args+body?? (: (Maybe (, Ident (List AST) AST))
(case tokens
(\ (@list [_ (#;FormS (@list& [_ (#SymbolS name)] args))] body))
@@ -2179,13 +2177,12 @@
(fail "Wrong syntax for defmacro"))))
(defmacro #export (defsig tokens)
- (let [[export? tokens'] (: (, Bool (List AST))
- (case tokens
- (\ (@list& [_ (#TagS "" "export")] tokens'))
- [true tokens']
+ (let [[export? tokens'] (case tokens
+ (\ (@list& [_ (#TagS "" "export")] tokens'))
+ [true tokens']
- _
- [false tokens]))
+ _
+ [false tokens])
?parts (: (Maybe (, Ident (List AST) (List AST)))
(case tokens'
(\ (@list& [_ (#FormS (@list& [_ (#SymbolS name)] args))] sigs))
@@ -2206,7 +2203,7 @@
(lambda [token]
(case token
(\ [_ (#FormS (@list [_ (#SymbolS _ "_lux_:")] type [_ (#SymbolS ["" name])]))])
- (wrap (: (, Text AST) [name type]))
+ (wrap [name type])
_
(fail "Signatures require typed members!"))))
@@ -2530,7 +2527,7 @@
(\ [_ (#FormS (@list [_ (#SymbolS _ "_lux_def")] [_ (#SymbolS "" tag-name)] value))])
(case (get tag-name tag-mappings)
(#Some tag)
- (wrap (: (, AST AST) [tag value]))
+ (wrap [tag value])
_
(fail (text:++ "Unknown structure member: " tag-name)))
@@ -2541,13 +2538,12 @@
(wrap (@list (record$ members)))))
(defmacro #export (defstruct tokens)
- (let [[export? tokens'] (: (, Bool (List AST))
- (case tokens
- (\ (@list& [_ (#TagS "" "export")] tokens'))
- [true tokens']
+ (let [[export? tokens'] (case tokens
+ (\ (@list& [_ (#TagS "" "export")] tokens'))
+ [true tokens']
- _
- [false tokens]))
+ _
+ [false tokens])
?parts (: (Maybe (, AST (List AST) AST (List AST)))
(case tokens'
(\ (@list& [_ (#FormS (@list& name args))] type defs))
@@ -2623,10 +2619,10 @@
(-> (List AST) (Lux (, (Maybe Text) (List AST))))
(case tokens
(\ (@list& [_ (#TagS "" "as")] [_ (#SymbolS "" alias)] tokens'))
- (return (: (, (Maybe Text) (List AST)) [(#Some alias) tokens']))
+ (return [(#Some alias) tokens'])
_
- (return (: (, (Maybe Text) (List AST)) [#None tokens]))))
+ (return [#None tokens])))
(def (parse-referrals tokens)
(-> (List AST) (Lux (, Referrals (List AST))))
@@ -2634,23 +2630,23 @@
(\ (@list& [_ (#TagS "" "refer")] referral tokens'))
(case referral
[_ (#TagS "" "all")]
- (return (: (, Referrals (List AST)) [#All tokens']))
+ (return [#All tokens'])
(\ [_ (#FormS (@list& [_ (#TagS "" "only")] defs))])
(do Lux/Monad
[defs' (extract-defs defs)]
- (return (: (, Referrals (List AST)) [(#Only defs') tokens'])))
+ (return [(#Only defs') tokens']))
(\ [_ (#FormS (@list& [_ (#TagS "" "exclude")] defs))])
(do Lux/Monad
[defs' (extract-defs defs)]
- (return (: (, Referrals (List AST)) [(#Exclude defs') tokens'])))
+ (return [(#Exclude defs') tokens']))
_
(fail "Incorrect syntax for referral."))
_
- (return (: (, Referrals (List AST)) [#Nothing tokens]))))
+ (return [#Nothing tokens])))
(def (extract-symbol syntax)
(-> AST (Lux Ident))
@@ -2667,10 +2663,10 @@
(\ (@list& [_ (#TagS "" "open")] [_ (#FormS (@list& [_ (#TextS prefix)] structs))] tokens'))
(do Lux/Monad
[structs' (map% Lux/Monad extract-symbol structs)]
- (return (: (, (Maybe Openings) (List AST)) [(#Some prefix structs') tokens'])))
+ (return [(#Some prefix structs') tokens']))
_
- (return (: (, (Maybe Openings) (List AST)) [#None tokens]))))
+ (return [#None tokens])))
(def (decorate-imports super-name tokens)
(-> Text (List AST) (Lux (List AST)))
@@ -2708,7 +2704,7 @@
#let [[openings extra] openings+extra]
extra (decorate-imports m-name extra)
sub-imports (parse-imports extra)]
- (wrap (case (: (, Referrals (Maybe Text) (Maybe Openings)) [referral alias openings])
+ (wrap (case [referral alias openings]
[#Nothing #None #None] sub-imports
_ (@list& [m-name alias referral openings] sub-imports))))
@@ -2741,7 +2737,7 @@
#cursor cursor}
(case (get module modules)
(#Some =module)
- (let [to-alias (map (: (-> (, Text (, Bool (DefData' (-> (List AST) (StateE Compiler (List AST))))))
+ (let [to-alias (map (: (-> (, Text (, Bool DefData))
(List Text))
(lambda [gdef]
(let [[name [export? _]] gdef]
diff --git a/source/lux/data/text.lux b/source/lux/data/text.lux
index 3fad6c7aa..6c3a3dfee 100644
--- a/source/lux/data/text.lux
+++ b/source/lux/data/text.lux
@@ -149,8 +149,7 @@
[_ in] (split 2 in)
post-idx (index-of "}" in)
[var post] (split post-idx in)
- #let [[_ post] (? (: (, Text Text) ["" ""])
- (split 1 post))]]
+ #let [[_ post] (? ["" ""] (split 1 post))]]
(wrap [pre var post])))
(do-template [<name> <type> <tag>]
diff --git a/source/lux/math.lux b/source/lux/math.lux
index 0f247cea8..a60ce512c 100644
--- a/source/lux/math.lux
+++ b/source/lux/math.lux
@@ -72,7 +72,7 @@
(def #export (lcm x y)
(-> Int Int Int)
- (case (: (, Int Int) [x y])
+ (case [x y]
(\or [_ 0] [0 _])
0
diff --git a/source/lux/meta/lux.lux b/source/lux/meta/lux.lux
index a34f92253..c71fd70b0 100644
--- a/source/lux/meta/lux.lux
+++ b/source/lux/meta/lux.lux
@@ -77,7 +77,7 @@
(#;Some $module)
(case (|> (: (Module Compiler) $module) (get@ #;defs) (get name))
(#;Some gdef)
- (case (: (, Bool (DefData' Macro)) gdef)
+ (case (: (, Bool DefData) gdef)
[exported? (#;MacroD macro')]
(if (or exported? (text:= module current-module))
(#;Some macro')
@@ -210,7 +210,7 @@
(case (get module (get@ #;modules state))
(#;Some =module)
(using List/Monad
- (#;Right [state (join (map (: (-> (, Text (, Bool (DefData' Macro)))
+ (#;Right [state (join (map (: (-> (, Text (, Bool DefData))
(List Text))
(lambda [gdef]
(let [[name [export? _]] gdef]
@@ -222,22 +222,6 @@
#;None
(#;Left ($ text:++ "Unknown module: " module))))
-(def (show-envs envs)
- (-> (List (Env Text (, LuxVar Type))) Text)
- (|> envs
- (F;map (lambda [env]
- (case env
- {#;name name #;inner-closures _ #;locals {#;counter _ #;mappings locals} #;closure _}
- ($ text:++ name ": " (|> locals
- (F;map (: (All [a] (-> (, Text a) Text))
- (lambda [b] (let [[label _] b] label))))
- (:: List/Functor)
- (interpose " ")
- (foldL text:++ text:unit))))))
- (:: List/Functor)
- (interpose "\n")
- (foldL text:++ text:unit)))
-
(def (try-both f x1 x2)
(All [a b]
(-> (-> a (Maybe b)) a a (Maybe b)))
@@ -245,7 +229,7 @@
#;None (f x2)
(#;Some y) (#;Some y)))
-(def (find-in-env name state)
+(def #export (find-in-env name state)
(-> Text Compiler (Maybe Type))
(case state
{#;source source #;modules modules
@@ -266,8 +250,8 @@
closure))))
envs)))
-(def (find-in-defs name state)
- (-> Ident Compiler (Maybe Type))
+(def (find-in-defs' name state)
+ (-> Ident Compiler (Maybe DefData))
(let [[v-prefix v-name] name
{#;source source #;modules modules
#;envs envs #;type-vars types #;host host
@@ -284,10 +268,23 @@
(#;Some [_ def-data])
(case def-data
- (#;TypeD value) (#;Some Type)
- (#;ValueD type _) (#;Some type)
- (#;MacroD m) (#;Some Macro)
- (#;AliasD name') (find-in-defs name' state))))))
+ (#;AliasD name') (find-in-defs' name' state)
+ _ (#;Some def-data)
+ )))
+ ))
+
+(def #export (find-in-defs name state)
+ (-> Ident Compiler (Maybe Type))
+ (case (find-in-defs' name state)
+ (#;Some def-data)
+ (case def-data
+ (#;ValueD [type value]) (#;Some type)
+ (#;MacroD _) (#;Some Macro)
+ (#;TypeD _) (#;Some Type)
+ _ #;None)
+
+ #;None
+ #;None))
(def #export (find-var-type name)
(-> Ident (Lux Type))
@@ -306,9 +303,21 @@
(#;Right [state struct-type])
_
- (let [{#;source source #;modules modules
- #;envs envs #;type-vars types #;host host
- #;seed seed #;eval? eval? #;expected expected
- #;cursor cursor} state]
- (#;Left ($ text:++ "Unknown var: " (ident->text name) "\n\n" (show-envs envs))))))))
+ (#;Left ($ text:++ "Unknown var: " (ident->text name)))))))
+ ))
+
+(def #export (find-type name)
+ (-> Ident (Lux Type))
+ (do Lux/Monad
+ [name' (normalize name)]
+ (: (Lux Type)
+ (lambda [state]
+ (case (find-in-defs' name' state)
+ (#;Some def-data)
+ (case def-data
+ (#;TypeD type) (#;Right [state type])
+ _ (#;Left ($ text:++ "Definition is not a type: " (ident->text name))))
+
+ _
+ (#;Left ($ text:++ "Unknown var: " (ident->text name))))))
))
diff --git a/source/lux/meta/syntax.lux b/source/lux/meta/syntax.lux
index 3d62bba2e..01acefd36 100644
--- a/source/lux/meta/syntax.lux
+++ b/source/lux/meta/syntax.lux
@@ -209,13 +209,12 @@
## [Syntax]
(defmacro #export (defsyntax tokens)
- (let [[exported? tokens] (: (, Bool (List AST))
- (case tokens
- (\ (@list& [_ (#;TagS ["" "export"])] tokens'))
- [true tokens']
+ (let [[exported? tokens] (case tokens
+ (\ (@list& [_ (#;TagS ["" "export"])] tokens'))
+ [true tokens']
- _
- [false tokens]))]
+ _
+ [false tokens])]
(case tokens
(\ (@list [_ (#;FormS (@list& [_ (#;SymbolS ["" name])] args))]
body))
diff --git a/src/lux/analyser.clj b/src/lux/analyser.clj
index 552ccd77d..fbc360628 100644
--- a/src/lux/analyser.clj
+++ b/src/lux/analyser.clj
@@ -529,8 +529,11 @@
(fn [state]
(|case (try ((aba1 analyse eval! compile-module compile-token exo-type ?token) state)
(catch Error e
- (prn e)
- (assert false (prn-str 'analyse-basic-ast (&/show-ast token)))))
+ (prn 'analyse-basic-ast/Error-1 e)
+ (prn 'analyse-basic-ast/Error-2 (&/show-ast token))
+ (prn 'analyse-basic-ast/Error-3 (&type/show-type exo-type))
+ (throw e))
+ )
(&/$Right state* output)
(return* state* output)
diff --git a/src/lux/analyser/base.clj b/src/lux/analyser/base.clj
index 8c52748d7..414d005f1 100644
--- a/src/lux/analyser/base.clj
+++ b/src/lux/analyser/base.clj
@@ -126,9 +126,9 @@
)
;; [Exports]
-(defn expr-type [syntax+]
+(defn expr-type* [syntax+]
(|let [[_ type] syntax+]
- (return type)))
+ type))
(defn analyse-1 [analyse exo-type elem]
(|do [output (analyse exo-type elem)]
diff --git a/src/lux/analyser/host.clj b/src/lux/analyser/host.clj
index c6c5cb39b..0b333ce07 100644
--- a/src/lux/analyser/host.clj
+++ b/src/lux/analyser/host.clj
@@ -209,14 +209,12 @@
(defn analyse-jvm-aastore [analyse ?array ?idx ?elem]
(|do [=array (analyse-1+ analyse ?array)
- =elem (analyse-1+ analyse ?elem)
- =array-type (&&/expr-type =array)]
- (return (&/|list (&/T (&/V &&/$jvm-aastore (&/T =array ?idx =elem)) =array-type)))))
+ =elem (analyse-1+ analyse ?elem)]
+ (return (&/|list (&/T (&/V &&/$jvm-aastore (&/T =array ?idx =elem)) (&&/expr-type* =array))))))
(defn analyse-jvm-aaload [analyse ?array ?idx]
- (|do [=array (analyse-1+ analyse ?array)
- =array-type (&&/expr-type =array)]
- (return (&/|list (&/T (&/V &&/$jvm-aaload (&/T =array ?idx)) =array-type)))))
+ (|do [=array (analyse-1+ analyse ?array)]
+ (return (&/|list (&/T (&/V &&/$jvm-aaload (&/T =array ?idx)) (&&/expr-type* =array))))))
(defn ^:private analyse-modifiers [modifiers]
(&/fold% (fn [so-far modif]
diff --git a/src/lux/analyser/lux.clj b/src/lux/analyser/lux.clj
index 375c82f27..62202c1c9 100644
--- a/src/lux/analyser/lux.clj
+++ b/src/lux/analyser/lux.clj
@@ -28,23 +28,31 @@
;; [Exports]
(defn analyse-tuple [analyse exo-type ?elems]
- (|do [exo-type* (&type/actual-type exo-type)]
- (|case exo-type*
- (&/$TupleT ?members)
- (|do [=elems (&/map2% (fn [elem-t elem]
- (&&/analyse-1 analyse elem-t elem))
- ?members ?elems)]
+ (|do [unknown? (&type/unknown? exo-type)]
+ (if unknown?
+ (|do [=elems (&/map% #(|do [=analysis (analyse-1+ analyse %)]
+ (return =analysis))
+ ?elems)
+ _ (&type/check exo-type (&/V &/$TupleT (&/|map &&/expr-type* =elems)))]
(return (&/|list (&/T (&/V &&/$tuple =elems)
exo-type))))
+ (|do [exo-type* (&type/actual-type exo-type)]
+ (|case exo-type*
+ (&/$TupleT ?members)
+ (|do [=elems (&/map2% (fn [elem-t elem]
+ (&&/analyse-1 analyse elem-t elem))
+ ?members ?elems)]
+ (return (&/|list (&/T (&/V &&/$tuple =elems)
+ exo-type))))
+
+ (&/$UnivQ _)
+ (&type/with-var
+ (fn [$var]
+ (|do [exo-type** (&type/apply-type exo-type* $var)]
+ (analyse-tuple analyse exo-type** ?elems))))
- (&/$UnivQ _)
- (&type/with-var
- (fn [$var]
- (|do [exo-type** (&type/apply-type exo-type* $var)]
- (analyse-tuple analyse exo-type** ?elems))))
-
- _
- (fail (str "[Analyser Error] Tuples require tuple-types: " (&type/show-type exo-type*))))))
+ _
+ (fail (str "[Analyser Error] Tuples require tuple-types: " (&type/show-type exo-type*))))))))
(defn ^:private analyse-variant-body [analyse exo-type ?values]
(|do [output (|case ?values
@@ -206,8 +214,7 @@
(->> top-outer (&/get$ &/$closure) (&/get$ &/$mappings) (&/|get name)))
(&/|list))
(&/|reverse inner) scopes)]
- ((|do [btype (&&/expr-type =local)
- _ (&type/check exo-type btype)]
+ ((|do [_ (&type/check exo-type (&&/expr-type* =local))]
(return (&/|list =local)))
(&/set$ &/$envs (&/|++ inner* outer) state))))
))))
@@ -271,8 +278,8 @@
macro-expansion #(-> macro (.apply ?args) (.apply %))
;; :let [_ (prn 'MACRO-EXPAND|POST (&/ident->text real-name))]
;; :let [_ (when (or (= "defsig" (aget real-name 1))
- ;; ;; (= "type" (aget real-name 1))
- ;; ;; (= &&/$struct r-name)
+ ;; ;; (= "..?" (aget real-name 1))
+ ;; ;; (= "try$" (aget real-name 1))
;; )
;; (->> (&/|map &/show-ast macro-expansion)
;; (&/|interpose "\n")
@@ -297,8 +304,7 @@
_ (&/assert! (> num-branches 0) "[Analyser Error] Can't have empty branches in \"case'\" expression.")
_ (&/assert! (even? num-branches) "[Analyser Error] Unbalanced branches in \"case'\" expression.")
=value (analyse-1+ analyse ?value)
- =value-type (&&/expr-type =value)
- =match (&&case/analyse-branches analyse exo-type =value-type (&/|as-pairs ?branches))]
+ =match (&&case/analyse-branches analyse exo-type (&&/expr-type* =value) (&/|as-pairs ?branches))]
(return (&/|list (&/T (&/V &&/$case (&/T =value =match))
exo-type)))))
@@ -376,11 +382,10 @@
(if ?
(fail (str "[Analyser Error] Can't redefine " (str module-name ";" ?name)))
(|do [=value (&/with-scope ?name
- (analyse-1+ analyse ?value))
- =value-type (&&/expr-type =value)]
+ (analyse-1+ analyse ?value))]
(|case =value
[(&&/$var (&/$Global ?r-module ?r-name)) _]
- (|do [_ (&&module/def-alias module-name ?name ?r-module ?r-name =value-type)
+ (|do [_ (&&module/def-alias module-name ?name ?r-module ?r-name (&&/expr-type* =value))
;; :let [_ (println 'analyse-def/ALIAS (str module-name ";" ?name) '=> (str ?r-module ";" ?r-name))
;; _ (println)]
]
@@ -412,16 +417,17 @@
_ (&&module/declare-tags module-name tags def-type)]
(return (&/|list))))
-(defn analyse-import [analyse compile-module compile-token ?path]
+(defn analyse-import [analyse compile-module compile-token path]
+ ;; (prn 'analyse-import path)
(|do [module-name &/get-module-name
- _ (if (= module-name ?path)
- (fail (str "[Analyser Error] Module can't import itself: " ?path))
+ _ (if (= module-name path)
+ (fail (str "[Analyser Error] Module can't import itself: " path))
(return nil))]
(&/save-module
- (|do [already-compiled? (&&module/exists? ?path)
- ;; :let [_ (prn 'analyse-import module-name ?path already-compiled?)]
- _ (&&module/add-import ?path)
- _ (&/when% (not already-compiled?) (compile-module ?path))]
+ (|do [already-compiled? (&&module/exists? path)
+ ;; :let [_ (prn 'analyse-import module-name path already-compiled?)]
+ _ (&&module/add-import path)
+ _ (&/when% (not already-compiled?) (compile-module path))]
(return (&/|list))))))
(defn analyse-export [analyse compile-token name]
diff --git a/src/lux/compiler/lux.clj b/src/lux/compiler/lux.clj
index 6a02ed21d..c17d10494 100644
--- a/src/lux/compiler/lux.clj
+++ b/src/lux/compiler/lux.clj
@@ -176,8 +176,8 @@
)))
(defn compile-def [compile ?name ?body]
- (|do [=value-type (&a/expr-type ?body)
- :let [def-type (cond (&type/type= &type/Type =value-type)
+ (|do [:let [=value-type (&a/expr-type* ?body)
+ def-type (cond (&type/type= &type/Type =value-type)
"type"
:else
diff --git a/src/lux/type.clj b/src/lux/type.clj
index 8300d470c..f067867d8 100644
--- a/src/lux/type.clj
+++ b/src/lux/type.clj
@@ -395,7 +395,7 @@
(->> state (&/get$ &/$type-vars) (&/get$ &/$mappings)))]
(fn [state]
(return* (&/update$ &/$type-vars #(->> %
- (&/update$ &/$counter dec)
+ ;; (&/update$ &/$counter dec)
(&/set$ &/$mappings (&/|remove id mappings*)))
state)
nil)))
@@ -949,3 +949,13 @@
_
(fail (str "[Type Error] Type is not named: " (show-type type)))
))
+
+(defn unknown? [type]
+ "(-> Type (Lux Bool))"
+ (|case type
+ (&/$VarT id)
+ (|do [? (bound? id)]
+ (return (not ?)))
+
+ _
+ (return false)))