aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
authorEduardo Julian2018-12-15 19:34:57 -0400
committerEduardo Julian2018-12-15 19:34:57 -0400
commit00b9d6913fd39266208c7c8b61250967bb0f6636 (patch)
tree265b437be71727964190d1b546b1ea8a45ffeb00 /stdlib/source
parentde728c05f0c7fbc47b0d0d9db02d141d734eb755 (diff)
Changed the "instance?" macro in "lux/host.jvm.lux" into the "check" macro.
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux/host.jvm.lux41
1 files changed, 25 insertions, 16 deletions
diff --git a/stdlib/source/lux/host.jvm.lux b/stdlib/source/lux/host.jvm.lux
index 969935dc3..59996d9a2 100644
--- a/stdlib/source/lux/host.jvm.lux
+++ b/stdlib/source/lux/host.jvm.lux
@@ -1446,24 +1446,33 @@
(with-gensyms [g!_]
(wrap (list (`' ("lux try" (.function ((~ g!_) (~ g!_)) (~ expr))))))))
-(syntax: #export (instance? {#let [imports (class-imports *compiler*)]}
- {class (generic-type^ imports (list))}
- {obj (p.maybe s.any)})
+(syntax: #export (check {#let [imports (class-imports *compiler*)]}
+ {class (generic-type^ imports (list))}
+ {unchecked (p.maybe s.any)})
{#.doc (doc "Checks whether an object is an instance of a particular class."
"Caveat emptor: Cannot check for polymorphism, so avoid using parameterized classes."
- (instance? String "YOLO"))}
- (case obj
- (#.Some obj)
- (wrap (list (` ((~ (code.text (format "jvm instanceof" ":" (simple-class$ (list) class)))) (~ obj)))))
-
- #.None
- (do @
- [g!_ (macro.gensym "_")
- g!obj (macro.gensym "obj")]
- (wrap (list (` (: (-> (primitive "java.lang.Object") Bit)
- (function ((~ g!_) (~ g!obj))
- ((~ (code.text (format "jvm instanceof" ":" (simple-class$ (list) class)))) (~ g!obj))))))))
- ))
+ (case (check String "YOLO")
+ (#.Some value-as-string)
+ #.None))}
+ (with-gensyms [g!_ g!unchecked]
+ (let [class-name (simple-class$ (list) class)
+ class-type (` (.primitive (~ (code.text class-name))))
+ check-type (` (.Maybe (~ class-type)))
+ check-code (` (if ((~ (code.text (format "jvm instanceof" ":" class-name))) (~ g!unchecked))
+ (#.Some (.:coerce (~ class-type)
+ (~ g!unchecked)))
+ #.None))]
+ (case unchecked
+ (#.Some unchecked)
+ (wrap (list (` (: (~ check-type)
+ (let [(~ g!unchecked) (~ unchecked)]
+ (~ check-code))))))
+
+ #.None
+ (wrap (list (` (: (-> (primitive "java.lang.Object") (~ check-type))
+ (function ((~ g!_) (~ g!unchecked))
+ (~ check-code))))))
+ ))))
(syntax: #export (synchronized lock body)
{#.doc (doc "Evaluates body, while holding a lock on a given object."