Skip to main content

Module inst

Module inst 

Source
Expand description

The instructions.

Every instruction names its operands and its destination by slot number. There is no operand stack: no push, no pop, no stack-effect table, no discipline to get wrong.

That is ADR 0034’s “parameters, locals, temporaries and captures share the one slot numbering” taken literally. If a temporary is a slot, then an instruction that consumes a temporary names a slot, and the thing an operand stack exists to provide is already there.

Two things fall out of that, and they are why it is worth choosing:

  • A frame’s roots are a static fact. A stack machine’s set of live references changes as operands are pushed and popped, so its reference map has to be indexed by program counter. Here the map does not change between a function’s first instruction and its last, and crate::RefMap is one bit per slot.
  • A call needs no argument buffer. The callee’s frame begins where the caller’s ends, so Inst::Call copies the words of argument i into the run parameter i occupies and transfers control. Nothing is pushed, permuted, or copied back.

§The instruction set describes families, not cases

There is one LoadField, not one per value kind that has fields; one Arith, not one per numeric type; one Alloc, not one per collection. A field of an inline value needs no instruction at all — it is a slot offset the lowering computes. What an object is is a question the object answers at run time, from its own header. Nothing here grows a case because a corpus program was refused, because nothing here refuses anything.

The two instructions that carry an immediate — Inst::ArithImm and Inst::CmpImm — are the same rule applied to an operand rather than to a type. They are not add.int.imm, sub.int.imm, lt.int.imm and eight more: the operator is a field, as it already is on Inst::Arith and Inst::Cmp, so the family stays two however many operators the language grows. What they say that no other instruction can is that an operand is a constant, which is a fact the source stated and every other representation of it throws away.

Enums§

ArithOp
CmpOp
Compare
What a comparison compares.
Convert
A conversion between two scalar representations.
Inst
One instruction.
Len
How many elements an Inst::Alloc asks for.
Num
Which numeric interpretation an arithmetic or comparison instruction gives its operand words.

Type Aliases§

Pc
An index into a function’s instructions.
Slot
A slot in the current frame: memory[frame_base + slot].