aboutsummaryrefslogtreecommitdiff
path: root/lux-js/source
diff options
context:
space:
mode:
authorEduardo Julian2021-07-11 01:51:04 -0400
committerEduardo Julian2021-07-11 01:51:04 -0400
commitabe24425ced15fd784ef6c62d6f186af72b491db (patch)
tree42b6e3cbd179c83fae8941fa4b128b13afc766f5 /lux-js/source
parent4610968193df10af12c91f699fec39aeb3ef703a (diff)
Re-named ":coerce" to ":as" since it technically doesn't do coercions.
Diffstat (limited to 'lux-js/source')
-rw-r--r--lux-js/source/program.lux92
1 files changed, 46 insertions, 46 deletions
diff --git a/lux-js/source/program.lux b/lux-js/source/program.lux
index 43ced94d8..28b18227f 100644
--- a/lux-js/source/program.lux
+++ b/lux-js/source/program.lux
@@ -152,7 +152,7 @@
(def: jvm_int
(-> (I64 Any) java/lang/Integer)
- (|>> (:coerce java/lang/Long) java/lang/Long::intValue))
+ (|>> (:as java/lang/Long) java/lang/Long::intValue))
(def: (js_int value)
(-> Int org/openjdk/nashorn/api/scripting/JSObject)
@@ -161,7 +161,7 @@
## Methods
(program/IntValue
[] (getValue self) java/lang/Object
- (:coerce java/lang/Object value))
+ (:as java/lang/Object value))
(org/openjdk/nashorn/api/scripting/AbstractJSObject
[] (getMember self {member java/lang/String}) java/lang/Object
(case member
@@ -172,7 +172,7 @@
(|> value .nat runtime.low jvm_int)
_
- (error! (exception.construct ..unknown_member [member (:coerce java/lang/Object value)]))))
+ (error! (exception.construct ..unknown_member [member (:as java/lang/Object value)]))))
))
(def: (::toString js_object)
@@ -197,10 +197,10 @@
(org/openjdk/nashorn/api/scripting/AbstractJSObject
[] (call self {this java/lang/Object} {args [java/lang/Object]}) java/lang/Object
(|> (java/util/Arrays::copyOfRange value
- (|> args (array.read 0) maybe.assume (:coerce Int))
+ (|> args (array.read 0) maybe.assume (:as Int))
(.int (array.size value)))
js_object
- (:coerce java/lang/Object)))
+ (:as java/lang/Object)))
))
(def: (js_structure value)
@@ -209,20 +209,20 @@
(function (_ sub_value)
(<| (case (ffi.check [java/lang/Object] sub_value)
(#.Some sub_value)
- (|> sub_value (:coerce (Array java/lang/Object)) js_structure)
+ (|> sub_value (:as (Array java/lang/Object)) js_structure)
#.None)
(case (ffi.check java/lang/Long sub_value)
(#.Some sub_value)
- (|> sub_value (:coerce Int) js_int)
+ (|> sub_value (:as Int) js_int)
#.None)
## else
- (:coerce org/openjdk/nashorn/api/scripting/JSObject sub_value))))]
+ (:as org/openjdk/nashorn/api/scripting/JSObject sub_value))))]
(ffi.object [] org/openjdk/nashorn/api/scripting/AbstractJSObject [program/StructureValue]
[]
## Methods
(program/StructureValue
[] (getValue self) java/lang/Object
- (:coerce (Array java/lang/Object) value))
+ (:as (Array java/lang/Object) value))
(org/openjdk/nashorn/api/scripting/AbstractJSObject
[] (isArray self) boolean
#1)
@@ -230,15 +230,15 @@
[] (getMember self {member java/lang/String}) java/lang/Object
(case member
(^or "toJSON" "toString")
- (:coerce java/lang/Object
- (::toString value))
+ (:as java/lang/Object
+ (::toString value))
"length"
(jvm_int (array.size value))
"slice"
- (:coerce java/lang/Object
- (::slice js_object value))
+ (:as java/lang/Object
+ (::slice js_object value))
(^ (static runtime.variant_tag_field))
(|> value (array.read 0) maybe.assume)
@@ -252,18 +252,18 @@
(ffi.null))
(^ (static runtime.variant_value_field))
- (|> value (array.read 2) maybe.assume js_object (:coerce java/lang/Object))
+ (|> value (array.read 2) maybe.assume js_object (:as java/lang/Object))
_
- (error! (exception.construct ..unknown_member [(:coerce Text member) (:coerce java/lang/Object value)])))
+ (error! (exception.construct ..unknown_member [(:as Text member) (:as java/lang/Object value)])))
)
(org/openjdk/nashorn/api/scripting/AbstractJSObject
[] (getSlot self {idx int}) java/lang/Object
(|> value
- (array.read (|> idx java/lang/Integer::longValue (:coerce Nat)))
+ (array.read (|> idx java/lang/Integer::longValue (:as Nat)))
maybe.assume
js_object
- (:coerce java/lang/Object)))
+ (:as java/lang/Object)))
)))
(exception: undefined_has_no_lux_representation)
@@ -331,7 +331,7 @@
#.None
(case (lux_object member)
(#try.Success parsed_member)
- (recur (inc idx) (array.write! idx (:coerce java/lang/Object parsed_member) output))
+ (recur (inc idx) (array.write! idx (:as java/lang/Object parsed_member) output))
(#try.Failure error)
#.None))
@@ -384,18 +384,18 @@
#.None
(if (org/openjdk/nashorn/api/scripting/JSObject::isFunction js_object)
(exception.return js_object)
- ## (exception.throw ..unknown_kind_of_host_object (:coerce java/lang/Object js_object))
+ ## (exception.throw ..unknown_kind_of_host_object (:as java/lang/Object js_object))
(exception.return js_object)))))
#.None)
## else
- (exception.throw ..unknown_kind_of_host_object (:coerce java/lang/Object js_object))
+ (exception.throw ..unknown_kind_of_host_object (:as java/lang/Object js_object))
)))
(def: (ensure_function function)
(-> Any (Maybe org/openjdk/nashorn/api/scripting/JSObject))
(do maybe.monad
[function (|> function
- (:coerce java/lang/Object)
+ (:as java/lang/Object)
(ffi.check org/openjdk/nashorn/api/scripting/JSObject))]
(if (org/openjdk/nashorn/api/scripting/JSObject::isFunction function)
(#.Some function)
@@ -409,8 +409,8 @@
(as_is (def: (call_macro inputs lux macro)
(-> (List Code) Lux org/openjdk/nashorn/api/scripting/JSObject (Try (Try [Lux (List Code)])))
(let [to_js (: (-> Any java/lang/Object)
- (|>> (:coerce (Array java/lang/Object)) js_structure (:coerce java/lang/Object)))]
- (<| (:coerce (Try (Try [Lux (List Code)])))
+ (|>> (:as (Array java/lang/Object)) js_structure (:as java/lang/Object)))]
+ (<| (:as (Try (Try [Lux (List Code)])))
(org/openjdk/nashorn/api/scripting/JSObject::call #.None
(|> (array.new 2)
(: (Array java/lang/Object))
@@ -429,21 +429,21 @@
(case (call_macro inputs lux macro)
(#try.Success output)
(|> output
- (:coerce java/lang/Object)
+ (:as java/lang/Object)
lux_object
- (:coerce (Try (Try [Lux (List Code)]))))
+ (:as (Try (Try [Lux (List Code)]))))
(#try.Failure error)
(#try.Failure error))
#.None
- (exception.throw ..cannot_apply_a_non_function (:coerce java/lang/Object macro))))
+ (exception.throw ..cannot_apply_a_non_function (:as java/lang/Object macro))))
)
@.js
(def: (expander macro inputs lux)
Expander
- (#try.Success ((:coerce Macro' macro) inputs lux)))
+ (#try.Success ((:as Macro' macro) inputs lux)))
})
(for {@.old
@@ -485,7 +485,7 @@
(def: define! (..define! interpreter))
(def: (ingest context content)
- (|> content (\ utf8.codec decode) try.assume (:coerce _.Statement)))
+ (|> content (\ utf8.codec decode) try.assume (:as _.Statement)))
(def: (re_learn context content)
(..execute! interpreter content))
@@ -543,7 +543,7 @@
(def: define! ..define!)
(def: (ingest context content)
- (|> content (\ utf8.codec decode) try.assume (:coerce _.Statement)))
+ (|> content (\ utf8.codec decode) try.assume (:as _.Statement)))
(def: (re_learn context content)
(..execute! content))
@@ -558,14 +558,14 @@
(-> Archive (runtime.Operation platform.Phase_Wrapper))
(do phase.monad
[]
- (wrap (:coerce platform.Phase_Wrapper
- (for {## The implementation for @.old is technically incorrect.
- ## However, the JS compiler runs fast enough on Node to be fully hosted there.
- ## And running the JS compiler on the JVM (on top of Nashorn) is impractically slow.
- ## This means that in practice, only the @.js implementation matters.
- ## And since no cross-language boundary needs to be handled, it's a correct implementation.
- @.old (|>>)
- @.js (|>>)})))))
+ (wrap (:as platform.Phase_Wrapper
+ (for {## The implementation for @.old is technically incorrect.
+ ## However, the JS compiler runs fast enough on Node to be fully hosted there.
+ ## And running the JS compiler on the JVM (on top of Nashorn) is impractically slow.
+ ## This means that in practice, only the @.js implementation matters.
+ ## And since no cross-language boundary needs to be handled, it's a correct implementation.
+ @.old (|>>)
+ @.js (|>>)})))))
(def: platform
(IO (Platform [Register Text] _.Expression _.Statement))
@@ -594,31 +594,31 @@
(def: (extender phase_wrapper)
(-> platform.Phase_Wrapper Extender)
## TODO: Stop relying on coercions ASAP.
- (<| (:coerce Extender)
+ (<| (:as Extender)
(function (@self handler))
- (:coerce Handler)
+ (:as Handler)
(function (@self name phase))
- (:coerce Phase)
+ (:as Phase)
(function (@self archive parameters))
- (:coerce Operation)
+ (:as Operation)
(function (@self state))
- (:coerce Try)
+ (:as Try)
try.assume
- (:coerce Try)
+ (:as Try)
(do try.monad
[handler (try.from_maybe (..ensure_function handler))
#let [to_js (: (-> Any java/lang/Object)
- (|>> (:coerce (Array java/lang/Object)) js_structure (:coerce java/lang/Object)))]
+ (|>> (:as (Array java/lang/Object)) js_structure (:as java/lang/Object)))]
output (org/openjdk/nashorn/api/scripting/JSObject::call #.None
(|> (array.new 5)
(: (Array java/lang/Object))
(array.write! 0 name)
- (array.write! 1 (:coerce java/lang/Object (extender phase)))
+ (array.write! 1 (:as java/lang/Object (extender phase)))
(array.write! 2 (to_js archive))
(array.write! 3 (to_js parameters))
(array.write! 4 (to_js state)))
handler)]
- (lux_object (:coerce java/lang/Object output)))))
+ (lux_object (:as java/lang/Object output)))))
@.js
(def: (extender phase_wrapper handler)