3 ms·
Perhaps this is a ridiculous question but is it possible to implement a language twice: both as compiled and as interpreted or JITted, the latter giving you a q
by Waterluvian 4y ago
Perhaps this is a ridiculous question but is it possible to implement a language twice: both as compiled and as interpreted or JITted, the latter giving you a quicker feedback loop at the cost of runtime performance, size, etc. ?
- adamdusty 4y agoOf course it is! These guys made an interpreter and JIT for C: https://developers.redhat.com/blog/2021/04/27/the-mir-c-interpreter-and-just-in-time-jit-compiler# https://developers.redhat.com/blog/2021/04/27/the-mir-c-inte...
- nicoburns 4y agoYes. See Dart as an example of a language that has done this in practice.
- drng 4y agoGHC (with GHCI) gives you this for Haskell. After moving from Haskell to C++ work, I really miss the interactive feedback loop (among many other things).
- kldx 4y agoHave you tried https://root.cern/cling/ https://root.cern/cling/ ? It works great in a jupyter notebook for quick prototyping of C++.
- mhh__ 4y agoIf you do a good compiler you can get this for free almost trivially. The important thing is to have people using both so you make sure the jit path can be dumb enough to be fast.
- mynameisash 4y agoI'm woefully rusty on my compiler knowledge. Would the direction matter? That is, would it be easier or harder to build an interpreter for C or Rust versus compiling Python or JS to machine code? Or would it all be the same?
- gleenn 4y agoClojure is also basically interpreted but can also be compiled ahead of time for reasons including performance.
- wtetzner 4y agoI believe Clojure is always compiled.
- gleenn 4y agoStart a REPL and you can type code in that is immediately executed, and has no side-effects in terms of classfiles being generated or otherwise. How is that not interpreted?
- wtetzner 4y agoClojure uses a custom classloader to compile and load bytecode at runtime.
- fulafel 4y agoGenerating class files is an optional compilation mode in Clojure. You can also load bytecode and define classes without involving files on the JVM, which is what eval (used by the repl) does https://clojure.org/reference/compilation https://clojure.org/reference/compilation (also see the eval definition at https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L3211 https://github.com/clojure/clojure/blob/master/src/clj/cloju... - it calls into the compiler). The JVM could still just interpret the JVM bytecode instead of JIT compiling first of course. Python is also technically compiled like this