aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/translation/js
diff options
context:
space:
mode:
authorEduardo Julian2018-02-17 11:40:12 -0400
committerEduardo Julian2018-02-17 11:40:12 -0400
commitd01f75d220539efd7d58ee9534d3ef3a7bbc3cdc (patch)
treeb0b4f7d06b3e57b3ec304a1323feaa1c44f605c9 /new-luxc/source/luxc/lang/translation/js
parent24b5c3a973dbfea7bd3de102c909af5483ade0f7 (diff)
- Added tests for normal JS (non-procedure) behavior.
- Fixed a few bugs.
Diffstat (limited to '')
-rw-r--r--new-luxc/source/luxc/lang/translation/js.lux22
-rw-r--r--new-luxc/source/luxc/lang/translation/js/case.jvm.lux4
-rw-r--r--new-luxc/source/luxc/lang/translation/js/eval.jvm.lux29
-rw-r--r--new-luxc/source/luxc/lang/translation/js/expression.jvm.lux2
-rw-r--r--new-luxc/source/luxc/lang/translation/js/reference.jvm.lux4
-rw-r--r--new-luxc/source/luxc/lang/translation/js/runtime.jvm.lux9
-rw-r--r--new-luxc/source/luxc/lang/translation/js/statement.jvm.lux9
7 files changed, 35 insertions, 44 deletions
diff --git a/new-luxc/source/luxc/lang/translation/js.lux b/new-luxc/source/luxc/lang/translation/js.lux
index 9b1b2b503..680439355 100644
--- a/new-luxc/source/luxc/lang/translation/js.lux
+++ b/new-luxc/source/luxc/lang/translation/js.lux
@@ -35,8 +35,10 @@
(host.import java/lang/Long
(intValue [] Integer))
-(host.import java/lang/AbstractStringBuilder
- (append [String] AbstractStringBuilder))
+(host.import java/lang/CharSequence)
+
+(host.import java/lang/Appendable
+ (append [CharSequence] Appendable))
(host.import java/lang/StringBuilder
(new [])
@@ -80,8 +82,8 @@
(def: #export module-js-name Text "module.js")
-(def: #export (init-module-buffer _)
- (-> Top (Meta Unit))
+(def: #export init-module-buffer
+ (Meta Unit)
(function [compiler]
(#e.Success [(update@ #.host
(|>> (:! Host)
@@ -297,12 +299,6 @@
(:! Object)))
))
-## (def: (wrap-lux-object object)
-## (-> Top JSObject)
-## (if (host.instance? JSObject object)
-## (lux-obj object)
-## obj))
-
(def: #export unit Text "\u0000")
(def: (module-name module)
@@ -319,7 +315,8 @@
(-> JS (Meta Unit))
(do macro.Monad<Meta>
[module-buffer module-buffer
- #let [_ (AbstractStringBuilder::append [code] module-buffer)]]
+ #let [_ (Appendable::append [(:! CharSequence code)]
+ module-buffer)]]
(execute code)))
(def: #export (save-definition name code)
@@ -333,7 +330,8 @@
module-buffer module-buffer
program-buffer program-buffer
#let [module-code (StringBuilder::toString [] module-buffer)
- _ (AbstractStringBuilder::append [(format module-code "\n")] program-buffer)]]
+ _ (Appendable::append [(:! CharSequence (format module-code "\n"))]
+ program-buffer)]]
(wrap (ioC.write target
(format module "/" module-js-name)
(|> module-code
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<Meta>
[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 [<register> <translation> <prefix>]
[(def: #export (<register> register)
(-> Register //.Expression)
- (format <prefix> (%n register)))
+ (format <prefix> (%i (nat-to-int register))))
(def: #export (<translation> 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<Meta>
- [_ (//.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)