diff options
author | Eduardo Julian | 2018-05-06 23:27:12 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-05-06 23:27:12 -0400 |
commit | fb72b937aba7886ce204379e97aa06c327a4029f (patch) | |
tree | 20bc243f1605c5b6c37b833b8046b82eac805494 /new-luxc/source/luxc/lang/translation/r | |
parent | 0b53bcc87ad3563daedaa64306d0bbe6df01ca49 (diff) |
- Implemented Nat functionality in pure Lux.
Diffstat (limited to '')
4 files changed, 7 insertions, 190 deletions
diff --git a/new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux index a9e661130..9554abc86 100644 --- a/new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/r/procedure/common.jvm.lux @@ -229,9 +229,6 @@ Nullary <expression>)] - [nat//min runtimeT.int//zero] - [nat//max runtimeT.int//-one] - [int//min runtimeT.int//min] [int//max runtimeT.int//max] @@ -260,12 +257,6 @@ [int//div runtimeT.int///] [int//rem runtimeT.int//%] - [nat//add runtimeT.int//+] - [nat//sub runtimeT.int//-] - [nat//mul runtimeT.int//*] - [nat//div runtimeT.nat///] - [nat//rem runtimeT.nat//%] - [deg//add runtimeT.int//+] [deg//sub runtimeT.int//-] [deg//rem runtimeT.int//-] @@ -297,14 +288,11 @@ Binary (<cmp> paramO subjectO))] - [nat//= runtimeT.int//=] - [nat//< runtimeT.nat//<] - [int//= runtimeT.int//=] [int//< runtimeT.int//<] [deg//= runtimeT.int//=] - [deg//< runtimeT.nat//<] + [deg//< runtimeT.int//<] ) (def: (apply1 func) @@ -312,23 +300,7 @@ (function (_ value) (r.apply (list value) func))) -(def: nat//char (|>> runtimeT.int64-low (apply1 (r.global "intToUtf8")))) - -(def: nat-procs - Bundle - (<| (prefix "nat") - (|> (dict.new text.Hash<Text>) - (install "+" (binary nat//add)) - (install "-" (binary nat//sub)) - (install "*" (binary nat//mul)) - (install "/" (binary nat//div)) - (install "%" (binary nat//rem)) - (install "=" (binary nat//=)) - (install "<" (binary nat//<)) - (install "min" (nullary nat//min)) - (install "max" (nullary nat//max)) - (install "to-int" (unary id)) - (install "char" (unary nat//char))))) +(def: int//char (|>> runtimeT.int64-low (apply1 (r.global "intToUtf8")))) (def: int-procs Bundle @@ -343,8 +315,8 @@ (install "<" (binary int//<)) (install "min" (nullary int//min)) (install "max" (nullary int//max)) - (install "to-nat" (unary id)) - (install "to-frac" (unary runtimeT.int//to-float))))) + (install "to-frac" (unary runtimeT.int//to-float)) + (install "char" (unary int//char))))) (def: deg-procs Bundle @@ -544,7 +516,6 @@ (<| (prefix "lux") (|> lux-procs (dict.merge bit-procs) - (dict.merge nat-procs) (dict.merge int-procs) (dict.merge deg-procs) (dict.merge frac-procs) 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 88b40bcca..70a9f62df 100644 --- a/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/r/runtime.jvm.lux @@ -664,83 +664,6 @@ @@bit//logical-right-shift )) -(runtime: (nat//< param subject) - (with-vars [pH sH] - ($_ 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))))] - (|> 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!"))] - short-circuit-check [(|> (@@ subject) (nat//< (@@ parameter))) - int//zero]] - (r.cond (list valid-division-check - short-circuit-check - - [(|> (@@ parameter) - (nat//< (|> (@@ subject) (bit//logical-right-shift (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)))] - (|> (@@ subject) (int//- flat)))) - -(def: runtime//nat - Runtime - ($_ r.then - @@nat//< - @@nat/// - @@nat//%)) - (runtime: (deg//* param subject) (with-vars [sL sH pL pH bottom middle top] ($_ r.then @@ -1035,7 +958,6 @@ runtime//bit runtime//int runtime//adt - runtime//nat runtime//deg runtime//frac runtime//text diff --git a/new-luxc/source/luxc/lang/translation/ruby/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/ruby/procedure/common.jvm.lux index a13dae50b..e38dfff28 100644 --- a/new-luxc/source/luxc/lang/translation/ruby/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/ruby/procedure/common.jvm.lux @@ -233,9 +233,6 @@ Nullary (<encode> <const>))] - [nat//min 0 ruby.int] - [nat//max -1 ruby.int] - [frac//smallest Double::MIN_VALUE ruby.float] [frac//min (f/* -1.0 Double::MAX_VALUE) ruby.float] [frac//max Double::MAX_VALUE ruby.float] @@ -282,12 +279,6 @@ [int//div ruby./] [int//rem ruby.%] - [nat//add ruby.+] - [nat//sub ruby.-] - [nat//mul ruby.*] - [nat//div runtimeT.nat///] - [nat//rem runtimeT.nat//%] - [deg//add ruby.+] [deg//sub ruby.-] [deg//mul runtimeT.deg//*] @@ -319,21 +310,10 @@ Binary (<cmp> paramO subjectO))] - [nat//= ruby.=] - [nat//< runtimeT.nat//<] [int//= ruby.=] [int//< ruby.<] [deg//= ruby.=] - [deg//< runtimeT.nat//<]) - -(do-template [<name>] - [(def: (<name> inputO) - Unary - inputO)] - - [nat//to-int] - [int//to-nat] - ) + [deg//< ruby.<]) (def: frac//encode Unary @@ -370,26 +350,6 @@ [frac//to-deg runtimeT.deg//from-frac] ) -(def: nat//char - Unary - (ruby.send "chr" (list))) - -(def: nat-procs - Bundle - (<| (prefix "nat") - (|> (dict.new text.Hash<Text>) - (install "+" (binary nat//add)) - (install "-" (binary nat//sub)) - (install "*" (binary nat//mul)) - (install "/" (binary nat//div)) - (install "%" (binary nat//rem)) - (install "=" (binary nat//=)) - (install "<" (binary nat//<)) - (install "min" (nullary nat//min)) - (install "max" (nullary nat//max)) - (install "to-int" (unary nat//to-int)) - (install "char" (unary nat//char))))) - (def: int-procs Bundle (<| (prefix "int") @@ -403,8 +363,8 @@ (install "<" (binary int//<)) (install "min" (nullary int//min)) (install "max" (nullary int//max)) - (install "to-nat" (unary int//to-nat)) - (install "to-frac" (unary int//to-frac))))) + (install "to-frac" (unary int//to-frac)) + (install "char" (unary (ruby.send "chr" (list))))))) (def: deg-procs Bundle @@ -647,7 +607,6 @@ (<| (prefix "lux") (|> lux-procs (dict.merge bit-procs) - (dict.merge nat-procs) (dict.merge int-procs) (dict.merge deg-procs) (dict.merge frac-procs) diff --git a/new-luxc/source/luxc/lang/translation/ruby/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/ruby/runtime.jvm.lux index c3f2981e1..7f66b0cd5 100644 --- a/new-luxc/source/luxc/lang/translation/ruby/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/ruby/runtime.jvm.lux @@ -181,40 +181,6 @@ (def: high (-> Expression Expression) (bit//logical-right-shift (ruby.int 32))) (def: low (-> Expression Expression) (ruby.bit-and "0xFFFFFFFF")) -(runtime: (nat//< param subject) - (ruby.block! (list (ruby.set! (list "ph") (high param)) - (ruby.set! (list "sh") (high subject)) - (ruby.return! (ruby.or (ruby.< "ph" "sh") - (ruby.and (ruby.= "ph" "sh") - (ruby.< (low param) (low subject)))))))) - -(runtime: (nat/// param subject) - (ruby.if! (ruby.< (ruby.int 0) param) - (ruby.if! (nat//< param subject) - (ruby.return! (ruby.int 0)) - (ruby.return! (ruby.int 1))) - (ruby.block! (list (ruby.set! (list "quotient") (|> subject - (ruby.bit-shr (ruby.int 1)) - (ruby./ param) - (ruby.bit-shl (ruby.int 1)))) - (ruby.set! (list "remainder") (ruby.- (ruby.* param "quotient") - subject)) - (ruby.if! (ruby.not (nat//< param "remainder")) - (ruby.return! (ruby.+ (ruby.int 1) "quotient")) - (ruby.return! "quotient")))))) - -(runtime: (nat//% param subject) - (let [flat (|> subject - (nat/// param) - (ruby.* param))] - (ruby.return! (ruby.- flat subject)))) - -(def: runtime//nat - Runtime - (format @@nat//< - @@nat/// - @@nat//%)) - (runtime: (deg//* param subject) (ruby.block! (list (ruby.set! (list "sL") (low subject)) (ruby.set! (list "sH") (high subject)) @@ -366,7 +332,6 @@ (format runtime//lux "\n" runtime//adt "\n" runtime//bit "\n" - runtime//nat "\n" runtime//deg "\n" runtime//text "\n" runtime//array "\n" |