aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool/compiler/phase/translation/js/runtime.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/tool/compiler/phase/translation/js/runtime.lux48
1 files changed, 39 insertions, 9 deletions
diff --git a/stdlib/source/lux/tool/compiler/phase/translation/js/runtime.lux b/stdlib/source/lux/tool/compiler/phase/translation/js/runtime.lux
index c8e86dcb5..a7b8a5a05 100644
--- a/stdlib/source/lux/tool/compiler/phase/translation/js/runtime.lux
+++ b/stdlib/source/lux/tool/compiler/phase/translation/js/runtime.lux
@@ -149,8 +149,7 @@
(runtime: (lux//program-args)
(with-vars [process output idx]
- (_.if (_.and (_.not (_.= (_.type-of process)
- _.undefined))
+ (_.if (_.and (|> process _.type-of (_.= _.undefined) _.not)
(|> process (_.the "argv")))
($_ _.then
(_.define output ..none)
@@ -671,9 +670,11 @@
(runtime: (js//get object field)
(with-vars [temp]
- (_.if (|> temp (_.= _.undefined) _.not)
- (_.return (..some temp))
- (_.return ..none))))
+ ($_ _.then
+ (_.define temp (_.at field object))
+ (_.if (_.= _.undefined temp)
+ (_.return ..none)
+ (_.return (..some temp))))))
(runtime: (js//set object field input)
($_ _.then
@@ -685,18 +686,46 @@
(_.delete (_.at field object))
(_.return object)))
-(runtime: (js//call object method inputs)
- (_.return (_.apply/2 (_.at method object) object inputs)))
-
(def: runtime//js
Statement
($_ _.then
@js//get
@js//set
@js//delete
- @js//call
))
+(runtime: (array//read idx array)
+ (let [fail! (_.return ..none)]
+ (_.if (_.< (_.the "length" array) idx)
+ (with-vars [temp]
+ ($_ _.then
+ (_.define temp (_.at idx array))
+ (_.if (_.= _.undefined temp)
+ fail!
+ (_.return (..some temp)))))
+ fail!)))
+
+(runtime: (array//write idx value array)
+ (_.if (_.< (_.the "length" array) idx)
+ ($_ _.then
+ (_.set (_.at idx array) value)
+ (_.return (..some array)))
+ (_.return ..none)))
+
+(runtime: (array//delete idx array)
+ (_.if (_.< (_.the "length" array) idx)
+ ($_ _.then
+ (_.delete (_.at idx array))
+ (_.return (..some array)))
+ (_.return ..none)))
+
+(def: runtime//array
+ Statement
+ ($_ _.then
+ @array//read
+ @array//write
+ @array//delete))
+
(def: runtime
Statement
($_ _.then
@@ -706,6 +735,7 @@
runtime//text
runtime//io
runtime//js
+ runtime//array
))
(def: #export artifact Text (format prefix ".js"))