aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-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
5 files changed, 107 insertions, 104 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))