From d01f75d220539efd7d58ee9534d3ef3a7bbc3cdc Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 17 Feb 2018 11:40:12 -0400 Subject: - Added tests for normal JS (non-procedure) behavior. - Fixed a few bugs. --- .../source/luxc/lang/translation/js/eval.jvm.lux | 29 ++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'new-luxc/source/luxc/lang/translation/js/eval.jvm.lux') diff --git a/new-luxc/source/luxc/lang/translation/js/eval.jvm.lux b/new-luxc/source/luxc/lang/translation/js/eval.jvm.lux index bcf70bcae..fada5a70c 100644 --- a/new-luxc/source/luxc/lang/translation/js/eval.jvm.lux +++ b/new-luxc/source/luxc/lang/translation/js/eval.jvm.lux @@ -12,13 +12,14 @@ (host.import java/lang/Object (toString [] String)) -(host.import java/lang/Number - (doubleValue [] double) - (longValue [] Long)) - (host.import java/lang/Integer (longValue [] Long)) +(host.import java/lang/Number + (doubleValue [] double) + (longValue [] Long) + (intValue [] Integer)) + (host.import javax/script/ScriptEngine (eval [String] #try #? Object)) @@ -51,18 +52,14 @@ [[(Number::longValue [] (:! Number high)) (Number::longValue [] (:! Number low))] [high low]]) - (#.Some (nat-to-int (n/+ (|> high (:! Int) int-to-nat (bit.shift-left +32)) - (|> low (:! Int) int-to-nat)))) + (#.Some (nat-to-int (n/+ (|> high (:! Nat) (bit.shift-left +32)) + (if (i/< 0 (:! Int low)) + (|> low (:! Nat) (bit.shift-left +32) (bit.shift-right +32)) + (|> low (:! Nat)))))) _ #.None)) -(def: (extend-array by input) - (All [a] (-> Nat (Array a) (Array a))) - (let [size (array.size input)] - (|> (array.new (n/+ by size)) - (array.copy size +0 input +0)))) - (def: (array element-parser js-object) (-> (-> Object (Error Top)) ScriptObjectMirror (Maybe (Array Object))) (if (JSObject::isArray [] js-object) @@ -77,17 +74,13 @@ (#.Some member) (case (element-parser member) (#e.Success parsed-member) - (recur num-keys - (n/inc idx) - (array.write idx (:! Object parsed-member) output)) + (recur num-keys (n/inc idx) (array.write idx (:! Object parsed-member) output)) (#e.Error error) #.None) #.None - (recur (n/inc num-keys) - (n/inc idx) - (extend-array +1 output)))) + (recur num-keys (n/inc idx) output))) (#.Some output)))) #.None)) -- cgit v1.2.3