L1InstructionWriter

class L1InstructionWriter(    module: A_Module,     startingLineNumber: Int,     phrase: A_Phrase)

An instance of this class can be used to construct a compiled code object without detailed knowledge of the level one nybblecode instruction set.

Author

Mark van Gulik

Parameters

module

The module containing this code.

startingLineNumber

Where this code starts in the module.

phrase

The phrase that should be captured for this raw function. nil is also valid, but less informative.

Constructors

Link copied to clipboard
fun L1InstructionWriter(    module: A_Module,     startingLineNumber: Int,     phrase: A_Phrase)

Create a new L1InstructionWriter Level One instruction writer.

Functions

Link copied to clipboard
fun addLiteral(literal: A_BasicObject): Int

Locate or record the specified literal object. Answer its 1-based index.

Link copied to clipboard
fun argumentTypes(vararg argTypes: A_Type)

Set the array of types of the arguments.

Link copied to clipboard
fun argumentTypesTuple(argTypes: A_Tuple)

Specify the types of the arguments that the resulting compiled code object will accept.

Link copied to clipboard
fun compiledCode(): AvailObject

Produce the compiled code object which we have just incrementally specified.

Link copied to clipboard
fun createLocal(localType: A_Type): Int

Declare a local variable with the specified type. Answer its index. The index is relative to the start of the arguments.

Link copied to clipboard
fun createOuter(outerType: A_Type): Int

Declare an outer (lexically captured) variable, specifying its type.

Link copied to clipboard
fun write(    lineNumber: Int,     operation: L1Operation,     vararg operands: Int)

Write an L1 instruction to the nybblecode stream. Some opcodes (automatically) write an extension nybble (0xF). Also write any operands. Validate that the right number of operands are provided.

Properties

Link copied to clipboard
var primitive: Primitive? = null

The primitive of the compiled code being generated.

Link copied to clipboard
var returnType: A_Type? = null

The return type of the FunctionDescriptor under construction.

Link copied to clipboard
var returnTypeIfPrimitiveFails: A_Type? = null

The return type that will be produced if the function is not a primitive, or if the primitive fails.