diff options
author | Eduardo Julian | 2017-09-05 18:38:50 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-09-05 18:38:50 -0400 |
commit | b3e5ca5f28e4bc54613dbfd6d6df1ef51d724707 (patch) | |
tree | 7db5e4fe21719ea92b45ee65b7c29303e464e130 /stdlib | |
parent | dd505e9d5c528388e80ca5a2cd3d08c8001ed634 (diff) |
- Changed the code examples for JVM interop macros.
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/source/lux/host.jvm.lux | 82 |
1 files changed, 22 insertions, 60 deletions
diff --git a/stdlib/source/lux/host.jvm.lux b/stdlib/source/lux/host.jvm.lux index 42a076b8f..62a3da2a6 100644 --- a/stdlib/source/lux/host.jvm.lux +++ b/stdlib/source/lux/host.jvm.lux @@ -1308,47 +1308,24 @@ [methods (p;some (method-def^ imports class-vars))]) {#;doc (doc "Allows defining JVM classes in Lux code." "For example:" - (class: #final (JvmPromise A) [] + (class: #final (TestClass A) [Runnable] ## Fields - (#private resolved boolean) - (#private datum A) - (#private waitingList (java.util.List lux.Function)) + (#private foo boolean) + (#private bar A) + (#private baz java.lang.Object) ## Methods - (#public [] new [] [] - (exec (:= .resolved false) - (:= .waitingList (ArrayList.new [])) + (#public [] (new [value A]) [] + (exec (:= .foo true) + (:= .bar value) + (:= .baz "") [])) - (#public [] resolve [{value A}] boolean - (let [container (.new! [])] - (synchronized _jvm_this - (if .resolved - false - (exec (:= .datum value) - (:= .resolved true) - (let [sleepers .waitingList - sleepers-count (java.util.List.size [] sleepers)] - (L/map (function [idx] - (let [sleeper (java.util.List.get [(l2i idx)] sleepers)] - (Executor.execute [(runnable (lux.Function.apply [(:! Object value)] sleeper))] - executor))) - (i.range 0 (i.dec (i2l sleepers-count))))) - (:= .waitingList (null)) - true))))) - (#public [] poll [] A - .datum) - (#public [] wasResolved [] boolean - (synchronized _jvm_this - .resolved)) - (#public [] waitOn [{callback lux.Function}] void - (synchronized _jvm_this - (exec (if .resolved - (lux.Function.apply [(:! Object .datum)] callback) - (:! Object (java.util.List.add [callback] .waitingList))) - []))) - (#public #static [A] make [{value A}] (lux.concurrency.promise.JvmPromise A) - (let [container (.new! [])] - (exec (.resolve! (:! (host lux.concurrency.promise.JvmPromise [Unit]) container) [(:! Unit value)]) - container)))) + (#public (virtual) java.lang.Object + "") + (#public #static (static) java.lang.Object + "") + (Runnable [] (run) void + []) + ) "The vector corresponds to parent interfaces." "An optional super-class can be specified before the vector. If not specified, java.lang.Object will be assumed." @@ -1410,11 +1387,11 @@ "The 1st vector corresponds to parent interfaces." "The 2nd vector corresponds to arguments to the super class constructor." "An optional super-class can be specified before the 1st vector. If not specified, java.lang.Object will be assumed." - (object [java.lang.Runnable] + (object [Runnable] [] - (java.lang.Runnable (run) void - (exec (do-something some-input) - []))) + (Runnable [] (run) void + (exec (do-something some-value) + []))) )} (let [def-code (format "anon-class:" (spaced (list (super-class-decl$ super) @@ -1506,24 +1483,9 @@ (syntax: #export (do-to obj [methods (p;some partial-call^)]) {#;doc (doc "Call a variety of methods on an object; then return the object." - (do-to vreq - (HttpServerRequest.setExpectMultipart [true]) - (ReadStream.handler [(object [(Handler Buffer)] - [] - ((Handler A) (handle [buffer A]) void - (io;run (do Monad<IO> - [_ (write (Buffer.getBytes [] buffer) body)] - (wrap [])))) - )]) - (ReadStream.endHandler [[(object [(Handler Void)] - [] - ((Handler A) (handle [_ A]) void - (exec (do Monad<Promise> - [#let [_ (io;run (close body))] - response (handler (request$ vreq body))] - (respond! response vreq)) - [])) - )]])))} + (do-to object + (ClassName.method1 [arg0 arg1 arg2]) + (ClassName.method2 [arg3 arg4 arg5])))} (with-gensyms [g!obj] (wrap (list (` (let [(~ g!obj) (~ obj)] (exec (~@ (L/map (complete-call$ g!obj) methods)) |