aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool/compiler/phase/generation/js/extension/host.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/tool/compiler/phase/generation/js/extension/host.lux60
1 files changed, 51 insertions, 9 deletions
diff --git a/stdlib/source/lux/tool/compiler/phase/generation/js/extension/host.lux b/stdlib/source/lux/tool/compiler/phase/generation/js/extension/host.lux
index 3cf3c6c07..bb3d6138d 100644
--- a/stdlib/source/lux/tool/compiler/phase/generation/js/extension/host.lux
+++ b/stdlib/source/lux/tool/compiler/phase/generation/js/extension/host.lux
@@ -3,6 +3,7 @@
[abstract
["." monad (#+ do)]]
[control
+ ["." function]
["<>" parser
["<s>" synthesis (#+ Parser)]]]
[data
@@ -70,6 +71,55 @@
(bundle.install "delete" (binary array::delete))
)))
+(def: object::new
+ (..custom
+ [($_ <>.and <s>.any (<>.some <s>.any))
+ (function (_ extension phase [constructorS inputsS])
+ (do /////.monad
+ [constructorG (phase constructorS)
+ inputsG (monad.map @ phase inputsS)]
+ (wrap (_.new constructorG inputsG))))]))
+
+(def: object::get
+ Handler
+ (custom
+ [($_ <>.and <s>.text <s>.any)
+ (function (_ extension phase [fieldS objectS])
+ (do /////.monad
+ [objectG (phase objectS)]
+ (wrap (_.the fieldS objectG))))]))
+
+(def: object::do
+ Handler
+ (custom
+ [($_ <>.and <s>.text <s>.any (<>.some <s>.any))
+ (function (_ extension phase [methodS objectS inputsS])
+ (do /////.monad
+ [objectG (phase objectS)
+ inputsG (monad.map @ phase inputsS)]
+ (wrap (_.do methodS inputsG objectG))))]))
+
+(template [<!> <?> <unit>]
+ [(def: <!> (Nullary Expression) (function.constant <unit>))
+ (def: <?> (Unary Expression) (_.= <unit>))]
+
+ [object::null object::null? _.null]
+ [object::undefined object::undefined? _.undefined]
+ )
+
+(def: object
+ Bundle
+ (<| (bundle.prefix "object")
+ (|> bundle.empty
+ (bundle.install "new" object::new)
+ (bundle.install "get" object::get)
+ (bundle.install "do" object::do)
+ (bundle.install "null" (nullary object::null))
+ (bundle.install "null?" (unary object::null?))
+ (bundle.install "undefined" (nullary object::undefined))
+ (bundle.install "undefined?" (unary object::undefined?))
+ )))
+
(def: js::constant
(..custom
[<s>.text
@@ -87,20 +137,12 @@
inputsG (monad.map @ phase inputsS)]
(wrap (_.apply/* abstractionG inputsG))))]))
-(def: js::undefined?
- (..custom
- [<s>.any
- (function (_ extension phase valueS)
- (|> valueS
- phase
- (:: /////.monad map (_.= _.undefined))))]))
-
(def: #export bundle
Bundle
(<| (bundle.prefix "js")
(|> bundle.empty
(bundle.install "constant" js::constant)
(bundle.install "apply" js::apply)
- (bundle.install "undefined?" js::undefined?)
(dictionary.merge ..array)
+ (dictionary.merge ..object)
)))