Most active commenters
  • Imustaskforhelp(3)
  • amszmidt(3)

←back to thread

414 points henry_flower | 13 comments | | HN request time: 0.001s | source | bottom
Show context
digitalsushi ◴[] No.43108644[source]
Spock levels of fascinating from me. I want to learn how to compile a pdp11 emulator on my mac.
replies(4): >>43108726 #>>43108732 #>>43108743 #>>43109755 #
snovymgodym ◴[] No.43108726[source]
https://opensimh.org/

Works great on Apple Silicon

replies(1): >>43108833 #
haunter ◴[] No.43108833[source]
What’s the difference between an emulator and a simulator in this context?
replies(3): >>43108965 #>>43108980 #>>43119814 #
1. o11c ◴[] No.43108980{3}[source]
In theory, an emulator is oriented around producing a result (this may mean making acceptable compromises), whereas a simulator is oriented around inspection of state (this usually means being exact).

In practice the terms are often conflated.

replies(2): >>43110169 #>>43111430 #
2. codr7 ◴[] No.43110169[source]
The difference is about as crystal clear as compiler/interpreter.
replies(1): >>43116620 #
3. ijustlovemath ◴[] No.43111430[source]
Adding some anecdata, I feel like emulator is mainly used in the context of gaming, in which case they actually care a great deal about accurate reproduction (see: assembly bugs in N64 emulators that had to be reproduced in order to build TAS). I haven't seen it used much for old architectures; instead I'd call those virtual machines.

definitely agree on simulator though!

4. Imustaskforhelp ◴[] No.43116620[source]
compiler creates a binary in elf format or other format which can be run given a shared object exists.

Intepreter either writes it in bytecode and then executes the bytecode line by line ?

Atleast that is what I believe the difference is , care to elaborate , is there some hidden joke of compiler vs intepreter that I don't know about ?

replies(3): >>43117570 #>>43119591 #>>43119624 #
5. dpassens ◴[] No.43117570{3}[source]
I assume GP meant that a lot of compilers also interpret and interpreters also compile.

For compilers, constant folding is a pretty obvious optimization. Instead of compiling constant expressions, like 1+2, to code that evaluates those expressions, the compiler can already evaluate it itself and just produce the final result, in this case 3.

Then, some language features require compilers to perform some interpretation, either explicitly like C++'s constexpr, or implicitly, like type checking.

Likewise, interpreters can do some compilation. You already mentioned bytecode. Producing the bytecode is a form of compilation. Incidentally, you can skip the bytecode and interpret a program by, for example, walking its abstract syntax tree.

Also, compilers don't necessarily create binaries that are immediately runnable. Java's compiler, for example, produces JVM bytecode, which requires a JVM to be run. And TypeScript's compiler outputs JavaScript.

replies(3): >>43117637 #>>43118771 #>>43119639 #
6. codr7 ◴[] No.43117637{4}[source]
Thank you!
7. Imustaskforhelp ◴[] No.43118771{4}[source]
Then what is the difference, I always thought of Java as closer to python in the sense that it's running the byte code. And python also has bytecode.

I don't know what the difference is , I know there can be intepreters of compilers but generally speaking it's hard to find compilers of intepreters

Eg C++ has compilers , intepreters both (cpi) , gcc

Js doesn't have compilers IIRC , it can have transpilers Js2c is good one but i am not sure if they are failsafe (70% ready) ,

I also have to thank you , this is a great comment

replies(2): >>43119705 #>>43119734 #
8. amszmidt ◴[] No.43119591{3}[source]
An interpreter runs the code as it is being read in.

A compiler processes the code and provides an intermediate result which is then "interpreted" by the machine.

So to take the "writes it in byte code" -- that is a compiler. "executes the byte code" -- is the interpreter.

If byte code is "machine code" or not, is really secondary.

replies(1): >>43124450 #
9. somat ◴[] No.43119624{3}[source]
I would generalize it to a compiler produces some sort of artifact that is intended to later be used directly, while for an interpreter the whole mechanism(source to execution) is intended to be used directly.

The same tool can often be used to do both. trival example: a web browser. save your web page as a pdf? compiler. otherwise interpreter. but what if the code it is executing is not artisanal handcrafted js but the result of a typescript compiler?

10. amszmidt ◴[] No.43119639{4}[source]
While an interpreter can do optimizations, they do not produce "byte code" -- by that time they are compilers!

As for the comparison with the JVM .. compare to a compiler that produces x86 code, it cannot be run without an x86 machine. You need a machine to run something, be it virtual or not.

11. amszmidt ◴[] No.43119705{5}[source]
The easy definition is that an interpreter takes somethings and runs/executes it.

A compiler takes the same thing, but produces an intermediate form (byte code, machine code, another languages sometimes called "transpilar"). That you can then pass through an interpreter of sorts.

There is no difference between Java and JVM, and Python and the Python Virtual Machine, or even a C compiler targeting x86 and a x86 CPU. One might call some byte code, and the other machine code .. they do the same thing.

12. o11c ◴[] No.43119734{5}[source]
Programming languages mostly occupy a 4-dimensional space at runtime. These axes are actually a bit more complicated than just a line:

* The first axis is static vs dynamic types. Java is mostly statically-typed (though casting remains common and generics have some awkward spots); Python is entirely dynamically-typed at runtime (external static type-checkers do not affect this).

* The second axis is AOT vs JIT. Java has two phases - a trivial AOT bytecode compilation, then an incredibly advanced non-cached runtime native JIT (as opposed to the shitty tracing JIT that dynamically-typed languages have to settle for); Python traditionally has an automatically-cached barely-AOT bytecode compiler but nothing else (it has been making steps toward runtime JIT stuff, but poor decisions elsewhere limit the effectiveness).

* The third axis is indirect vs inlined objects. Java and Python both force all objects to be indirect, though they differ in terms of primitives. Java has been trying to add support for value types for decades, but the implementation is badly designed; this is one place where C# is a clear winner. Java can sometimes inline stack-local objects though.

* The fourth axis is deterministic memory management vs garbage collection. Java and Python both have GC, though in practice Python is semi-deterministic, and the language has a somewhat easier way to make it more deterministic (`with`, though it is subject to unfixable race conditions)

I have collected a bunch more information about language implementation theory: https://gist.github.com/o11c/6b08643335388bbab0228db763f9921...

13. Imustaskforhelp ◴[] No.43124450{4}[source]
Then isn't theoretically all languages assembly intepreters in the endd