aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool/compiler/phase/generation/python/extension/common.lux
blob: 7e1b4d2c180196a52087eb2f4525700df588f038 (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
(.module:
  [lux #*
   [host (#+ import:)]
   [abstract
    ["." monad (#+ do)]]
   [control
    ["." function]]
   [data
    ["." product]
    [collection
     ["." dictionary]]]
   [target
    ["_" python (#+ 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 _.is)))
      (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 (function.compose ///runtime.i64//64 (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 _.float/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 _.int/1))
          (bundle.install "encode" (unary _.repr/1))
          (bundle.install "decode" (unary ///runtime.frac//decode)))))

(def: (text//clip [paramO extraO subjectO])
  (Trinary (Expression Any))
  (///runtime.text//clip subjectO paramO extraO))

(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 _.+)))
          (bundle.install "index" (trinary text//index))
          (bundle.install "size" (unary _.len/1))
          (bundle.install "char" (binary (product.uncurry ///runtime.text//char)))
          (bundle.install "clip" (trinary text//clip))
          )))

(def: io-procs
  Bundle
  (<| (bundle.prefix "io")
      (|> bundle.empty
          (bundle.install "log" (unary ///runtime.io//log!))
          (bundle.install "error" (unary ///runtime.io//throw!))
          (bundle.install "exit" (unary ///runtime.io//exit!))
          (bundle.install "current-time" (nullary (function (_ _)
                                                    (///runtime.io//current-time! ///runtime.unit)))))))

(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)
          )))