aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux
diff options
context:
space:
mode:
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.lux40
1 files changed, 28 insertions, 12 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 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 [(~' @)]
<js-definition>)))))
-(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 ";"