Skip to content

Clojure support #92

@darkleaf

Description

@darkleaf

H!
I've been trying to use coroutines for Clojure.
I found that your library is promising.
But Clojure's compiler makes slightly different bytecode than Java does.

(defn x []
  (let [my-coroutine (reify Coroutine
                       (run [_ c]
                         (.suspend c)))
        r            (CoroutineRunner. my-coroutine)]
    (doto r
      (.execute))))

The compiler produces this bytecode

  public void run(com.offbynull.coroutines.user.Continuation) throws java.lang.Exception;
    Code:
       0: aload_1
       1: aconst_null
       2: astore_1
       3: checkcast     #30                 // class com/offbynull/coroutines/user/Continuation
       6: invokevirtual #33                 // Method com/offbynull/coroutines/user/Continuation.suspend:()V
       9: aconst_null
      10: pop
      11: return

Java Decompiler decompiles it to the following Java code

 public void run(Continuation c) throws Exception {
    c = null; // wrong decompilation
    c.suspend();
    null;
  }

I think that the decompiler is wrong because every Java method call in Clojure has the same bytecode.
So the bytecode is correct.

But when I run the code I've got a NullPointerException on the (.suspend c) line.
Maybe this library has the same mistake?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions