Interpreter
public struct Interpreter
A virtual machine that executes Hylo’s in-memory IR representation.
-
The program to be executed.
Declaration
Swift
private let program: IR.Program -
The stack- and dynamically-allocated memory in use by the program.
Declaration
Swift
private var memory: Memory -
Local variables, parameters, and return addresses.
Declaration
Swift
private var callStack: Stack -
Identity of the next instruction to be executed.
Declaration
Swift
private var programCounter: CodePointer -
True iff the program is still running.
Declaration
Swift
public private(set) var isRunning: Bool { get } -
Text written so far to the process’ standard output stream.
Declaration
Swift
public private(set) var standardOutput: String { get } -
Text written so far to the process’ standard error stream.
Declaration
Swift
public private(set) var standardError: String { get } -
The type layouts that have been computed so far.
Declaration
Swift
private var typeLayout: TypeLayoutCache -
The top stack frame.
Declaration
Swift
private var topOfStack: StackFrame { get set } -
An instance executing
p.Precondition
p.entry != nilDeclaration
Swift
public init(_ p: IR.Program) -
The value of the current instruction’s result, if it has been computed.
Declaration
Swift
private var currentRegister: InstructionResult? { get set } -
Executes a single instruction.
Declaration
Swift
public mutating func step() throws -
The instruction at which the program counter points.
Precondition
the program is running.Declaration
Swift
public var currentInstruction: any Instruction { get } -
Moves the program counter to the next instruction.
Declaration
Swift
mutating func advanceProgramCounter() throws -
Removes topmost stack frame and points
programCounterto next instruction of any previous stack frame, or stops the program if the stack is now empty.Precondition
the program is running.Declaration
Swift
mutating func popStackFrame() -
Allocates memory for an object of type
tand returns the address.Declaration
Swift
mutating func allocate(_ t: TypeLayout) -> Address -
Deallocates
aallocated on stack.Declaration
Swift
mutating func deallocateStack(_ a: Address) throws -
Returns the address produced by executing instruction identified by
iin the current frame, ornilif it didn’t produce an address.Declaration
Swift
func addressProduced(by i: InstructionID) -> Address? -
Returns the address to be deallocated by
i.Declaration
Swift
func addressToBeDeallocated(by i: DeallocStack) -> Address
View on GitHub