Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extending the jvm as a target #38

Closed
zcaudate opened this issue Feb 16, 2019 · 6 comments
Closed

extending the jvm as a target #38

zcaudate opened this issue Feb 16, 2019 · 6 comments

Comments

@zcaudate
Copy link

I'm curious about the possibility of the compiler targeting the jvm. I asked this question on reddit a while back and the amount of upvotes surprised me: https://www.reddit.com/r/Clojure/comments/aluoar/what_is_the_status_of_some_of_the_clojure_static/

@bakpakin
Copy link
Member

It’s an interesting idea and there are a lot of ways to go about it.

  • Run Janet via JNI and allow communication with Java
  • Reimplement Janet in Java, sans GC. The code would probably be simpler as well if we reused Java concepts.
  • Same as above, but compile Janet bytecode to Java bytecode. I’m not sure If this would be easy or very difficult.
  • write another compiler to emit Java bytecode directly from the Janet source. This would actually might be easier than translating from one bytecode to another.

I’m not sure what the most useful approach would be, but the first is probably the least amount of work, as the runtime doesn’t need to be rewritten.

All that said, porting to the JVM is not really a goal right now unless someone wanted to spearhead that effort.

@zcaudate
Copy link
Author

I had assumed that the c byte code provides an intermediary for targeting various virtual machines (llvm,jvm, custom hardware etc).

Am I wrong in thinking that?

@zcaudate
Copy link
Author

For me, there is a serious need for an clojure compiler - mainly for targeting android. It’s rather a long term thing but I’d like that problem solved.

If that were possible I have a feeling that many clojure devs that would jump onboard. I’m not sure what your goals are for Janet but this is something to consider.

Honestly, if I had a knowledge to write a compiler, I would have done it by now.

@bakpakin
Copy link
Member

No, the bytecode is executed directly by the interpreter. To really port Janet to the JVM, one would probably have to rewrite the entire language in Java.

Can Clojure not do AOT compilation on Android? I would have assumed that would be easily possible.

@bakpakin
Copy link
Member

bakpakin commented Feb 17, 2019

I had assumed that the c byte code provides an intermediary for targeting various virtual machines (llvm,jvm, custom hardware etc).

llvm isn't a virtual machine. It is a compiler intermediate representation. The bytecode that the Janet compiler produces is run in a bytecode interpreter.

Janet is not really looking to be at all compatible with Clojure. Clojure has some cool ideas, and many other ideas that are infeasible without a really good compiler (GHC) or a really good JITting runtime (JVM). Janet will never have lazy sequences as a core abstraction because they are too slow. Clojure jumps through many hoops to make them reasonably fast, like using chunked sequences, and that is already considering the Clojure is implemented on top of the JVM, which is good at optimizing code that produces a lot of garbage.

If you are looking for a static Clojure compiler, look elsewhere. If you are looking for a kind-of Clojure-like language that can run on the JVM, Janet is not there yet, and probably won't ever be unless someone else works on that.

@zcaudate
Copy link
Author

Thanks for the clarifications. And congrats on the amazing work with Janet. It’s finally got me excited about clojure again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants