aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux
diff options
context:
space:
mode:
authorEduardo Julian2018-04-14 13:32:43 -0400
committerEduardo Julian2018-04-14 13:32:43 -0400
commit0bba53ceb52502510e0f6ba4c53a951933532a61 (patch)
tree82bd7fe239dc7996e9542fc9b5fea5768579bd0f /new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux
parent1a3fa23f5c0444f0f8273cbc21875eeabdc321aa (diff)
- Made everything an expression for R translation.
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux')
-rw-r--r--new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux897
1 files changed, 444 insertions, 453 deletions
diff --git a/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux
index 9b6d0c862..b75da1804 100644
--- a/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux
+++ b/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux
@@ -12,7 +12,7 @@
[io #+ Process])
[//]
(luxc [lang]
- (lang (host [r #+ SVar Expression Statement @@]))))
+ (lang (host [r #+ SVar Expression @@]))))
(def: prefix Text "LuxRuntime")
@@ -60,7 +60,7 @@
(-> Expression Expression)
(variant +1 true))
-(type: Runtime Statement)
+(type: Runtime Expression)
(def: declaration
(s.Syntax [Text (List Text)])
@@ -84,7 +84,7 @@
(~ type)
(r.apply (list (~+ argsC+)) (~ @runtime))))
(` (def: (~ implementation)
- r.Statement
+ r.Expression
(~ (case argsC+
#.Nil
(` (r.set! (~ $runtime) (~ definition)))
@@ -118,12 +118,11 @@
(runtime: (int//unsigned-low input)
(with-vars [low]
- ($_ r.then!
+ ($_ r.then
(r.set! low (|> (@@ input) (r.nth (r.string //.int-low-field))))
- (r.do!
- (r.if (|> (@@ low) (r.>= (r.int 0)))
- (@@ low)
- (|> (@@ low) (r.+ f2^32)))))))
+ (r.if (|> (@@ low) (r.>= (r.int 0)))
+ (@@ low)
+ (|> (@@ low) (r.+ f2^32))))))
(runtime: (int//to-float input)
(let [high (|> (@@ input)
@@ -131,12 +130,11 @@
high-shift)
low (|> (@@ input)
int//unsigned-low)]
- (r.do! (|> high (r.+ low)))))
+ (|> high (r.+ low))))
(runtime: (int//new high low)
- (r.do!
- (r.named-list (list [//.int-high-field (as-integer (@@ high))]
- [//.int-low-field (as-integer (@@ low))]))))
+ (r.named-list (list [//.int-high-field (as-integer (@@ high))]
+ [//.int-low-field (as-integer (@@ low))])))
(do-template [<name> <high> <low>]
[(runtime: <name>
@@ -152,13 +150,13 @@
(def: int64-low (r.nth (r.string //.int-low-field)))
(runtime: (bit//not input)
- (r.do! (int//new (|> (@@ input) int64-high r.bit-not)
- (|> (@@ input) int64-low r.bit-not))))
+ (int//new (|> (@@ input) int64-high r.bit-not)
+ (|> (@@ input) int64-low r.bit-not)))
(runtime: (int//+ param subject)
(with-vars [sH sL pH pL
x00 x16 x32 x48]
- ($_ r.then!
+ ($_ r.then
(r.set! sH (|> (@@ subject) int64-high))
(r.set! sL (|> (@@ subject) int64-low))
(r.set! pH (|> (@@ param) int64-high))
@@ -179,262 +177,261 @@
new-half (function (_ top bottom)
(|> top bottom-16 move-top-16
(r.bit-or (bottom-16 bottom))))]
- ($_ r.then!
+ ($_ r.then
(r.set! x00 (|> s00 (r.+ p00)))
(r.set! x16 (|> (@@ x00) top-16 (r.+ s16) (r.+ p16)))
(r.set! x32 (|> (@@ x16) top-16 (r.+ s32) (r.+ p32)))
(r.set! x48 (|> (@@ x32) top-16 (r.+ s48) (r.+ p48)))
- (r.do! (int//new (new-half (@@ x48) (@@ x32))
- (new-half (@@ x16) (@@ x00)))))))))
+ (int//new (new-half (@@ x48) (@@ x32))
+ (new-half (@@ x16) (@@ x00))))))))
(runtime: (int//= reference sample)
(let [comparison (: (-> (-> Expression Expression) Expression)
(function (_ field)
(|> (field (@@ sample)) (r.= (field (@@ reference))))))]
- (r.do! (|> (comparison int64-high)
- (r.and (comparison int64-low))))))
+ (|> (comparison int64-high)
+ (r.and (comparison int64-low)))))
(runtime: (int//negate input)
- (r.do!
- (r.if (|> (@@ input) (int//= int//min))
- int//min
- (|> (@@ input) bit//not (int//+ int//one)))))
+ (r.if (|> (@@ input) (int//= int//min))
+ int//min
+ (|> (@@ input) bit//not (int//+ int//one))))
(runtime: int//-one
(int//negate int//one))
(runtime: (int//- param subject)
- (r.do! (int//+ (int//negate (@@ param)) (@@ subject))))
+ (int//+ (int//negate (@@ param)) (@@ subject)))
(runtime: (int//< reference sample)
(with-vars [r-? s-?]
- ($_ r.then!
+ ($_ r.then
(r.set! s-? (|> (@@ sample) int64-high (r.< (r.int 0))))
(r.set! r-? (|> (@@ reference) int64-high (r.< (r.int 0))))
- (r.do! (|> (|> (@@ s-?) (r.and (r.not (@@ r-?))))
- (r.or (|> (r.not (@@ s-?)) (r.and (@@ r-?)) r.not))
- (r.or (|> (@@ sample)
- (int//- (@@ reference))
- int64-high
- (r.< (r.int 0)))))))))
+ (|> (|> (@@ s-?) (r.and (r.not (@@ r-?))))
+ (r.or (|> (r.not (@@ s-?)) (r.and (@@ r-?)) r.not))
+ (r.or (|> (@@ sample)
+ (int//- (@@ reference))
+ int64-high
+ (r.< (r.int 0))))))))
(runtime: (int//from-float input)
- (r.do!
- (r.cond (list [(r.apply (list (@@ input)) (r.global "is.nan"))
- int//zero]
- [(|> (@@ input) (r.<= (r.negate f2^63)))
- int//min]
- [(|> (@@ input) (r.+ (r.float 1.0)) (r.>= f2^63))
- int//max]
- [(|> (@@ input) (r.< (r.float 0.0)))
- (|> (@@ input) r.negate int//from-float int//negate)])
- (int//new (|> (@@ input) (r./ f2^32))
- (|> (@@ input) (r.%% f2^32))))))
+ (r.cond (list [(r.apply (list (@@ input)) (r.global "is.nan"))
+ int//zero]
+ [(|> (@@ input) (r.<= (r.negate f2^63)))
+ int//min]
+ [(|> (@@ input) (r.+ (r.float 1.0)) (r.>= f2^63))
+ int//max]
+ [(|> (@@ input) (r.< (r.float 0.0)))
+ (|> (@@ input) r.negate int//from-float int//negate)])
+ (int//new (|> (@@ input) (r./ f2^32))
+ (|> (@@ input) (r.%% f2^32)))))
(runtime: (int//* param subject)
(with-vars [sH sL pH pL
x00 x16 x32 x48]
- ($_ r.then!
+ ($_ r.then
(r.set! sH (|> (@@ subject) int64-high))
(r.set! pH (|> (@@ param) int64-high))
(let [negative-subject? (|> (@@ sH) (r.< (r.int 0)))
negative-param? (|> (@@ pH) (r.< (r.int 0)))]
- (r.cond! (list [negative-subject?
- (r.if! negative-param?
- (r.do! (int//* (int//negate (@@ param))
- (int//negate (@@ subject))))
- (r.do! (int//negate (int//* (@@ param)
- (int//negate (@@ subject))))))]
-
- [negative-param?
- (r.do! (int//negate (int//* (int//negate (@@ param))
- (@@ subject))))])
- ($_ r.then!
- (r.set! sL (|> (@@ subject) int64-low))
- (r.set! pL (|> (@@ param) int64-low))
- (let [bits16 (r.code "0xFFFF")
- move-top-16 (r.bit-shl (r.int 16))
- top-16 (r.bit-ushr (r.int 16))
- bottom-16 (r.bit-and bits16)
- split-16 (function (_ source)
- [(|> source top-16)
- (|> source bottom-16)])
- split-int (function (_ high low)
- [(split-16 high)
- (split-16 low)])
- new-half (function (_ top bottom)
- (|> top bottom-16 move-top-16
- (r.bit-or (bottom-16 bottom))))
-
- [[_s48 _s32] [_s16 _s00]] (split-int (@@ sH) (@@ sL))
- [[_p48 _p32] [_p16 _p00]] (split-int (@@ pH) (@@ pL))
- x16-top (|> (@@ x16) top-16)
- x32-top (|> (@@ x32) top-16)]
- (with-vars [s48 s32 s16 s00
- p48 p32 p16 p00]
- ($_ r.then!
- (r.set! s48 _s48) (r.set! s32 _s32) (r.set! s16 _s16) (r.set! s00 _s00)
- (r.set! p48 _p48) (r.set! p32 _p32) (r.set! p16 _p16) (r.set! p00 _p00)
- (r.set! x00 (|> (@@ s00) (r.* (@@ p00))))
- (r.set! x16 (|> (@@ x00) top-16 (r.+ (|> (@@ s16) (r.* (@@ p00))))))
- (r.set! x32 x16-top)
- (r.set! x16 (|> (@@ x16) bottom-16 (r.+ (|> (@@ s00) (r.* (@@ p16))))))
- (r.set! x32 (|> (@@ x32) (r.+ x16-top) (r.+ (|> (@@ s32) (r.* (@@ p00))))))
- (r.set! x48 x32-top)
- (r.set! x32 (|> (@@ x32) bottom-16 (r.+ (|> (@@ s16) (r.* (@@ p16))))))
- (r.set! x48 (|> (@@ x48) (r.+ x32-top)))
- (r.set! x32 (|> (@@ x32) bottom-16 (r.+ (|> (@@ s00) (r.* (@@ p32))))))
- (r.set! x48 (|> (@@ x48) (r.+ x32-top)
- (r.+ (|> (@@ s48) (r.* (@@ p00))))
- (r.+ (|> (@@ s32) (r.* (@@ p16))))
- (r.+ (|> (@@ s16) (r.* (@@ p32))))
- (r.+ (|> (@@ s00) (r.* (@@ p48))))))
- (r.do! (int//new (new-half (@@ x48) (@@ x32))
- (new-half (@@ x16) (@@ x00))))))
- )))))))
+ (r.cond (list [negative-subject?
+ (r.if negative-param?
+ (int//* (int//negate (@@ param))
+ (int//negate (@@ subject)))
+ (int//negate (int//* (@@ param)
+ (int//negate (@@ subject)))))]
+
+ [negative-param?
+ (int//negate (int//* (int//negate (@@ param))
+ (@@ subject)))])
+ ($_ r.then
+ (r.set! sL (|> (@@ subject) int64-low))
+ (r.set! pL (|> (@@ param) int64-low))
+ (let [bits16 (r.code "0xFFFF")
+ move-top-16 (r.bit-shl (r.int 16))
+ top-16 (r.bit-ushr (r.int 16))
+ bottom-16 (r.bit-and bits16)
+ split-16 (function (_ source)
+ [(|> source top-16)
+ (|> source bottom-16)])
+ split-int (function (_ high low)
+ [(split-16 high)
+ (split-16 low)])
+ new-half (function (_ top bottom)
+ (|> top bottom-16 move-top-16
+ (r.bit-or (bottom-16 bottom))))
+ x16-top (|> (@@ x16) top-16)
+ x32-top (|> (@@ x32) top-16)]
+ (with-vars [s48 s32 s16 s00
+ p48 p32 p16 p00]
+ (let [[[_s48 _s32] [_s16 _s00]] (split-int (@@ sH) (@@ sL))
+ [[_p48 _p32] [_p16 _p00]] (split-int (@@ pH) (@@ pL))
+ set-subject-chunks! ($_ r.then (r.set! s48 _s48) (r.set! s32 _s32) (r.set! s16 _s16) (r.set! s00 _s00))
+ set-param-chunks! ($_ r.then (r.set! p48 _p48) (r.set! p32 _p32) (r.set! p16 _p16) (r.set! p00 _p00))]
+ ($_ r.then
+ set-subject-chunks!
+ set-param-chunks!
+ (r.set! x00 (|> (@@ s00) (r.* (@@ p00))))
+ (r.set! x16 (|> (@@ x00) top-16 (r.+ (|> (@@ s16) (r.* (@@ p00))))))
+ (r.set! x32 x16-top)
+ (r.set! x16 (|> (@@ x16) bottom-16 (r.+ (|> (@@ s00) (r.* (@@ p16))))))
+ (r.set! x32 (|> (@@ x32) (r.+ x16-top) (r.+ (|> (@@ s32) (r.* (@@ p00))))))
+ (r.set! x48 x32-top)
+ (r.set! x32 (|> (@@ x32) bottom-16 (r.+ (|> (@@ s16) (r.* (@@ p16))))))
+ (r.set! x48 (|> (@@ x48) (r.+ x32-top)))
+ (r.set! x32 (|> (@@ x32) bottom-16 (r.+ (|> (@@ s00) (r.* (@@ p32))))))
+ (r.set! x48 (|> (@@ x48) (r.+ x32-top)
+ (r.+ (|> (@@ s48) (r.* (@@ p00))))
+ (r.+ (|> (@@ s32) (r.* (@@ p16))))
+ (r.+ (|> (@@ s16) (r.* (@@ p32))))
+ (r.+ (|> (@@ s00) (r.* (@@ p48))))))
+ (int//new (new-half (@@ x48) (@@ x32))
+ (new-half (@@ x16) (@@ x00))))))
+ )))))))
(def: (limit-shift! shift)
- (-> SVar Statement)
+ (-> SVar Expression)
(r.set! shift (|> (@@ shift) (r.bit-and (r.int 63)))))
(def: (no-shift-clause shift input)
- (-> SVar SVar [Expression Statement])
+ (-> SVar SVar [Expression Expression])
[(|> (@@ shift) (r.= (r.int 0)))
- (r.do! (@@ input))])
+ (@@ input)])
(runtime: (bit//shift-left shift input)
- ($_ r.then!
+ ($_ r.then
(limit-shift! shift)
- (r.cond! (list (no-shift-clause shift input)
- [(|> (@@ shift) (r.< (r.int 32)))
- (let [mid (|> (int64-low (@@ input)) (r.bit-ushr (|> (r.int 32) (r.- (@@ shift)))))
- high (|> (int64-high (@@ input))
- (r.bit-shl (@@ shift))
- (r.bit-or mid))
- low (|> (int64-low (@@ input))
- (r.bit-shl (@@ shift)))]
- (r.do! (int//new high low)))])
- (let [high (|> (int64-high (@@ input))
- (r.bit-shl (|> (@@ shift) (r.- (r.int 32)))))]
- (r.do! (int//new high (r.int 0)))))))
+ (r.cond (list (no-shift-clause shift input)
+ [(|> (@@ shift) (r.< (r.int 32)))
+ (let [mid (|> (int64-low (@@ input)) (r.bit-ushr (|> (r.int 32) (r.- (@@ shift)))))
+ high (|> (int64-high (@@ input))
+ (r.bit-shl (@@ shift))
+ (r.bit-or mid))
+ low (|> (int64-low (@@ input))
+ (r.bit-shl (@@ shift)))]
+ (int//new high low))])
+ (let [high (|> (int64-high (@@ input))
+ (r.bit-shl (|> (@@ shift) (r.- (r.int 32)))))]
+ (int//new high (r.int 0))))))
(runtime: (bit//signed-shift-right-32 shift input)
(let [top-bit (|> (@@ input) (r.bit-and (r.int (hex "80000000"))))]
- (r.do! (|> (@@ input)
- (r.bit-ushr (@@ shift))
- (r.bit-or top-bit)))))
+ (|> (@@ input)
+ (r.bit-ushr (@@ shift))
+ (r.bit-or top-bit))))
(runtime: (bit//signed-shift-right shift input)
- ($_ r.then!
+ ($_ r.then
(limit-shift! shift)
- (r.cond! (list (no-shift-clause shift input)
- [(|> (@@ shift) (r.< (r.int 32)))
- (let [mid (|> (int64-high (@@ input)) (r.bit-shl (|> (r.int 32) (r.- (@@ shift)))))
- high (|> (int64-high (@@ input))
- (bit//signed-shift-right-32 (@@ shift)))
- low (|> (int64-low (@@ input))
- (r.bit-ushr (@@ shift))
- (r.bit-or mid))]
- (r.do! (int//new high low)))])
- (let [low (|> (int64-high (@@ input))
- (bit//signed-shift-right-32 (|> (@@ shift) (r.- (r.int 32)))))
- high (r.if (|> (int64-high (@@ input)) (r.>= (r.int 0)))
- (r.int 0)
- (r.int -1))]
- (r.do! (int//new high low))))))
+ (r.cond (list (no-shift-clause shift input)
+ [(|> (@@ shift) (r.< (r.int 32)))
+ (let [mid (|> (int64-high (@@ input)) (r.bit-shl (|> (r.int 32) (r.- (@@ shift)))))
+ high (|> (int64-high (@@ input))
+ (bit//signed-shift-right-32 (@@ shift)))
+ low (|> (int64-low (@@ input))
+ (r.bit-ushr (@@ shift))
+ (r.bit-or mid))]
+ (int//new high low))])
+ (let [low (|> (int64-high (@@ input))
+ (bit//signed-shift-right-32 (|> (@@ shift) (r.- (r.int 32)))))
+ high (r.if (|> (int64-high (@@ input)) (r.>= (r.int 0)))
+ (r.int 0)
+ (r.int -1))]
+ (int//new high low)))))
(runtime: (int/// param subject)
(let [negative? (|>> (int//< int//zero))
valid-division-check [(|> (@@ param) (int//= int//zero))
- (r.stop! (r.string "Cannot divide by zero!"))]
+ (r.stop (r.string "Cannot divide by zero!"))]
short-circuit-check [(|> (@@ subject) (int//= int//zero))
- (r.do! int//zero)]]
- (r.cond! (list valid-division-check
- short-circuit-check
-
- [(|> (@@ subject) (int//= int//min))
- (r.cond! (list [(|> (|> (@@ param) (int//= int//one))
- (r.or (|> (@@ param) (int//= int//-one))))
- (r.do! int//min)]
- [(|> (@@ param) (int//= int//min))
- (r.do! int//one)])
- (with-vars [approximation]
- ($_ r.then!
- (r.set! approximation
- (|> (@@ subject)
- (bit//signed-shift-right (r.int 1))
- (int/// (@@ param))
- (bit//shift-left (r.int 1))))
- (r.if! (|> (@@ approximation) (int//= int//zero))
- (r.do! (r.if (negative? (@@ param))
- int//one
- int//-one))
- (let [remainder (int//- (int//* (@@ param) (@@ approximation))
- (@@ subject))]
- (r.do! (|> remainder
- (int/// (@@ param))
- (int//+ (@@ approximation)))))))))]
- [(|> (@@ param) (int//= int//min))
- (r.do! int//zero)]
-
- [(negative? (@@ subject))
- (r.do! (r.if (negative? (@@ param))
- (|> (int//negate (@@ subject))
- (int/// (int//negate (@@ param))))
- (|> (int//negate (@@ subject))
- (int/// (@@ param))
- int//negate)))]
-
- [(negative? (@@ param))
- (r.do! (|> (@@ param)
- int//negate
- (int/// (@@ subject))
- int//negate))])
- (with-vars [result remainder approximate approximate-result log2 approximate-remainder]
- ($_ r.then!
- (r.set! result int//zero)
- (r.set! remainder (@@ subject))
- (r.while! (|> (|> (@@ remainder) (int//< (@@ param)))
- (r.or (|> (@@ remainder) (int//= (@@ param)))))
- (let [calc-rough-estimate (r.apply (list (|> (int//to-float (@@ remainder)) (r./ (int//to-float (@@ param)))))
- (r.global "floor"))
- calc-approximate-result (int//from-float (@@ approximate))
- calc-approximate-remainder (|> (@@ approximate-result) (int//* (@@ param)))
- delta (r.if (|> (r.float 48.0) (r.<= (@@ log2)))
- (r.float 1.0)
- (r.** (|> (@@ log2) (r.- (r.float 48.0)))
- (r.float 2.0)))]
- ($_ r.then!
- (r.set! approximate (r.apply (list (r.float 1.0) calc-rough-estimate)
- (r.global "max")))
- (r.set! log2 (let [log (function (_ input)
- (r.apply (list input) (r.global "log")))]
- (r.apply (list (|> (log (r.int 2))
- (r./ (log (@@ approximate)))))
- (r.global "ceil"))))
- (r.set! approximate-result calc-approximate-result)
- (r.set! approximate-remainder calc-approximate-remainder)
- (r.while! (|> (negative? (@@ approximate-remainder))
- (r.or (|> (@@ approximate-remainder) (int//< (@@ remainder)))))
- ($_ r.then!
- (r.set! approximate (|> delta (r.- (@@ approximate))))
- (r.set! approximate-result calc-approximate-result)
- (r.set! approximate-remainder calc-approximate-remainder)))
- (r.set! result (|> (r.if (|> (@@ approximate-result) (int//= int//zero))
- int//one
- (@@ approximate-result))
- (int//+ (@@ result))))
- (r.set! remainder (|> (@@ remainder) (int//- (@@ approximate-remainder)))))))
- (r.do! (@@ result))))
- )))
+ int//zero]]
+ (r.cond (list valid-division-check
+ short-circuit-check
+
+ [(|> (@@ subject) (int//= int//min))
+ (r.cond (list [(|> (|> (@@ param) (int//= int//one))
+ (r.or (|> (@@ param) (int//= int//-one))))
+ int//min]
+ [(|> (@@ param) (int//= int//min))
+ int//one])
+ (with-vars [approximation]
+ ($_ r.then
+ (r.set! approximation
+ (|> (@@ subject)
+ (bit//signed-shift-right (r.int 1))
+ (int/// (@@ param))
+ (bit//shift-left (r.int 1))))
+ (r.if (|> (@@ approximation) (int//= int//zero))
+ (r.if (negative? (@@ param))
+ int//one
+ int//-one)
+ (let [remainder (int//- (int//* (@@ param) (@@ approximation))
+ (@@ subject))]
+ (|> remainder
+ (int/// (@@ param))
+ (int//+ (@@ approximation))))))))]
+ [(|> (@@ param) (int//= int//min))
+ int//zero]
+
+ [(negative? (@@ subject))
+ (r.if (negative? (@@ param))
+ (|> (int//negate (@@ subject))
+ (int/// (int//negate (@@ param))))
+ (|> (int//negate (@@ subject))
+ (int/// (@@ param))
+ int//negate))]
+
+ [(negative? (@@ param))
+ (|> (@@ param)
+ int//negate
+ (int/// (@@ subject))
+ int//negate)])
+ (with-vars [result remainder approximate approximate-result log2 approximate-remainder]
+ ($_ r.then
+ (r.set! result int//zero)
+ (r.set! remainder (@@ subject))
+ (r.while (|> (|> (@@ remainder) (int//< (@@ param)))
+ (r.or (|> (@@ remainder) (int//= (@@ param)))))
+ (let [calc-rough-estimate (r.apply (list (|> (int//to-float (@@ remainder)) (r./ (int//to-float (@@ param)))))
+ (r.global "floor"))
+ calc-approximate-result (int//from-float (@@ approximate))
+ calc-approximate-remainder (|> (@@ approximate-result) (int//* (@@ param)))
+ delta (r.if (|> (r.float 48.0) (r.<= (@@ log2)))
+ (r.float 1.0)
+ (r.** (|> (@@ log2) (r.- (r.float 48.0)))
+ (r.float 2.0)))]
+ ($_ r.then
+ (r.set! approximate (r.apply (list (r.float 1.0) calc-rough-estimate)
+ (r.global "max")))
+ (r.set! log2 (let [log (function (_ input)
+ (r.apply (list input) (r.global "log")))]
+ (r.apply (list (|> (log (r.int 2))
+ (r./ (log (@@ approximate)))))
+ (r.global "ceil"))))
+ (r.set! approximate-result calc-approximate-result)
+ (r.set! approximate-remainder calc-approximate-remainder)
+ (r.while (|> (negative? (@@ approximate-remainder))
+ (r.or (|> (@@ approximate-remainder) (int//< (@@ remainder)))))
+ ($_ r.then
+ (r.set! approximate (|> delta (r.- (@@ approximate))))
+ (r.set! approximate-result calc-approximate-result)
+ (r.set! approximate-remainder calc-approximate-remainder)))
+ (r.set! result (|> (r.if (|> (@@ approximate-result) (int//= int//zero))
+ int//one
+ (@@ approximate-result))
+ (int//+ (@@ result))))
+ (r.set! remainder (|> (@@ remainder) (int//- (@@ approximate-remainder)))))))
+ (@@ result)))
+ )))
(runtime: (int//% param subject)
(let [flat (|> (@@ subject) (int/// (@@ param)) (int//* (@@ param)))]
- (r.do! (|> (@@ subject) (int//- flat)))))
+ (|> (@@ subject) (int//- flat))))
(def: runtime//int
Runtime
- ($_ r.then!
+ ($_ r.then
@@int//unsigned-low
@@int//to-float
@@int//new
@@ -454,25 +451,25 @@
(runtime: (lux//try op)
(with-vars [error value]
- (r.do! (r.try ($_ r.then!
- (r.set! value (r.apply (list ..unit) (@@ op)))
- (r.do! (..right (@@ value))))
- #.None
- (#.Some (r.function (list error)
- (r.do! (..left (@@ error)))))
- #.None))))
+ (r.try ($_ r.then
+ (r.set! value (r.apply (list ..unit) (@@ op)))
+ (..right (@@ value)))
+ #.None
+ (#.Some (r.function (list error)
+ (..left (@@ error))))
+ #.None)))
(runtime: (lux//program-args program-args)
(with-vars [inputs value]
- ($_ r.then!
+ ($_ r.then
(r.set! inputs ..none)
- (<| (r.for-in! value (@@ program-args))
+ (<| (r.for-in value (@@ program-args))
(r.set! inputs (..some (r.list (list (@@ value) (@@ inputs))))))
- (r.do! (@@ inputs)))))
+ (@@ inputs))))
(def: runtime//lux
Runtime
- ($_ r.then!
+ ($_ r.then
@@lux//try
@@lux//program-args))
@@ -482,13 +479,13 @@
(r.apply (list raw-time) (r.global "as.numeric"))))
(runtime: (io//current-time! _)
- (r.do! (|> current-time-float
- (r.* (r.float 1_000.0))
- int//from-float)))
+ (|> current-time-float
+ (r.* (r.float 1_000.0))
+ int//from-float))
(def: runtime//io
Runtime
- ($_ r.then!
+ ($_ r.then
@@io//current-time!))
(def: minimum-index-length
@@ -509,28 +506,28 @@
(runtime: (product//left product index)
(let [$index_min_length (r.var "index_min_length")]
- ($_ r.then!
+ ($_ r.then
(r.set! $index_min_length (minimum-index-length index))
- (r.do! (r.if (|> (r.length (@@ product)) (r.> (@@ $index_min_length)))
- ## No need for recursion
- (product-element (@@ product) (@@ index))
- ## Needs recursion
- (product//left (product-tail product)
- (updated-index (@@ $index_min_length) (@@ product))))))))
+ (r.if (|> (r.length (@@ product)) (r.> (@@ $index_min_length)))
+ ## No need for recursion
+ (product-element (@@ product) (@@ index))
+ ## Needs recursion
+ (product//left (product-tail product)
+ (updated-index (@@ $index_min_length) (@@ product)))))))
(runtime: (product//right product index)
(let [$index_min_length (r.var "index_min_length")]
- ($_ r.then!
+ ($_ r.then
(r.set! $index_min_length (minimum-index-length index))
- (r.do! (r.cond (list [## Last element.
- (|> (r.length (@@ product)) (r.= (@@ $index_min_length)))
- (product-element (@@ product) (@@ index))]
- [## Needs recursion
- (|> (r.length (@@ product)) (r.< (@@ $index_min_length)))
- (product//right (product-tail product)
- (updated-index (@@ $index_min_length) (@@ product)))])
- ## Must slice
- (|> (@@ product) (r.slice-from (@@ index))))))))
+ (r.cond (list [## Last element.
+ (|> (r.length (@@ product)) (r.= (@@ $index_min_length)))
+ (product-element (@@ product) (@@ index))]
+ [## Needs recursion
+ (|> (r.length (@@ product)) (r.< (@@ $index_min_length)))
+ (product//right (product-tail product)
+ (updated-index (@@ $index_min_length) (@@ product)))])
+ ## Must slice
+ (|> (@@ product) (r.slice-from (@@ index)))))))
(runtime: (sum//get sum wanted_tag wants_last)
(let [no-match r.null
@@ -544,23 +541,23 @@
(|> (@@ wanted_tag) (r.- sum-tag))
(@@ wants_last))
no-match)]
- (r.do! (r.cond (list [(r.= sum-tag (@@ wanted_tag))
- (r.if (r.= (@@ wants_last) sum-flag)
- sum-value
- test-recursion)]
+ (r.cond (list [(r.= sum-tag (@@ wanted_tag))
+ (r.if (r.= (@@ wants_last) sum-flag)
+ sum-value
+ test-recursion)]
- [(|> (@@ wanted_tag) (r.> sum-tag))
- test-recursion]
+ [(|> (@@ wanted_tag) (r.> sum-tag))
+ test-recursion]
- [(|> (|> (@@ wants_last) (r.= (r.string "")))
- (r.and (|> (@@ wanted_tag) (r.< sum-tag))))
- (variant' (|> sum-tag (r.- (@@ wanted_tag))) sum-flag sum-value)])
+ [(|> (|> (@@ wants_last) (r.= (r.string "")))
+ (r.and (|> (@@ wanted_tag) (r.< sum-tag))))
+ (variant' (|> sum-tag (r.- (@@ wanted_tag))) sum-flag sum-value)])
- no-match))))
+ no-match)))
(def: runtime//adt
Runtime
- ($_ r.then!
+ ($_ r.then
@@product//left
@@product//right
@@sum//get
@@ -568,10 +565,10 @@
(do-template [<name> <op>]
[(runtime: (<name> mask input)
- (r.do! (int//new (<op> (int64-high (@@ mask))
- (int64-high (@@ input)))
- (<op> (int64-low (@@ mask))
- (int64-low (@@ input))))))]
+ (int//new (<op> (int64-high (@@ mask))
+ (int64-high (@@ input)))
+ (<op> (int64-low (@@ mask))
+ (int64-low (@@ input)))))]
[bit//and r.bit-and]
[bit//or r.bit-or]
@@ -580,42 +577,42 @@
(runtime: (bit//count-32 input)
(with-vars [count]
- ($_ r.then!
+ ($_ r.then
(r.set! count (r.int 0))
(let [last-input-bit (|> (@@ input) (r.bit-and (r.int 1)))
update-count! (r.set! count (|> (@@ count) (r.+ last-input-bit)))
consume-input! (r.set! input (|> (@@ input) (r.bit-ushr (r.int 1))))
input-remaining? (|> (@@ input) (r.= (r.int 0)))]
- (r.while! input-remaining?
- ($_ r.then!
- update-count!
- consume-input!)))
- (r.do! (@@ count)))))
+ (r.while input-remaining?
+ ($_ r.then
+ update-count!
+ consume-input!)))
+ (@@ count))))
(runtime: (bit//count input)
- (r.do! (int//from-float (r.+ (int64-high (@@ input))
- (int64-low (@@ input))))))
+ (int//from-float (r.+ (int64-high (@@ input))
+ (int64-low (@@ input)))))
(runtime: (bit//shift-right shift input)
- ($_ r.then!
+ ($_ r.then
(limit-shift! shift)
- (r.cond! (list (no-shift-clause shift input)
- [(|> (@@ shift) (r.< (r.int 32)))
- (let [mid (|> (int64-high (@@ input)) (r.bit-shl (|> (r.int 32) (r.- (@@ shift)))))
- high (|> (int64-high (@@ input)) (r.bit-ushr (@@ shift)))
- low (|> (int64-low (@@ input))
- (r.bit-ushr (@@ shift))
- (r.bit-or mid))]
- (r.do! (int//new high low)))]
- [(|> (@@ shift) (r.= (r.int 32)))
- (let [high (int64-high (@@ input))]
- (r.do! (int//new (r.int 0) high)))])
- (let [low (|> (int64-high (@@ input)) (r.bit-ushr (|> (@@ shift) (r.- (r.int 32)))))]
- (r.do! (int//new (r.int 0) low))))))
+ (r.cond (list (no-shift-clause shift input)
+ [(|> (@@ shift) (r.< (r.int 32)))
+ (let [mid (|> (int64-high (@@ input)) (r.bit-shl (|> (r.int 32) (r.- (@@ shift)))))
+ high (|> (int64-high (@@ input)) (r.bit-ushr (@@ shift)))
+ low (|> (int64-low (@@ input))
+ (r.bit-ushr (@@ shift))
+ (r.bit-or mid))]
+ (int//new high low))]
+ [(|> (@@ shift) (r.= (r.int 32)))
+ (let [high (int64-high (@@ input))]
+ (int//new (r.int 0) high))])
+ (let [low (|> (int64-high (@@ input)) (r.bit-ushr (|> (@@ shift) (r.- (r.int 32)))))]
+ (int//new (r.int 0) low)))))
(def: runtime//bit
Runtime
- ($_ r.then!
+ ($_ r.then
@@bit//and
@@bit//or
@@bit//xor
@@ -630,84 +627,84 @@
(runtime: (nat//< param subject)
(with-vars [pH sH]
- ($_ r.then!
+ ($_ r.then
(r.set! pH (..int64-high (@@ param)))
(r.set! sH (..int64-high (@@ subject)))
(let [lesser-high? (|> (@@ sH) (r.< (@@ pH)))
equal-high? (|> (@@ sH) (r.= (@@ pH)))
lesser-low? (|> (..int64-low (@@ subject)) (r.< (..int64-low (@@ param))))]
- (r.do! (|> lesser-high?
- (r.or (|> equal-high?
- (r.and lesser-low?)))))))))
+ (|> lesser-high?
+ (r.or (|> equal-high?
+ (r.and lesser-low?))))))))
(runtime: (nat/// parameter subject)
(let [negative? (int//< int//zero)
valid-division-check [(|> (@@ parameter) (int//= int//zero))
- (r.stop! (r.string "Cannot divide by zero!"))]
+ (r.stop (r.string "Cannot divide by zero!"))]
short-circuit-check [(|> (@@ subject) (nat//< (@@ parameter)))
- (r.do! int//zero)]]
- (r.cond! (list valid-division-check
- short-circuit-check
-
- [(|> (@@ parameter)
- (nat//< (|> (@@ subject) (bit//shift-right (r.int 1)))))
- (r.do! int//one)])
- (with-vars [result remainder approximate log2 approximate-result approximate-remainder delta]
- ($_ r.then!
- (r.set! result int//zero)
- (r.set! remainder (@@ subject))
- (r.while! (|> (|> (@@ remainder) (nat//< (@@ parameter)))
- (r.or (|> (@@ remainder) (int//= (@@ parameter)))))
- (let [rough-estimate (r.apply (list (|> (int//to-float (@@ parameter)) (r./ (int//to-float (@@ remainder)))))
- (r.global "floor"))
- calculate-approximate-result (int//from-float (@@ approximate))
- calculate-approximate-remainder (int//* (@@ parameter) (@@ approximate-result))
- delta (r.if (|> (r.float 48.0) (r.<= (@@ log2)))
- (r.float 1.0)
- (r.** (|> (r.float 48.0) (r.- (@@ log2)))
- (r.float 2.0)))
- update-approximates! ($_ r.then!
- (r.set! approximate-result calculate-approximate-result)
- (r.set! approximate-remainder calculate-approximate-remainder))]
- ($_ r.then!
- (r.set! approximate (r.apply (list (r.float 1.0) rough-estimate)
- (r.global "max")))
- (r.set! log2 (let [log (function (_ input)
- (r.apply (list input) (r.global "log")))]
- (r.apply (list (|> (log (r.int 2))
- (r./ (log (@@ approximate)))))
- (r.global "ceil"))))
- update-approximates!
- (r.while! (|> (negative? (@@ approximate-remainder))
- (r.or (|> (@@ approximate-remainder) (int//< (@@ remainder)))))
- ($_ r.then!
- (r.set! approximate (|> delta (r.- (@@ approximate))))
- update-approximates!))
- ($_ r.then!
- (r.set! result (|> (@@ result)
- (int//+ (r.if (|> (@@ approximate-result) (int//= int//zero))
- int//one
- (@@ approximate-result)))))
- (r.set! remainder (|> (@@ remainder) (int//- (@@ approximate-remainder))))))))
- (r.do! (@@ result))))
- )))
+ int//zero]]
+ (r.cond (list valid-division-check
+ short-circuit-check
+
+ [(|> (@@ parameter)
+ (nat//< (|> (@@ subject) (bit//shift-right (r.int 1)))))
+ int//one])
+ (with-vars [result remainder approximate log2 approximate-result approximate-remainder delta]
+ ($_ r.then
+ (r.set! result int//zero)
+ (r.set! remainder (@@ subject))
+ (r.while (|> (|> (@@ remainder) (nat//< (@@ parameter)))
+ (r.or (|> (@@ remainder) (int//= (@@ parameter)))))
+ (let [rough-estimate (r.apply (list (|> (int//to-float (@@ parameter)) (r./ (int//to-float (@@ remainder)))))
+ (r.global "floor"))
+ calculate-approximate-result (int//from-float (@@ approximate))
+ calculate-approximate-remainder (int//* (@@ parameter) (@@ approximate-result))
+ delta (r.if (|> (r.float 48.0) (r.<= (@@ log2)))
+ (r.float 1.0)
+ (r.** (|> (r.float 48.0) (r.- (@@ log2)))
+ (r.float 2.0)))
+ update-approximates! ($_ r.then
+ (r.set! approximate-result calculate-approximate-result)
+ (r.set! approximate-remainder calculate-approximate-remainder))]
+ ($_ r.then
+ (r.set! approximate (r.apply (list (r.float 1.0) rough-estimate)
+ (r.global "max")))
+ (r.set! log2 (let [log (function (_ input)
+ (r.apply (list input) (r.global "log")))]
+ (r.apply (list (|> (log (r.int 2))
+ (r./ (log (@@ approximate)))))
+ (r.global "ceil"))))
+ update-approximates!
+ (r.while (|> (negative? (@@ approximate-remainder))
+ (r.or (|> (@@ approximate-remainder) (int//< (@@ remainder)))))
+ ($_ r.then
+ (r.set! approximate (|> delta (r.- (@@ approximate))))
+ update-approximates!))
+ ($_ r.then
+ (r.set! result (|> (@@ result)
+ (int//+ (r.if (|> (@@ approximate-result) (int//= int//zero))
+ int//one
+ (@@ approximate-result)))))
+ (r.set! remainder (|> (@@ remainder) (int//- (@@ approximate-remainder))))))))
+ (@@ result)))
+ )))
(runtime: (nat//% param subject)
(let [flat (|> (@@ subject)
(nat/// (@@ param))
(int//* (@@ param)))]
- (r.do! (|> (@@ subject) (int//- flat)))))
+ (|> (@@ subject) (int//- flat))))
(def: runtime//nat
Runtime
- ($_ r.then!
+ ($_ r.then
@@nat//<
@@nat///
@@nat//%))
(runtime: (deg//* param subject)
(with-vars [sL sH pL pH bottom middle top]
- ($_ r.then!
+ ($_ r.then
(r.set! sL (int//from-float (int64-low (@@ subject))))
(r.set! sH (int//from-float (int64-high (@@ subject))))
(r.set! pL (int//from-float (int64-low (@@ param))))
@@ -717,57 +714,57 @@
middle (r.+ (r.* (@@ pL) (@@ sH))
(r.* (@@ pH) (@@ sL)))
top (r.* (@@ pH) (@@ sH))]
- (r.do! (|> bottom
- (r.+ middle)
- (bit//shift-right (r.int 32))
- (r.+ top)))))))
+ (|> bottom
+ (r.+ middle)
+ (bit//shift-right (r.int 32))
+ (r.+ top))))))
(runtime: (deg//leading-zeroes input)
(with-vars [zeroes remaining]
- ($_ r.then!
+ ($_ r.then
(r.set! zeroes (r.int 64))
(r.set! remaining (@@ input))
- (r.while! (|> (@@ remaining) (int//= int//zero) r.not)
- ($_ r.then!
- (r.set! zeroes (|> (@@ zeroes) (r.- (r.int 1))))
- (r.set! remaining (|> (@@ remaining) (bit//shift-right (r.int 1))))))
- (r.do! (@@ zeroes)))))
+ (r.while (|> (@@ remaining) (int//= int//zero) r.not)
+ ($_ r.then
+ (r.set! zeroes (|> (@@ zeroes) (r.- (r.int 1))))
+ (r.set! remaining (|> (@@ remaining) (bit//shift-right (r.int 1))))))
+ (@@ zeroes))))
(runtime: (deg/// param subject)
(with-vars [min-shift]
- (r.if! (|> (@@ subject) (int//= (@@ param)))
- (r.do! int//-one)
- ($_ r.then!
- (r.set! min-shift
- (r.apply (list (deg//leading-zeroes (@@ param))
- (deg//leading-zeroes (@@ subject)))
- (r.global "min")))
- (let [subject' (|> (@@ subject) (bit//shift-left (@@ min-shift)))
- param' (|> (@@ param) (bit//shift-left (@@ min-shift)) int64-low int//from-float)]
- (r.do! (|> subject'
- (int/// param')
- (bit//shift-left (r.int 32)))))))))
+ (r.if (|> (@@ subject) (int//= (@@ param)))
+ int//-one
+ ($_ r.then
+ (r.set! min-shift
+ (r.apply (list (deg//leading-zeroes (@@ param))
+ (deg//leading-zeroes (@@ subject)))
+ (r.global "min")))
+ (let [subject' (|> (@@ subject) (bit//shift-left (@@ min-shift)))
+ param' (|> (@@ param) (bit//shift-left (@@ min-shift)) int64-low int//from-float)]
+ (|> subject'
+ (int/// param')
+ (bit//shift-left (r.int 32))))))))
(runtime: (deg//from-frac input)
(with-vars [two32 shifted]
- ($_ r.then!
+ ($_ r.then
(r.set! two32 (|> (r.float 2.0) (r.** (r.float 32.0))))
(r.set! shifted (|> (@@ input) (r.%% (r.float 1.0)) (r.* (@@ two32))))
(let [low (|> (@@ shifted) (r.%% (r.float 1.0)) (r.* (@@ two32)) as-integer)
high (|> (@@ shifted) as-integer)]
- (r.do! (int//new high low))))))
+ (int//new high low)))))
(runtime: (deg//to-frac input)
(with-vars [two32]
- ($_ r.then!
+ ($_ r.then
(r.set! two32 f2^32)
(let [high (|> (int64-high (@@ input)) (r./ (@@ two32)))
low (|> (int64-low (@@ input)) (r./ (@@ two32)) (r./ (@@ two32)))]
- (r.do! (|> low (r.+ high)))))))
+ (|> low (r.+ high))))))
(def: runtime//deg
Runtime
- ($_ r.then!
+ ($_ r.then
@@deg//*
@@deg//leading-zeroes
@@deg///
@@ -776,15 +773,15 @@
(runtime: (frac//decode input)
(with-vars [output]
- ($_ r.then!
+ ($_ r.then
(r.set! output (r.apply (list (@@ input)) (r.global "as.numeric")))
- (r.do! (r.if (|> (@@ output) (r.= r.n/a))
- ..none
- (..some (@@ output)))))))
+ (r.if (|> (@@ output) (r.= r.n/a))
+ ..none
+ (..some (@@ output))))))
(def: runtime//frac
Runtime
- ($_ r.then!
+ ($_ r.then
@@frac//decode))
(def: inc (-> Expression Expression) (|>> (r.+ (r.int 1))))
@@ -810,37 +807,33 @@
(runtime: (text//index subject param start)
(with-vars [idx startF subjectL]
- ($_ r.then!
+ ($_ r.then
(r.set! startF (int//to-float (@@ start)))
(r.set! subjectL (text-length (@@ subject)))
- (r.do!
- (r.if (|> (@@ startF) (within? (@@ subjectL)))
- (r.block
- ($_ r.then!
- (r.set! idx (|> (r.apply-kw (list (@@ param) (r.if (|> (@@ startF) (r.= (r.int 0)))
- (@@ subject)
- (text-clip (inc (@@ startF))
- (inc (@@ subjectL))
- (@@ subject))))
- (list ["fixed" (r.bool true)])
- (r.global "regexpr"))
- (r.nth (r.int 1))))
- (r.do!
- (r.if (|> (@@ idx) (r.= (r.int -1)))
- ..none
- (..some (int//from-float (|> (@@ idx) (r.+ (@@ startF)))))))))
- ..none)))))
+ (r.if (|> (@@ startF) (within? (@@ subjectL)))
+ ($_ r.then
+ (r.set! idx (|> (r.apply-kw (list (@@ param) (r.if (|> (@@ startF) (r.= (r.int 0)))
+ (@@ subject)
+ (text-clip (inc (@@ startF))
+ (inc (@@ subjectL))
+ (@@ subject))))
+ (list ["fixed" (r.bool true)])
+ (r.global "regexpr"))
+ (r.nth (r.int 1))))
+ (r.if (|> (@@ idx) (r.= (r.int -1)))
+ ..none
+ (..some (int//from-float (|> (@@ idx) (r.+ (@@ startF)))))))
+ ..none))))
(runtime: (text//clip text from to)
(with-vars [length]
- ($_ r.then!
+ ($_ r.then
(r.set! length (r.length (@@ text)))
- (r.do!
- (r.if ($_ r.and
- (|> (@@ to) (within? (@@ length)))
- (|> (@@ from) (up-to? (@@ to))))
- (..some (text-clip (inc (@@ from)) (inc (@@ to)) (@@ text)))
- ..none)))))
+ (r.if ($_ r.and
+ (|> (@@ to) (within? (@@ length)))
+ (|> (@@ from) (up-to? (@@ to))))
+ (..some (text-clip (inc (@@ from)) (inc (@@ to)) (@@ text)))
+ ..none))))
(def: (char-at idx text)
(-> Expression Expression Expression)
@@ -848,66 +841,66 @@
(r.global "utf8ToInt")))
(runtime: (text//char text idx)
- (r.if! (|> (@@ idx) (within? (r.length (@@ text))))
- ($_ r.then!
- (r.set! idx (inc (@@ idx)))
- (r.do! (..some (int//from-float (char-at (@@ idx) (@@ text))))))
- (r.do! ..none)))
+ (r.if (|> (@@ idx) (within? (r.length (@@ text))))
+ ($_ r.then
+ (r.set! idx (inc (@@ idx)))
+ (..some (int//from-float (char-at (@@ idx) (@@ text)))))
+ ..none))
(runtime: (text//hash input)
(let [bits-32 (r.code "0xFFFFFFFF")]
(with-vars [idx hash]
- ($_ r.then!
+ ($_ r.then
(r.set! hash (r.int 0))
- (r.for-in! idx (r.range (r.int 1) (text-length (@@ input)))
- (r.set! hash (|> (@@ hash)
- (r.bit-shl (r.int 5))
- (r.- (@@ hash))
- (r.+ (char-at (@@ idx) (@@ input)))
- (r.bit-and bits-32))))
- (r.do! (int//from-float (@@ hash)))))))
+ (r.for-in idx (r.range (r.int 1) (text-length (@@ input)))
+ (r.set! hash (|> (@@ hash)
+ (r.bit-shl (r.int 5))
+ (r.- (@@ hash))
+ (r.+ (char-at (@@ idx) (@@ input)))
+ (r.bit-and bits-32))))
+ (int//from-float (@@ hash))))))
(def: runtime//text
Runtime
- ($_ r.then!
+ ($_ r.then
@@text//index
@@text//clip
@@text//char
@@text//hash))
-(def: (check-index-out-of-bounds array idx body!)
- (-> Expression Expression Statement Statement)
- (r.if! (|> idx (r.<= (r.length array)))
- body!
- (r.stop! (r.string "Array index out of bounds!"))))
+(def: (check-index-out-of-bounds array idx body)
+ (-> Expression Expression Expression Expression)
+ (r.if (|> idx (r.<= (r.length array)))
+ body
+ (r.stop (r.string "Array index out of bounds!"))))
(runtime: (array//new size)
(with-vars [output]
- ($_ r.then!
+ ($_ r.then
(r.set! output (r.list (list)))
(r.set-nth! (|> (@@ size) (r.+ (r.int 1)))
r.null
output)
- (r.do! (@@ output)))))
+ (@@ output))))
(runtime: (array//get array idx)
(with-vars [temp]
(<| (check-index-out-of-bounds (@@ array) (@@ idx))
- ($_ r.then!
+ ($_ r.then
(r.set! temp (|> (@@ array) (r.nth (@@ idx))))
- (r.if! (|> (@@ temp) (r.= r.null))
- (r.do! ..none)
- (r.do! (..some (@@ temp))))))))
+ (r.if (|> (@@ temp) (r.= r.null))
+ ..none
+ (..some (@@ temp)))))))
(runtime: (array//put array idx value)
(<| (check-index-out-of-bounds (@@ array) (@@ idx))
- ($_ r.then!
+ ($_ r.then
(r.set-nth! (@@ idx) (@@ value) array)
- (r.do! (@@ array)))))
+ (@@ array))))
(def: runtime//array
Runtime
- ($_ r.then!
+ ($_ r.then
@@array//new
@@array//get
@@array//put))
@@ -916,27 +909,25 @@
(runtime: (atom//compare-and-swap atom old new)
(let [atom//field (r.string atom//field)]
- (r.do!
- (r.if (|> (@@ atom) (r.nth atom//field) (r.= (@@ old)))
- (r.block
- ($_ r.then!
- (r.set-nth! atom//field (@@ new) atom)
- (r.do! (r.bool true))))
- (r.bool false)))))
+ (r.if (|> (@@ atom) (r.nth atom//field) (r.= (@@ old)))
+ ($_ r.then
+ (r.set-nth! atom//field (@@ new) atom)
+ (r.bool true))
+ (r.bool false))))
(def: runtime//atom
Runtime
- ($_ r.then!
+ ($_ r.then
@@atom//compare-and-swap))
(runtime: (box//write value box)
- ($_ r.then!
+ ($_ r.then
(r.set-nth! (r.int 1) (@@ value) box)
- (r.do! ..unit)))
+ ..unit))
(def: runtime//box
Runtime
- ($_ r.then!
+ ($_ r.then
@@box//write))
(def: process//incoming
@@ -944,51 +935,51 @@
(r.var (lang.normalize-name "process//incoming")))
(def: (list-append! value rlist)
- (-> Expression SVar Statement)
+ (-> Expression SVar Expression)
(r.set-nth! (r.length (@@ rlist)) value rlist))
(runtime: (process//loop _)
(let [empty (r.list (list))]
(with-vars [queue process]
- (let [migrate-incoming! ($_ r.then!
+ (let [migrate-incoming! ($_ r.then
(r.set! queue empty)
- (<| (r.for-in! process (@@ process//incoming))
+ (<| (r.for-in process (@@ process//incoming))
(list-append! (@@ process) queue))
(r.set! process//incoming empty))
- consume-queue! (<| (r.for-in! process (@@ queue))
- (r.do! (r.apply (list ..unit) (@@ process))))]
- ($_ r.then!
+ consume-queue! (<| (r.for-in process (@@ queue))
+ (r.apply (list ..unit) (@@ process)))]
+ ($_ r.then
migrate-incoming!
consume-queue!
- (r.when! (|> (r.length (@@ queue)) (r.> (r.int 0)))
- (r.do! (process//loop ..unit))))))))
+ (r.when (|> (r.length (@@ queue)) (r.> (r.int 0)))
+ (process//loop ..unit)))))))
(runtime: (process//future procedure)
- ($_ r.then!
+ ($_ r.then
(list-append! (@@ procedure) process//incoming)
- (r.do! ..unit)))
+ ..unit))
(runtime: (process//schedule milli-seconds procedure)
(let [to-seconds (|>> (r./ (r.float 1_000.0)))
to-millis (|>> (r.* (r.float 1_000.0)))]
(with-vars [start now seconds _arg elapsed-time]
- ($_ r.then!
+ ($_ r.then
(r.set! start current-time-float)
(r.set! seconds (to-seconds (@@ milli-seconds)))
(list-append! (r.function (list _arg)
- ($_ r.then!
+ ($_ r.then
(r.set! now current-time-float)
(r.set! elapsed-time (|> (@@ now) (r.- (@@ start))))
- (r.if! (|> (@@ elapsed-time) (r.>= (@@ seconds)))
- (r.do! (@@ procedure))
- (r.do! (process//schedule (to-millis (@@ elapsed-time))
- (@@ procedure))))))
+ (r.if (|> (@@ elapsed-time) (r.>= (@@ seconds)))
+ (@@ procedure)
+ (process//schedule (to-millis (@@ elapsed-time))
+ (@@ procedure)))))
process//incoming)
- (r.do! ..unit)))))
+ ..unit))))
(def: runtime//process
Runtime
- ($_ r.then!
+ ($_ r.then
(r.set! process//incoming (r.list (list)))
@@process//loop
@@process//future
@@ -997,7 +988,7 @@
(def: runtime
Runtime
- ($_ r.then!
+ ($_ r.then
runtime//int
runtime//lux
runtime//adt