# Can you compile Julia into Scheme/FemtoLisp or directly its VM code (or other language more appropriate)?

**URL:** <https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746>\
**Category:** Offtopic\
**Created:** [October 14, 2022, 4:52pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746 "2022-10-14T16:52:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 14, 2022, 4:52pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/1 "2022-10-14T16:52:01Z")

</div>

Julia compiles code into native code, but it may take time, and at the opposite end you can use Julia as an interpreter with `julia --compile=min` but it’s very slow at runtime (only the non-compilation step is fast).

Python DOES compile into bytecode, and I was thinking, do we need such as a middle-ground (in some cases, even for a limited subset of Julia), then a question which bytecode to choose. It just occurred to me, Julia already includes another language FemtoLisp (used for the parser, though it’s on the way out for that).

> the fastest lisp interpreter I could in under 1000 lines of C […] it is fast, ranking among the fastest non-native-compiled Scheme implementations. It achieves this level of speed even though many primitives (e.g. `filter` and `for-each`) are written in the language instead of C. femtolisp uses a bytecode compiler and VM, with the compiler written in femtolisp. Bytecode is first-class, can be printed and read, and is “human readable” (the representation is a string of normal low-ASCII characters).

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 14, 2022, 5:03pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/2 "2022-10-14T17:03:32Z")

</div>

compiler team is already thin and stretched, let’s not derail ourselves into directions that benefits virtually nobody (“just use Python?”)

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 14, 2022, 5:09pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/3 "2022-10-14T17:09:43Z")

</div>

I’m not asking anyone in the core team to do it (nor asking if already possible), just would it be viable. And if done, would it be wanted integrated into Julia?

You’re right it’s already possible to compile Julia to Python, and that would be one way. I’m thinking something you could annotate packages with, compile=min is already possible there, and I’m not sure Python [VM] would be wanted there.

If you use Python you need the Python runtime, which is larger.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 14, 2022, 5:13pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/4 "2022-10-14T17:13:12Z")

</div>

compiling to femptolisp wouldn’t make much sense. the better way to get this type of tradeoff would be too gave an interpreter over Julia bytecode with a simplified type inference and inliner that gives up more often but is faster.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 14, 2022, 5:15pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/5 "2022-10-14T17:15:51Z")

</div>

> [@Oscar\_Smith](#):
>
> interpreter over Julia bytecode

There is “no Julia bytecode”, right? You mean it could be defined? Yes, I’m not sure what’s optimal (while I have given VMs a lot of thought), for Julia, why not FemtoLisp’s (or Python’s, or Graal or whatever is available)?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 14, 2022, 5:16pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/6 "2022-10-14T17:16:10Z")

</div>

so the answer is no, that’s not how Julia currently works at all, we don’t compile to femptolisp first; not sure if this is technically super accurate, but femptolisp parses Julia source code into expressions which is then handled by Julia compiler. what femptolisp sees is Julia source code, and we don’t stay very long in “domain?”

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 14, 2022, 5:16pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/7 "2022-10-14T17:16:42Z")

</div>

Julia has an ir format that is basically a bytecode.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 14, 2022, 5:18pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/8 "2022-10-14T17:18:18Z")

</div>

> [@Oscar\_Smith](#):
>
> inliner that gives up more often but is faster.

The inliner is part of the (optimization) problem. Optimization is costly, especially it, and it’s only on and off, but some middle ground likely a good idea. I would be ok with no inlining and just bytecode, since a lot of code isn’t sped-critical.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 14, 2022, 5:18pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/9 "2022-10-14T17:18:49Z")

</div>

so maybe [GitHub - JuliaDebug/JuliaInterpreter.jl: Interpreter for Julia code](https://github.com/JuliaDebug/JuliaInterpreter.jl) can have better / alternaive heuristics?

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 14, 2022, 5:20pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/10 "2022-10-14T17:20:46Z")

</div>

Do you know if compile=min interprets that LLVM IR I forgot about (or source code directly?), and why it’s so slow at runtime (much slower than Python’s). I’m not sure it was ever meant for interpretation. Then you need LLVM, and I would like interpretation without requiring that huge dependency.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 14, 2022, 5:24pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/11 "2022-10-14T17:24:05Z")

</div>

Thanks, wasn’t aware of (or had forgotten) that, which isn’t part of Julia. I recall the debugger very slow, because if this I guess, any idea why or what you have in mind with better heuristics? Like just useing that on some code, not hot-code/loops?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 14, 2022, 5:43pm UTC](https://discourse.julialang.org/t/can-you-compile-julia-into-scheme-femtolisp-or-directly-its-vm-code-or-other-language-more-appropriate/88746/12 "2022-10-14T17:43:23Z")

</div>

the main reason the debugger is slow is that when you are debugging, it’s very hard to perform optimizations without missing breakpoints.
