Search code examples
compiler-constructiongrammarinterpreterjitj

Is it possible to implement an interpreted-only language in a JITted one?


For example, J is a language that is, to the best of my knowledge, only interpreted since writing a compiler is impossible/impractical due its grammar type (I'm far from being an expert).

Given that we now have languages that combine a JIT with metaprogramming abilities such as Racket or Scheme, would it be possible to implement an interpreter-only language as a set of macros to compile to the host language without compromising the original language behaviour?

I am asking this because, as I understand it, a JIT blurs the "compile-time vs runtime" frontier and therefore when you run, say a JITted Scheme program, it should be able to offer the same behaviour as an equivalent interpreter.

Is that correct?


Solution

  • A JITted version of a program have to have exactly the same identifiable behaviour as an interpreted version, otherwise the implementation is buggy.

    I'd like to say that all programming languages can be implemented with a JIT, however the machine code generated might have to make a lot of runtime calls to aid it while executing, it might have to bail out to the interpreter for hard to solve cases. Deoptimization and recompilation can also help.

    But in the end the interpreter is just deciding what machine code to execute, a JIT can do the same but in another way.