On Sun, Jan 30, 2022 at 1:08 PM Dan Stromberg <drsalists@gmail.com> wrote:
On Sun, Jan 30, 2022 at 8:58 AM David Barto <david@kdbarto.org> wrote:
Yes, the UCSD P-code interpreter was ported to 4.1 BSD on the VAX and it ran natively there. I used it on sdcsvax in my senior year (1980).

This reminds me of a question I've had percolating in the back of my mind.

Was USCD Pascal "compiled" or "interpreted" or both?

As others have mentioned, both. The compiler generated P-code, which was a specialized bytecode representation of the compiled Pascal source.

The beauty of this is that it makes porting the system fairly easy; one need only write a P-code interpreter. Assuming the system ships with a p-code "binary" representation of the compiler in addition to the sources, one could make it self-hosting very easily. With a threaded P-code interpreter, it can also be quite small, making constrained 8-bit microcomputers (like the Apple II) reasonable targets for Pascal.

This sort of representation also has some interesting properties with respect to the actual bytecode used; it could, for example, have some understanding of the semantics of types in the programming language. The Dis virtual machine for the Limbo programming language used with the Inferno virtual operating system did this; Dis understood Limbo strings, whereas this isn't true on most machine architectures.

And is Java?  They both have a byte code interpreter.  Yes, modern Java is JIT-compiled, but does that make Java a compiled language in the Oracle implementation, or is it an interpreter with a pretty good runtime?

Again, both. The compiler emits java bytecodes, which the JVM interprets.

Wasn't Java referred to as "compiled" even back before the JIT compiler was added?

Yes!

Granted, gcj is compiled.

Well, gcj (optionally) compiles to native machine code and comes with a library that implements the functionality usually provided by the JVM; that is, it can target a platform other than the JVM and give mostly the same functionality. But javac and gcj are both very much compilers.

But Oracle's implementation of Java is commonly referred to as a "Compiler".  And what about back before Java's JIT compiler was added - ISTR recall Java was referred to as a compiled language before the JIT addition.

This is correct. A compiler simply transforms some representation of data into a different representation of that same data, possibly with some semantic loss; the canonical example is textual "source code" for some programming language translated into object code for some target hardware architecture, but this need not be the case. We were discussing troff and TeX the other day; both of these are compilers, in that they take some high-level source representation of a document and transform it into a typeset representation. (Note: I mean "semantic loss" in the sense that, say, we may lose details about types or the organization of data in the compiled artifact.)

And then there's the CPython implementation of Python.  It too uses a byte code interpreter, but it's commonly referred to as "interpreted".  But is it really?  Granted, it has an implicit, cached compilation step, but is it less compiled for that?

I think that "interpreted" in this context means the load-and-go nature of the system and the transience of the bytecode: the text is internally compiled and then executed, but these steps are often linked and, while one can coax the Python "interpreter" to emit .pyc and/or .pyo files, usually one does not: the compiled bytecodes are lost as soon as the program is done executing.

Is there consistency here?

Not really. As an interesting aside, before Java became widespread I heard folks mention "P-code" as a generic term for what most folks mean when they say "bytecode." Now we often just say "bytecode." Similarly with JIT in lieu of "load and go", though Java's JIT is a bit different (it's converting from bytecode to native machine code on the fly; it's even more elaborate when things like hot-spot are taken into account, where the runtime has a kind of built-in profiler and will optimize particularly expensive bits of the code over time).

        - Dan C.