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/js/runtime.jvm.lux | |
parent | 0b53bcc87ad3563daedaa64306d0bbe6df01ca49 (diff) |
- Implemented Nat functionality in pure Lux.
Diffstat (limited to 'new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux')
-rw-r--r-- | new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux b/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux index afb3cd538..5fab92941 100644 --- a/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux @@ -584,99 +584,6 @@ __int/// __int//%)) -(runtime: nat//< "ltN64" - (let [high (function (_ i64) (format "(" i64 "." //.int-high-field ")")) - low (function (_ i64) (format "(" i64 "." //.int-low-field ")")) - i32 (function (_ word) (format "(" word " >>> 0)"))] - (js.function @ (list "subject" "parameter") - (list (js.return! (js.or (js.> (i32 (high "subject")) - (i32 (high "parameter"))) - (js.and (js.= (high "subject") - (high "parameter")) - (js.> (i32 (low "subject")) - (i32 (low "parameter")))))))))) - -(def: (<N param subject) - (-> Expression Expression Expression) - (js.apply nat//< (list subject param))) - -(def: (<=N param subject) - (-> Expression Expression Expression) - (js.or (js.apply nat//< (list subject param)) - (js.apply int//= (list subject param)))) - -(def: (>N param subject) - (-> Expression Expression Expression) - (js.apply nat//< (list param subject))) - -(def: (>=N param subject) - (-> Expression Expression Expression) - (js.or (js.apply nat//< (list param subject)) - (js.apply int//= (list subject param)))) - -(runtime: nat/// "divN64" - (let [negative? (function (_ value) - (js.apply int//< (list value int//zero))) - valid-division-check [(=I int//zero "parameter") - (js.throw! (js.string "Cannot divide by zero!"))] - short-circuit-check [(=I int//zero "subject") - (js.return! int//zero)]] - (js.function @ (list "subject" "parameter") - (list (js.cond! (list valid-division-check - short-circuit-check - - [(>N "subject" "parameter") - (js.return! int//zero)] - - [(>N (js.apply bit//logical-right-shift - (list "subject" (js.number 1.0))) - "parameter") - (js.return! int//one)]) - (js.block! (list (js.var! "result" (#.Some int//zero)) - (js.var! "remainder" (#.Some "subject")) - (js.while! (>=N "parameter" "remainder") - (let [rough-estimate (js.apply "Math.floor" (list (js./ (js.apply int//to-number (list "parameter")) - (js.apply int//to-number (list "remainder"))))) - log2 (js./ "Math.LN2" - (js.apply "Math.log" (list "approximate"))) - approx-result (js.apply int//from-number (list "approximate")) - approx-remainder (js.apply int//* (list "approximate_result" "parameter"))] - (list (js.var! "approximate" (#.Some (js.apply "Math.max" (list (js.number 1.0) - rough-estimate)))) - (js.var! "log2" (#.Some (js.apply "Math.ceil" (list log2)))) - (js.var! "delta" (#.Some (js.? (js.<= (js.number 48.0) "log2") - (js.number 1.0) - (js.apply "Math.pow" (list (js.number 2.0) - (js.- (js.number 48.0) - "log2")))))) - (js.var! "approximate_result" (#.Some approx-result)) - (js.var! "approximate_remainder" (#.Some approx-remainder)) - (js.while! (js.or (negative? "approximate_remainder") - (>N "remainder" - "approximate_remainder")) - (list (js.set! "approximate" (js.- "delta" "approximate")) - (js.set! "approximate_result" approx-result) - (js.set! "approximate_remainder" approx-remainder))) - (js.block! (list (js.set! "result" (js.apply int//+ (list "result" - (js.? (=I int//zero "approximate_result") - int//one - "approximate_result")))) - (js.set! "remainder" (js.apply int//- (list "remainder" "approximate_remainder")))))))) - (js.return! "result"))) - ))))) - -(runtime: nat//% "remN64" - (js.function @ (list "subject" "parameter") - (list (let [flat (js.apply int//* (list (js.apply nat/// (list "subject" "parameter")) - "parameter"))] - (js.return! (js.apply int//- (list "subject" flat))))))) - -(def: runtime//nat - Runtime - (format __nat//< - __nat/// - __nat//%)) - (runtime: deg//* "mulD64" (format "(function " @ "(l,r) {" "var lL = " int//from-number "(l.L);" @@ -900,7 +807,6 @@ runtime//adt runtime//bit runtime//int - runtime//nat runtime//deg runtime//text runtime//array |