blob: 07f76e2581b5fda8552229d28202065f3dde118f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
(.module:
[lux #*
[host (#+ import:)]
[abstract
["." monad (#+ do)]]
[control
["." function]]
[data
["." product]
["." text]
[number
["f" frac]]
[collection
["." dictionary]]]
[target
["_" php (#+ Expression)]]]
["." /// #_
["#." runtime (#+ Operation Phase Handler Bundle)]
["#." primitive]
[//
[extension (#+ Nullary Unary Binary Trinary
nullary unary binary trinary)]
[//
[extension
["." bundle]]]]])
(def: lux-procs
Bundle
(|> bundle.empty
(bundle.install "is" (binary (product.uncurry _.=)))
(bundle.install "try" (unary ///runtime.lux//try))))
(def: i64-procs
Bundle
(<| (bundle.prefix "i64")
(|> bundle.empty
(bundle.install "and" (binary (product.uncurry _.bit-and)))
(bundle.install "or" (binary (product.uncurry _.bit-or)))
(bundle.install "xor" (binary (product.uncurry _.bit-xor)))
(bundle.install "left-shift" (binary (product.uncurry _.bit-shl)))
(bundle.install "logical-right-shift" (binary (product.uncurry ///runtime.i64//logic-right-shift)))
(bundle.install "arithmetic-right-shift" (binary (product.uncurry _.bit-shr)))
(bundle.install "=" (binary (product.uncurry _.=)))
(bundle.install "+" (binary (product.uncurry _.+)))
(bundle.install "-" (binary (product.uncurry _.-)))
)))
(def: int-procs
Bundle
(<| (bundle.prefix "int")
(|> bundle.empty
(bundle.install "<" (binary (product.uncurry _.<)))
(bundle.install "*" (binary (product.uncurry _.*)))
(bundle.install "/" (binary (product.uncurry _./)))
(bundle.install "%" (binary (product.uncurry _.%)))
(bundle.install "frac" (unary _.floatval/1))
(bundle.install "char" (unary _.chr/1)))))
(import: #long java/lang/Double
(#static MIN_VALUE double)
(#static MAX_VALUE double))
(template [<name> <const>]
[(def: (<name> _)
(Nullary (Expression Any))
(_.float <const>))]
[frac//smallest (java/lang/Double::MIN_VALUE)]
[frac//min (f.* -1.0 (java/lang/Double::MAX_VALUE))]
[frac//max (java/lang/Double::MAX_VALUE)]
)
(def: frac-procs
Bundle
(<| (bundle.prefix "frac")
(|> bundle.empty
(bundle.install "+" (binary (product.uncurry _.+)))
(bundle.install "-" (binary (product.uncurry _.-)))
(bundle.install "*" (binary (product.uncurry _.*)))
(bundle.install "/" (binary (product.uncurry _./)))
(bundle.install "%" (binary (product.uncurry _.%)))
(bundle.install "=" (binary (product.uncurry _.=)))
(bundle.install "<" (binary (product.uncurry _.<)))
(bundle.install "smallest" (nullary frac//smallest))
(bundle.install "min" (nullary frac//min))
(bundle.install "max" (nullary frac//max))
(bundle.install "int" (unary _.intval/1))
(bundle.install "encode" (unary _.strval/1))
(bundle.install "decode" (unary (|>> _.floatval/1 ///runtime.some)))
)))
(def: (text//index [startO partO textO])
(Trinary (Expression Any))
(///runtime.text//index textO partO startO))
(def: text-procs
Bundle
(<| (bundle.prefix "text")
(|> bundle.empty
(bundle.install "=" (binary (product.uncurry _.=)))
(bundle.install "<" (binary (product.uncurry _.<)))
(bundle.install "concat" (binary (product.uncurry _.concat)))
(bundle.install "index" (trinary text//index))
(bundle.install "size" (unary _.strlen/1))
(bundle.install "char" (binary (function (text//char [text idx])
(|> text (_.nth idx) _.ord/1))))
(bundle.install "clip" (trinary (function (text//clip [from to text])
(_.substr/3 [text from (_.- from to)]))))
)))
(def: io-procs
Bundle
(<| (bundle.prefix "io")
(|> bundle.empty
(bundle.install "log" (unary (|>> (_.concat (_.string text.new-line)) _.print/1)))
(bundle.install "error" (unary ///runtime.io//throw!))
(bundle.install "exit" (unary _.exit/1))
(bundle.install "current-time" (nullary (|>> _.time/0 (_.* (_.int +1,000))))))))
(def: #export bundle
Bundle
(<| (bundle.prefix "lux")
(|> lux-procs
(dictionary.merge i64-procs)
(dictionary.merge int-procs)
(dictionary.merge frac-procs)
(dictionary.merge text-procs)
(dictionary.merge io-procs)
)))
|