From 4369bd0ee320d85590efa9c71db591200fb54cd2 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 21 Feb 2018 22:31:08 -0400 Subject: - Fixed the failing simple tests. --- .../lang/translation/js/procedure/common.jvm.lux | 38 ++++++++++++-------- .../luxc/lang/translation/js/runtime.jvm.lux | 40 +++++++++++++++------- 2 files changed, 52 insertions(+), 26 deletions(-) (limited to 'new-luxc/source/luxc/lang') diff --git a/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux b/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux index 849ff67d0..ce79bda35 100644 --- a/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/js/procedure/common.jvm.lux @@ -152,6 +152,14 @@ [bit//and runtimeT.bit//and] [bit//or runtimeT.bit//or] [bit//xor runtimeT.bit//xor] + ) + +(do-template [ ] + [(def: ( [subjectJS paramJS]) + Binary + (let [simple-param (format runtimeT.int//to-number "(" paramJS ")")] + (format "(" subjectJS "," simple-param ")")))] + [bit//shift-left runtimeT.bit//shift-left] [bit//shift-right runtimeT.bit//signed-shift-right] [bit//unsigned-shift-right runtimeT.bit//shift-right] @@ -199,21 +207,21 @@ Nullary ( ))] - [nat//min 0 runtimeT.int-constant] - [nat//max -1 runtimeT.int-constant] + [nat//min 0 runtimeT.int] + [nat//max -1 runtimeT.int] - [int//min Long::MIN_VALUE runtimeT.int-constant] - [int//max Long::MAX_VALUE runtimeT.int-constant] + [int//min Long::MIN_VALUE runtimeT.int] + [int//max Long::MAX_VALUE runtimeT.int] - [frac//smallest Double::MIN_VALUE runtimeT.frac-constant] - [frac//min (f/* -1.0 Double::MAX_VALUE) runtimeT.frac-constant] - [frac//max Double::MAX_VALUE runtimeT.frac-constant] - [frac//not-a-number Double::NaN runtimeT.frac-constant] - [frac//positive-infinity Double::POSITIVE_INFINITY runtimeT.frac-constant] - [frac//negative-infinity Double::NEGATIVE_INFINITY runtimeT.frac-constant] - - [deg//min 0 runtimeT.int-constant] - [deg//max -1 runtimeT.int-constant] + [frac//smallest Double::MIN_VALUE runtimeT.frac] + [frac//min (f/* -1.0 Double::MAX_VALUE) runtimeT.frac] + [frac//max Double::MAX_VALUE runtimeT.frac] + [frac//not-a-number Double::NaN runtimeT.frac] + [frac//positive-infinity Double::POSITIVE_INFINITY runtimeT.frac] + [frac//negative-infinity Double::NEGATIVE_INFINITY runtimeT.frac] + + [deg//min 0 runtimeT.int] + [deg//max -1 runtimeT.int] ) (do-template [ ] @@ -287,7 +295,9 @@ (def: (frac//decode inputJS) Unary - (format "parseFloat(" inputJS ")")) + (let [decoding (format "parseFloat(" inputJS ")") + thunk (format "(function () {" decoding "}")] + (lux//try decoding))) (do-template [ ] [(def: ( inputJS) 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 aceac4089..0ff5e46b9 100644 --- a/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux @@ -59,15 +59,15 @@ (function [(~' @)] ))))) -(def: #export (int-constant value) +(def: #export (int value) (-> Int //.Expression) - (format "{" + (format "({" //.int-high-field " : " (|> value int-to-nat //.high nat-to-int %i) ", " //.int-low-field " : " (|> value int-to-nat //.low nat-to-int %i) - "}")) + "})")) -(def: #export (frac-constant value) +(def: #export (frac value) (-> Frac //.Expression) (%f value)) @@ -180,7 +180,7 @@ (runtime: int//to-number "toNumberI64" (format "(function " @ "(i64) {" - "return (i64.H * " int//2^32 ") + " @ "(i64);" + "return (i64.H * " int//2^32 ") + " int//unsigned-low "(i64);" "})")) (runtime: int//zero "ZERO" @@ -272,13 +272,28 @@ "}") "})")) +(runtime: bit//count32 "countI32" + (let [last-input-bit "input & 1" + update-count! (format "count += " last-input-bit ";") + consume-input! "input = input >>> 1;" + input-remaining? "input !== 0"] + (format "(function " @ "(input) {" + "var count = 0;" + "while(" input-remaining? ") {" + update-count! + consume-input! + "}" + "return count;" + "})"))) + (runtime: bit//count "countI64" - (format "(function " @ "(input) {" - "var hs = (input.H).toString(2);" - "var ls = (input.L).toString(2);" - "var num1s = hs.concat(ls).replace(/0/g,'').length;" - "return " int//from-number "(num1s);" - "})")) + (let [high (format bit//count32 "(input.H)") + low (format bit//count32 "(input.L)") + whole (format "(" high " + " low ")") + cast (format int//from-number "(" whole ")")] + (format "(function " @ "(input) {" + "return " cast ";" + "})"))) (runtime: bit//shift-left "shlI64" (format "(function " @ "(input,shift) {" @@ -347,6 +362,7 @@ __bit//or __bit//xor __bit//not + __bit//count32 __bit//count __bit//shift-left __bit//signed-shift-right @@ -443,7 +459,7 @@ ## Special case: L = MIN "else {" "var halfL = " bit//signed-shift-right "(l,1);" - "var approx = " bit//shift-left "(" @ "(halfL,r)," int//one ");" + "var approx = " bit//shift-left "(" @ "(halfL,r),1);" (format "if((approx.H === 0) && (approx.L === 0)) {" (format "if(r.H < 0) {" "return " int//one ";" -- cgit v1.2.3