diff options
author | Eduardo Julian | 2021-08-19 04:59:06 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-08-19 04:59:06 -0400 |
commit | d772fe99d5d4990c6774481fb64d12280cdb6aae (patch) | |
tree | 209a2ce3b8e896be15db40bc58db830a5304b4f9 /stdlib/source/library | |
parent | e00ba096c8837abe85d366e0c1293c09dbe84d81 (diff) |
Enabled compile-time code evaluation (i.e. "eval" function).
Diffstat (limited to '')
38 files changed, 271 insertions, 433 deletions
diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index 6554978c9..6c1335fe9 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -691,33 +691,55 @@ ... #seed Nat ... #scope_type_vars (List Nat) ... #extensions Any +... #eval (-> Type Code (-> Lux (Either Text [Lux Any]))) ... #host Any}) ("lux def type tagged" Lux (#Named ["library/lux" "Lux"] - (#Product ... "lux.info" - Info - (#Product ... "lux.source" - Source - (#Product ... "lux.location" - Location - (#Product ... "lux.current_module" - (#Apply Text Maybe) - (#Product ... "lux.modules" - (#Apply (#Product Text Module) List) - (#Product ... "lux.scopes" - (#Apply Scope List) - (#Product ... "lux.type_context" - Type_Context - (#Product ... "lux.expected" - (#Apply Type Maybe) - (#Product ... "lux.seed" - Nat - (#Product ... scope_type_vars - (#Apply Nat List) - (#Product ... extensions - Any - ... "lux.host" - Any)))))))))))) + ({Lux + (#Apply Nothing + (#UnivQ #End + (#Product + ... info + Info + (#Product + ... source + Source + (#Product + ... location + Location + (#Product + ... current_module + (#Apply Text Maybe) + (#Product + ... modules + (#Apply (#Product Text Module) List) + (#Product + ... scopes + (#Apply Scope List) + (#Product + ... type_context + Type_Context + (#Product + ... expected + (#Apply Type Maybe) + (#Product + ... seed + Nat + (#Product + ... scope_type_vars + (#Apply Nat List) + (#Product + ... extensions + Any + (#Product + ... eval + (#Function Type + (#Function Code + (#Function Lux + (#Sum Text (#Product Lux Any))))) + ... host + Any))))))))))))))} + (#Apply (#Parameter 1) (#Parameter 0)))) (record$ (#Item [(tag$ ["library/lux" "doc"]) (text$ ("lux text concat" ("lux text concat" "Represents the state of the Lux compiler during a run." __paragraph) @@ -725,7 +747,7 @@ ("lux text concat" "It is provided to macros during their invocation, so they can access compiler data." __paragraph) "Caveat emptor: Avoid fiddling with it, unless you know what you're doing.")))] #End)) - ["info" "source" "location" "current_module" "modules" "scopes" "type_context" "expected" "seed" "scope_type_vars" "extensions" "host"] + ["info" "source" "location" "current_module" "modules" "scopes" "type_context" "expected" "seed" "scope_type_vars" "extensions" "eval" "host"] #1) ... (type: .public (Meta a) @@ -1223,7 +1245,7 @@ (failure "Wrong syntax for Ex")} tokens))) -(def:'' .private (list\reverse list) +(def:'' .private (list\reversed list) #End (All [a] (#Function ($' List a) ($' List a))) (list\fold ("lux type check" (All [a] (#Function a (#Function ($' List a) ($' List a)))) @@ -1248,7 +1270,7 @@ _ (failure "Wrong syntax for ->")} - (list\reverse tokens))) + (list\reversed tokens))) (macro:' .public (list xs) (#Item [(tag$ ["library/lux" "doc"]) @@ -1261,7 +1283,7 @@ (#Item (tuple$ (#Item [head (#Item [tail #End])])) #End)))) (tag$ ["library/lux" "End"]) - (list\reverse xs)) + (list\reversed xs)) #End))) (macro:' .public (list& xs) @@ -1281,7 +1303,7 @@ _ (failure "Wrong syntax for list&")} - (list\reverse xs))) + (list\reversed xs))) (macro:' .public (Variant tokens) (#Item [(tag$ ["library/lux" "doc"]) @@ -1300,7 +1322,7 @@ (in_meta (list (list\fold (function'' [left right] (form$ (list (tag$ ["library/lux" "Sum"]) left right))) last prevs)))} - (list\reverse tokens))) + (list\reversed tokens))) (macro:' .public (Tuple tokens) (#Item [(tag$ ["library/lux" "doc"]) @@ -1319,7 +1341,7 @@ (in_meta (list (list\fold (function'' [left right] (form$ (list (tag$ ["library/lux" "Product"]) left right))) last prevs)))} - (list\reverse tokens))) + (list\reversed tokens))) (macro:' .private (function' tokens) (let'' [name tokens'] ({(#Item [[_ (#Identifier ["" name])] tokens']) @@ -1340,7 +1362,7 @@ arg)) body'))) body - (list\reverse targs))))))} + (list\reversed targs))))))} args) _ @@ -1412,7 +1434,7 @@ (form$ (list (record$ (list [label body])) value))} binding))) body - (list\reverse (pairs bindings))))) + (list\reversed (pairs bindings))))) _ (failure "Wrong syntax for let'")} @@ -1512,7 +1534,7 @@ _ (failure "Wrong syntax for $_")} - (list\reverse tokens')) + (list\reversed tokens')) _ (failure "Wrong syntax for $_")} @@ -1588,7 +1610,7 @@ value))} var)))) body - (list\reverse (pairs bindings)))] + (list\reversed (pairs bindings)))] (in_meta (list (form$ (list (record$ (list [(record$ (list [(tag$ ["library/lux" "in"]) g!in] [(tag$ ["library/lux" "bind"]) g!bind])) body'])) monad))))) @@ -1690,7 +1712,7 @@ {#info info #source source #current_module _ #modules modules #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} state] + #scope_type_vars scope_type_vars #eval _eval} state] ({(#Some {#module_hash _ #module_aliases _ #definitions definitions #imports _ #tags tags #types types #module_annotations _ #module_state _}) ({(#Some constant) ({(#Left real_name) @@ -1749,7 +1771,7 @@ leftI)) lastO inits))} - (list\reverse elems)) + (list\reversed elems)) #0 (do meta_monad [=elems (monad\map meta_monad untemplated elems)] @@ -1874,7 +1896,7 @@ ({{#info info #source source #current_module current_module #modules modules #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} + #scope_type_vars scope_type_vars #eval _eval} ({(#Some module_name) (#Right [state module_name]) @@ -1979,7 +2001,7 @@ _ (failure "Wrong syntax for <|")} - (list\reverse tokens))) + (list\reversed tokens))) (def:''' .private (function\composite f g) (list [(tag$ ["library/lux" "doc"]) @@ -2101,7 +2123,7 @@ #End (All [a] (-> ($' List ($' List a)) ($' List a))) - (list\fold list\compose #End (list\reverse xs))) + (list\fold list\compose #End (list\reversed xs))) (macro:' .public (template tokens) (list [(tag$ ["library/lux" "doc"]) @@ -2298,7 +2320,7 @@ #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} + #scope_type_vars scope_type_vars #eval _eval} (#Right state (macro' modules current_module module name))} state))))) @@ -2563,12 +2585,12 @@ #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} + #scope_type_vars scope_type_vars #eval _eval} (#Right {#info info #source source #current_module _ #modules modules #scopes scopes #type_context types #host host #seed ("lux i64 +" 1 seed) #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} + #scope_type_vars scope_type_vars #eval _eval} (local_identifier$ ($_ text\compose "__gensym__" prefix (nat\encode seed))))} state)) @@ -2607,7 +2629,7 @@ _ (failure "Wrong syntax for exec")} - (list\reverse tokens))) + (list\reversed tokens))) (macro:' .private (def:' tokens) (let' [parts (: (Maybe [Code Code (List Code) (Maybe Code) Code]) @@ -2687,14 +2709,14 @@ ($_ text\compose "(" (|> xs (list\map code\encode) (list\interposed " ") - list\reverse + list\reversed (list\fold text\compose "")) ")") [_ (#Tuple xs)] ($_ text\compose "[" (|> xs (list\map code\encode) (list\interposed " ") - list\reverse + list\reversed (list\fold text\compose "")) "]") [_ (#Record kvs)] @@ -2702,7 +2724,7 @@ (list\map (function' [kv] ({[k v] ($_ text\compose (code\encode k) " " (code\encode v))} kv))) (list\interposed " ") - list\reverse + list\reversed (list\fold text\compose "")) "}")} code)) @@ -2735,7 +2757,7 @@ (failure ($_ text\compose "'lux.case' expects an even number of tokens: " (|> branches (list\map code\encode) (list\interposed " ") - list\reverse + list\reversed (list\fold text\compose ""))))} branches)) @@ -2832,7 +2854,7 @@ (case tokens (^ (list [_ (#Tuple bindings)] body)) (if (multiple? 2 (list\size bindings)) - (|> bindings pairs list\reverse + (|> bindings pairs list\reversed (list\fold (: (-> [Code Code] Code Code) (function' [lr body'] (let' [[l r] lr] @@ -2874,7 +2896,7 @@ (` ([(~ g!name) (~ g!blank)] (.case (~ g!blank) (~ arg) (~ body'))))))))] (in_meta (list (nest (..local_identifier$ g!name) head - (list\fold (nest g!blank) body (list\reverse tail)))))) + (list\fold (nest g!blank) body (list\reversed tail)))))) #None (failure "Wrong syntax for function"))) @@ -3261,7 +3283,7 @@ (template [<name> <form> <message> <documentation>] [(macro: .public (<name> tokens) {#.doc <documentation>} - (case (list\reverse tokens) + (case (list\reversed tokens) (^ (list& last init)) (in_meta (list (list\fold (: (-> Code Code Code) (function (_ pre post) (` <form>))) @@ -3458,7 +3480,7 @@ (let [{#info info #source source #current_module _ #modules modules #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} state] + #scope_type_vars scope_type_vars #eval _eval} state] (case (plist\value name modules) (#Some module) (#Right state module) @@ -3515,7 +3537,7 @@ (let [{#info info #source source #current_module _ #modules modules #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} state] + #scope_type_vars scope_type_vars #eval _eval} state] (case expected (#Some type) (#Right state type) @@ -4032,9 +4054,9 @@ jumps ("lux i64 -" 1 relatives)] (if (n/< (list\size parts) jumps) (let [prefix (|> parts - list\reverse + list\reversed (list\after jumps) - list\reverse + list\reversed (text\interposed ..module_separator)) clean ("lux text clip" relatives (|> module "lux text size" ("lux i64 -" relatives)) module) output (case ("lux text size" clean) @@ -4128,7 +4150,7 @@ {#info info #source source #current_module current_module #modules modules #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} + #scope_type_vars scope_type_vars #eval _eval} [current_module modules])] (case (plist\value module modules) (#Some =module) @@ -4196,7 +4218,7 @@ {#info info #source source #current_module _ #modules modules #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} + #scope_type_vars scope_type_vars #eval _eval} (list\one (: (-> Scope (Maybe Type)) (function (_ env) (case env @@ -4219,7 +4241,7 @@ {#info info #source source #current_module _ #modules modules #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} state] + #scope_type_vars scope_type_vars #eval _eval} state] (case (plist\value v_module modules) #None #None @@ -4243,7 +4265,7 @@ {#info info #source source #current_module _ #modules modules #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} state] + #scope_type_vars scope_type_vars #eval _eval} state] (case (plist\value v_module modules) #None (#Left (text\compose "Unknown definition: " (name\encode name))) @@ -4301,7 +4323,7 @@ (let [{#info _ #source _ #current_module _ #modules _ #scopes _ #type_context type_context #host _ #seed _ #expected _ #location _ #extensions extensions - #scope_type_vars _} compiler + #scope_type_vars _ #eval _eval} compiler {#ex_counter _ #var_counter _ #var_bindings var_bindings} type_context] (case (type_variable type_id var_bindings) #None @@ -4337,16 +4359,16 @@ name _ - ($_ text\compose "(" name " " (|> params (list\map type\encode) (list\interposed " ") list\reverse (list\fold text\compose "")) ")")) + ($_ text\compose "(" name " " (|> params (list\map type\encode) (list\interposed " ") list\reversed (list\fold text\compose "")) ")")) (#Sum _) - ($_ text\compose "(Or " (|> (flat_variant type) (list\map type\encode) (list\interposed " ") list\reverse (list\fold text\compose "")) ")") + ($_ text\compose "(Or " (|> (flat_variant type) (list\map type\encode) (list\interposed " ") list\reversed (list\fold text\compose "")) ")") (#Product _) - ($_ text\compose "[" (|> (flat_tuple type) (list\map type\encode) (list\interposed " ") list\reverse (list\fold text\compose "")) "]") + ($_ text\compose "[" (|> (flat_tuple type) (list\map type\encode) (list\interposed " ") list\reversed (list\fold text\compose "")) "]") (#Function _) - ($_ text\compose "(-> " (|> (flat_lambda type) (list\map type\encode) (list\interposed " ") list\reverse (list\fold text\compose "")) ")") + ($_ text\compose "(-> " (|> (flat_lambda type) (list\map type\encode) (list\interposed " ") list\reversed (list\fold text\compose "")) ")") (#Parameter id) (nat\encode id) @@ -4367,7 +4389,7 @@ (let [[func args] (flat_application type)] ($_ text\compose "(" (type\encode func) " " - (|> args (list\map type\encode) (list\interposed " ") list\reverse (list\fold text\compose "")) + (|> args (list\map type\encode) (list\interposed " ") list\reversed (list\fold text\compose "")) ")")) (#Named name _) @@ -4435,7 +4457,7 @@ " ''???'')"))} (if ("lux i64 =" 0 (n/% 2 (list\size tokens))) (failure "cond requires an uneven number of arguments.") - (case (list\reverse tokens) + (case (list\reversed tokens) (^ (list& else branches')) (in_meta (list (list\fold (: (-> [Code Code] Code Code) (function (_ branch else) @@ -4834,14 +4856,14 @@ (function (_ [s b] v) (` (..with@ (~ s) (~ v) (~ b))))) value - (list\reverse pairs)) + (list\reversed pairs)) [_ accesses'] (list\fold (: (-> [Code Code] [Code (List (List Code))] [Code (List (List Code))]) (function (_ [new_slot new_binding] [old_record accesses']) [(` (value@ (~ new_slot) (~ new_binding))) (#Item (list new_binding old_record) accesses')])) [record (: (List (List Code)) #End)] pairs) - accesses (list\joined (list\reverse accesses'))]] + accesses (list\joined (list\reversed accesses'))]] (in (list (` (let [(~+ accesses)] (~ update_expr))))))) @@ -5525,7 +5547,7 @@ (list) (list g!_ (` #.None)))))))) (` (#.Some (~ body))) - (: (List [Code Code]) (list\reverse levels)))] + (: (List [Code Code]) (list\reversed levels)))] (list init_pattern inner_pattern_body))) (macro: .public (^multi tokens) @@ -5608,7 +5630,7 @@ {#info info #source source #current_module _ #modules modules #scopes scopes #type_context types #host host #seed seed #expected expected #location location #extensions extensions - #scope_type_vars scope_type_vars} + #scope_type_vars scope_type_vars #eval _eval} (#Right [state scope_type_vars]))) (macro: .public (:parameter tokens) @@ -5625,7 +5647,7 @@ (^ (list [_ (#Nat idx)])) (do meta_monad [stvs ..scope_type_vars] - (case (..item idx (list\reverse stvs)) + (case (..item idx (list\reversed stvs)) (#Some var_id) (in (list (` (#Ex (~ (nat$ var_id)))))) @@ -5999,11 +6021,11 @@ [(def: (<name> g!meta untemplated_pattern elems) (-> Code (-> Code (Meta Code)) (-> (List Code) (Meta Code))) - (case (list\reverse elems) + (case (list\reversed elems) (#Item [_ (#Form (#Item [[_ (#Identifier ["" "~+"])] (#Item [spliced #End])]))] inits) (do meta_monad - [=inits (monad\map meta_monad untemplated_pattern (list\reverse inits))] + [=inits (monad\map meta_monad untemplated_pattern (list\reversed inits))] (in (` [(~ g!meta) (<tag> (~ (untemplated_list& spliced =inits)))]))) _ diff --git a/stdlib/source/library/lux/control/parser/json.lux b/stdlib/source/library/lux/control/parser/json.lux index 65569ff9e..cc954fc1b 100644 --- a/stdlib/source/library/lux/control/parser/json.lux +++ b/stdlib/source/library/lux/control/parser/json.lux @@ -23,7 +23,6 @@ ["." // ("#\." functor)]) (type: .public (Parser a) - {#.doc "A JSON parser."} (//.Parser (List JSON) a)) (exception: .public (unconsumed_input {input (List JSON)}) @@ -33,8 +32,6 @@ (exception: .public empty_input) (def: .public (result parser json) - {#.doc (example "Executes the parser against a JSON object." - "Verifies that all of the JSON was consumed by the parser.")} (All [a] (-> (Parser a) JSON (Try a))) (case (//.result parser (list json)) (#try.Success [remainder output]) @@ -49,7 +46,6 @@ (#try.Failure error))) (def: .public any - {#.doc "Just returns the JSON input without applying any logic."} (Parser JSON) (<| (function (_ inputs)) (case inputs @@ -63,9 +59,8 @@ (exception.report ["Value" (/.format value)])) -(template [<name> <type> <tag> <desc>] +(template [<name> <type> <tag>] [(def: .public <name> - {#.doc (code.text ($_ text\compose "Reads a JSON value as " <desc> "."))} (Parser <type>) (do //.monad [head ..any] @@ -76,10 +71,10 @@ _ (//.failure (exception.error ..unexpected_value [head])))))] - [null /.Null #/.Null "null"] - [boolean /.Boolean #/.Boolean "boolean"] - [number /.Number #/.Number "number"] - [string /.String #/.String "string"] + [null /.Null #/.Null] + [boolean /.Boolean #/.Boolean] + [number /.Number #/.Number] + [string /.String #/.String] ) (exception: .public [a] (value_mismatch {reference JSON} {sample JSON}) @@ -120,13 +115,11 @@ ) (def: .public (nullable parser) - {#.doc (example "Enhances parser by adding NULL-handling.")} (All [a] (-> (Parser a) (Parser (Maybe a)))) (//.or ..null parser)) (def: .public (array parser) - {#.doc "Parses the contents of a JSON array."} (All [a] (-> (Parser a) (Parser a))) (do //.monad [head ..any] @@ -148,8 +141,6 @@ (//.failure (exception.error ..unexpected_value [head]))))) (def: .public (object parser) - {#.doc (example "Parses the contents of a JSON object." - "Use this with the 'field' combinator.")} (All [a] (-> (Parser a) (Parser a))) (do //.monad [head ..any] @@ -176,8 +167,6 @@ (//.failure (exception.error ..unexpected_value [head]))))) (def: .public (field field_name parser) - {#.doc (example "Parses a field inside a JSON object." - "Use this inside the 'object' combinator.")} (All [a] (-> Text (Parser a) (Parser a))) (function (recur inputs) (case inputs @@ -204,7 +193,6 @@ (exception.except ..unconsumed_input inputs)))) (def: .public dictionary - {#.doc "Parses a dictionary-like JSON object."} (All [a] (-> (Parser a) (Parser (Dictionary Text a)))) (|>> (//.and ..string) //.some diff --git a/stdlib/source/library/lux/control/parser/synthesis.lux b/stdlib/source/library/lux/control/parser/synthesis.lux index dadf00655..b336a0d58 100644 --- a/stdlib/source/library/lux/control/parser/synthesis.lux +++ b/stdlib/source/library/lux/control/parser/synthesis.lux @@ -49,12 +49,9 @@ (exception: .public empty_input) (type: .public Parser - {#.doc (example "A parser for the Lux compiler's synthesis nodes using during optimization.")} (//.Parser (List Synthesis))) (def: .public (result parser input) - {#.doc (example "Executes the parser against the inputs." - "Ensures all inputs are consumed by the parser.")} (All [a] (-> (Parser a) (List Synthesis) (Try a))) (case (parser input) (#try.Failure error) @@ -67,7 +64,6 @@ (exception.except ..unconsumed_input unconsumed))) (def: .public any - {#.doc (example "Yields a synthesis node without subjecting it to any analysis.")} (Parser Synthesis) (.function (_ input) (case input @@ -78,7 +74,6 @@ (#try.Success [tail head])))) (def: .public end! - {#.doc "Ensures there are no more inputs."} (Parser Any) (.function (_ tokens) (case tokens @@ -86,7 +81,6 @@ _ (exception.except ..expected_empty_input [tokens])))) (def: .public end? - {#.doc "Checks whether there are no more inputs."} (Parser Bit) (.function (_ tokens) (#try.Success [tokens (case tokens @@ -128,7 +122,6 @@ ) (def: .public (tuple parser) - {#.doc (example "Parses the contents of a tuple.")} (All [a] (-> (Parser a) (Parser a))) (.function (_ input) (case input @@ -141,7 +134,6 @@ (exception.except ..cannot_parse input)))) (def: .public (function expected parser) - {#.doc (example "Parses the body of a function with the 'expected' arity.")} (All [a] (-> Arity (Parser a) (Parser [(Environment Synthesis) a]))) (.function (_ input) (case input @@ -156,7 +148,6 @@ (exception.except ..cannot_parse input)))) (def: .public (loop init_parsers iteration_parser) - {#.doc (example "Parses the initial values and the body of a loop.")} (All [a b] (-> (Parser a) (Parser b) (Parser [Register a b]))) (.function (_ input) (case input diff --git a/stdlib/source/library/lux/control/parser/text.lux b/stdlib/source/library/lux/control/parser/text.lux index 46ed6e987..b95df4bfd 100644 --- a/stdlib/source/library/lux/control/parser/text.lux +++ b/stdlib/source/library/lux/control/parser/text.lux @@ -21,7 +21,6 @@ ["." //]) (type: .public Offset - {#.doc (example "An offset into a block of text.")} Nat) (def: start_offset @@ -29,11 +28,9 @@ 0) (type: .public Parser - {#.doc (example "A parser for text.")} (//.Parser [Offset Text])) (type: .public Slice - {#.doc (example "A slice of a block of text.")} {#basis Offset #distance Offset}) @@ -56,8 +53,6 @@ (exception: .public cannot_slice) (def: .public (result parser input) - {#.doc (example "Executes a parser against a block of text." - "Verifies that the entire input has been processed.")} (All [a] (-> (Parser a) Text (Try a))) (case (parser [start_offset input]) (#try.Failure msg) @@ -69,7 +64,6 @@ (exception.except ..unconsumed_input [end_offset input])))) (def: .public offset - {#.doc (example "Yields the current offset into the input.")} (Parser Offset) (function (_ (^@ input [offset tape])) (#try.Success [input offset]))) @@ -87,7 +81,6 @@ slices)))) (def: .public any - {#.doc "Yields the next character without applying any logic."} (Parser Text) (function (_ [offset tape]) (case (/.char offset tape) @@ -98,7 +91,6 @@ (exception.except ..cannot_parse [])))) (def: .public any! - {#.doc "Yields the next character (as a slice) without applying any logic."} (Parser Slice) (function (_ [offset tape]) (case (/.char offset tape) @@ -110,9 +102,8 @@ _ (exception.except ..cannot_slice [])))) -(template [<name> <type> <any> <caveat>] +(template [<name> <type> <any>] [(`` (def: .public (<name> parser) - {#.doc (example (~~ (template.text ["Produce a character" <caveat> " if the parser fails."])))} (All [a] (-> (Parser a) (Parser <type>))) (function (_ input) (case (parser input) @@ -122,8 +113,8 @@ _ (exception.except ..expected_to_fail input)))))] - [not Text ..any ""] - [not! Slice ..any! " (as a slice)"] + [not Text ..any] + [not! Slice ..any!] ) (exception: .public (cannot_match {reference Text}) @@ -131,7 +122,6 @@ ["Reference" (/.format reference)])) (def: .public (this reference) - {#.doc (example "Checks that a specific text shows up in the input.")} (-> Text (Parser Any)) (function (_ [offset tape]) (case (/.index_of' offset reference tape) @@ -145,7 +135,6 @@ (exception.except ..cannot_match [reference])))) (def: .public end! - {#.doc "Ensure the parser's input is empty."} (Parser Any) (function (_ (^@ input [offset tape])) (if (n.= offset (/.size tape)) @@ -153,7 +142,6 @@ (exception.except ..unconsumed_input input)))) (def: .public next - {#.doc "Yields the next character (without consuming it from the input)."} (Parser Text) (function (_ (^@ input [offset tape])) (case (/.char offset tape) @@ -164,13 +152,11 @@ (exception.except ..cannot_parse [])))) (def: .public remaining - {#.doc "Get all of the remaining input (without consuming it)."} (Parser Text) (function (_ (^@ input [offset tape])) (#try.Success [input (remaining' offset tape)]))) (def: .public (range bottom top) - {#.doc "Only yields characters within a range."} (-> Nat Nat (Parser Text)) (do //.monad [char any @@ -182,7 +168,6 @@ (template [<name> <bottom> <top> <desc>] [(def: .public <name> - {#.doc (code.text ($_ /\compose "Only yields " <desc> " characters."))} (Parser Text) (..range (char <bottom>) (char <top>)))] @@ -193,17 +178,14 @@ ) (def: .public alpha - {#.doc "Yields alphabetic characters."} (Parser Text) (//.either lower upper)) (def: .public alpha_num - {#.doc "Yields alphanumeric characters."} (Parser Text) (//.either alpha decimal)) (def: .public hexadecimal - {#.doc "Yields hexadecimal digits."} (Parser Text) ($_ //.either decimal @@ -265,7 +247,6 @@ ["Character" (/.format (/.of_char character))])) (def: .public (satisfies parser) - {#.doc "Yields characters that satisfy a predicate."} (-> (-> Char Bit) (Parser Text)) (function (_ [offset tape]) (case (/.char offset tape) @@ -278,12 +259,10 @@ (exception.except ..cannot_parse [])))) (def: .public space - {#.doc "Yields white-space."} (Parser Text) (..satisfies /.space?)) (def: .public (and left right) - {#.doc (example "Yields the outputs of both parsers composed together.")} (-> (Parser Text) (Parser Text) (Parser Text)) (do //.monad [=left left @@ -291,7 +270,6 @@ (in ($_ /\compose =left =right)))) (def: .public (and! left right) - {#.doc (example "Yields the outputs of both parsers composed together (as a slice).")} (-> (Parser Slice) (Parser Slice) (Parser Slice)) (do //.monad [[left::basis left::distance] left @@ -300,7 +278,6 @@ (template [<name> <base> <doc_modifier>] [(def: .public (<name> parser) - {#.doc (code.text ($_ /\compose "Yields " <doc_modifier> " characters as a single continuous text (as a slice)."))} (-> (Parser Text) (Parser Text)) (|> parser <base> (\ //.monad map /.together)))] @@ -310,7 +287,6 @@ (template [<name> <base> <doc_modifier>] [(def: .public (<name> parser) - {#.doc (code.text ($_ /\compose "Yields " <doc_modifier> " characters as a single continuous text (as a slice)."))} (-> (Parser Slice) (Parser Slice)) (with_slices (<base> parser)))] @@ -320,7 +296,6 @@ (template [<name> <base> <doc_modifier>] [(def: .public (<name> amount parser) - {#.doc (code.text ($_ /\compose "Yields " <doc_modifier> " N characters (as a slice)."))} (-> Nat (Parser Text) (Parser Text)) (|> parser (<base> amount) @@ -333,7 +308,6 @@ (template [<name> <base> <doc_modifier>] [(def: .public (<name> amount parser) - {#.doc (code.text ($_ /\compose "Yields " <doc_modifier> " N characters (as a slice)."))} (-> Nat (Parser Slice) (Parser Slice)) (with_slices (<base> amount parser)))] @@ -361,7 +335,6 @@ (//.after (this start)))) (def: .public (local local_input parser) - {#.doc "Applies a parser against the given input."} (All [a] (-> Text (Parser a) (Parser a))) (function (_ real_input) (case (..result parser local_input) @@ -372,7 +345,6 @@ (#try.Success [real_input value])))) (def: .public (slice parser) - {#.doc (example "Converts a slice to a block of text.")} (-> (Parser Slice) (Parser Text)) (do //.monad [[basis distance] parser] @@ -385,7 +357,6 @@ (exception.except ..cannot_slice []))))) (def: .public (then structured text) - {#.doc (example "Embeds a text parser into an arbitrary parser that yields text.")} (All [s a] (-> (Parser a) (//.Parser s Text) diff --git a/stdlib/source/library/lux/control/parser/tree.lux b/stdlib/source/library/lux/control/parser/tree.lux index cba23cf82..1f7a54a1a 100644 --- a/stdlib/source/library/lux/control/parser/tree.lux +++ b/stdlib/source/library/lux/control/parser/tree.lux @@ -13,23 +13,19 @@ ["." //]) (type: .public (Parser t a) - {#.doc (example "A parser of arbitrary trees.")} (//.Parser (Zipper t) a)) (def: .public (result' parser zipper) - {#.doc (example "Applies the parser against a tree zipper.")} (All [t a] (-> (Parser t a) (Zipper t) (Try a))) (do try.monad [[zipper output] (//.result parser zipper)] (in output))) (def: .public (result parser tree) - {#.doc (example "Applies the parser against a tree.")} (All [t a] (-> (Parser t a) (Tree t) (Try a))) (result' parser (zipper.zipper tree))) (def: .public value - {#.doc (example "Yields the value inside the current tree node.")} (All [t] (Parser t t)) (function (_ zipper) (#try.Success [zipper (zipper.value zipper)]))) diff --git a/stdlib/source/library/lux/control/parser/type.lux b/stdlib/source/library/lux/control/parser/type.lux index e6ea2b3dd..029d130fd 100644 --- a/stdlib/source/library/lux/control/parser/type.lux +++ b/stdlib/source/library/lux/control/parser/type.lux @@ -1,6 +1,4 @@ (.module: - {#.doc (.example "Parsing of Lux types." - "Used mostly for polytypic programming.")} [library [lux (#- function local) [abstract @@ -61,15 +59,12 @@ (text.interposed ""))])) (type: .public Env - {#.doc (example "An environment for type parsing.")} (Dictionary Nat [Type Code])) (type: .public (Parser a) - {#.doc (example "A parser of Lux types.")} (//.Parser [Env (List Type)] a)) (def: .public fresh - {#.doc (example "An empty parsing environment.")} Env (dictionary.empty n.hash)) @@ -88,13 +83,10 @@ (exception.except ..unconsumed_input remaining)))) (def: .public (result poly type) - {#.doc (example "Applies a parser against a type." - "Verifies that the parser fully consumes the type's information.")} (All [a] (-> (Parser a) Type (Try a))) (result' ..fresh poly (list type))) (def: .public env - {#.doc (example "Yields the current parsing environment.")} (Parser Env) (.function (_ [env inputs]) (#try.Success [[env inputs] env]))) @@ -110,7 +102,6 @@ (#try.Success [[env remaining] output])))) (def: .public next - {#.doc (example "Inspect a type in the input stream without consuming it.")} (Parser Type) (.function (_ [env inputs]) (case inputs @@ -121,7 +112,6 @@ (#try.Success [[env inputs] headT])))) (def: .public any - {#.doc (example "Yields a type, without examination.")} (Parser Type) (.function (_ [env inputs]) (case inputs @@ -132,7 +122,6 @@ (#try.Success [[env tail] headT])))) (def: .public (local types poly) - {#.doc (example "Apply a parser to the given inputs.")} (All [a] (-> (List Type) (Parser a) (Parser a))) (.function (_ [env pass_through]) (case (result' env poly types) @@ -222,7 +211,6 @@ (in [funcL all_varsL output]))))) (def: .public (function in_poly out_poly) - {#.doc (example "Parses a function's inputs and output.")} (All [i o] (-> (Parser i) (Parser o) (Parser [i o]))) (do //.monad [headT any @@ -233,7 +221,6 @@ (//.failure (exception.error ..not_function headT))))) (def: .public (applied poly) - {#.doc (example "Parses a type application.")} (All [a] (-> (Parser a) (Parser a))) (do //.monad [headT any @@ -242,9 +229,8 @@ (//.failure (exception.error ..not_application headT)) (..local (#.Item funcT paramsT) poly)))) -(template [<name> <test> <doc>] +(template [<name> <test>] [(def: .public (<name> expected) - {#.doc (example <doc>)} (-> Type (Parser Any)) (do //.monad [actual any] @@ -252,12 +238,9 @@ (in []) (//.failure (exception.error ..types_do_not_match [expected actual])))))] - [exactly type\= - "Parses a type exactly."] - [sub check.subsumes? - "Parses a sub type."] - [super (function.flipped check.subsumes?) - "Parses a super type."] + [exactly type\=] + [sub check.subsumes?] + [super (function.flipped check.subsumes?)] ) (def: .public (adjusted_idx env idx) @@ -299,7 +282,6 @@ (//.failure (exception.error ..not_parameter headT))))) (def: .public existential - {#.doc (example "Yields an existential type.")} (Parser Nat) (do //.monad [headT any] @@ -311,7 +293,6 @@ (//.failure (exception.error ..not_existential headT))))) (def: .public named - {#.doc (example "Yields a named type.")} (Parser [Name Type]) (do //.monad [inputT any] diff --git a/stdlib/source/library/lux/control/parser/xml.lux b/stdlib/source/library/lux/control/parser/xml.lux index 5785ecba8..2b0332544 100644 --- a/stdlib/source/library/lux/control/parser/xml.lux +++ b/stdlib/source/library/lux/control/parser/xml.lux @@ -18,7 +18,6 @@ ["." //]) (type: .public (Parser a) - {#.doc (example "A parser of XML-encoded data.")} (//.Parser [Attrs (List XML)] a)) (exception: .public empty_input) @@ -50,13 +49,10 @@ (#try.Failure error))) (def: .public (result parser documents) - {#.doc (example "Applies a parser against a stream of XML documents." - "Verifies that all of the inputs are consumed by the parser.")} (All [a] (-> (Parser a) (List XML) (Try a))) (..result' parser /.attributes documents)) (def: .public text - {#.doc (example "Yields text from a text node.")} (Parser Text) (function (_ [attrs documents]) (case documents @@ -72,7 +68,6 @@ (exception.except ..unexpected_input []))))) (def: .public tag - {#.doc (example "Yields the tag from the next node.")} (Parser Tag) (function (_ [attrs documents]) (case documents @@ -88,7 +83,6 @@ (#try.Success [[attrs documents] tag]))))) (def: .public (attribute name) - {#.doc (example "Yields the value of an attribute in the current node.")} (-> Attribute (Parser Text)) (function (_ [attrs documents]) (case (dictionary.value name attrs) @@ -99,7 +93,6 @@ (#try.Success [[attrs documents] value])))) (def: .public (node expected parser) - {#.doc (example "Parses the contents of the next node if the tag matches.")} (All [a] (-> Tag (Parser a) (Parser a))) (function (_ [attrs documents]) (case documents @@ -119,7 +112,6 @@ (exception.except ..wrong_tag [expected actual])))))) (def: .public any - {#.doc (example "Yields the next node.")} (Parser XML) (function (_ [attrs documents]) (case documents @@ -132,7 +124,6 @@ (exception: .public nowhere) (def: .public (somewhere parser) - {#.doc (example "Applies the parser somewhere among the remaining inputs; instead of demanding that the parser succeeds against the immediate inputs.")} (All [a] (-> (Parser a) (Parser a))) (function (recur [attrs input]) (case (//.result parser [attrs input]) diff --git a/stdlib/source/library/lux/data/binary.lux b/stdlib/source/library/lux/data/binary.lux index 13b9b5a9d..6028c1a68 100644 --- a/stdlib/source/library/lux/data/binary.lux +++ b/stdlib/source/library/lux/data/binary.lux @@ -33,9 +33,7 @@ ["Offset" (%.nat offset)] ["Length" (%.nat length)])) -(with_expansions [<documentation> (as_is {#.doc (example "A binary BLOB of data.")}) - <jvm> (as_is (type: .public Binary - <documentation> +(with_expansions [<jvm> (as_is (type: .public Binary (ffi.type [byte])) (ffi.import: java/lang/Object) @@ -78,17 +76,14 @@ (length ffi.Number)]) (type: .public Binary - <documentation> Uint8Array)) @.python (type: .public Binary - <documentation> (primitive "bytearray")) @.scheme (as_is (type: .public Binary - <documentation> (primitive "bytevector")) (ffi.import: (make-bytevector [Nat] Binary)) @@ -98,7 +93,6 @@ ... Default (type: .public Binary - <documentation> (array.Array (I64 Any))))) (template: (!size binary) @@ -171,7 +165,6 @@ (|>> !size)) (def: .public (empty size) - {#.doc (example "A fresh/empty binary BLOB of the specified size.")} (-> Nat Binary) (for {@.old (ffi.array byte size) @.jvm (ffi.array byte size) @@ -200,14 +193,12 @@ output)))) (def: .public (read/8! index binary) - {#.doc (example "Read 1 byte (8 bits) at the given index.")} (-> Nat Binary (Try I64)) (if (n.< (..!size binary) index) (#try.Success (!read index binary)) (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (read/16! index binary) - {#.doc (example "Read 2 bytes (16 bits) at the given index.")} (-> Nat Binary (Try I64)) (if (n.< (..!size binary) (n.+ 1 index)) (#try.Success ($_ i64.or @@ -216,7 +207,6 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (read/32! index binary) - {#.doc (example "Read 4 bytes (32 bits) at the given index.")} (-> Nat Binary (Try I64)) (if (n.< (..!size binary) (n.+ 3 index)) (#try.Success ($_ i64.or @@ -227,7 +217,6 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (read/64! index binary) - {#.doc (example "Read 8 bytes (64 bits) at the given index.")} (-> Nat Binary (Try I64)) (if (n.< (..!size binary) (n.+ 7 index)) (#try.Success ($_ i64.or @@ -242,7 +231,6 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (write/8! index value binary) - {#.doc (example "Write 1 byte (8 bits) at the given index.")} (-> Nat (I64 Any) Binary (Try Binary)) (if (n.< (..!size binary) index) (#try.Success (|> binary @@ -250,7 +238,6 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (write/16! index value binary) - {#.doc (example "Write 2 bytes (16 bits) at the given index.")} (-> Nat (I64 Any) Binary (Try Binary)) (if (n.< (..!size binary) (n.+ 1 index)) (#try.Success (|> binary @@ -259,7 +246,6 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (write/32! index value binary) - {#.doc (example "Write 4 bytes (32 bits) at the given index.")} (-> Nat (I64 Any) Binary (Try Binary)) (if (n.< (..!size binary) (n.+ 3 index)) (#try.Success (|> binary @@ -270,7 +256,6 @@ (exception.except ..index_out_of_bounds [(..!size binary) index]))) (def: .public (write/64! index value binary) - {#.doc (example "Write 8 bytes (64 bits) at the given index.")} (-> Nat (I64 Any) Binary (Try Binary)) (if (n.< (..!size binary) (n.+ 7 index)) (for {@.scheme (let [write_high (|>> (!write index (i64.right_shifted 56 value)) @@ -323,7 +308,6 @@ ["Target output space" (%.nat target_output)]))) (def: .public (copy bytes source_offset source target_offset target) - {#.doc (example "Mutates the target binary BLOB by copying bytes from the source BLOB to it.")} (-> Nat Nat Binary Nat Binary (Try Binary)) (with_expansions [<jvm> (as_is (do try.monad [_ (java/lang/System::arraycopy source (.int source_offset) target (.int target_offset) (.int bytes))] @@ -345,7 +329,6 @@ (#try.Success target)))))))) (def: .public (slice offset length binary) - {#.doc (example "Yields a subset of the binary BLOB, so long as the specified range is valid.")} (-> Nat Nat Binary (Try Binary)) (let [size (..!size binary) limit (n.+ length offset)] @@ -359,7 +342,6 @@ (..copy length offset binary 0 (..empty length))))))) (def: .public (after bytes binary) - {#.doc (example "Yields a binary BLOB with at most the specified number of bytes removed.")} (-> Nat Binary Binary) (case bytes 0 binary diff --git a/stdlib/source/library/lux/data/bit.lux b/stdlib/source/library/lux/data/bit.lux index efdca1f5b..6d7b7c9c3 100644 --- a/stdlib/source/library/lux/data/bit.lux +++ b/stdlib/source/library/lux/data/bit.lux @@ -61,7 +61,5 @@ _ (#.Left "Wrong syntax for Bit.")))) (def: .public complement - {#.doc (example "Generates the complement of a predicate." - "That is a predicate that returns the oposite of the original predicate.")} (All [a] (-> (-> a Bit) (-> a Bit))) (function.composite not)) diff --git a/stdlib/source/library/lux/data/collection/array.lux b/stdlib/source/library/lux/data/collection/array.lux index ae6aa7b96..c7fe53e3f 100644 --- a/stdlib/source/library/lux/data/collection/array.lux +++ b/stdlib/source/library/lux/data/collection/array.lux @@ -22,7 +22,6 @@ "#Array") (type: .public (Array a) - {#.doc "Mutable arrays."} (#.Primitive ..type_name (#.Item a #.End))) (with_expansions [<index_type> (primitive "java.lang.Long") @@ -37,7 +36,6 @@ (as_is)) (def: .public (empty size) - {#.doc (.example "An empty array of the specified size.")} (All [a] (-> Nat (Array a))) (for {@.old (:expected ("jvm anewarray" "(java.lang.Object )" size)) @@ -110,7 +108,6 @@ #.None)) (def: .public (write! index value array) - {#.doc (.example "Mutate the array by writing a value to the specified index.")} (All [a] (-> Nat a (Array a) (Array a))) (for {@.old @@ -130,7 +127,6 @@ @.scheme ("scheme array write" index value array)})) (def: .public (delete! index array) - {#.doc (.example "Mutate the array by deleting the value at the specified index.")} (All [a] (-> Nat (Array a) (Array a))) (if (n.< (size array) index) @@ -160,7 +156,6 @@ false)) (def: .public (update! index transform array) - {#.doc (.example "Mutate the array by updating the value at the specified index.")} (All [a] (-> Nat (-> a a) (Array a) (Array a))) (case (read! index array) @@ -171,8 +166,6 @@ (write! index (transform value) array))) (def: .public (upsert! index default transform array) - {#.doc (.example "Mutate the array by updating the value at the specified index." - "If there is no value, update and write the default value given.")} (All [a] (-> Nat a (-> a a) (Array a) (Array a))) (write! index @@ -180,7 +173,6 @@ array)) (def: .public (copy! length src_start src_array dest_start dest_array) - {#.doc (.example "Writes the contents of one array into the other.")} (All [a] (-> Nat Nat (Array a) Nat (Array a) (Array a))) @@ -197,7 +189,6 @@ (list.indices length)))) (def: .public (occupancy array) - {#.doc "Finds out how many cells in an array are occupied."} (All [a] (-> (Array a) Nat)) (list\fold (function (_ idx count) (case (read! idx array) @@ -210,12 +201,10 @@ (list.indices (size array)))) (def: .public (vacancy array) - {#.doc "Finds out how many cells in an array are vacant."} (All [a] (-> (Array a) Nat)) (n.- (..occupancy array) (..size array))) (def: .public (filter! p xs) - {#.doc (.example "Delete every item of the array that fails to satisfy the predicate.")} (All [a] (-> (Predicate a) (Array a) (Array a))) (list\fold (function (_ idx xs') @@ -231,7 +220,6 @@ (list.indices (size xs)))) (def: .public (example p xs) - {#.doc (.example "Yields the first item in the array that satisfies the predicate.")} (All [a] (-> (Predicate a) (Array a) (Maybe a))) (let [arr_size (size xs)] @@ -248,7 +236,6 @@ #.None)))) (def: .public (example+ p xs) - {#.doc "Just like 'example', but with access to the index of each value."} (All [a] (-> (-> Nat a Bit) (Array a) (Maybe [Nat a]))) (let [arr_size (size xs)] @@ -265,7 +252,6 @@ #.None)))) (def: .public (clone xs) - {#.doc (.example "Yields a shallow clone of the array.")} (All [a] (-> (Array a) (Array a))) (let [arr_size (size xs)] (list\fold (function (_ idx ys) @@ -290,7 +276,6 @@ (-- 0)) (def: .public (list array) - {#.doc (.example "Yields a list with every non-empty item in the array.")} (All [a] (-> (Array a) (List a))) (loop [idx (-- (size array)) output #.End] @@ -308,7 +293,6 @@ output))))) (def: .public (list' default array) - {#.doc (.example "Like 'list', but uses the 'default' value when encountering an empty cell in the array.")} (All [a] (-> a (Array a) (List a))) (loop [idx (-- (size array)) output #.End] diff --git a/stdlib/source/library/lux/data/collection/bits.lux b/stdlib/source/library/lux/data/collection/bits.lux index b5059ea8a..6c375247c 100644 --- a/stdlib/source/library/lux/data/collection/bits.lux +++ b/stdlib/source/library/lux/data/collection/bits.lux @@ -21,7 +21,6 @@ i64.width) (type: .public Bits - {#.doc (example "A bit-map.")} (Array Chunk)) (def: empty_chunk @@ -33,7 +32,6 @@ (array.empty 0)) (def: .public (size bits) - {#.doc (example "Measures the size of a bit-map by counting all the 1s in the bit-map.")} (-> Bits Nat) (array\fold (function (_ chunk total) (|> chunk i64.ones (n.+ total))) diff --git a/stdlib/source/library/lux/data/collection/dictionary.lux b/stdlib/source/library/lux/data/collection/dictionary.lux index 6773a3b95..faab0f7b2 100644 --- a/stdlib/source/library/lux/data/collection/dictionary.lux +++ b/stdlib/source/library/lux/data/collection/dictionary.lux @@ -556,7 +556,6 @@ colls))) (type: .public (Dictionary k v) - {#.doc "A dictionary implemented as a Hash-Array Mapped Trie (HAMT)."} {#hash (Hash k) #root (Node k v)}) @@ -565,7 +564,6 @@ (value@ #..hash)) (def: .public (empty key_hash) - {#.doc (example "An empty dictionary.")} (All [k v] (-> (Hash k) (Dictionary k v))) {#hash key_hash #root empty_node}) @@ -594,14 +592,12 @@ (exception: .public key_already_exists) (def: .public (has' key val dict) - {#.doc "Only puts the KV-pair if the key is not already present."} (All [k v] (-> k v (Dictionary k v) (Try (Dictionary k v)))) (case (value key dict) #.None (#try.Success (has key val dict)) (#.Some _) (exception.except ..key_already_exists []))) (def: .public (revised key f dict) - {#.doc "Transforms the value located at key (if available), using the given function."} (All [k v] (-> k (-> v v) (Dictionary k v) (Dictionary k v))) (case (value key dict) #.None @@ -611,8 +607,6 @@ (has key (f val) dict))) (def: .public (revised' key default f dict) - {#.doc (example "Updates the value at the key; if it exists." - "Otherwise, puts a value by applying the function to a default.")} (All [k v] (-> k v (-> v v) (Dictionary k v) (Dictionary k v))) (..has key (f (maybe.else default @@ -651,16 +645,12 @@ ) (def: .public (merged dict2 dict1) - {#.doc (example "Merges 2 dictionaries." - "If any collisions with keys occur, the values of dict2 will overwrite those of dict1.")} (All [k v] (-> (Dictionary k v) (Dictionary k v) (Dictionary k v))) (list\fold (function (_ [key val] dict) (has key val dict)) dict1 (entries dict2))) (def: .public (merged_with f dict2 dict1) - {#.doc (example "Merges 2 dictionaries." - "If any collisions with keys occur, a new value will be computed by applying 'f' to the values of dict2 and dict1.")} (All [k v] (-> (-> v v v) (Dictionary k v) (Dictionary k v) (Dictionary k v))) (list\fold (function (_ [key val2] dict) (case (value key dict) @@ -673,7 +663,6 @@ (entries dict2))) (def: .public (re_bound from_key to_key dict) - {#.doc (example "If there is a value under 'from_key', remove 'from_key' and store the value under 'to_key'.")} (All [k v] (-> k k (Dictionary k v) (Dictionary k v))) (case (value from_key dict) #.None @@ -685,7 +674,6 @@ (has to_key val)))) (def: .public (sub keys dict) - {#.doc "A sub-dictionary, with only the specified keys."} (All [k v] (-> (List k) (Dictionary k v) (Dictionary k v))) (let [[key_hash _] dict] (list\fold (function (_ key new_dict) diff --git a/stdlib/source/library/lux/data/collection/dictionary/ordered.lux b/stdlib/source/library/lux/data/collection/dictionary/ordered.lux index 567c1f457..f19843db9 100644 --- a/stdlib/source/library/lux/data/collection/dictionary/ordered.lux +++ b/stdlib/source/library/lux/data/collection/dictionary/ordered.lux @@ -46,12 +46,10 @@ ) (type: .public (Dictionary k v) - {#.doc (example "A dictionary data-structure with ordered entries.")} {#&order (Order k) #root (Maybe (Node k v))}) (def: .public (empty order) - {#.doc (example "An empty dictionary, employing the given order.")} (All [k v] (-> (Order k) (Dictionary k v))) {#&order order #root #.None}) diff --git a/stdlib/source/library/lux/data/collection/dictionary/plist.lux b/stdlib/source/library/lux/data/collection/dictionary/plist.lux index c56994d6c..e98a2c51b 100644 --- a/stdlib/source/library/lux/data/collection/dictionary/plist.lux +++ b/stdlib/source/library/lux/data/collection/dictionary/plist.lux @@ -14,8 +14,6 @@ ... https://en.wikipedia.org/wiki/Property_list (type: .public (PList a) - {#.doc (example "A property list." - "It's a simple dictionary-like structure with Text keys.")} (List [Text a])) (def: .public empty diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index cb52d478d..a4bb340e7 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -51,7 +51,6 @@ xs)) (def: .public (only keep? xs) - {#.doc (.example "A list with only values that satisfy the predicate.")} (All [a] (-> (Predicate a) (List a) (List a))) (case xs @@ -64,7 +63,6 @@ (only keep? xs')))) (def: .public (partition satisfies? list) - {#.doc "Divide the list into all elements that satisfy a predicate, and all elements that do not."} (All [a] (-> (Predicate a) (List a) [(List a) (List a)])) (case list #.End @@ -77,8 +75,6 @@ [in (#.Item head out)])))) (def: .public (pairs xs) - {#.doc (.example "Cut the list into pairs of 2." - "Caveat emptor: If the list has an un-even number of elements, the last one will be skipped.")} (All [a] (-> (List a) (List [a a]))) (case xs (^ (list& x1 x2 xs')) @@ -147,14 +143,12 @@ (split_when' predicate (#.Item x ys) xs')))) (def: .public (split_when predicate xs) - {#.doc "Segment the list by using a predicate to tell when to cut."} (All [a] (-> (Predicate a) (List a) [(List a) (List a)])) (let [[ys' xs'] (split_when' predicate #.End xs)] [(reversed ys') xs'])) (def: .public (sub size list) - {#.doc "Segment the list into sub-lists of (at most) the given size."} (All [a] (-> Nat (List a) (List (List a)))) (case list #.End @@ -165,7 +159,6 @@ (#.Item pre (sub size post))))) (def: .public (repeated n x) - {#.doc "A list of the value x, repeated n times."} (All [a] (-> Nat a (List a))) (case n @@ -183,7 +176,6 @@ (list))) (def: .public (iterations f x) - {#.doc "Generates a list element by element until the function returns #.None."} (All [a] (-> (-> a (Maybe a)) a (List a))) (case (f x) @@ -235,7 +227,6 @@ (all check xs'))))) (def: .public (example predicate xs) - {#.doc "Yields the first value in the list that satisfies the predicate."} (All [a] (-> (Predicate a) (List a) (Maybe a))) (..one (function (_ value) @@ -245,7 +236,6 @@ xs)) (def: .public (interposed sep xs) - {#.doc "Puts a value between every two elements in the list."} (All [a] (-> a (List a) (List a))) (case xs @@ -279,7 +269,6 @@ ) (def: .public (item i xs) - {#.doc "Fetches the element at the specified index."} (All [a] (-> Nat (List a) (Maybe a))) (case xs @@ -371,7 +360,6 @@ (|>> reversed (fold compose identity)))) (def: .public (sorted < xs) - {#.doc (.example "A list ordered by a comparison function.")} (All [a] (-> (-> a a Bit) (List a) (List a))) (case xs #.End @@ -421,7 +409,6 @@ ) (def: .public (indices size) - {#.doc "Produces all the valid indices for a given size."} (All [a] (-> Nat (List Nat))) (case size 0 (list) @@ -454,11 +441,6 @@ _ (recur input' output'))))) (macro: .public (zipped tokens state) - {#.doc (.example "Create list zippers with the specified number of input lists." - (def: .public zipped/2 (zipped 2)) - (def: .public zipped/3 (zipped 3)) - (zipped/3 xs ys zs) - ((zipped 3) xs ys zs))} (case tokens (^ (list [_ (#.Nat num_lists)])) (if (n.> 0 num_lists) @@ -499,11 +481,6 @@ (def: .public zipped/3 (zipped 3)) (macro: .public (zipped_with tokens state) - {#.doc (.example "Create list zippers with the specified number of input lists." - (def: .public zipped_with/2 (zipped_with 2)) - (def: .public zipped_with/3 (zipped_with 3)) - (zipped_with/2 + xs ys) - ((zipped_with 2) + xs ys))} (case tokens (^ (list [_ (#.Nat num_lists)])) (if (n.> 0 num_lists) @@ -559,8 +536,6 @@ (last xs'))) (def: .public (inits xs) - {#.doc (.example "For a list of size N, yields the first N-1 elements." - "Will yield a #.None for empty lists.")} (All [a] (-> (List a) (Maybe (List a)))) (case xs #.End @@ -579,12 +554,10 @@ )) (def: .public together - {#.doc (.example "The sequential combination of all the lists.")} (All [a] (-> (List (List a)) (List a))) (\ ..monad join)) (implementation: .public (with monad) - {#.doc (.example "Enhances a monad with List functionality.")} (All [M] (-> (Monad M) (Monad (All [a] (M (List a)))))) (def: &functor @@ -605,12 +578,10 @@ (in (..together lla))))) (def: .public (lifted monad) - {#.doc (.example "Wraps a monadic value with List machinery.")} (All [M a] (-> (Monad M) (-> (M a) (M (List a))))) (\ monad map (\ ..monad in))) (def: .public (enumeration xs) - {#.doc "Pairs every element in the list with its index, starting at 0."} (All [a] (-> (List a) (List [Nat a]))) (loop [idx 0 xs xs] @@ -622,11 +593,6 @@ (#.Item [idx x] (recur (++ idx) xs'))))) (macro: .public (when tokens state) - {#.doc (.example "Can be used as a guard in (co)monadic be/do expressions." - (do monad - [value (do_something 1 2 3) - ..when (passes_test? value)] - (do_something_else 4 5 6)))} (case tokens (^ (.list test then)) (#.Right [state (.list (` (.if (~ test) diff --git a/stdlib/source/library/lux/data/collection/queue.lux b/stdlib/source/library/lux/data/collection/queue.lux index a54543eae..e8caf83f7 100644 --- a/stdlib/source/library/lux/data/collection/queue.lux +++ b/stdlib/source/library/lux/data/collection/queue.lux @@ -12,7 +12,6 @@ ["n" nat]]]]]) (type: .public (Queue a) - {#.doc (example "A first-in, first-out sequential data-structure.")} {#front (List a) #rear (List a)}) @@ -32,7 +31,6 @@ (list\compose front (list.reversed rear)))) (def: .public front - {#.doc (example "Yields the first value in the queue, if any.")} (All [a] (-> (Queue a) (Maybe a))) (|>> (value@ #front) list.head)) diff --git a/stdlib/source/library/lux/data/collection/row.lux b/stdlib/source/library/lux/data/collection/row.lux index e77ef1bdf..16929459e 100644 --- a/stdlib/source/library/lux/data/collection/row.lux +++ b/stdlib/source/library/lux/data/collection/row.lux @@ -183,7 +183,6 @@ #.End)))) (type: .public (Row a) - {#.doc (example "A sequential data-structure with fast random access.")} {#level Level #size Nat #root (Hierarchy a) @@ -242,7 +241,6 @@ (exception: base_was_not_found) (def: .public (within_bounds? row idx) - {#.doc (example "Determines whether the index is within the bounds of the row.")} (All [a] (-> (Row a) Nat Bit)) (n.< (value@ #size row) idx)) @@ -350,17 +348,15 @@ (All [a] (-> (List a) (Row a))) (list\fold ..suffix ..empty)) -(def: .public (member? a/Equivalence row val) +(def: .public (member? equivalence row val) (All [a] (-> (Equivalence a) (Row a) a Bit)) - (list.member? a/Equivalence (list row) val)) + (list.member? equivalence (list row) val)) (def: .public empty? (All [a] (-> (Row a) Bit)) (|>> (value@ #size) (n.= 0))) (syntax: .public (row [elems (<>.some <code>.any)]) - {#.doc (example "Row literals." - (row 12 34 56 78 90))} (in (.list (` (..of_list (.list (~+ elems))))))) (implementation: (node_equivalence Equivalence<a>) diff --git a/stdlib/source/library/lux/data/collection/sequence.lux b/stdlib/source/library/lux/data/collection/sequence.lux index 42cd682df..2bed3b721 100644 --- a/stdlib/source/library/lux/data/collection/sequence.lux +++ b/stdlib/source/library/lux/data/collection/sequence.lux @@ -20,25 +20,20 @@ ["n" nat]]]]]) (type: .public (Sequence a) - {#.doc "An infinite sequence of values."} (Cont [a (Sequence a)])) (def: .public (iterations step init) - {#.doc "A stateful way of infinitely calculating the values of a sequence."} (All [a b] (-> (-> a [a b]) a (Sequence b))) (let [[next x] (step init)] (//.pending [x (iterations step next)]))) (def: .public (repeated x) - {#.doc "Repeat a value forever."} (All [a] (-> a (Sequence a))) (//.pending [x (repeated x)])) (def: .public (cycle [start next]) - {#.doc (example "Go over the elements of a list forever." - "The list should not be empty.")} (All [a] (-> [a (List a)] (Sequence a))) (loop [head start @@ -103,7 +98,6 @@ ) (def: .public (only predicate sequence) - {#.doc (example "A new sequence only with items that satisfy the predicate.")} (All [a] (-> (-> a Bit) (Sequence a) (Sequence a))) (let [[head tail] (//.result sequence)] (if (predicate head) @@ -111,9 +105,6 @@ (only predicate tail)))) (def: .public (partition left? xs) - {#.doc (example "Split a sequence in two based on a predicate." - "The left side contains all entries for which the predicate is #1." - "The right side contains all entries for which the predicate is #0.")} (All [a] (-> (-> a Bit) (Sequence a) [(Sequence a) (Sequence a)])) [(..only left? xs) (..only (bit.complement left?) xs)]) @@ -139,10 +130,6 @@ (syntax: .public (^sequence& [patterns (<code>.form (<>.many <code>.any)) body <code>.any branches (<>.some <code>.any)]) - {#.doc (example "Allows destructuring of sequences in pattern-matching expressions." - "Caveat emptor: Only use it for destructuring, and not for testing values within the sequences." - (let [(^sequence& x y z _tail) (some_sequence_func +1 +2 +3)] - (func x y z)))} (with_identifiers [g!sequence] (let [body+ (` (let [(~+ (list\join (list\map (function (_ pattern) (list (` [(~ pattern) (~ g!sequence)]) diff --git a/stdlib/source/library/lux/data/color.lux b/stdlib/source/library/lux/data/color.lux index 1cebc0408..d34918cf2 100644 --- a/stdlib/source/library/lux/data/color.lux +++ b/stdlib/source/library/lux/data/color.lux @@ -42,29 +42,25 @@ (|>> (f.* rgb_factor) f.int .nat)) (type: .public RGB - {#.doc (example "Red-Green-Blue color format.")} {#red Nat #green Nat #blue Nat}) (type: .public HSL - {#.doc (example "Hue-Saturation-Lightness color format.")} [Frac Frac Frac]) (type: .public CMYK - {#.doc (example "Cyan-Magenta-Yellow-Key color format.")} {#cyan Frac #magenta Frac #yellow Frac #key Frac}) (type: .public HSB - {#.doc (example "Hue-Saturation-Brightness color format.")} [Frac Frac Frac]) (abstract: .public Color - {#.doc (example "A color value, independent of color format.")} - + {} + RGB (def: .public (of_rgb [red green blue]) @@ -128,7 +124,6 @@ (|> ..top (n.- value))) (def: .public (complement color) - {#.doc (example "The opposite color.")} (-> Color Color) (let [[red green blue] (:representation color)] (:abstraction {#red (complement' red) @@ -409,13 +404,7 @@ (type: .public Palette (-> Spread Nat Color (List Color))) -(syntax: (palette_documentation [name <code>.local_identifier]) - (let [name (text.replaced "_" "-" name) - g!documentation (code.text (format "A " name " palette."))] - (in (list (` {#.doc (.example (~ g!documentation))}))))) - (`` (def: .public (analogous spread variations color) - (~~ (..palette_documentation analogous)) Palette (let [[hue saturation brightness] (hsb color) spread (..normal spread)] @@ -426,7 +415,6 @@ (list.indices variations))))) (`` (def: .public (monochromatic spread variations color) - (~~ (..palette_documentation monochromatic)) Palette (let [[hue saturation brightness] (hsb color) spread (..normal spread)] @@ -439,25 +427,20 @@ of_hsb)))))) (type: .public Alpha - {#.doc (example "The degree of transparency of a pigment.")} Rev) (def: .public transparent - {#.doc (example "The maximum degree of transparency.")} Alpha rev\bottom) (def: .public translucent - {#.doc (example "The average degree of transparency.")} Alpha .5) (def: .public opaque - {#.doc (example "The minimum degree of transparency.")} Alpha rev\top) (type: .public Pigment - {#.doc (example "A color with some degree of transparency.")} {#color Color #alpha Alpha}) diff --git a/stdlib/source/library/lux/data/color/named.lux b/stdlib/source/library/lux/data/color/named.lux index f94dacd1a..5e5e5bc65 100644 --- a/stdlib/source/library/lux/data/color/named.lux +++ b/stdlib/source/library/lux/data/color/named.lux @@ -1,30 +1,10 @@ (.module: [library [lux #* - [control - ["<>" parser - ["<.>" code]]] - [data - ["." text - ["%" format (#+ format)]]] - [macro - ["." syntax (#+ syntax:)] - ["." code]] [math [number (#+ hex)]]]] ["." // (#+ Color)]) -(syntax: (documentation [<red> <code>.text - <green> <code>.text - <blue> <code>.text - <name> <code>.local_identifier]) - (|> <name> - (text.replaced "_" " ") - (format <red> <green> <blue> " | ") - code.text - list - in)) - (template [<red> <green> <blue> <name>] [(`` (def: .public <name> {#.doc (example (~~ (..documentation <red> <green> <blue> <name>)))} diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index d7f3c9544..bc91e8880 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -392,21 +392,21 @@ (-> (Type Declaration) Code) (|>> ..signature code.text)) -(def: (make_get_const_parser class_name field_name) +(def: (get_const_parser class_name field_name) (-> Text Text (Parser Code)) (do <>.monad [.let [dotted_name (format "::" field_name)] _ (<code>.this! (code.identifier ["" dotted_name]))] (in (get_static_field class_name field_name)))) -(def: (make_get_var_parser class_name field_name self_name) +(def: (get_var_parser class_name field_name self_name) (-> Text Text Text (Parser Code)) (do <>.monad [.let [dotted_name (format "::" field_name)] _ (<code>.this! (code.identifier ["" dotted_name]))] (in (get_virtual_field class_name field_name (code.local_identifier self_name))))) -(def: (make_put_var_parser class_name field_name self_name) +(def: (put_var_parser class_name field_name self_name) (-> Text Text Text (Parser Code)) (do <>.monad [.let [dotted_name (format "::" field_name)] @@ -450,17 +450,17 @@ (-> Text Text [Member_Declaration FieldDecl] (Parser Code)) (case field (#ConstantField _) - (make_get_const_parser class_name field_name) + (get_const_parser class_name field_name) (#VariableField _) - (<>.either (make_get_var_parser class_name field_name self_name) - (make_put_var_parser class_name field_name self_name)))) + (<>.either (get_var_parser class_name field_name self_name) + (put_var_parser class_name field_name self_name)))) (def: (decorate_input [class value]) (-> [(Type Value) Code] Code) (` [(~ (code.text (..signature class))) (~ value)])) -(def: (make_constructor_parser class_name arguments) +(def: (constructor_parser class_name arguments) (-> Text (List Argument) (Parser Code)) (do <>.monad [args (: (Parser (List Code)) @@ -471,7 +471,7 @@ (list.zipped/2 (list\map product.right arguments)) (list\map ..decorate_input)))))))) -(def: (make_static_method_parser class_name method_name arguments) +(def: (static_method_parser class_name method_name arguments) (-> Text Text (List Argument) (Parser Code)) (do <>.monad [.let [dotted_name (format "::" method_name "!")] @@ -497,30 +497,30 @@ (list.zipped/2 (list\map product.right arguments)) (list\map ..decorate_input))))))))] - [make_special_method_parser "jvm member invoke special"] - [make_virtual_method_parser "jvm member invoke virtual"] + [special_method_parser "jvm member invoke special"] + [virtual_method_parser "jvm member invoke virtual"] ) (def: (method->parser class_name [[method_name _ _] meth_def]) (-> Text [Member_Declaration Method_Definition] (Parser Code)) (case meth_def (#ConstructorMethod strict? type_vars self_name args constructor_args return_expr exs) - (make_constructor_parser class_name args) + (constructor_parser class_name args) (#StaticMethod strict? type_vars args return_type return_expr exs) - (make_static_method_parser class_name method_name args) + (static_method_parser class_name method_name args) (#VirtualMethod final? strict? type_vars self_name args return_type return_expr exs) - (make_virtual_method_parser class_name method_name args self_name) + (virtual_method_parser class_name method_name args self_name) (#OverridenMethod strict? owner_class type_vars self_name args return_type return_expr exs) - (make_special_method_parser class_name method_name args self_name) + (special_method_parser class_name method_name args self_name) (#AbstractMethod type_vars args return_type exs) - (make_virtual_method_parser class_name method_name args "") + (virtual_method_parser class_name method_name args "") (#NativeMethod type_vars args return_type exs) - (make_virtual_method_parser class_name method_name args ""))) + (virtual_method_parser class_name method_name args ""))) (def: privacy_modifier^ (Parser Privacy) diff --git a/stdlib/source/library/lux/macro/syntax/definition.lux b/stdlib/source/library/lux/macro/syntax/definition.lux index 14e907870..79fde60e7 100644 --- a/stdlib/source/library/lux/macro/syntax/definition.lux +++ b/stdlib/source/library/lux/macro/syntax/definition.lux @@ -124,7 +124,7 @@ <code>.bit )))) -(exception: .public (lacks_type! {definition Definition}) +(exception: .public (lacks_type {definition Definition}) (exception.report ["Definition" (%.code (..format definition))])) @@ -138,5 +138,5 @@ (in []) (#.Right _) - (<>.lifted (exception.except ..lacks_type! [definition])))] + (<>.lifted (exception.except ..lacks_type [definition])))] (in definition))) diff --git a/stdlib/source/library/lux/math/number/rev.lux b/stdlib/source/library/lux/math/number/rev.lux index 3fc60202c..c7d5641ce 100644 --- a/stdlib/source/library/lux/math/number/rev.lux +++ b/stdlib/source/library/lux/math/number/rev.lux @@ -25,6 +25,7 @@ Rev (.rev (//i64.left_shifted (//nat.- <power> //i64.width) 1)))] + [00 /1] [01 /2] [02 /4] [03 /8] diff --git a/stdlib/source/library/lux/meta.lux b/stdlib/source/library/lux/meta.lux index 7b6e893d3..0b4b809fc 100644 --- a/stdlib/source/library/lux/meta.lux +++ b/stdlib/source/library/lux/meta.lux @@ -599,3 +599,10 @@ (#try.Failure error) (..failure error))) + +(def: .public (eval type code) + (-> Type Code (Meta Any)) + (do {! ..monad} + [eval (\ ! map (value@ #.eval) + ..compiler_state)] + (eval type code))) diff --git a/stdlib/source/library/lux/test.lux b/stdlib/source/library/lux/test.lux index 29af87345..e92cd49e4 100644 --- a/stdlib/source/library/lux/test.lux +++ b/stdlib/source/library/lux/test.lux @@ -310,7 +310,7 @@ Text (text.of_char 31)) -(def: encode_coverage +(def: encoded_coverage (-> (List Text) Text) (list\fold (function (_ short aggregate) (case aggregate @@ -318,7 +318,7 @@ _ (format aggregate ..coverage_separator short))) "")) -(def: (decode_coverage module encoding) +(def: (coverage module encoding) (-> Text Text (Set Name)) (loop [remaining encoding output (set.of_list name.hash (list))] @@ -366,7 +366,7 @@ (def: (covering' module coverage test) (-> Text Text Test Test) - (let [coverage (..decode_coverage module coverage)] + (let [coverage (..coverage module coverage)] (|> (..context module test) (random\map (async\map (function (_ [tally documentation]) [(revised@ #expected_coverage (set.union coverage) tally) @@ -388,7 +388,7 @@ (#.Item short aggregate) aggregate)) #.End) - ..encode_coverage)]] + ..encoded_coverage)]] (in (list (` ((~! ..covering') (~ (code.text module)) (~ (code.text coverage)) diff --git a/stdlib/source/library/lux/tool/compiler/default/init.lux b/stdlib/source/library/lux/tool/compiler/default/init.lux index 04971dadd..c01a1f6c1 100644 --- a/stdlib/source/library/lux/tool/compiler/default/init.lux +++ b/stdlib/source/library/lux/tool/compiler/default/init.lux @@ -169,9 +169,9 @@ (in [buffer registry]))) ... TODO: Inline ASAP -(def: (process_directive archive expander pre_payoad code) +(def: (process_directive wrapper archive expander pre_payoad code) (All [directive] - (-> Archive Expander (Payload directive) Code + (-> ///phase.Wrapper Archive Expander (Payload directive) Code (All [anchor expression] (///directive.Operation anchor expression directive [Requirements (Payload directive)])))) @@ -181,26 +181,26 @@ (///generation.set_buffer pre_buffer)) _ (///directive.lifted_generation (///generation.set_registry pre_registry)) - requirements (let [execute! (directiveP.phase expander)] + requirements (let [execute! (directiveP.phase wrapper expander)] (execute! archive code)) post_payload (..get_current_payload pre_payoad)] (in [requirements post_payload]))) -(def: (iteration' archive expander reader source pre_payload) +(def: (iteration' wrapper archive expander reader source pre_payload) (All [directive] - (-> Archive Expander Reader Source (Payload directive) + (-> ///phase.Wrapper Archive Expander Reader Source (Payload directive) (All [anchor expression] (///directive.Operation anchor expression directive [Source Requirements (Payload directive)])))) (do ///phase.monad [[source code] (///directive.lifted_analysis (..read source reader)) - [requirements post_payload] (process_directive archive expander pre_payload code)] + [requirements post_payload] (process_directive wrapper archive expander pre_payload code)] (in [source requirements post_payload]))) -(def: (iteration archive expander module source pre_payload aliases) +(def: (iteration wrapper archive expander module source pre_payload aliases) (All [directive] - (-> Archive Expander Module Source (Payload directive) Aliases + (-> ///phase.Wrapper Archive Expander Module Source (Payload directive) Aliases (All [anchor expression] (///directive.Operation anchor expression directive (Maybe [Source Requirements (Payload directive)]))))) @@ -208,7 +208,7 @@ [reader (///directive.lifted_analysis (..reader module aliases source))] (function (_ state) - (case (///phase.result' state (..iteration' archive expander reader source pre_payload)) + (case (///phase.result' state (..iteration' wrapper archive expander reader source pre_payload)) (#try.Success [state source&requirements&buffer]) (#try.Success [state (#.Some source&requirements&buffer)]) @@ -228,11 +228,11 @@ (-> .Module Aliases) (|>> (value@ #.module_aliases) (dictionary.of_list text.hash))) -(def: .public (compiler expander prelude write_directive) +(def: .public (compiler wrapper expander prelude write_directive) (All [anchor expression directive] - (-> Expander Module (-> directive Binary) + (-> ///phase.Wrapper Expander Module (-> directive Binary) (Instancer (///directive.State+ anchor expression directive) .Module))) - (let [execute! (directiveP.phase expander)] + (let [execute! (directiveP.phase wrapper expander)] (function (_ key parameters input) (let [dependencies (default_dependencies prelude input)] {#///.dependencies dependencies @@ -243,7 +243,7 @@ (..begin dependencies hash input)) .let [module (value@ #///.module input)]] (loop [iteration (<| (///phase.result' state) - (..iteration archive expander module source buffer ///syntax.no_aliases))] + (..iteration wrapper archive expander module source buffer ///syntax.no_aliases))] (do ! [[state ?source&requirements&temporary_payload] iteration] (case ?source&requirements&temporary_payload @@ -284,5 +284,5 @@ (value@ #///directive.referrals) (monad.map ! (execute! archive))) temporary_payload (..get_current_payload temporary_payload)] - (..iteration archive expander module source temporary_payload (..module_aliases analysis_module))))))})])) + (..iteration wrapper archive expander module source temporary_payload (..module_aliases analysis_module))))))})])) )))))})))) diff --git a/stdlib/source/library/lux/tool/compiler/default/platform.lux b/stdlib/source/library/lux/tool/compiler/default/platform.lux index 1ac28821f..b5eed68f8 100644 --- a/stdlib/source/library/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/library/lux/tool/compiler/default/platform.lux @@ -64,15 +64,12 @@ (with_expansions [<type_vars> (as_is anchor expression directive) <Operation> (as_is ///generation.Operation <type_vars>)] - (type: .public Phase_Wrapper - (All [s i o] (-> (Phase s i o) Any))) - (type: .public (Platform <type_vars>) {#&file_system (file.System Async) #host (///generation.Host expression directive) #phase (///generation.Phase <type_vars>) #runtime (<Operation> [Registry Output]) - #phase_wrapper (-> Archive (<Operation> Phase_Wrapper)) + #phase_wrapper (-> Archive (<Operation> ///phase.Wrapper)) #write (-> directive Binary)}) ... TODO: Get rid of this @@ -197,7 +194,7 @@ (def: (phase_wrapper archive platform state) (All [<type_vars>] - (-> Archive <Platform> <State+> (Try [<State+> Phase_Wrapper]))) + (-> Archive <Platform> <State+> (Try [<State+> ///phase.Wrapper]))) (let [phase_wrapper (value@ #phase_wrapper platform)] (|> archive phase_wrapper @@ -206,8 +203,8 @@ (def: (complete_extensions host_directive_bundle phase_wrapper [analysers synthesizers generators directives]) (All [<type_vars>] - (-> (-> Phase_Wrapper (///directive.Bundle <type_vars>)) - Phase_Wrapper + (-> (-> ///phase.Wrapper (///directive.Bundle <type_vars>)) + ///phase.Wrapper [(Dictionary Text ///analysis.Handler) (Dictionary Text ///synthesis.Handler) (Dictionary Text (///generation.Handler <type_vars>)) @@ -230,11 +227,11 @@ ///analysis.Bundle <Platform> <Bundle> - (-> Phase_Wrapper (///directive.Bundle <type_vars>)) + (-> ///phase.Wrapper (///directive.Bundle <type_vars>)) (Program expression directive) - [Type Type Type] (-> Phase_Wrapper Extender) + [Type Type Type] (-> ///phase.Wrapper Extender) Import (List Context) - (Async (Try [<State+> Archive])))) + (Async (Try [<State+> Archive ///phase.Wrapper])))) (do {! (try.with async.monad)} [.let [state (//init.state (value@ #static.host static) module @@ -247,7 +244,8 @@ [archive analysis_state bundles] (ioW.thaw (value@ #host platform) (value@ #&file_system platform) static import compilation_sources) .let [with_missing_extensions (: (All [<type_vars>] - (-> <Platform> (Program expression directive) <State+> (Async (Try <State+>)))) + (-> <Platform> (Program expression directive) <State+> + (Async (Try [///phase.Wrapper <State+>])))) (function (_ platform program state) (async\in (do try.monad @@ -256,19 +254,20 @@ (initialize_state (extender phase_wrapper) (:expected (..complete_extensions host_directive_bundle phase_wrapper (:expected bundles))) analysis_state) - (try\map (//init.with_default_directives expander host_analysis program anchorT,expressionT,directiveT (extender phase_wrapper))))))))]] + (try\map (|>> (//init.with_default_directives expander host_analysis program anchorT,expressionT,directiveT (extender phase_wrapper)) + [phase_wrapper])))))))]] (if (archive.archived? archive archive.runtime_module) (do ! - [state (with_missing_extensions platform program state)] - (in [state archive])) + [[phase_wrapper state] (with_missing_extensions platform program state)] + (in [state archive phase_wrapper])) (do ! [[state [archive payload]] (|> (..process_runtime archive platform) (///phase.result' state) async\in) _ (..cache_module static platform 0 payload) - state (with_missing_extensions platform program state)] - (in [state archive]))))) + [phase_wrapper state] (with_missing_extensions platform program state)] + (in [state archive phase_wrapper]))))) (def: compilation_log_separator (format text.new_line text.tab)) @@ -523,9 +522,9 @@ try.trusted product.left)) - (def: .public (compile import static expander platform compilation context) + (def: .public (compile phase_wrapper import static expander platform compilation context) (All [<type_vars>] - (-> Import Static Expander <Platform> Compilation <Context> <Return>)) + (-> ///phase.Wrapper Import Static Expander <Platform> Compilation <Context> <Return>)) (let [[compilation_sources compilation_host_dependencies compilation_libraries compilation_target compilation_module] compilation base_compiler (:sharing [<type_vars>] <Context> @@ -533,7 +532,7 @@ (///.Compiler <State+> .Module Any) (:expected - ((//init.compiler expander syntax.prelude (value@ #write platform)) $.key (list)))) + ((//init.compiler phase_wrapper expander syntax.prelude (value@ #write platform)) $.key (list)))) compiler (..parallel context (function (_ importer import! module_id [archive state] module) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux index aefd908c4..45216a70f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis.lux @@ -553,4 +553,5 @@ #.seed 0 #.scope_type_vars (list) #.extensions [] + #.eval (:as (-> Type Code (Meta Any)) []) #.host []}) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux index 1859802d6..8bba841e2 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/evaluation.lux @@ -27,7 +27,7 @@ [descriptor (#+ Module)]]]]]]]]) (type: .public Eval - (-> Archive Nat Type Code (Operation Any))) + (-> Archive Type Code (Operation Any))) (def: (context [module_id artifact_id]) (-> Context Context) @@ -42,12 +42,14 @@ (generation.Phase anchor expression artifact) Eval)) (let [analyze (analysisP.phase expander)] - (function (eval archive count type exprC) + (function (eval archive type exprC) (do phase.monad [exprA (type.with_type type (analyze archive exprC)) module (extensionP.lifted - meta.current_module_name)] + meta.current_module_name) + count (extensionP.lifted + meta.seed)] (phase.lifted (do try.monad [exprS (|> exprA (synthesisP.phase archive) (phase.result synthesis_state))] (phase.result generation_state diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux index ee12a8bf0..c8cfe9c0e 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis.lux @@ -124,10 +124,10 @@ (compile archive expansion)) _ - (/function.on compile argsC+ functionT functionA archive functionC))) + (/function.apply compile argsC+ functionT functionA archive functionC))) _ - (/function.on compile argsC+ functionT functionA archive functionC))) + (/function.apply compile argsC+ functionT functionA archive functionC))) _ (//.except ..unrecognized_syntax [location.dummy code']))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux index b3642f5f3..fc7575260 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux @@ -84,7 +84,7 @@ (#.Var id) (do ///.monad [?caseT' (//type.with_env - (check.read id))] + (check.read' id))] (.case ?caseT' (#.Some caseT') (recur envs caseT') @@ -110,7 +110,7 @@ (do ///.monad [funcT' (//type.with_env (do check.monad - [?funct' (check.read funcT_id)] + [?funct' (check.read' funcT_id)] (.case ?funct' (#.Some funct') (in funct') diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux index 69e75f374..8aa2f284f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux @@ -71,7 +71,7 @@ (#.Var id) (do ! [?expectedT' (//type.with_env - (check.read id))] + (check.read' id))] (case ?expectedT' (#.Some expectedT') (recur expectedT') @@ -85,8 +85,7 @@ functionA (recur functionT) _ (//type.with_env (check.check expectedT functionT))] - (in functionA)) - )) + (in functionA)))) (#.Function inputT outputT) (<| (\ ! map (.function (_ [scope bodyA]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux index 0420b7811..452bf6bc1 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/inference.lux @@ -166,7 +166,8 @@ (#.Var infer_id) (do ///.monad - [?inferT' (//type.with_env (check.read infer_id))] + [?inferT' (//type.with_env + (check.read' infer_id))] (case ?inferT' (#.Some inferT') (general archive analyse inferT' args) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux index fe296c83e..886ffe065 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux @@ -119,7 +119,7 @@ (#.Var id) (do ! [?expectedT' (//type.with_env - (check.read id))] + (check.read' id))] (case ?expectedT' (#.Some expectedT') (//type.with_type expectedT' @@ -144,7 +144,8 @@ (case funT (#.Var funT_id) (do ! - [?funT' (//type.with_env (check.read funT_id))] + [?funT' (//type.with_env + (check.read' funT_id))] (case ?funT' (#.Some funT') (//type.with_type (#.Apply inputT funT') @@ -208,7 +209,7 @@ (#.Var id) (do ! [?expectedT' (//type.with_env - (check.read id))] + (check.read' id))] (case ?expectedT' (#.Some expectedT') (//type.with_type expectedT' @@ -237,7 +238,8 @@ (case funT (#.Var funT_id) (do ! - [?funT' (//type.with_env (check.read funT_id))] + [?funT' (//type.with_env + (check.read' funT_id))] (case ?funT' (#.Some funT') (//type.with_type (#.Apply inputT funT') diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/directive.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/directive.lux index cc34e04cf..3c6425da3 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/directive.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/directive.lux @@ -1,16 +1,17 @@ (.module: [library [lux #* + ["." meta] [abstract ["." monad (#+ do)]] [control + ["." try] ["." exception (#+ exception:)]] [data [text ["%" format (#+ format)]] [collection - ["." list ("#\." fold monoid)]]] - ["." meta]]] + ["." list ("#\." fold monoid)]]]]] ["." // #_ ["#." extension] ["#." analysis @@ -18,11 +19,14 @@ ["/#" // #_ ["/" directive (#+ Phase)] ["#." analysis + ["." evaluation] ["#/." macro (#+ Expander)]] [/// ["//" phase] [reference (#+) - [variable (#+)]]]]]) + [variable (#+)]] + [meta + [archive (#+ Archive)]]]]]) (exception: .public (not_a_directive {code Code}) (exception.report @@ -36,44 +40,68 @@ (exception.report ["Name" (%.name name)])) +(type: Eval + (-> Type Code (Meta Any))) + +(def: (meta_eval archive bundle compiler_eval) + (-> Archive ///analysis.Bundle evaluation.Eval + Eval) + (function (_ type code lux) + (case (compiler_eval archive type code [bundle lux]) + (#try.Success [[_bundle lux'] value]) + (#try.Success [lux' value]) + + (#try.Failure error) + (#try.Failure error)))) + (with_expansions [<lux_def_module> (as_is [|form_location| (#.Form (list& [|text_location| (#.Text "lux def module")] annotations))])] - (def: .public (phase expander) - (-> Expander Phase) - (let [analyze (//analysis.phase expander)] + (def: .public (phase wrapper expander) + (-> //.Wrapper Expander Phase) + (let [analysis (//analysis.phase expander)] (function (recur archive code) - (case code - (^ [_ (#.Form (list& [_ (#.Text name)] inputs))]) - (//extension.apply archive recur [name inputs]) + (do {! //.monad} + [state //.get_state + .let [compiler_eval (meta_eval archive + (value@ [#//extension.state #/.analysis #/.state #//extension.bundle] state) + (evaluation.evaluator expander + (value@ [#//extension.state #/.synthesis #/.state] state) + (value@ [#//extension.state #/.generation #/.state] state) + (value@ [#//extension.state #/.generation #/.phase] state))) + extension_eval (:as Eval (wrapper (:expected compiler_eval)))] + _ (//.set_state (with@ [#//extension.state #/.analysis #/.state #//extension.state #.eval] extension_eval state))] + (case code + (^ [_ (#.Form (list& [_ (#.Text name)] inputs))]) + (//extension.apply archive recur [name inputs]) - (^ [_ (#.Form (list& macro inputs))]) - (do {! //.monad} - [expansion (/.lifted_analysis - (do ! - [macroA (//analysis/type.with_type Macro - (analyze archive macro))] - (case macroA - (^ (///analysis.constant macro_name)) - (do ! - [?macro (//extension.lifted (meta.macro macro_name)) - macro (case ?macro - (#.Some macro) - (in macro) - - #.None - (//.except ..macro_was_not_found macro_name))] - (//extension.lifted (///analysis/macro.expand expander macro_name macro inputs))) - - _ - (//.except ..invalid_macro_call code))))] - (case expansion - (^ (list& <lux_def_module> referrals)) - (|> (recur archive <lux_def_module>) - (\ ! map (revised@ #/.referrals (list\compose referrals)))) + (^ [_ (#.Form (list& macro inputs))]) + (do ! + [expansion (/.lifted_analysis + (do ! + [macroA (//analysis/type.with_type Macro + (analysis archive macro))] + (case macroA + (^ (///analysis.constant macro_name)) + (do ! + [?macro (//extension.lifted (meta.macro macro_name)) + macro (case ?macro + (#.Some macro) + (in macro) + + #.None + (//.except ..macro_was_not_found macro_name))] + (//extension.lifted (///analysis/macro.expand expander macro_name macro inputs))) + + _ + (//.except ..invalid_macro_call code))))] + (case expansion + (^ (list& <lux_def_module> referrals)) + (|> (recur archive <lux_def_module>) + (\ ! map (revised@ #/.referrals (list\compose referrals)))) - _ - (|> expansion - (monad.map ! (recur archive)) - (\ ! map (list\fold /.merge_requirements /.no_requirements))))) + _ + (|> expansion + (monad.map ! (recur archive)) + (\ ! map (list\fold /.merge_requirements /.no_requirements))))) - _ - (//.except ..not_a_directive code)))))) + _ + (//.except ..not_a_directive code))))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lux.lux index d26820e9a..e56a48572 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lux.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lux.lux @@ -164,9 +164,8 @@ (case args (^ (list typeC valueC)) (do {! ////.monad} - [seed (///.lifted meta.seed) - actualT (\ ! map (|>> (:as Type)) - (eval archive seed Type typeC)) + [actualT (\ ! map (|>> (:as Type)) + (eval archive Type typeC)) _ (typeA.infer actualT)] (typeA.with_type actualT (analyse archive valueC))) @@ -180,9 +179,8 @@ (case args (^ (list typeC valueC)) (do {! ////.monad} - [seed (///.lifted meta.seed) - actualT (\ ! map (|>> (:as Type)) - (eval archive seed Type typeC)) + [actualT (\ ! map (|>> (:as Type)) + (eval archive Type typeC)) _ (typeA.infer actualT) [valueT valueA] (typeA.with_inference (analyse archive valueC))] @@ -240,7 +238,8 @@ (///bundle.install "error" (unary Text Nothing)) (///bundle.install "exit" (unary Int Nothing))))) -(def: I64* (type (I64 Any))) +(def: I64* + (type (I64 Any))) (def: bundle::i64 Bundle diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux index 1e7ca8cc3..f26b13ade 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/function.lux @@ -34,7 +34,7 @@ (def: arity_arguments (-> Arity (List Synthesis)) - (|>> dec + (|>> -- (enum.range n.enum 1) (list\map (|>> /.variable/local)))) diff --git a/stdlib/source/library/lux/tool/compiler/phase.lux b/stdlib/source/library/lux/tool/compiler/phase.lux index 92680654d..7e137387e 100644 --- a/stdlib/source/library/lux/tool/compiler/phase.lux +++ b/stdlib/source/library/lux/tool/compiler/phase.lux @@ -34,6 +34,9 @@ (type: .public (Phase s i o) (-> Archive i (Operation s o))) +(type: .public Wrapper + (All [s i o] (-> (Phase s i o) Any))) + (def: .public (result' state operation) (All [s o] (-> s (Operation s o) (Try [s o]))) |