Professional Documents
Culture Documents
Abstract Machines
Dario Della Monica
School of Computer Science, Reykjavik University, Iceland
Abstraction
mechanism to manage system complexity by isolating
important aspects
it is everywhere
in
in
in
in
our lives
science
computer science
programming language
Abstraction
mechanism to manage system complexity by isolating
important aspects
it is everywhere
in
in
in
in
our lives
science
computer science
programming language
Abstraction
mechanism to manage system complexity by isolating
important aspects
it is everywhere
in
in
in
in
our lives
science
computer science
programming language
Abstraction
mechanism to manage system complexity by isolating
important aspects
it is everywhere
in
in
in
in
our lives
science
computer science
programming language
Abstraction
mechanism to manage system complexity by isolating
important aspects
it is everywhere
in
in
in
in
our lives
science
computer science
programming language
Abstraction
mechanism to manage system complexity by isolating
important aspects
it is everywhere
in
in
in
in
our lives
science
computer science
programming language
interpreters/compilers
Abstraction
mechanism to manage system complexity by isolating
important aspects
it is everywhere
in
in
in
in
our lives
science
computer science
programming language
interpreters/compilers
Abstract machine
(adding a level)
Abstraction
mechanism to manage system complexity by isolating
important aspects
it is everywhere
in
in
in
in
our lives
science
computer science
programming language
interpreters/compilers
Abstract machine
(adding a level)
Hierarchy
Dario Della Monica
Outline
2 Implementation of a Language
Outline
2 Implementation of a Language
Abstract Machine
The Concept
An electronic, digital computer is a physical machine that
executes algorithms which are suitably formalised.
An abstract machine is nothing more than an abstraction of
the concept of a physical computer.
An abstract machine permits step-by-step execution of a
program.
It is abstract because it omits the many details of real physical
machines.
Abstract Machine
Interpreter
Data
Sequence
control
Memory
Operations
Data
control
Program
Memory
management
The Interpreter
Fetch
next instruction
Decode
Fetch
operands
Choose
Execute OP1
Execute OP2
Store the
risult
Execute OPn
Execute HALT
Stop
Machine Language
Parts: Memory
Primary, secondary, cache, registers for storing data and
programs.
Data divided into primitive types: integers, reals, chars.
All data represented as bits.
Parts: Language LH
Simple instructions:
OpCode Operand1 Operand2
ADD
R5,
R0
ADD
(R5),
(R0)
Internal representation: Instructions are data stored in a
particular format.
The set of possible instructions depends on the particular
physical machine.
Parts: Interpreter
1
Parts: Interpreter
The interpreter is implemented as a set of physical devices
which comprise the Control Unit (CU)
Supports the execution of the fetch-decode-execute cycle.
fetch-decode-execute cycle
fetch phase: the next instruction (whose address is kept in the
PC register) to be executed is retrieved from memory. The
instruction an operation code and perhaps some operands
is stored in the instruction register.
decode phase: the instruction stored in the instruction register
is decoded using special logic circuits. The operands are
retrieved by data transfer operations using the address modes
specified in the instruction.
execute phase: the primitive hardware operation is executed.
Storage is performed by means of data-transfer operations.
Outline
2 Implementation of a Language
Implementation of a Language
Three options:
implementation in hardware;
simulation using software;
simulation (emulation) using firmware.
Program in L
Interpreter for L
written in LO
Output dati
Execution on M O
Input data
MO
Definition (Interpreter)
An interpreter for language L, written in language Lo, is a
program which implements a partial function:
ILLo : (Prog L D) D
Characteristics
Programs in L are not explicitly translated there is only a
decoding procedure.
In order to execute an instruction of L, the interpreter ILLo
uses a set of instructions in Lo which corresponds to an
instruction in language L.
Not a real translation, because the code corresponding to an
instruction of L is executed, not output, by the interpreter.
Input data
Program
written in L
Program
written in LO
Compiler
from L to LO
Execution on M A
Abstract macchine M A
Output data
Execution M O
Host macchine M O
Definition (Compiler)
A compiler from L to Lo is a program which implements a
function:
CL,Lo : Prog L Prog Lo
such that, given a program P L , if
CL,Lo (P L ) = Pc Lo ,
(2)
(3)
Characteristics
L is called the source language, while Lo is called the object
language.
To execute a program P L (written in L) on input data D,
CL,Lo is executed with P L as input.
This produces a compiled program Pc Lo as its output
(written in Lo).
Then Pc Lo can be executed on the machine MoLo supplying
it with input data D to obtain the desired result.
The translation phase (called compilation) is separate from
the execution phase.
Interpreted implementation
Disadvantage: low efficiency.
The interpreter ILLo must perform a decoding of Ls constructs
while it executes.
As part of the time required for the execution of P L , it is also
necessary to add in the time required to perform decoding.
Compiled implementation
Advantage: high efficiency.
The execution of Pc Lo is more efficient than an interpretive
implementation because the former does not have the
overhead of the instruction decoding phase.
Decoding an instruction of language L is performed once by
the compiler, independent of the number of times this
instruction occurs at runtime.
Compilation
Some instructions for input/output are often translated into
operating system calls, which simulate at runtime (and
therefore interprets) the high-level instructions.
Input data
Program
written in L
Compiler
from L to Li
Program
written in Li
Interpreter for Li
written
in Lo or SRT
Program
written in L
Compiler
from L to Li
Program
written in Li
Output data
Execution on M O
Compilation on M A
MA
MO
Different cases:
1
2
In practice:
We tend to interpret those language constructs which are
furthest from the host machine language and to compile the
rest.
Compiled solutions are preferred when execution efficiency is
desired.
The interpreted approach is preferred when greater flexibility
is required.
Portability
First time adopted by the Pascal language, using P-code as
intermediate machine
http://en.wikipedia.org/wiki/P-code_machine.
Used by Java, whose abstract (intermediate) machine is called
the Java Virtual Machine and its corresponding machine
language is Java Byte Code.
http://en.wikipedia.org/wiki/Java_bytecode
Dario Della Monica
Important note
One should not talk about an interpreted language or a
compiled language
Why not?
One should, instead, talk of interpretative or compiled
implementations of a language.
Software
Firmware
Hardware