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/case.jvm.lux | 4 +--
.../source/luxc/lang/translation/js/eval.jvm.lux | 29 ++++++++--------------
.../luxc/lang/translation/js/expression.jvm.lux | 2 +-
.../luxc/lang/translation/js/reference.jvm.lux | 4 +--
.../luxc/lang/translation/js/runtime.jvm.lux | 9 ++++---
.../luxc/lang/translation/js/statement.jvm.lux | 9 +++----
6 files changed, 25 insertions(+), 32 deletions(-)
(limited to 'new-luxc/source/luxc/lang/translation/js')
diff --git a/new-luxc/source/luxc/lang/translation/js/case.jvm.lux b/new-luxc/source/luxc/lang/translation/js/case.jvm.lux
index 626181984..cbb0e6c77 100644
--- a/new-luxc/source/luxc/lang/translation/js/case.jvm.lux
+++ b/new-luxc/source/luxc/lang/translation/js/case.jvm.lux
@@ -12,8 +12,8 @@
[".T" primitive]
[".T" reference]))
-(def: #export (translate-let translate valueS register bodyS)
- (-> (-> ls.Synthesis (Meta //.Expression)) ls.Synthesis Nat ls.Synthesis
+(def: #export (translate-let translate register valueS bodyS)
+ (-> (-> ls.Synthesis (Meta //.Expression)) Nat ls.Synthesis ls.Synthesis
(Meta //.Expression))
(do macro.Monad
[valueJS (translate valueS)
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))
diff --git a/new-luxc/source/luxc/lang/translation/js/expression.jvm.lux b/new-luxc/source/luxc/lang/translation/js/expression.jvm.lux
index 4634497a1..1bde82766 100644
--- a/new-luxc/source/luxc/lang/translation/js/expression.jvm.lux
+++ b/new-luxc/source/luxc/lang/translation/js/expression.jvm.lux
@@ -56,7 +56,7 @@
(referenceT.translate-definition definition)
(^code ("lux let" (~ [_ (#.Nat register)]) (~ inputS) (~ exprS)))
- (caseT.translate-let translate inputS register exprS)
+ (caseT.translate-let translate register inputS exprS)
(^code ("lux case" (~ inputS) (~ pathPS)))
(caseT.translate-case translate inputS pathPS)
diff --git a/new-luxc/source/luxc/lang/translation/js/reference.jvm.lux b/new-luxc/source/luxc/lang/translation/js/reference.jvm.lux
index 66d340949..d9e508193 100644
--- a/new-luxc/source/luxc/lang/translation/js/reference.jvm.lux
+++ b/new-luxc/source/luxc/lang/translation/js/reference.jvm.lux
@@ -11,7 +11,7 @@
(do-template [ ]
[(def: #export ( register)
(-> Register //.Expression)
- (format (%n register)))
+ (format (%i (nat-to-int register))))
(def: #export ( register)
(-> Register (Meta //.Expression))
@@ -23,7 +23,7 @@
(def: #export (translate-variable var)
(-> Variable (Meta //.Expression))
(if (variableL.captured? var)
- (translate-captured (int-to-nat var))
+ (translate-captured (variableL.captured-register var))
(translate-local (int-to-nat var))))
(def: #export global
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 e9653547d..aceac4089 100644
--- a/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux
+++ b/new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux
@@ -1059,9 +1059,9 @@
(def: #export atom-field Text "V")
(runtime: atom//compare-and-swap "atomCompareAndSwap"
- (format "(function " @ "(atom,old,new) {"
- "if(atom." atom-field " === old) {"
- "atom." atom-field " = new;"
+ (format "(function " @ "(atom,oldV,newV) {"
+ "if(atom." atom-field " === oldV) {"
+ "atom." atom-field " = newV;"
"return true;"
"}"
"else {"
@@ -1127,5 +1127,6 @@
(def: #export translate
(Meta (Process Unit))
(do macro.Monad
- [_ (//.save-js runtime)]
+ [_ //.init-module-buffer
+ _ (//.save-js runtime)]
(//.save-module! artifact)))
diff --git a/new-luxc/source/luxc/lang/translation/js/statement.jvm.lux b/new-luxc/source/luxc/lang/translation/js/statement.jvm.lux
index e430d22ae..a2c0c6510 100644
--- a/new-luxc/source/luxc/lang/translation/js/statement.jvm.lux
+++ b/new-luxc/source/luxc/lang/translation/js/statement.jvm.lux
@@ -6,7 +6,8 @@
(luxc (lang [".L" module]))
[//]
(// [".T" runtime]
- [".T" reference]))
+ [".T" reference]
+ [".T" eval]))
(def: #export (translate-def name expressionT expressionJS metaV)
(-> Text Type //.Expression Code (Meta Unit))
@@ -22,10 +23,8 @@
_
(do @
- [#let [def-name (referenceT.global def-ident)]
- ## _ (hostT.save (format "var " def-name " = " expressionJS ";"))
- #let [expressionV (: Top [])]
- ## expressionV (hostT.eval def-name)
+ [_ (//.save-definition def-ident expressionJS)
+ expressionV (evalT.eval (referenceT.global def-ident))
_ (moduleL.define def-ident [expressionT metaV expressionV])
_ (if (macro.type? metaV)
(case (macro.declared-tags metaV)
--
cgit v1.2.3