1

I don't quite get the definition and use case of an abstract machine and how its actually related to a compiler or interpreter

I googled what abstract machines were but understood very little out of it.

An abstract machine is a model of a computer system (considered either as hardware or software) constructed to allow a detailed and precise analysis of how the computer system works.

Here are some articles I read but understood not that much out of:

2 Answers2

1

A definition of machine would be some working/processing engine. Here it means a computer. It relates to high-level language and machine code. An abstract machine is a model of a computer system/architecture. With many simplifications and generalizations. So the instruction set could be without registers but with a stack holding the operands of instructions.

A compiler or interpreter for code running on this non-existing abstract machine is much simpler to write, than for one single physical machine, and there exist many different physical machines.

You could write an interpreter for the code of your abstract machine and port that interpreter to many physical machines. Or you could compile to a physical machine by first compiling to the abstract machine code, and converting that to physical machine code.

Say you have L programming languages (Java, C) and M different systems (Windows, Linux on ARM, Androids), then going indirect via an abstract machine (JVM, LLVM) simplifies the effort to L+M implementations. Whereas otherwise you would need to write L*M implementations. Furthermore you entirely separate the aspects of programming language quirks and physical machine quirks.

The specification of an abstract machine, a high level theoretical computer, can be more universal and strict. And is just a tiny fraction of the specification of a real computer architecture. And it avoids bugs in chip design.

An abstract machine is the Esperanto intermediary for translating a high level language into machine language.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • 1
    In a nutshell, an abstract machine is an intermediate language between a programming language and its machine language output? – Humble Penguin Dec 01 '22 at 16:33
  • 1
    I would make a distinction between an abstract machine and a virtual machine. The abstract machine specifies an interface, while the virtual machine is a concrete implementation of that specification in software. (As opposed to the hardware J"V"M implementations people worked on in the late 90s.) – chepner Dec 01 '22 at 16:33
  • 1
    I would consider a Turing machine as an example of an abstract machine. Nobody actually implements any particular Turing machine in software or hardware, but the fact that you can design one is sufficient for proving various properties about algorithms intended to "run" on them. – chepner Dec 01 '22 at 16:36
  • whats the point of having an abstract machine? Isn't it more complicated to convert source code into an abstract machine program and then into a concrete executable? – Humble Penguin Dec 01 '22 at 16:38
  • No it is easier to separate concentrating on the high level language and concentrating on the machine language. One the one side data flow analysis (var usage), on the other side a multitude of numerical optimisations (/16, *7). The code is less complex. – Joop Eggen Dec 01 '22 at 17:37
  • @chepner thanks, I also wanted to mention that distinction, w.r.t. the _virtual machine_. An abstract machine as pure API+rules as opposed to a VM having an implementation I do not see so strict. Nowadays there are almost always reference implementations. – Joop Eggen Dec 01 '22 at 17:47
  • 1
    The intermediate serves as a common denominator to avoid having to write n^2 language implementations, one for each combination of language and host platform. You can write n front ends to compile Java, Python, C++, etc to the intermediate, then n backends that compile the intermediate to arm, x86, powerpc. Also, most optimizations are either language independent or OS independent, and so you can write them *once* for the intermediate language, rather than n times for each individual language or platform. – chepner Dec 01 '22 at 18:03
0

A NOT gate is an abstract machine: 0 goes in, 1 comes out, or 1 goes in, 0 comes out. But how does that happen? What is 0? What is 1? We don't care: we can reason about how NOT gates interact with AND gates and OR gates and what have to you to build up more complicated circuits.

There are, however, many ways you can realize this abstract machine as a concrete, working machine: transistors, diodes, DNA, relays, etc.

chepner
  • 497,756
  • 71
  • 530
  • 681