aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux.lux
diff options
context:
space:
mode:
authorEduardo Julian2021-08-08 17:56:15 -0400
committerEduardo Julian2021-08-08 17:56:15 -0400
commitf621a133e6e0a516c0586270fea8eaffb4829d82 (patch)
tree399396ee2f6a10df10cea9b78c51c76679b70e59 /stdlib/source/library/lux.lux
parent17e7566be51df5e428a6b10e6469201a8a9468da (diff)
No more #export magic syntax.
Diffstat (limited to 'stdlib/source/library/lux.lux')
-rw-r--r--stdlib/source/library/lux.lux1436
1 files changed, 792 insertions, 644 deletions
diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux
index e9b0278e5..ec1eac721 100644
--- a/stdlib/source/library/lux.lux
+++ b/stdlib/source/library/lux.lux
@@ -23,7 +23,7 @@
[dummy_location (9 #1 (0 #0))]
#1)
-## (type: #export Any
+## (type: .public Any
## (Ex [a] a))
("lux def" Any
("lux type check type"
@@ -37,7 +37,7 @@
(0 #0)))]
#1)
-## (type: #export Nothing
+## (type: .public Nothing
## (All [a] a))
("lux def" Nothing
("lux type check type"
@@ -51,7 +51,7 @@
(0 #0)))]
#1)
-## (type: #export (List a)
+## (type: .public (List a)
## #End
## (#Item a (List a)))
("lux def type tagged" List
@@ -156,7 +156,7 @@
#End))]
#1)
-## (type: #export (Maybe a)
+## (type: .public (Maybe a)
## #None
## (#Some a))
("lux def type tagged" Maybe
@@ -175,7 +175,7 @@
["None" "Some"]
#1)
-## (type: #export #rec Type
+## (type: .public #rec Type
## (#Primitive Text (List Type))
## (#Sum Type Type)
## (#Product Type Type)
@@ -229,7 +229,7 @@
["Primitive" "Sum" "Product" "Function" "Parameter" "Var" "Ex" "UnivQ" "ExQ" "Apply" "Named"]
#1)
-## (type: #export Location
+## (type: .public Location
## {#module Text
## #line Nat
## #column Nat})
@@ -243,7 +243,7 @@
["module" "line" "column"]
#1)
-## (type: #export (Ann m v)
+## (type: .public (Ann m v)
## {#meta m
## #datum v})
("lux def type tagged" Ann
@@ -261,7 +261,7 @@
["meta" "datum"]
#1)
-## (type: #export (Code' w)
+## (type: .public (Code' w)
## (#Bit Bit)
## (#Nat Nat)
## (#Int Int)
@@ -313,7 +313,7 @@
["Bit" "Nat" "Int" "Rev" "Frac" "Text" "Identifier" "Tag" "Form" "Tuple" "Record"]
#1)
-## (type: #export Code
+## (type: .public Code
## (Ann Location (Code' (Ann Location))))
("lux def" Code
(#Named ["library/lux" "Code"]
@@ -326,6 +326,38 @@
#End))]
#1)
+("lux def" private
+ #0
+ [dummy_location
+ (#Record (#Item [[dummy_location (#Tag ["library/lux" "doc"])]
+ [dummy_location (#Text "The export policy for private/local definitions.")]]
+ #End))]
+ #1)
+
+("lux def" public
+ #1
+ [dummy_location
+ (#Record (#Item [[dummy_location (#Tag ["library/lux" "doc"])]
+ [dummy_location (#Text "The export policy for public/global definitions.")]]
+ #End))]
+ #1)
+
+("lux def" local
+ #0
+ [dummy_location
+ (#Record (#Item [[dummy_location (#Tag ["library/lux" "doc"])]
+ [dummy_location (#Text "The export policy for private/local definitions.")]]
+ #End))]
+ #1)
+
+("lux def" global
+ #1
+ [dummy_location
+ (#Record (#Item [[dummy_location (#Tag ["library/lux" "doc"])]
+ [dummy_location (#Text "The export policy for public/global definitions.")]]
+ #End))]
+ #1)
+
("lux def" _ann
("lux type check"
(#Function (#Apply (#Apply Location Ann)
@@ -414,7 +446,7 @@
[dummy_location (#Record #End)]
#0)
-## (type: #export Definition
+## (type: .public Definition
## [Bit Type Code Any])
("lux def" Definition
("lux type check type"
@@ -425,7 +457,7 @@
#End))
#1)
-## (type: #export Alias
+## (type: .public Alias
## Name)
("lux def" Alias
("lux type check type"
@@ -434,7 +466,7 @@
(record$ #End)
#1)
-## (type: #export Global
+## (type: .public Global
## (#Alias Alias)
## (#Definition Definition))
("lux def type tagged" Global
@@ -447,7 +479,7 @@
["Alias" "Definition"]
#1)
-## (type: #export (Bindings k v)
+## (type: .public (Bindings k v)
## {#counter Nat
## #mappings (List [k v])})
("lux def type tagged" Bindings
@@ -466,7 +498,7 @@
["counter" "mappings"]
#1)
-## (type: #export Ref
+## (type: .public Ref
## (#Local Nat)
## (#Captured Nat))
("lux def type tagged" Ref
@@ -479,7 +511,7 @@
["Local" "Captured"]
#1)
-## (type: #export Scope
+## (type: .public Scope
## {#name (List Text)
## #inner Nat
## #locals (Bindings Text [Type Nat])
@@ -504,7 +536,7 @@
(record$ #End)
#0)
-## (type: #export (Either l r)
+## (type: .public (Either l r)
## (#Left l)
## (#Right r))
("lux def type tagged" Either
@@ -523,7 +555,7 @@
["Left" "Right"]
#1)
-## (type: #export Source
+## (type: .public Source
## [Location Nat Text])
("lux def" Source
("lux type check type"
@@ -532,7 +564,7 @@
(record$ #End)
#1)
-## (type: #export Module_State
+## (type: .public Module_State
## #Active
## #Compiled
## #Cached)
@@ -550,7 +582,7 @@
["Active" "Compiled" "Cached"]
#1)
-## (type: #export Module
+## (type: .public Module
## {#module_hash Nat
## #module_aliases (List [Text Text])
## #definitions (List [Text Global])
@@ -592,7 +624,7 @@
["module_hash" "module_aliases" "definitions" "imports" "tags" "types" "module_annotations" "module_state"]
#1)
-## (type: #export Type_Context
+## (type: .public Type_Context
## {#ex_counter Nat
## #var_counter Nat
## #var_bindings (List [Nat (Maybe Type)])})
@@ -609,7 +641,7 @@
["ex_counter" "var_counter" "var_bindings"]
#1)
-## (type: #export Mode
+## (type: .public Mode
## #Build
## #Eval
## #Interpreter)
@@ -627,7 +659,7 @@
["Build" "Eval" "Interpreter"]
#1)
-## (type: #export Info
+## (type: .public Info
## {#target Text
## #version Text
## #mode Mode})
@@ -647,7 +679,7 @@
["target" "version" "mode"]
#1)
-## (type: #export Lux
+## (type: .public Lux
## {#info Info
## #source Source
## #location Location
@@ -696,7 +728,7 @@
["info" "source" "location" "current_module" "modules" "scopes" "type_context" "expected" "seed" "scope_type_vars" "extensions" "host"]
#1)
-## (type: #export (Meta a)
+## (type: .public (Meta a)
## (-> Lux (Either Text [Lux a])))
("lux def" Meta
("lux type check type"
@@ -714,7 +746,7 @@
#End)))
#1)
-## (type: #export Macro'
+## (type: .public Macro'
## (-> (List Code) (Meta (List Code))))
("lux def" Macro'
("lux type check type"
@@ -723,7 +755,7 @@
(record$ #End)
#1)
-## (type: #export Macro
+## (type: .public Macro
## (primitive "#Macro"))
("lux def" Macro
("lux type check type"
@@ -839,9 +871,9 @@
#0)
("lux def" as_def
- ("lux type check" (#Function Code (#Function Code (#Function Code (#Function Bit Code))))
- (function'' [name value annotations exported?]
- (form$ (#Item (text$ "lux def") (#Item name (#Item value (#Item annotations (#Item (bit$ exported?) #End))))))))
+ ("lux type check" (#Function Code (#Function Code (#Function Code (#Function Code Code))))
+ (function'' [name value annotations export_policy]
+ (form$ (#Item (text$ "lux def") (#Item name (#Item value (#Item annotations (#Item export_policy #End))))))))
(record$ #End)
#0)
@@ -874,39 +906,22 @@
("lux def" def:''
("lux macro"
(function'' [tokens]
- ({(#Item [[_ (#Tag ["" "export"])]
+ ({(#Item [export_policy
(#Item [[_ (#Form (#Item [name args]))]
(#Item [meta (#Item [type (#Item [body #End])])])])])
(in_meta (#Item [(as_def name (as_checked type (as_function name args body))
(form$ (#Item (identifier$ ["library/lux" "record$"])
(#Item meta
#End)))
- #1)
+ export_policy)
#End]))
- (#Item [[_ (#Tag ["" "export"])] (#Item [name (#Item [meta (#Item [type (#Item [body #End])])])])])
+ (#Item [export_policy (#Item [name (#Item [meta (#Item [type (#Item [body #End])])])])])
(in_meta (#Item [(as_def name (as_checked type body)
(form$ (#Item (identifier$ ["library/lux" "record$"])
(#Item meta
#End)))
- #1)
- #End]))
-
- (#Item [[_ (#Form (#Item [name args]))]
- (#Item [meta (#Item [type (#Item [body #End])])])])
- (in_meta (#Item [(as_def name (as_checked type (as_function name args body))
- (form$ (#Item (identifier$ ["library/lux" "record$"])
- (#Item meta
- #End)))
- #0)
- #End]))
-
- (#Item [name (#Item [meta (#Item [type (#Item [body #End])])])])
- (in_meta (#Item [(as_def name (as_checked type body)
- (form$ (#Item (identifier$ ["library/lux" "record$"])
- (#Item meta
- #End)))
- #0)
+ export_policy)
#End]))
_
@@ -918,28 +933,20 @@
("lux def" macro:'
("lux macro"
(function'' [tokens]
- ({(#Item [_ (#Form (#Item name args))] (#Item body #End))
+ ({(#Item export_policy (#Item [_ (#Form (#Item name args))] (#Item body #End)))
(in_meta (#Item (as_def name (as_macro (as_function name args body))
(form$ (#Item (identifier$ ["library/lux" "record$"])
(#Item (tag$ ["library/lux" "End"])
#End)))
- #0)
+ export_policy)
#End))
- (#Item [_ (#Tag ["" "export"])] (#Item [_ (#Form (#Item name args))] (#Item body #End)))
- (in_meta (#Item (as_def name (as_macro (as_function name args body))
- (form$ (#Item (identifier$ ["library/lux" "record$"])
- (#Item (tag$ ["library/lux" "End"])
- #End)))
- #1)
- #End))
-
- (#Item [_ (#Tag ["" "export"])] (#Item [_ (#Form (#Item name args))] (#Item meta_data (#Item body #End))))
+ (#Item export_policy (#Item [_ (#Form (#Item name args))] (#Item meta_data (#Item body #End))))
(in_meta (#Item (as_def name (as_macro (as_function name args body))
(form$ (#Item (identifier$ ["library/lux" "record$"])
(#Item meta_data
#End)))
- #1)
+ export_policy)
#End))
_
@@ -948,7 +955,7 @@
(record$ #.End)
#0)
-(macro:' #export (comment tokens)
+(macro:' .public (comment tokens)
(#Item [(tag$ ["library/lux" "doc"])
(text$ ("lux text concat"
("lux text concat" "## Throws away any code given to it." __paragraph)
@@ -958,7 +965,7 @@
#End)
(in_meta #End))
-(macro:' ($' tokens)
+(macro:' .private ($' tokens)
({(#Item x #End)
(in_meta tokens)
@@ -973,7 +980,7 @@
(failure "Wrong syntax for $'")}
tokens))
-(def:'' (list\map f xs)
+(def:'' .private (list\map f xs)
#End
(#UnivQ #End
(#UnivQ #End
@@ -987,12 +994,12 @@
(#Item (f x) (list\map f xs'))}
xs))
-(def:'' Replacement_Environment
+(def:'' .private Replacement_Environment
#End
Type
($' List (#Product Text Code)))
-(def:'' (replacement_environment xs ys)
+(def:'' .private (replacement_environment xs ys)
#End
(#Function ($' List Text) (#Function ($' List Code) Replacement_Environment))
({[(#Item x xs') (#Item y ys')]
@@ -1002,12 +1009,12 @@
#End}
[xs ys]))
-(def:'' (text\= reference sample)
+(def:'' .private (text\= reference sample)
#End
(#Function Text (#Function Text Bit))
("lux text =" reference sample))
-(def:'' (replacement for environment)
+(def:'' .private (replacement for environment)
#End
(#Function Text (#Function Replacement_Environment ($' Maybe Code)))
({#End
@@ -1022,7 +1029,7 @@
(text\= k for))}
environment))
-(def:'' (with_replacements reps syntax)
+(def:'' .private (with_replacements reps syntax)
#End
(#Function Replacement_Environment (#Function Code Code))
({[_ (#Identifier "" name)]
@@ -1051,7 +1058,7 @@
syntax}
syntax))
-(def:'' (n/* param subject)
+(def:'' .private (n/* param subject)
#.End
(#Function Nat (#Function Nat Nat))
("lux type as" Nat
@@ -1059,7 +1066,7 @@
("lux type as" Int param)
("lux type as" Int subject))))
-(def:'' (nested_quantification code)
+(def:'' .private (nested_quantification code)
#End
(#Function Code Code)
({[_ (#Tuple members)]
@@ -1082,7 +1089,7 @@
code}
code))
-(def:'' (quantified_args_parser args next)
+(def:'' .private (quantified_args_parser args next)
#End
## (-> (List Code) (-> (List Text) (Meta (List Code))) (Meta (List Code)))
(#Function ($' List Code)
@@ -1099,12 +1106,12 @@
(failure "Expected identifier.")}
args))
-(def:'' (type_parameter idx)
+(def:'' .private (type_parameter idx)
#End
(#Function Nat Code)
(form$ (#Item (tag$ ["library/lux" "Parameter"]) (#Item (nat$ idx) #End))))
-(def:'' (list\fold f init xs)
+(def:'' .private (list\fold f init xs)
#End
## (All [a b] (-> (-> b a a) a (List b) a))
(#UnivQ #End (#UnivQ #End (#Function (#Function (#Parameter 1)
@@ -1120,13 +1127,13 @@
(list\fold f (f x init) xs')}
xs))
-(def:'' (list\size list)
+(def:'' .private (list\size list)
#End
(#UnivQ #End
(#Function ($' List (#Parameter 1)) Nat))
(list\fold (function'' [_ acc] ("lux i64 +" 1 acc)) 0 list))
-(macro:' #export (All tokens)
+(macro:' .public (All tokens)
(#Item [(tag$ ["library/lux" "doc"])
(text$ ("lux text concat"
("lux text concat" "## Universal quantification." __paragraph)
@@ -1171,7 +1178,7 @@
(failure "Wrong syntax for All")}
tokens)))
-(macro:' #export (Ex tokens)
+(macro:' .public (Ex tokens)
(#Item [(tag$ ["library/lux" "doc"])
(text$ ("lux text concat"
("lux text concat" "## Existential quantification." __paragraph)
@@ -1216,7 +1223,7 @@
(failure "Wrong syntax for Ex")}
tokens)))
-(def:'' (list\reverse list)
+(def:'' .private (list\reverse list)
#End
(All [a] (#Function ($' List a) ($' List a)))
(list\fold ("lux type check" (All [a] (#Function a (#Function ($' List a) ($' List a))))
@@ -1224,7 +1231,7 @@
#End
list))
-(macro:' #export (-> tokens)
+(macro:' .public (-> tokens)
(#Item [(tag$ ["library/lux" "doc"])
(text$ ("lux text concat"
("lux text concat" "## Function types:" __paragraph)
@@ -1243,7 +1250,7 @@
(failure "Wrong syntax for ->")}
(list\reverse tokens)))
-(macro:' #export (list xs)
+(macro:' .public (list xs)
(#Item [(tag$ ["library/lux" "doc"])
(text$ ("lux text concat"
("lux text concat" "## List-construction macro." __paragraph)
@@ -1257,7 +1264,7 @@
(list\reverse xs))
#End)))
-(macro:' #export (list& xs)
+(macro:' .public (list& xs)
(#Item [(tag$ ["library/lux" "doc"])
(text$ ("lux text concat"
("lux text concat" "## List-construction macro, with the last element being a tail-list." __paragraph)
@@ -1276,7 +1283,7 @@
(failure "Wrong syntax for list&")}
(list\reverse xs)))
-(macro:' #export (Tuple tokens)
+(macro:' .public (Tuple tokens)
(#Item [(tag$ ["library/lux" "doc"])
(text$ ("lux text concat"
("lux text concat" "## Tuple types:" __paragraph)
@@ -1295,7 +1302,7 @@
prevs)))}
(list\reverse tokens)))
-(macro:' #export (Variant tokens)
+(macro:' .public (Variant tokens)
(#Item [(tag$ ["library/lux" "doc"])
(text$ ("lux text concat"
("lux text concat" "## Variant types:" __paragraph)
@@ -1314,7 +1321,7 @@
prevs)))}
(list\reverse tokens)))
-(macro:' (function' tokens)
+(macro:' .private (function' tokens)
(let'' [name tokens'] ({(#Item [[_ (#Identifier ["" name])] tokens'])
[name tokens']
@@ -1340,8 +1347,8 @@
(failure "Wrong syntax for function'")}
tokens')))
-(macro:' (def:''' tokens)
- ({(#Item [[_ (#Tag ["" "export"])]
+(macro:' .private (def:''' tokens)
+ ({(#Item [export_policy
(#Item [[_ (#Form (#Item [name args]))]
(#Item [meta (#Item [type (#Item [body #End])])])])])
(in_meta (list (form$ (list (text$ "lux def")
@@ -1355,9 +1362,9 @@
(form$ (#Item (identifier$ ["library/lux" "record$"])
(#Item meta
#End)))
- (bit$ #1)))))
+ export_policy))))
- (#Item [[_ (#Tag ["" "export"])] (#Item [name (#Item [meta (#Item [type (#Item [body #End])])])])])
+ (#Item [export_policy (#Item [name (#Item [meta (#Item [type (#Item [body #End])])])])])
(in_meta (list (form$ (list (text$ "lux def")
name
(form$ (list (text$ "lux type check")
@@ -1366,47 +1373,23 @@
(form$ (#Item (identifier$ ["library/lux" "record$"])
(#Item meta
#End)))
- (bit$ #1)))))
-
- (#Item [[_ (#Form (#Item [name args]))]
- (#Item [meta (#Item [type (#Item [body #End])])])])
- (in_meta (list (form$ (list (text$ "lux def")
- name
- (form$ (list (text$ "lux type check")
- type
- (form$ (list (identifier$ ["library/lux" "function'"])
- name
- (tuple$ args)
- body))))
- (form$ (#Item (identifier$ ["library/lux" "record$"])
- (#Item meta
- #End)))
- (bit$ #0)))))
-
- (#Item [name (#Item [meta (#Item [type (#Item [body #End])])])])
- (in_meta (list (form$ (list (text$ "lux def")
- name
- (form$ (list (text$ "lux type check") type body))
- (form$ (#Item (identifier$ ["library/lux" "record$"])
- (#Item meta
- #End)))
- (bit$ #0)))))
+ export_policy))))
_
(failure "Wrong syntax for def:'''")}
tokens))
-(def:''' #export Or
+(def:''' .public Or
#End
Macro
..Variant)
-(def:''' #export And
+(def:''' .public And
#End
Macro
..Tuple)
-(def:''' (pairs xs)
+(def:''' .private (pairs xs)
#End
(All [a] (-> ($' List a) ($' List (Tuple a a))))
({(#Item x (#Item y xs'))
@@ -1416,7 +1399,7 @@
#End}
xs))
-(macro:' (let' tokens)
+(macro:' .private (let' tokens)
({(#Item [[_ (#Tuple bindings)] (#Item [body #End])])
(in_meta (list (list\fold ("lux type check" (-> (Tuple Code Code) Code
Code)
@@ -1431,7 +1414,7 @@
(failure "Wrong syntax for let'")}
tokens))
-(def:''' (any? p xs)
+(def:''' .private (any? p xs)
#End
(All [a]
(-> (-> a Bit) ($' List a) Bit))
@@ -1444,13 +1427,13 @@
(p x))}
xs))
-(def:''' (with_location content)
+(def:''' .private (with_location content)
#End
(-> Code Code)
(tuple$ (list (tuple$ (list (text$ "") (nat$ 0) (nat$ 0)))
content)))
-(def:''' (untemplated_list tokens)
+(def:''' .private (untemplated_list tokens)
#End
(-> ($' List Code) Code)
({#End
@@ -1460,7 +1443,7 @@
(_ann (#Form (list (_ann (#Tag ["library/lux" "Item"])) token (untemplated_list tokens'))))}
tokens))
-(def:''' (list\compose xs ys)
+(def:''' .private (list\compose xs ys)
#End
(All [a] (-> ($' List a) ($' List a) ($' List a)))
({(#Item x xs')
@@ -1470,7 +1453,7 @@
ys}
xs))
-(def:''' (right_associativity op a1 a2)
+(def:''' .private (right_associativity op a1 a2)
#End
(-> Code Code Code Code)
({[_ (#Form parts)]
@@ -1480,14 +1463,14 @@
(form$ (list op a1 a2))}
op))
-(def:''' (function\flip func)
+(def:''' .private (function\flip func)
#End
(All [a b c]
(-> (-> a b c) (-> b a c)))
(function' [right left]
(func left right)))
-(macro:' #export (_$ tokens)
+(macro:' .public (_$ tokens)
(#Item [(tag$ ["library/lux" "doc"])
(text$ ("lux text concat"
("lux text concat" "## Left-association for the application of binary functions over variadic arguments." ..\n)
@@ -1509,7 +1492,7 @@
(failure "Wrong syntax for _$")}
tokens))
-(macro:' #export ($_ tokens)
+(macro:' .public ($_ tokens)
(#Item [(tag$ ["library/lux" "doc"])
(text$ ("lux text concat"
("lux text concat" "## Right-association for the application of binary functions over variadic arguments." ..\n)
@@ -1547,7 +1530,7 @@
["in" "bind"]
#0)
-(def:''' maybe_monad
+(def:''' .private maybe_monad
#End
($' Monad Maybe)
{#in
@@ -1559,7 +1542,7 @@
(#Some a) (f a)}
ma))})
-(def:''' meta_monad
+(def:''' .private meta_monad
#End
($' Monad Meta)
{#in
@@ -1577,7 +1560,7 @@
(f a state')}
(ma state))))})
-(macro:' (do tokens)
+(macro:' .private (do tokens)
({(#Item monad (#Item [_ (#Tuple bindings)] (#Item body #End)))
(let' [g!in (local_identifier$ "in")
g!bind (local_identifier$ " bind ")
@@ -1610,7 +1593,7 @@
(failure "Wrong syntax for do")}
tokens))
-(def:''' (monad\map m f xs)
+(def:''' .private (monad\map m f xs)
#End
## (All [m a b]
## (-> (Monad m) (-> a (m b)) (List a) (m (List b))))
@@ -1630,7 +1613,7 @@
(in (#Item y ys)))}
xs)))
-(def:''' (monad\fold m f y xs)
+(def:''' .private (monad\fold m f y xs)
#End
## (All [m a b]
## (-> (Monad m) (-> a b (m b)) b (List a) (m b)))
@@ -1650,7 +1633,7 @@
(monad\fold m f y' xs'))}
xs)))
-(macro:' #export (if tokens)
+(macro:' .public (if tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"Picks which expression to evaluate based on a bit test value." __paragraph
@@ -1665,12 +1648,12 @@
(failure "Wrong syntax for if")}
tokens))
-(def:''' PList
+(def:''' .private PList
#End
Type
(All [a] ($' List (Tuple Text a))))
-(def:''' (get k plist)
+(def:''' .private (get k plist)
#End
(All [a]
(-> Text ($' PList a) ($' Maybe a)))
@@ -1683,7 +1666,7 @@
#None}
plist))
-(def:''' (put k v dict)
+(def:''' .private (put k v dict)
#End
(All [a]
(-> Text a ($' PList a) ($' PList a)))
@@ -1696,12 +1679,12 @@
(#Item [[k' v'] (put k v dict')]))}
dict))
-(def:''' (text\compose x y)
+(def:''' .private (text\compose x y)
#End
(-> Text Text Text)
("lux text concat" x y))
-(def:''' (name\encode full_name)
+(def:''' .private (name\encode full_name)
#End
(-> Name Text)
(let' [[module name] full_name]
@@ -1709,7 +1692,7 @@
_ ($_ text\compose module "." name)}
module)))
-(def:''' (get_meta tag def_meta)
+(def:''' .private (get_meta tag def_meta)
#End
(-> Name Code ($' Maybe Code))
(let' [[prefix name] tag]
@@ -1736,7 +1719,7 @@
#None}
def_meta)))
-(def:''' (global_identifier full_name state)
+(def:''' .private (global_identifier full_name state)
#End
(-> Name ($' Meta Name))
(let' [[module name] full_name
@@ -1761,7 +1744,7 @@
(#Left ($_ text\compose "Unknown module: " module " @ " (name\encode full_name)))}
(get module modules))))
-(def:''' (code_list expression)
+(def:''' .private (code_list expression)
#End
(-> Code Code)
(let' [type (form$ (list (tag$ ["library/lux" "Apply"])
@@ -1769,7 +1752,7 @@
(identifier$ ["library/lux" "List"])))]
(form$ (list (text$ "lux type check") type expression))))
-(def:''' (spliced replace? untemplate elems)
+(def:''' .private (spliced replace? untemplate elems)
#End
(-> Bit (-> Code ($' Meta Code)) ($' List Code) ($' Meta Code))
({#1
@@ -1809,12 +1792,12 @@
(in (untemplated_list =elems)))}
replace?))
-(def:''' (untemplated_text value)
+(def:''' .private (untemplated_text value)
#End
(-> Text Code)
(with_location (form$ (list (tag$ ["library/lux" "Text"]) (text$ value)))))
-(def:''' (untemplate replace? subst token)
+(def:''' .private (untemplate replace? subst token)
#End
(-> Bit Text Code ($' Meta Code))
({[_ [_ (#Bit value)]]
@@ -1905,7 +1888,7 @@
(in (with_location (form$ (list (tag$ ["library/lux" "Record"]) (untemplated_list =fields))))))}
[replace? token]))
-(macro:' #export (primitive tokens)
+(macro:' .public (primitive tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Macro to treat define new primitive types." __paragraph
@@ -1921,7 +1904,7 @@
(failure "Wrong syntax for primitive")}
tokens))
-(def:'' (current_module_name state)
+(def:'' .private (current_module_name state)
#End
($' Meta Text)
({{#info info #source source #current_module current_module #modules modules
@@ -1936,7 +1919,7 @@
current_module)}
state))
-(macro:' #export (` tokens)
+(macro:' .public (` tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Hygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms." __paragraph
@@ -1954,7 +1937,7 @@
(failure "Wrong syntax for `")}
tokens))
-(macro:' #export (`' tokens)
+(macro:' .public (`' tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Unhygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms." __paragraph
@@ -1968,7 +1951,7 @@
(failure "Wrong syntax for `")}
tokens))
-(macro:' #export (' tokens)
+(macro:' .public (' tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Quotation as a macro." __paragraph
@@ -1982,7 +1965,7 @@
(failure "Wrong syntax for '")}
tokens))
-(macro:' #export (|> tokens)
+(macro:' .public (|> tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Piping macro." __paragraph
@@ -2008,7 +1991,7 @@
(failure "Wrong syntax for |>")}
tokens))
-(macro:' #export (<| tokens)
+(macro:' .public (<| tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Reverse piping macro." __paragraph
@@ -2034,14 +2017,14 @@
(failure "Wrong syntax for <|")}
(list\reverse tokens)))
-(def:''' (compose f g)
+(def:''' .private (compose f g)
(list [(tag$ ["library/lux" "doc"])
(text$ "Function composition.")])
(All [a b c]
(-> (-> b c) (-> a b) (-> a c)))
(function' [x] (f (g x))))
-(def:''' (get_name x)
+(def:''' .private (get_name x)
#End
(-> Code ($' Maybe Name))
({[_ (#Identifier sname)]
@@ -2051,7 +2034,7 @@
#None}
x))
-(def:''' (get_tag x)
+(def:''' .private (get_tag x)
#End
(-> Code ($' Maybe Name))
({[_ (#Tag sname)]
@@ -2061,7 +2044,7 @@
#None}
x))
-(def:''' (get_short x)
+(def:''' .private (get_short x)
#End
(-> Code ($' Maybe Text))
({[_ (#Identifier "" sname)]
@@ -2071,7 +2054,7 @@
#None}
x))
-(def:''' (tuple_list tuple)
+(def:''' .private (tuple_list tuple)
#End
(-> Code ($' Maybe ($' List Code)))
({[_ (#Tuple members)]
@@ -2081,7 +2064,7 @@
#None}
tuple))
-(def:''' (apply_template env template)
+(def:''' .private (apply_template env template)
#End
(-> Replacement_Environment Code Code)
({[_ (#Identifier "" sname)]
@@ -2109,28 +2092,28 @@
template}
template))
-(def:''' (every? p xs)
+(def:''' .private (every? p xs)
#End
(All [a]
(-> (-> a Bit) ($' List a) Bit))
(list\fold (function' [_2 _1] (if _1 (p _2) #0)) #1 xs))
-(def:''' (high_bits value)
+(def:''' .private (high_bits value)
(list)
(-> ($' I64 Any) I64)
("lux i64 right-shift" 32 value))
-(def:''' low_mask
+(def:''' .private low_mask
(list)
I64
(|> 1 ("lux i64 left-shift" 32) ("lux i64 -" 1)))
-(def:''' (low_bits value)
+(def:''' .private (low_bits value)
(list)
(-> ($' I64 Any) I64)
("lux i64 and" low_mask value))
-(def:''' (n/< reference sample)
+(def:''' .private (n/< reference sample)
(list)
(-> Nat Nat Bit)
(let' [referenceH (high_bits reference)
@@ -2143,25 +2126,25 @@
(low_bits sample))
#0))))
-(def:''' (n/<= reference sample)
+(def:''' .private (n/<= reference sample)
(list)
(-> Nat Nat Bit)
(if (n/< reference sample)
#1
("lux i64 =" reference sample)))
-(def:''' (list\join xs)
+(def:''' .private (list\join xs)
#End
(All [a]
(-> ($' List ($' List a)) ($' List a)))
(list\fold list\compose #End (list\reverse xs)))
-(macro:' #export (template tokens)
+(macro:' .public (template tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## By specifying a pattern (with holes), and the input data to fill those holes, repeats the pattern as many times as necessary." __paragraph
"(template [<name> <diff>]" ..\n
- " " "[(def: #export <name> (-> Int Int) (+ <diff>))]" __paragraph
+ " " "[(def: .public <name> (-> Int Int) (+ <diff>))]" __paragraph
" " "[inc +1]" ..\n
" " "[dec -1]"))])
({(#Item [[_ (#Tuple bindings)] (#Item [[_ (#Tuple templates)] data])])
@@ -2186,7 +2169,7 @@
(failure "Wrong syntax for template")}
tokens))
-(def:''' (n// param subject)
+(def:''' .private (n// param subject)
(list)
(-> Nat Nat Nat)
(if ("lux i64 <" +0 ("lux type as" Int param))
@@ -2205,7 +2188,7 @@
quotient
("lux i64 +" 1 quotient)))))
-(def:''' (n/% param subject)
+(def:''' .private (n/% param subject)
(list)
(-> Nat Nat Nat)
(let' [flat ("lux i64 *"
@@ -2213,19 +2196,19 @@
("lux type as" Int (n// param subject)))]
("lux i64 -" flat subject)))
-(def:''' (n/min left right)
+(def:''' .private (n/min left right)
(list)
(-> Nat Nat Nat)
(if (n/< right left)
left
right))
-(def:''' (bit\encode x)
+(def:''' .private (bit\encode x)
#End
(-> Bit Text)
(if x "#1" "#0"))
-(def:''' (digit::format digit)
+(def:''' .private (digit::format digit)
#End
(-> Nat Text)
({0 "0"
@@ -2235,7 +2218,7 @@
_ ("lux io error" "@digit::format Undefined behavior.")}
digit))
-(def:''' (nat\encode value)
+(def:''' .private (nat\encode value)
#End
(-> Nat Text)
({0
@@ -2252,14 +2235,14 @@
(loop value ""))}
value))
-(def:''' (int\abs value)
+(def:''' .private (int\abs value)
#End
(-> Int Int)
(if ("lux i64 <" +0 value)
("lux i64 *" -1 value)
value))
-(def:''' (int\encode value)
+(def:''' .private (int\encode value)
#End
(-> Int Text)
(if ("lux i64 =" +0 value)
@@ -2277,17 +2260,17 @@
(|> value ("lux i64 /" +10) int\abs)
(|> value ("lux i64 %" +10) int\abs ("lux type as" Nat) digit::format)))))
-(def:''' (frac\encode x)
+(def:''' .private (frac\encode x)
#End
(-> Frac Text)
("lux f64 encode" x))
-(def:''' (multiple? div n)
+(def:''' .private (multiple? div n)
#End
(-> Nat Nat Bit)
(|> n (n/% div) ("lux i64 =" 0)))
-(def:''' #export (not x)
+(def:''' .public (not x)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Bit negation." __paragraph
@@ -2296,7 +2279,7 @@
(-> Bit Bit)
(if x #0 #1))
-(def:''' (macro_type? type)
+(def:''' .private (macro_type? type)
(list)
(-> Type Bit)
({(#Named ["library/lux" "Macro"] (#Primitive "#Macro" #End))
@@ -2306,7 +2289,7 @@
#0}
type))
-(def:''' (macro' modules current_module module name)
+(def:''' .private (macro' modules current_module module name)
#End
(-> ($' List (Tuple Text Module))
Text Text Text
@@ -2328,7 +2311,7 @@
#None)}
("lux type check" Global gdef))))
-(def:''' (normal name)
+(def:''' .private (normal name)
#End
(-> Name ($' Meta Name))
({["" name]
@@ -2340,7 +2323,7 @@
(in_meta name)}
name))
-(def:''' (macro full_name)
+(def:''' .private (macro full_name)
#End
(-> Name ($' Meta ($' Maybe Macro)))
(do meta_monad
@@ -2355,7 +2338,7 @@
(#Right state (macro' modules current_module module name))}
state)))))
-(def:''' (macro? name)
+(def:''' .private (macro? name)
#End
(-> Name ($' Meta Bit))
(do meta_monad
@@ -2365,7 +2348,7 @@
#None #0}
output))))
-(def:''' (interpose sep xs)
+(def:''' .private (interpose sep xs)
#End
(All [a]
(-> a ($' List a) ($' List a)))
@@ -2379,7 +2362,7 @@
(list& x sep (interpose sep xs'))}
xs))
-(def:''' (single_expansion token)
+(def:''' .private (single_expansion token)
#End
(-> Code ($' Meta ($' List Code)))
({[_ (#Form (#Item [_ (#Identifier name)] args))]
@@ -2397,7 +2380,7 @@
(in_meta (list token))}
token))
-(def:''' (expansion token)
+(def:''' .private (expansion token)
#End
(-> Code ($' Meta ($' List Code)))
({[_ (#Form (#Item [_ (#Identifier name)] args))]
@@ -2418,7 +2401,7 @@
(in_meta (list token))}
token))
-(def:''' (full_expansion syntax)
+(def:''' .private (full_expansion syntax)
#End
(-> Code ($' Meta ($' List Code)))
({[_ (#Form (#Item [_ (#Identifier name)] args))]
@@ -2467,7 +2450,7 @@
(in_meta (list syntax))}
syntax))
-(def:''' (normal_type type)
+(def:''' .private (normal_type type)
#End
(-> Code Code)
({[_ (#Form (#Item [_ (#Tag tag)] parts))]
@@ -2495,7 +2478,7 @@
type}
type))
-(macro:' #export (type tokens)
+(macro:' .public (type tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Takes a type expression and returns its representation as data-structure." __paragraph
@@ -2514,7 +2497,7 @@
(failure "Wrong syntax for type")}
tokens))
-(macro:' #export (: tokens)
+(macro:' .public (: tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## The type-annotation macro." __paragraph
@@ -2526,7 +2509,7 @@
(failure "Wrong syntax for :")}
tokens))
-(macro:' #export (:as tokens)
+(macro:' .public (:as tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## The type-coercion macro." __paragraph
@@ -2538,7 +2521,7 @@
(failure "Wrong syntax for :as")}
tokens))
-(def:''' (empty? xs)
+(def:''' .private (empty? xs)
#End
(All [a] (-> ($' List a) Bit))
({#End #1
@@ -2546,7 +2529,7 @@
xs))
(template [<name> <type> <value>]
- [(def:''' (<name> xy)
+ [(def:''' .private (<name> xy)
#End
(All [a b] (-> (Tuple a b) <type>))
(let' [[x y] xy] <value>))]
@@ -2554,7 +2537,7 @@
[first a x]
[second b y])
-(def:''' (type_declaration type_codes)
+(def:''' .private (type_declaration type_codes)
#End
(-> ($' List Code) ($' Meta (Tuple Code ($' Maybe ($' List Text)))))
({(#Item [_ (#Record pairs)] #End)
@@ -2608,7 +2591,7 @@
(failure "Improper type-definition syntax")}
type_codes))
-(def:''' (gensym prefix state)
+(def:''' .private (gensym prefix state)
#End
(-> Text ($' Meta Code))
({{#info info #source source #current_module _ #modules modules
@@ -2624,7 +2607,7 @@
(local_identifier$ ($_ text\compose "__gensym__" prefix (nat\encode seed))))}
state))
-(macro:' #export (Rec tokens)
+(macro:' .public (Rec tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Parameter-less recursive types." __paragraph
@@ -2640,7 +2623,7 @@
(failure "Wrong syntax for Rec")}
tokens))
-(macro:' #export (exec tokens)
+(macro:' .public (exec tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Sequential execution of expressions (great for side-effects)." __paragraph
@@ -2661,30 +2644,24 @@
(failure "Wrong syntax for exec")}
(list\reverse tokens)))
-(macro:' (def:' tokens)
- (let' [[export? tokens'] ({(#Item [_ (#Tag ["" "export"])] tokens')
- [#1 tokens']
-
- _
- [#0 tokens]}
- tokens)
- parts (: (Maybe [Code (List Code) (Maybe Code) Code])
- ({(#Item [_ (#Form (#Item name args))] (#Item type (#Item body #End)))
- (#Some name args (#Some type) body)
+(macro:' .private (def:' tokens)
+ (let' [parts (: (Maybe [Code Code (List Code) (Maybe Code) Code])
+ ({(#Item export_policy (#Item [_ (#Form (#Item name args))] (#Item type (#Item body #End))))
+ (#Some [export_policy name args (#Some type) body])
- (#Item name (#Item type (#Item body #End)))
- (#Some name #End (#Some type) body)
+ (#Item export_policy (#Item name (#Item type (#Item body #End))))
+ (#Some [export_policy name #End (#Some type) body])
- (#Item [_ (#Form (#Item name args))] (#Item body #End))
- (#Some name args #None body)
+ (#Item export_policy (#Item [_ (#Form (#Item name args))] (#Item body #End)))
+ (#Some [export_policy name args #None body])
- (#Item name (#Item body #End))
- (#Some name #End #None body)
+ (#Item export_policy (#Item name (#Item body #End)))
+ (#Some [export_policy name #End #None body])
_
#None}
- tokens'))]
- ({(#Some name args ?type body)
+ tokens))]
+ ({(#Some [export_policy name args ?type body])
(let' [body' ({#End
body
@@ -2701,17 +2678,17 @@
(~ body'')
[(~ location_code)
(#.Record #.End)]
- (~ (bit$ export?)))))))
+ (~ export_policy))))))
#None
(failure "Wrong syntax for def'")}
parts)))
-(def:' (text\encode original)
+(def:' .private (text\encode original)
(-> Text Text)
($_ text\compose ..double_quote original ..double_quote))
-(def:' (code\encode code)
+(def:' .private (code\encode code)
(-> Code Text)
({[_ (#Bit value)]
(bit\encode value)
@@ -2764,7 +2741,7 @@
(list\fold text\compose "")) "}")}
code))
-(def:' (expander branches)
+(def:' .private (expander branches)
(-> (List Code) (Meta (List Code)))
({(#Item [_ (#Form (#Item [_ (#Identifier name)] args))]
(#Item body
@@ -2797,7 +2774,7 @@
(list\fold text\compose ""))))}
branches))
-(macro:' #export (case tokens)
+(macro:' .public (case tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## The pattern-matching macro." ..\n
@@ -2816,7 +2793,7 @@
(failure "Wrong syntax for case")}
tokens))
-(macro:' #export (^ tokens)
+(macro:' .public (^ tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Macro-expanding patterns." ..\n
@@ -2841,7 +2818,7 @@
_
(failure "Wrong syntax for ^ macro")))
-(macro:' #export (^or tokens)
+(macro:' .public (^or tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Or-patterns." ..\n
@@ -2870,7 +2847,7 @@
_
(failure "Wrong syntax for ^or")))
-(def:' (identifier? code)
+(def:' .private (identifier? code)
(-> Code Bit)
(case code
[_ (#Identifier _)]
@@ -2879,7 +2856,7 @@
_
#0))
-(macro:' #export (let tokens)
+(macro:' .public (let tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Creates local bindings." ..\n
@@ -2905,7 +2882,7 @@
_
(failure "Wrong syntax for let")))
-(macro:' #export (function tokens)
+(macro:' .public (function tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Syntax for creating functions." ..\n
@@ -2937,7 +2914,7 @@
#None
(failure "Wrong syntax for function")))
-(def:' (definition_annotation_value code)
+(def:' .private (definition_annotation_value code)
(-> Code Code)
(case code
[_ (#Bit value)]
@@ -2980,7 +2957,7 @@
(meta_code ["library/lux" "Record"]))
))
-(def:' (definition_annotations kvs)
+(def:' .private (definition_annotations kvs)
(-> (List [Code Code]) Code)
(untemplated_list (list\map (: (-> [Code Code] Code)
(function (_ [k v])
@@ -2988,40 +2965,189 @@
(~ (definition_annotation_value v))])))
kvs)))
-(def:' (with_func_args args meta)
+(def:' .private (with_function_parameters parameters meta)
(-> (List Code) Code Code)
- (case args
+ (case parameters
#End
meta
_
(` (#.Item [[(~ location_code) (#.Tag ["library/lux" "func_args"])]
- [(~ location_code) (#.Tuple (.list (~+ (list\map (function (_ arg)
- (` [(~ location_code) (#.Text (~ (text$ (code\encode arg))))]))
- args))))]]
+ [(~ location_code) (#.Tuple (.list (~+ (list\map (function (_ parameter)
+ (` [(~ location_code) (#.Text (~ (text$ (code\encode parameter))))]))
+ parameters))))]]
(~ meta)))))
-(def:' (with_type_args args)
+(def:' .private (with_type_args args)
(-> (List Code) Code)
(` {#.type_args [(~+ (list\map (function (_ arg) (text$ (code\encode arg)))
args))]}))
-(def:' (export^ tokens)
- (-> (List Code) [Bit (List Code)])
+(def:' .private (endP tokens)
+ (-> (List Code) (Maybe Any))
+ (case tokens
+ (^ (list))
+ (#.Some [])
+
+ _
+ #None))
+
+(def:' .private (anyP tokens)
+ (-> (List Code) (Maybe [(List Code) Code]))
+ (case tokens
+ (^ (list& code tokens'))
+ (#Some [tokens' code])
+
+ _
+ #.None))
+
+(def:' .private (local_identifierP tokens)
+ (-> (List Code) (Maybe [(List Code) Text]))
+ (case tokens
+ (^ (list& [_ (#Identifier ["" local_identifier])] tokens'))
+ (#Some [tokens' local_identifier])
+
+ _
+ #.None))
+
+(template [<parser> <item_type> <item_parser>]
+ [(def:' .private (<parser> tokens)
+ (-> (List Code) (Maybe (List <item_type>)))
+ (case tokens
+ #End
+ (#.Some #End)
+
+ _
+ (do maybe_monad
+ [% (<item_parser> tokens)
+ .let' [[tokens head] %]
+ tail (<parser> tokens)]
+ (in (#Item head tail)))))]
+
+ [parametersP Text local_identifierP]
+ [enhanced_parametersP Code anyP]
+ )
+
+(template [<parser> <parameter_type> <parameters_parser>]
+ [(def:' .private (<parser> tokens)
+ (-> (List Code) (Maybe [(List Code) [Text (List <parameter_type>)]]))
+ (case tokens
+ (^ (list& [_ (#Form local_declaration)] tokens'))
+ (do maybe_monad
+ [% (local_identifierP local_declaration)
+ .let' [[local_declaration name] %]
+ parameters (<parameters_parser> local_declaration)]
+ (in [tokens' [name parameters]]))
+
+ _
+ (do maybe_monad
+ [% (local_identifierP tokens)
+ .let' [[tokens' name] %]]
+ (in [tokens' [name #End]]))))]
+
+ [local_declarationP Text parametersP]
+ [enhanced_local_declarationP Code enhanced_parametersP]
+ )
+
+(template [<parser> <parameter_type> <local>]
+ [(def:' .private (<parser> tokens)
+ (-> (List Code) (Maybe [(List Code) [Code Text (List <parameter_type>)]]))
+ (do maybe_monad
+ [% (anyP tokens)
+ .let' [[tokens export_policy] %]
+ % (<local> tokens)
+ .let' [[tokens [name parameters]] %]]
+ (in [tokens [export_policy name parameters]])))]
+
+ [declarationP Text local_declarationP]
+ [enhanced_declarationP Code enhanced_local_declarationP]
+ )
+
+(def:' .private (annotationsP tokens)
+ (-> (List Code) (Maybe [(List Code) (List [Code Code])]))
(case tokens
- (#Item [_ (#Tag [_ "export"])] tokens')
- [#1 tokens']
+ (^ (list& [_ (#Record annotations)] tokens'))
+ (#Some [tokens' annotations])
+
+ tokens'
+ #None))
+
+(def:' .private (bodyP tokens)
+ (-> (List Code) (Maybe [(List Code) [(Maybe Code) Code]]))
+ (case tokens
+ ## TB
+ (^ (list& type body tokens'))
+ (#Some [tokens' [(#Some type) body]])
+
+ ## B
+ (^ (list& body tokens'))
+ (#Some [tokens' [#None body]])
_
- [#0 tokens]))
+ #None))
+
+(macro:' .private (maybe\else' tokens)
+ (case tokens
+ (^ (list else then))
+ (do meta_monad
+ [g!_ (gensym "g!_")]
+ (in (list (` (..case (~ then)
+ (#..Some (~ g!_))
+ (#..Some (~ g!_))
-(def:' (export ?)
- (-> Bit (List Code))
- (if ?
- (list (' #export))
- (list)))
+ #..None
+ (~ else))))))
-(macro:' #export (def: tokens)
+ _
+ (failure "Wrong syntax for maybe\else'")))
+
+(def:' .private (definitionP tokens)
+ (-> (List Code) (Maybe [Code Text (List Code) (List [Code Code]) (Maybe Code) Code]))
+ (|> (do maybe_monad
+ [% (anyP tokens)
+ .let' [[tokens export_policy] %]
+ % (enhanced_local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (annotationsP tokens)
+ .let' [[tokens annotations] %]
+ % (bodyP tokens)
+ .let' [[tokens [?type body]] %]
+ _ (endP tokens)]
+ (in [export_policy name parameters annotations ?type body]))
+ ## (^ (list _export_policy _declaration _annotations _type _body))
+ ## (^ (list _export_policy _declaration _annotations _body))
+ (maybe\else' (do maybe_monad
+ [% (enhanced_local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (bodyP tokens)
+ .let' [[tokens [?type body]] %]
+ _ (endP tokens)]
+ (in [(` ..private) name parameters #End ?type body])))
+ ## (^ (list _declaration _type _body))
+ ## (^ (list _declaration _body))
+ (maybe\else' (do maybe_monad
+ [% (enhanced_local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (annotationsP tokens)
+ .let' [[tokens annotations] %]
+ % (bodyP tokens)
+ .let' [[tokens [?type body]] %]
+ _ (endP tokens)]
+ (in [(` ..private) name parameters annotations ?type body])))
+ ## (^ (list _declaration _annotations _type _body))
+ ## (^ (list _declaration _annotations _body))
+ (maybe\else' (do maybe_monad
+ [% (enhanced_declarationP tokens)
+ .let' [[tokens [export_policy name parameters]] %]
+ % (bodyP tokens)
+ .let' [[tokens [?type body]] %]
+ _ (endP tokens)]
+ (in [export_policy name parameters #End ?type body])))
+ ## (^ (list _export_policy _declaration _type _body))
+ ## (^ (list _export_policy _declaration _body))
+ ))
+
+(macro:' .public (def: tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Defines global constants/functions." ..\n
@@ -3033,67 +3159,40 @@
"(def: branching_exponent" ..\n
" Int" ..\n
" +5)"))])
- (let [[exported? tokens'] (export^ tokens)
- parts (: (Maybe [Code (List Code) (Maybe Code) Code (List [Code Code])])
- (case tokens'
- (^ (list [_ (#Form (#Item name args))] [_ (#Record meta_kvs)] type body))
- (#Some [name args (#Some type) body meta_kvs])
-
- (^ (list name [_ (#Record meta_kvs)] type body))
- (#Some [name #End (#Some type) body meta_kvs])
-
- (^ (list [_ (#Form (#Item name args))] [_ (#Record meta_kvs)] body))
- (#Some [name args #None body meta_kvs])
-
- (^ (list name [_ (#Record meta_kvs)] body))
- (#Some [name #End #None body meta_kvs])
-
- (^ (list [_ (#Form (#Item name args))] type body))
- (#Some [name args (#Some type) body #End])
-
- (^ (list name type body))
- (#Some [name #End (#Some type) body #End])
-
- (^ (list [_ (#Form (#Item name args))] body))
- (#Some [name args #None body #End])
-
- (^ (list name body))
- (#Some [name #End #None body #End])
+ (case (definitionP tokens)
+ (#Some [export_policy name parameters annotations ?type body])
+ (let [body (case parameters
+ #End
+ body
- _
- #None))]
- (case parts
- (#Some name args ?type body meta)
- (let [body (case args
- #End
- body
-
- _
- (` (function ((~ name) (~+ args)) (~ body))))
- body (case ?type
- (#Some type)
- (` (: (~ type) (~ body)))
-
- #None
- body)
- =meta (definition_annotations meta)]
- (in_meta (list (` ("lux def" (~ name)
- (~ body)
- [(~ location_code)
- (#.Record (~ (with_func_args args =meta)))]
- (~ (bit$ exported?)))))))
-
- #None
- (failure "Wrong syntax for def:"))))
+ _
+ (` (function ((~ (..local_identifier$ name)) (~+ parameters))
+ (~ body))))
+ body (case ?type
+ (#Some type)
+ (` (: (~ type)
+ (~ body)))
+
+ #None
+ body)
+ =annotations (definition_annotations annotations)]
+ (in_meta (list (` ("lux def" (~ (..local_identifier$ name))
+ (~ body)
+ [(~ location_code)
+ (#.Record (~ (with_function_parameters parameters =annotations)))]
+ (~ export_policy))))))
+
+ #None
+ (failure "Wrong syntax for def:")))
-(def: (with_definition_annotation addition meta)
+(def: (with_definition_annotation addition annotations)
(-> [Code Code] Code Code)
- (case [addition meta]
+ (case [addition annotations]
[[name value] [location (#Record pairs)]]
[location (#Record (#Item [name value] pairs))]
_
- meta))
+ annotations))
(def: (merged_definition_annotations addition base)
(-> Code Code Code)
@@ -3104,11 +3203,53 @@
_
base))
-(macro:' #export (macro: tokens)
+(def:' .private (macroP tokens)
+ (-> (List Code) (Maybe [Code Text (List Text) (List [Code Code]) Code]))
+ (|> (do maybe_monad
+ [% (anyP tokens)
+ .let' [[tokens export_policy] %]
+ % (local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (annotationsP tokens)
+ .let' [[tokens annotations] %]
+ % (anyP tokens)
+ .let' [[tokens body] %]
+ _ (endP tokens)]
+ (in [export_policy name parameters annotations body]))
+ ## (^ (list _export_policy _declaration _annotations _body))
+ (maybe\else' (do maybe_monad
+ [% (local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (anyP tokens)
+ .let' [[tokens body] %]
+ _ (endP tokens)]
+ (in [(` ..private) name parameters #End body])))
+ ## (^ (list _declaration _body))
+ (maybe\else' (do maybe_monad
+ [% (local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (annotationsP tokens)
+ .let' [[tokens annotations] %]
+ % (anyP tokens)
+ .let' [[tokens body] %]
+ _ (endP tokens)]
+ (in [(` ..private) name parameters annotations body])))
+ ## (^ (list _declaration _annotations _body))
+ (maybe\else' (do maybe_monad
+ [% (declarationP tokens)
+ .let' [[tokens [export_policy name parameters]] %]
+ % (anyP tokens)
+ .let' [[tokens body] %]
+ _ (endP tokens)]
+ (in [export_policy name parameters #End body])))
+ ## (^ (list _export_policy _declaration _body))
+ ))
+
+(macro:' .public (macro: tokens)
(list [(tag$ ["library/lux" "doc"])
(text$ ($_ "lux text concat"
"## Macro-definition macro." ..\n
- "(macro: #export (name_of tokens)" ..\n
+ "(macro: .public (name_of tokens)" ..\n
" (case tokens" ..\n
" (^template [<tag>]" ..\n
" [(^ (list [_ (<tag> [prefix name])]))" ..\n
@@ -3117,108 +3258,25 @@
__paragraph
" _" ..\n
" (failure ''Wrong syntax for name_of'')))"))])
- (let [[exported? tokens] (export^ tokens)
- name+args+meta+body?? (: (Maybe [Name (List Code) (List [Code Code]) Code])
- (case tokens
- (^ (list [_ (#Form (list& [_ (#Identifier name)] args))] body))
- (#Some [name args (list) body])
-
- (^ (list [_ (#Identifier name)] body))
- (#Some [name #End (list) body])
-
- (^ (list [_ (#Form (list& [_ (#Identifier name)] args))] [_ (#Record meta_rec_parts)] body))
- (#Some [name args meta_rec_parts body])
-
- (^ (list [_ (#Identifier name)] [_ (#Record meta_rec_parts)] body))
- (#Some [name #End meta_rec_parts body])
-
- _
- #None))]
- (case name+args+meta+body??
- (#Some [name args meta body])
- (let [name (identifier$ name)
- body (case args
- #End
- body
+ (case (macroP tokens)
+ (#Some [export_policy name args annotations body])
+ (let [name (local_identifier$ name)
+ body (case args
+ #End
+ body
- _
- (` ("lux macro"
- (function ((~ name) (~+ args)) (~ body)))))
- =meta (definition_annotations meta)]
- (in_meta (list (` ("lux def" (~ name)
- (~ body)
- [(~ location_code)
- (#Record (~ =meta))]
- (~ (bit$ exported?)))))))
-
- #None
- (failure "Wrong syntax for macro:"))))
-
-(macro: #export (interface: tokens)
- {#.doc (text$ ($_ "lux text concat"
- "## Definition of signatures ala ML." ..\n
- "(interface: #export (Ord a)" ..\n
- " (: (Equivalence a)" ..\n
- " eq)" ..\n
- " (: (-> a a Bit)" ..\n
- " <)" ..\n
- " (: (-> a a Bit)" ..\n
- " <=)" ..\n
- " (: (-> a a Bit)" ..\n
- " >)" ..\n
- " (: (-> a a Bit)" ..\n
- " >=))"))}
- (let [[exported? tokens'] (export^ tokens)
- ?parts (: (Maybe [Name (List Code) Code (List Code)])
- (case tokens'
- (^ (list& [_ (#Form (list& [_ (#Identifier name)] args))] [meta_rec_location (#Record meta_rec_parts)] sigs))
- (#Some name args [meta_rec_location (#Record meta_rec_parts)] sigs)
-
- (^ (list& [_ (#Identifier name)] [meta_rec_location (#Record meta_rec_parts)] sigs))
- (#Some name #End [meta_rec_location (#Record meta_rec_parts)] sigs)
-
- (^ (list& [_ (#Form (list& [_ (#Identifier name)] args))] sigs))
- (#Some name args (` {}) sigs)
-
- (^ (list& [_ (#Identifier name)] sigs))
- (#Some name #End (` {}) sigs)
-
- _
- #None))]
- (case ?parts
- (#Some name args meta sigs)
- (do meta_monad
- [name+ (normal name)
- sigs' (monad\map meta_monad expansion sigs)
- members (: (Meta (List [Text Code]))
- (monad\map meta_monad
- (: (-> Code (Meta [Text Code]))
- (function (_ token)
- (case token
- (^ [_ (#Form (list [_ (#Text "lux type check")] type [_ (#Identifier ["" name])]))])
- (in [name type])
-
- _
- (failure "Signatures require typed members!"))))
- (list\join sigs')))
- .let [[_module _name] name+
- def_name (identifier$ name)
- sig_type (record$ (list\map (: (-> [Text Code] [Code Code])
- (function (_ [module_name m_type])
- [(local_tag$ module_name) m_type]))
- members))
- sig_meta (merged_definition_annotations (` {#.interface? #1})
- meta)
- usage (case args
- #End
- def_name
-
- _
- (` ((~ def_name) (~+ args))))]]
- (in_meta (list (` (..type: (~+ (export exported?)) (~ usage) (~ sig_meta) (~ sig_type))))))
-
- #None
- (failure "Wrong syntax for interface:"))))
+ _
+ (` ("lux macro"
+ (function ((~ name) (~+ (list\map local_identifier$ args))) (~ body)))))
+ =annotations (definition_annotations annotations)]
+ (in_meta (list (` ("lux def" (~ name)
+ (~ body)
+ [(~ location_code)
+ (#Record (~ =annotations))]
+ (~ export_policy))))))
+
+ #.None
+ (failure "Wrong syntax for macro:")))
(def: (find f xs)
(All [a b]
@@ -3236,7 +3294,7 @@
(#Some y))))
(template [<name> <form> <message> <documentation>]
- [(macro: #export (<name> tokens)
+ [(macro: .public (<name> tokens)
{#.doc <documentation>}
(case (list\reverse tokens)
(^ (list& last init))
@@ -3255,7 +3313,7 @@
(-> Text Text (Maybe Nat))
("lux text index" 0 part text))
-(def: #export (error! message)
+(def: .public (error! message)
{#.doc (text$ ($_ "lux text concat"
"## Causes an error, with the given error message." ..\n
"(error! ''OH NO!'')"))}
@@ -3506,7 +3564,7 @@
#None
(#Left "Not expecting any type.")))))
-(macro: #export (implementation tokens)
+(macro: .public (implementation tokens)
{#.doc "Not meant to be used directly. Prefer 'implementation:'."}
(do meta_monad
[tokens' (monad\map meta_monad expansion tokens)
@@ -3526,7 +3584,7 @@
(: (-> Code (Meta [Code Code]))
(function (_ token)
(case token
- (^ [_ (#Form (list [_ (#Text "lux def")] [_ (#Identifier "" tag_name)] value meta [_ (#Bit #0)]))])
+ (^ [_ (#Form (list [_ (#Text "lux def")] [_ (#Identifier "" tag_name)] value meta export_policy))])
(case (get tag_name tag_mappings)
(#Some tag)
(in [tag value])
@@ -3551,10 +3609,53 @@
head
tail)))
-(macro: #export (implementation: tokens)
+(def: (remainderP tokens)
+ (-> (List Code) (Maybe (List Code)))
+ (case tokens
+ #End
+ #None
+
+ _
+ (#Item tokens)))
+
+(def:' .private (implementationP tokens)
+ (-> (List Code) (Maybe [Code Text (List Code) (List [Code Code]) Code (List Code)]))
+ (|> (do maybe_monad
+ [% (enhanced_declarationP tokens)
+ .let' [[tokens [export_policy name parameters]] %]
+ % (annotationsP tokens)
+ .let' [[tokens annotations] %]
+ % (anyP tokens)
+ .let' [[tokens type] %]
+ tokens (remainderP tokens)]
+ (in [export_policy name parameters annotations type tokens]))
+ ## (^ (list _export_policy _declaration _annotations _type _body))
+ ## (^ (list _declaration _annotations _type _body))
+ (maybe\else' (do maybe_monad
+ [% (enhanced_local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (anyP tokens)
+ .let' [[tokens type] %]
+ tokens (remainderP tokens)]
+ (in [(` ..private) name parameters #End type tokens])))
+ ## (^ (list _declaration _type _body))
+ (maybe\else' (do maybe_monad
+ [% (anyP tokens)
+ .let' [[tokens export_policy] %]
+ % (enhanced_local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (anyP tokens)
+ .let' [[tokens type] %]
+ tokens (remainderP tokens)]
+ (in [export_policy name parameters #End type tokens])))
+ ## (^ (list _export_policy _declaration _type _body))
+ ))
+
+(macro: .public (implementation: tokens)
{#.doc (text$ ($_ "lux text concat"
"## Definition of structures ala ML." ..\n
- "(implementation: #export order (Order Int)" ..\n
+ "(implementation: .public order" ..\n
+ " (Order Int)" ..\n
" (def: &equivalence equivalence)" ..\n
" (def: (< test subject)" ..\n
" (< test subject))" ..\n
@@ -3566,135 +3667,207 @@
" (def: (>= test subject)" ..\n
" (or (> test subject)" ..\n
" (= test subject))))"))}
- (let [[exported? tokens'] (export^ tokens)
- ?parts (: (Maybe [Code (List Code) Code Code (List Code)])
- (case tokens'
- (^ (list& [_ (#Form (list& name args))] [meta_rec_location (#Record meta_rec_parts)] type definitions))
- (#Some name args type [meta_rec_location (#Record meta_rec_parts)] definitions)
-
- (^ (list& name [meta_rec_location (#Record meta_rec_parts)] type definitions))
- (#Some name #End type [meta_rec_location (#Record meta_rec_parts)] definitions)
+ (case (implementationP tokens)
+ (#Some [export_policy name args annotations type definitions])
+ (let [usage (case args
+ #End
+ (local_identifier$ name)
- (^ (list& [_ (#Form (list& name args))] type definitions))
- (#Some name args type (` {}) definitions)
-
- (^ (list& name type definitions))
- (#Some name #End type (` {}) definitions)
-
- _
- #None))]
- (case ?parts
- (#Some [name args type meta definitions])
- (let [usage (case args
- #End
- name
-
- _
- (` ((~ name) (~+ args))))]
- (in_meta (list (` (..def: (~+ (export exported?)) (~ usage)
- (~ (merged_definition_annotations (` {#.implementation? #1})
- meta))
- (~ type)
- (implementation (~+ definitions)))))))
+ _
+ (` ((~ (local_identifier$ name)) (~+ args))))]
+ (in_meta (list (` (..def: (~ export_policy) (~ usage)
+ (~ (merged_definition_annotations (` {#.implementation? #1})
+ (record$ annotations)))
+ (~ type)
+ (implementation (~+ definitions)))))))
- #None
- (failure "Wrong syntax for implementation:"))))
+ #None
+ (failure "Wrong syntax for implementation:")))
(def: (function\identity value)
(All [a] (-> a a))
value)
-(macro: #export (type: tokens)
+(def: (recP tokens)
+ (-> (List Code) [(List Code) Bit])
+ (case tokens
+ (^ (list& [_ (#Tag ["" "rec"])] tokens'))
+ [tokens' #1]
+
+ _
+ [tokens #0]))
+
+(def:' .private (typeP tokens)
+ (-> (List Code) (Maybe [Code Bit Text (List Text) (List [Code Code]) (List Code)]))
+ (|> (do maybe_monad
+ [% (anyP tokens)
+ .let' [[tokens export_policy] %]
+ .let' [[tokens rec?] (recP tokens)]
+ % (local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (annotationsP tokens)
+ .let' [[tokens annotations] %]
+ tokens (remainderP tokens)]
+ (in [export_policy rec? name parameters annotations tokens]))
+ ## (^ (list _export_policy _rec _declaration _annotations _body))
+ ## (^ (list _export_policy _declaration _annotations _body))
+ (maybe\else' (do maybe_monad
+ [.let' [[tokens rec?] (recP tokens)]
+ % (local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (annotationsP tokens)
+ .let' [[tokens annotations] %]
+ tokens (remainderP tokens)]
+ (in [(` ..private) rec? name parameters annotations tokens])))
+ ## (^ (list _rec _declaration _annotations _body))
+ ## (^ (list _declaration _annotations _body))
+ (maybe\else' (do maybe_monad
+ [.let' [[tokens rec?] (recP tokens)]
+ % (local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ tokens (remainderP tokens)]
+ (in [(` ..private) rec? name parameters #End tokens])))
+ ## (^ (list _rec _declaration _body))
+ ## (^ (list _declaration _body))
+ (maybe\else' (do maybe_monad
+ [% (anyP tokens)
+ .let' [[tokens export_policy] %]
+ .let' [[tokens rec?] (recP tokens)]
+ % (local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ tokens (remainderP tokens)]
+ (in [export_policy rec? name parameters #End tokens])))
+ ## (^ (list _export_policy _rec _declaration _body))
+ ## (^ (list _export_policy _declaration _body))
+ ))
+
+(macro: .public (type: tokens)
{#.doc (text$ ($_ "lux text concat"
"## The type-definition macro." ..\n
- "(type: (List a) #End (#Item a (List a)))"))}
- (let [[exported? tokens'] (export^ tokens)
- [rec? tokens'] (case tokens'
- (#Item [_ (#Tag [_ "rec"])] tokens')
- [#1 tokens']
+ "(type: (List a)" ..\n
+ " {#.doc (doc (: (List Nat) (list 0 1 2 3)))}" ..\n
+ " #End" ..\n
+ " (#Item a (List a)))"))}
+ (case (typeP tokens)
+ (#Some [export_policy rec? name args meta type_codes])
+ (do meta_monad
+ [type+tags?? (..type_declaration type_codes)
+ module_name current_module_name]
+ (let [type_name (local_identifier$ name)
+ [type tags??] type+tags??
+ type' (: (Maybe Code)
+ (if rec?
+ (if (empty? args)
+ (let [g!param (local_identifier$ "")
+ prime_name (local_identifier$ name)
+ type+ (with_replacements (list [name (` ((~ prime_name) .Nothing))])
+ type)]
+ (#Some (` ((All (~ prime_name) [(~ g!param)] (~ type+))
+ .Nothing))))
+ #None)
+ (case args
+ #End
+ (#Some type)
_
- [#0 tokens'])
- parts (: (Maybe [Text (List Code) (List [Code Code]) (List Code)])
- (case tokens'
- (^ (list [_ (#Identifier "" name)] [meta_location (#Record meta_parts)] [type_location (#Record type_parts)]))
- (#Some [name #End meta_parts (list [type_location (#Record type_parts)])])
-
- (^ (list& [_ (#Identifier "" name)] [meta_location (#Record meta_parts)] type_code1 type_codes))
- (#Some [name #End meta_parts (#Item type_code1 type_codes)])
-
- (^ (list& [_ (#Identifier "" name)] type_codes))
- (#Some [name #End (list) type_codes])
-
- (^ (list [_ (#Form (#Item [_ (#Identifier "" name)] args))] [meta_location (#Record meta_parts)] [type_location (#Record type_parts)]))
- (#Some [name args meta_parts (list [type_location (#Record type_parts)])])
-
- (^ (list& [_ (#Form (#Item [_ (#Identifier "" name)] args))] [meta_location (#Record meta_parts)] type_code1 type_codes))
- (#Some [name args meta_parts (#Item type_code1 type_codes)])
+ (#Some (` (.All (~ type_name) [(~+ (list\map local_identifier$ args))] (~ type)))))))
+ total_meta (let [meta (definition_annotations meta)
+ meta (if rec?
+ (` (#.Item (~ (flag_meta "type_rec?")) (~ meta)))
+ meta)]
+ (` [(~ location_code)
+ (#.Record (~ meta))]))]
+ (case type'
+ (#Some type'')
+ (let [typeC (` (#.Named [(~ (text$ module_name))
+ (~ (text$ name))]
+ (.type (~ type''))))]
+ (in_meta (list (case tags??
+ (#Some tags)
+ (` ("lux def type tagged" (~ type_name)
+ (~ typeC)
+ (~ total_meta)
+ [(~+ (list\map text$ tags))]
+ (~ export_policy)))
+
+ _
+ (` ("lux def" (~ type_name)
+ ("lux type check type"
+ (~ typeC))
+ (~ total_meta)
+ (~ export_policy)))))))
- (^ (list& [_ (#Form (#Item [_ (#Identifier "" name)] args))] type_codes))
- (#Some [name args (list) type_codes])
+ #None
+ (failure "Wrong syntax for type:"))))
- _
- #None))]
- (case parts
- (#Some name args meta type_codes)
- (do meta_monad
- [type+tags?? (..type_declaration type_codes)
- module_name current_module_name]
- (let [type_name (local_identifier$ name)
- [type tags??] type+tags??
- type' (: (Maybe Code)
- (if rec?
- (if (empty? args)
- (let [g!param (local_identifier$ "")
- prime_name (local_identifier$ name)
- type+ (with_replacements (list [name (` ((~ prime_name) .Nothing))])
- type)]
- (#Some (` ((All (~ prime_name) [(~ g!param)] (~ type+))
- .Nothing))))
- #None)
- (case args
- #End
- (#Some type)
+ #None
+ (failure "Wrong syntax for type:")))
+
+(def:' .private (interfaceP tokens)
+ (-> (List Code) (Maybe [Code Text (List Text) (List [Code Code]) (List Code)]))
+ (|> (do maybe_monad
+ [% (declarationP tokens)
+ .let' [[tokens [export_policy name parameters]] %]
+ % (annotationsP tokens)
+ .let' [[tokens annotations] %]]
+ (in [export_policy name parameters annotations tokens]))
+ ## (^ (list _export_policy _declaration _annotations _body))
+ ## (^ (list _declaration _annotations _body))
+ (maybe\else' (do maybe_monad
+ [% (local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]]
+ (in [(` ..private) name parameters #End tokens])))
+ ## (^ (list _declaration _body))
+ (maybe\else' (do maybe_monad
+ [% (declarationP tokens)
+ .let' [[tokens [export_policy name parameters]] %]]
+ (in [export_policy name parameters #End tokens])))
+ ## (^ (list _export_policy _declaration _body))
+ ))
+
+(macro: .public (interface: tokens)
+ {#.doc (text$ ($_ "lux text concat"
+ "## Definition of interfaces/signatures ala ML." ..\n
+ "(interface: .public (Order a)" ..\n
+ " (: (Equivalence a)" ..\n
+ " &equivalence)" ..\n
+ " (: (-> a a Bit)" ..\n
+ " <))"))}
+ (case (interfaceP tokens)
+ (#Some [export_policy name args annotations methods])
+ (do meta_monad
+ [methods' (monad\map meta_monad expansion methods)
+ members (: (Meta (List [Text Code]))
+ (monad\map meta_monad
+ (: (-> Code (Meta [Text Code]))
+ (function (_ token)
+ (case token
+ (^ [_ (#Form (list [_ (#Text "lux type check")] type [_ (#Identifier ["" name])]))])
+ (in [name type])
- _
- (#Some (` (.All (~ type_name) [(~+ args)] (~ type)))))))
- total_meta (let [meta (definition_annotations meta)
- meta (if rec?
- (` (#.Item (~ (flag_meta "type_rec?")) (~ meta)))
- meta)]
- (` [(~ location_code)
- (#.Record (~ meta))]))]
- (case type'
- (#Some type'')
- (let [typeC (` (#.Named [(~ (text$ module_name))
- (~ (text$ name))]
- (.type (~ type''))))]
- (in_meta (list (case tags??
- (#Some tags)
- (` ("lux def type tagged" (~ type_name)
- (~ typeC)
- (~ total_meta)
- [(~+ (list\map text$ tags))]
- (~ (bit$ exported?))))
-
- _
- (` ("lux def" (~ type_name)
- ("lux type check type"
- (~ typeC))
- (~ total_meta)
- (~ (bit$ exported?))))))))
+ _
+ (failure "Interfaces require typed members!"))))
+ (list\join methods')))
+ .let [def_name (local_identifier$ name)
+ interface_type (record$ (list\map (: (-> [Text Code] [Code Code])
+ (function (_ [module_name m_type])
+ [(local_tag$ module_name) m_type]))
+ members))
+ interface_annotations (merged_definition_annotations (` {#.interface? #1})
+ (record$ annotations))
+ usage (case args
+ #End
+ def_name
- #None
- (failure "Wrong syntax for type:"))))
+ _
+ (` ((~ def_name) (~+ (list\map local_identifier$ args)))))]]
+ (in_meta (list (` (..type: (~ export_policy) (~ usage) (~ interface_annotations) (~ interface_type))))))
- #None
- (failure "Wrong syntax for type:"))
- ))
+ #None
+ (failure "Wrong syntax for interface:")))
(template [<name> <to>]
- [(def: #export (<name> value)
+ [(def: .public (<name> value)
(-> (I64 Any) <to>)
(:as <to> value))]
@@ -3821,7 +3994,7 @@
(replace_all ..self_reference self)
(replace_all ..contextual_reference context)))
-(def: #export module_separator
+(def: .public module_separator
"/")
(def: parallel_hierarchy_sigil
@@ -4234,11 +4407,11 @@
(name\encode name)
))
-(macro: #export (^open tokens)
+(macro: .public (^open tokens)
{#.doc (text$ ($_ "lux text concat"
"## Same as the 'open' macro, but meant to be used as a pattern-matching macro for generating local bindings." ..\n
"## Takes an 'alias' text for the generated local bindings." ..\n
- "(def: #export (range (^open ''.'') minimum additional)" ..\n
+ "(def: .public (range (^open ''.'') minimum additional)" ..\n
" (All [a] (-> (Enum a) a a (List a)))" ..\n
" (range' <= succ minimum additional))"))}
(case tokens
@@ -4285,7 +4458,7 @@
_
(failure "Wrong syntax for ^open")))
-(macro: #export (cond tokens)
+(macro: .public (cond tokens)
{#.doc (text$ ($_ "lux text concat"
"## Branching structures with multiple test conditions." ..\n
"(cond (even? num) ''even''" ..\n
@@ -4320,7 +4493,7 @@
(All [a] (-> (List a) (List [Nat a])))
(enumeration' 0 xs))
-(macro: #export (get@ tokens)
+(macro: .public (get@ tokens)
{#.doc (text$ ($_ "lux text concat"
"## Accesses the value of a record at a given tag." ..\n
"(get@ #field my_record)"
@@ -4399,7 +4572,7 @@
[(~ location_code) (#.Record #End)]
#0)))))))
-(macro: #export (open: tokens)
+(macro: .public (open: tokens)
{#.doc (text$ ($_ "lux text concat"
"## Opens a implementation and generates a definition for each of its members (including nested members)."
__paragraph
@@ -4442,7 +4615,7 @@
_
(failure "Wrong syntax for open:")))
-(macro: #export (|>> tokens)
+(macro: .public (|>> tokens)
{#.doc (text$ ($_ "lux text concat"
"## Similar to the piping macro, but rather than taking an initial object to work on, creates a function for taking it." ..\n
"(|>> (list\map int\encode) (interpose '' '') (fold text\compose ''''))" ..\n
@@ -4453,7 +4626,7 @@
g!arg (gensym "arg")]
(in_meta (list (` (function ((~ g!_) (~ g!arg)) (|> (~ g!arg) (~+ tokens))))))))
-(macro: #export (<<| tokens)
+(macro: .public (<<| tokens)
{#.doc (text$ ($_ "lux text concat"
"## Similar to the piping macro, but rather than taking an initial object to work on, creates a function for taking it." ..\n
"(<<| (fold text\compose '''') (interpose '' '') (list\map int\encode))" ..\n
@@ -4538,7 +4711,7 @@
list\join)]]
(in (list\compose defs openings))))
-(macro: #export (refer tokens)
+(macro: .public (refer tokens)
(case tokens
(^ (list& [_ (#Text module_name)] options))
(do meta_monad
@@ -4575,7 +4748,7 @@
(~+ localizations)
(~+ openings)))))
-(macro: #export (module: tokens)
+(macro: .public (module: tokens)
{#.doc (text$ ($_ "lux text concat"
"## Module_definition macro."
__paragraph
@@ -4617,7 +4790,7 @@
(~ =imports)))]]
(in (#Item =module =refers))))
-(macro: #export (\ tokens)
+(macro: .public (\ tokens)
{#.doc (text$ ($_ "lux text concat"
"## Allows accessing the value of a implementation's member." ..\n
"(\ codec encode)"
@@ -4634,7 +4807,7 @@
_
(failure "Wrong syntax for \")))
-(macro: #export (set@ tokens)
+(macro: .public (set@ tokens)
{#.doc (text$ ($_ "lux text concat"
"## Sets the value of a record at a given tag." ..\n
"(set@ #name ''Lux'' lang)"
@@ -4723,7 +4896,7 @@
_
(failure "Wrong syntax for set@")))
-(macro: #export (update@ tokens)
+(macro: .public (update@ tokens)
{#.doc (text$ ($_ "lux text concat"
"## Modifies the value of a record at a given tag, based on some function." ..\n
"(update@ #age inc person)"
@@ -4798,7 +4971,7 @@
_
(failure "Wrong syntax for update@")))
-(macro: #export (^template tokens)
+(macro: .public (^template tokens)
{#.doc (text$ ($_ "lux text concat"
"## It's similar to template, but meant to be used during pattern-matching." ..\n
"(def: (reduced env type)" ..\n
@@ -4902,7 +5075,7 @@
(#Documentation_Example code)))
(template [<name> <extension> <doc>]
- [(def: #export <name>
+ [(def: .public <name>
{#.doc <doc>}
(All [s] (-> (I64 s) (I64 s)))
(|>> (<extension> 1)))]
@@ -5006,7 +5179,7 @@
[_ text] (..example_documentation (with_baseline baseline location) baseline example)]
(text\compose text __paragraph))))
-(macro: #export (doc tokens)
+(macro: .public (doc tokens)
{#.doc (text$ ($_ "lux text concat"
"## Creates code documentation, embedding text as comments and properly formatting the forms it's being given."
__paragraph
@@ -5069,7 +5242,7 @@
## (~ (type_code anonymous))))
(identifier$ [module name])))
-(macro: #export (loop tokens)
+(macro: .public (loop tokens)
{#.doc (doc "Allows arbitrary looping, using the 'recur' form to re-start the loop."
"Can be used in monadic code to create monadic loops."
(loop [count +0
@@ -5126,7 +5299,7 @@
#.None
(failure "Wrong syntax for loop"))))
-(macro: #export (^slots tokens)
+(macro: .public (^slots tokens)
{#.doc (doc "Allows you to extract record members as local variables with the same names."
"For example:"
(let [(^slots [#foo #bar #baz]) quux]
@@ -5204,7 +5377,7 @@
pairs)]
(in (list [location (#Record =pairs)])))))
-(macro: #export (with_expansions tokens)
+(macro: .public (with_expansions tokens)
{#.doc (doc "Controlled macro-expansion."
"Bind an arbitraty number of Code nodes resulting from macro-expansion to local bindings."
"Wherever a binding appears, the bound Code nodes will be spliced in there."
@@ -5322,7 +5495,7 @@
## (\ meta_monad in token)
))
-(macro: #export (static tokens)
+(macro: .public (static tokens)
(case tokens
(^ (list pattern))
(do meta_monad
@@ -5376,7 +5549,7 @@
(: (List [Code Code]) (list\reverse levels)))]
(list init_pattern inner_pattern_body)))
-(macro: #export (^multi tokens)
+(macro: .public (^multi tokens)
{#.doc (doc "Multi-level pattern matching."
"Useful in situations where the result of a branch depends on further refinements on the values being matched."
"For example:"
@@ -5436,7 +5609,7 @@
(|>> name\encode
(text\compose "Wrong syntax for ")))
-(macro: #export (name_of tokens)
+(macro: .public (name_of tokens)
{#.doc (doc "Given an identifier or a tag, gives back a 2 tuple with the prefix and name parts, both as Text."
(name_of #.doc)
"=>"
@@ -5460,10 +5633,10 @@
(#Right state scope_type_vars)
))
-(macro: #export (:parameter tokens)
+(macro: .public (:parameter tokens)
{#.doc (doc "Allows you to refer to the type-variables in a polymorphic function's type, by their index."
"In the example below, 0 corresponds to the 'a' variable."
- (def: #export (of_list list)
+ (def: .public (of_list list)
(All [a] (-> (List a) (Row a)))
(list\fold add
(: (Row (:parameter 0))
@@ -5483,7 +5656,7 @@
_
(failure (..wrong_syntax_error (name_of ..$)))))
-(def: #export (is? reference sample)
+(def: .public (is? reference sample)
{#.doc (doc "Tests whether the 2 values are identical (not just 'equal')."
"This one should succeed:"
(let [value +5]
@@ -5494,7 +5667,7 @@
(All [a] (-> a a Bit))
("lux is" reference sample))
-(macro: #export (^@ tokens)
+(macro: .public (^@ tokens)
{#.doc (doc "Allows you to simultaneously bind and de-structure a value."
(def: (hash (^@ set [Hash<a> _]))
(list\fold (function (_ elem acc) (+ (\ Hash<a> hash elem) acc))
@@ -5510,7 +5683,7 @@
_
(failure (..wrong_syntax_error (name_of ..^@)))))
-(macro: #export (^|> tokens)
+(macro: .public (^|> tokens)
{#.doc (doc "Pipes the value being pattern-matched against prior to binding it to a variable."
(case input
(^|> value [inc (% 10) (max 1)])
@@ -5526,7 +5699,7 @@
_
(failure (..wrong_syntax_error (name_of ..^|>)))))
-(macro: #export (:assume tokens)
+(macro: .public (:assume tokens)
{#.doc (doc "Coerces the given expression to the type of whatever is expected."
(: Dinosaur (:assume (list +1 +2 +3))))}
(case tokens
@@ -5544,7 +5717,7 @@
(function (_ compiler)
(#Right [compiler (get@ #location compiler)])))
-(macro: #export (undefined tokens)
+(macro: .public (undefined tokens)
{#.doc (doc "Meant to be used as a stand-in for functions with undefined implementations."
"Undefined expressions will type-check against everything, so they make good dummy implementations."
"However, if an undefined expression is ever evaluated, it will raise a runtime error."
@@ -5563,7 +5736,7 @@
_
(failure (..wrong_syntax_error (name_of ..undefined)))))
-(macro: #export (:of tokens)
+(macro: .public (:of tokens)
{#.doc (doc "Generates the type corresponding to a given expression."
"Example #1:"
(let [my_num +123]
@@ -5590,107 +5763,82 @@
_
(failure (..wrong_syntax_error (name_of ..:of)))))
-(def: (complex_declaration_parser tokens)
- (-> (List Code) (Meta [[Text (List Text)] (List Code)]))
- (case tokens
- (^ (list& [_ (#Form (list& [_ (#Identifier ["" name])] args'))] tokens'))
- (do meta_monad
- [args (monad\map meta_monad
- (function (_ arg')
- (case arg'
- [_ (#Identifier ["" arg_name])]
- (in arg_name)
-
- _
- (failure "Could not parse an argument.")))
- args')]
- (in [[name args] tokens']))
-
- _
- (failure "Could not parse a complex declaration.")
- ))
-
-(def: (any_parser tokens)
- (-> (List Code) (Meta [Code (List Code)]))
+(def: (tupleP tokens)
+ (-> (List Code) (Maybe [(List Code) (List Code)]))
(case tokens
- (^ (list& token tokens'))
- (in_meta [token tokens'])
-
- _
- (failure "Could not parse anything.")
- ))
-
-(def: (many_parser tokens)
- (-> (List Code) (Meta [(List Code) (List Code)]))
- (case tokens
- (^ (list& head tail))
- (in_meta [tokens (list)])
-
- _
- (failure "Could not parse anything.")
- ))
+ (^ (list& [_ (#Tuple tuple)] tokens'))
+ (#Some [tokens' tuple])
-(def: (end_parser tokens)
- (-> (List Code) (Meta Any))
- (case tokens
- (^ (list))
- (in_meta [])
-
_
- (failure "Expected input Codes to be empty.")
- ))
-
-(def: (anns_parser tokens)
- (-> (List Code) (Meta [Code (List Code)]))
- (case tokens
- (^ (list& [_ (#Record _anns)] tokens'))
- (in_meta [(record$ _anns) tokens'])
-
- _
- (in_meta [(' {}) tokens])
- ))
+ #None))
-(macro: #export (template: tokens)
+(def:' .private (templateP tokens)
+ (-> (List Code) (Maybe [Code Text (List Text) (List [Code Code]) (List Code)]))
+ (|> (do maybe_monad
+ [% (declarationP tokens)
+ .let' [[tokens [export_policy name parameters]] %]
+ % (annotationsP tokens)
+ .let' [[tokens annotations] %]
+ % (tupleP tokens)
+ .let' [[tokens templates] %]
+ _ (endP tokens)]
+ (in [export_policy name parameters annotations templates]))
+ ## (^ (list _export_policy _declaration _annotations _body))
+ ## (^ (list _declaration _annotations _body))
+ (maybe\else' (do maybe_monad
+ [% (declarationP tokens)
+ .let' [[tokens [export_policy name parameters]] %]
+ % (tupleP tokens)
+ .let' [[tokens templates] %]
+ _ (endP tokens)]
+ (in [export_policy name parameters #End templates])))
+ ## (^ (list _export_policy _declaration _body))
+ (maybe\else' (do maybe_monad
+ [% (local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (tupleP tokens)
+ .let' [[tokens templates] %]
+ _ (endP tokens)]
+ (in [(` ..private) name parameters #End templates])))
+ ## (^ (list _declaration _body))
+ ))
+
+(macro: .public (template: tokens)
{#.doc (doc "Define macros in the style of template and ^template."
"For simple macros that do not need any fancy features."
(template: (square x)
(* x x)))}
- (do meta_monad
- [.let [[export? tokens] (export^ tokens)]
- name+args|tokens (complex_declaration_parser tokens)
- .let [[[name args] tokens] name+args|tokens]
- anns|tokens (anns_parser tokens)
- .let [[anns tokens] anns|tokens]
- input_templates|tokens (many_parser tokens)
- .let [[input_templates tokens] input_templates|tokens]
- _ (end_parser tokens)
- g!tokens (gensym "tokens")
- g!compiler (gensym "compiler")
- g!_ (gensym "_")
- .let [rep_env (list\map (function (_ arg)
- [arg (` ((~' ~) (~ (local_identifier$ arg))))])
- args)]
- this_module current_module_name]
- (in (list (` (macro: (~+ (export export?))
- ((~ (local_identifier$ name)) (~ g!tokens) (~ g!compiler))
- (~ anns)
- (case (~ g!tokens)
- (^ (list (~+ (list\map local_identifier$ args))))
- (#.Right [(~ g!compiler)
- (list (~+ (list\map (function (_ template)
- (` (`' (~ (with_replacements rep_env
- template)))))
- input_templates)))])
-
- (~ g!_)
- (#.Left (~ (text$ (..wrong_syntax_error [this_module name]))))
- )))))
- ))
-
-(macro: #export (as_is tokens compiler)
+ (case (templateP tokens)
+ (#.Some [export_policy name args anns input_templates])
+ (do meta_monad
+ [g!tokens (gensym "tokens")
+ g!compiler (gensym "compiler")
+ g!_ (gensym "_")
+ .let [rep_env (list\map (function (_ arg)
+ [arg (` ((~' ~) (~ (local_identifier$ arg))))])
+ args)]
+ this_module current_module_name]
+ (in (list (` (macro: (~ export_policy)
+ ((~ (local_identifier$ name)) (~ g!tokens) (~ g!compiler))
+ (~ (record$ anns))
+ (case (~ g!tokens)
+ (^ (list (~+ (list\map local_identifier$ args))))
+ (#.Right [(~ g!compiler)
+ (list (~+ (list\map (function (_ template)
+ (` (`' (~ (with_replacements rep_env
+ template)))))
+ input_templates)))])
+
+ (~ g!_)
+ (#.Left (~ (text$ (..wrong_syntax_error [this_module name]))))))))))
+
+ #.None
+ (failure (..wrong_syntax_error (name_of ..template:)))))
+
+(macro: .public (as_is tokens compiler)
(#Right [compiler tokens]))
-(macro: #export (char tokens compiler)
+(macro: .public (char tokens compiler)
(case tokens
(^multi (^ (list [_ (#Text input)]))
(|> input "lux text size" ("lux i64 =" 1)))
@@ -5750,7 +5898,7 @@
(in_meta (list pick))
(target_pick target options' default)))))
-(macro: #export (for tokens)
+(macro: .public (for tokens)
(do meta_monad
[target ..target]
(case tokens
@@ -5804,7 +5952,7 @@
_
(in_meta [(list) code])))
-(macro: #export (`` tokens)
+(macro: .public (`` tokens)
(case tokens
(^ (list raw))
(do meta_monad
@@ -5897,7 +6045,7 @@
(..untemplated_record g!meta untemplated_pattern fields)
)))
-(macro: #export (^code tokens)
+(macro: .public (^code tokens)
(case tokens
(^ (list& [_meta (#Form (list template))] body branches))
(do meta_monad
@@ -5912,15 +6060,15 @@
_
(failure (..wrong_syntax_error (name_of ..^code)))))
-(def: #export false
+(def: .public false
Bit
#0)
-(def: #export true
+(def: .public true
Bit
#1)
-(macro: #export (:let tokens)
+(macro: .public (:let tokens)
(case tokens
(^ (list [_ (#Tuple bindings)] bodyT))
(if (multiple? 2 (list\size bindings))
@@ -5935,7 +6083,7 @@
_
(..failure (..wrong_syntax_error (name_of ..:let)))))
-(macro: #export (try tokens)
+(macro: .public (try tokens)
{#.doc (doc (case (try (risky_computation input))
(#.Right success)
(do_something success)