The Virtual Machine


Primitives

Primitives are low-level routines that carry out fundamental computer operations (such as addidtion, file saving, and logical comparision). You can directly invoke one of these primitives by putting a line like this in your mtehod definition:

<primitive: 58>

Predefined Primitives can be found in the Interpreter's class variable PrimitiveTable. Evaluate the  following expression to inspect the primitive table:

Interpreter primitiveTable inspect

Browse the * method in class Float to see how to call a primitive:

* aNumber
    "Primitive. Answer the result of multiplying the receiver by aNumber.
    Fail if the argument is not a Float. Essential. See Object documentation
    whatIsAPrimitive."


    <primitive: 49>
    ^ (aNumber adaptFloat: self) * aNumber adaptToFloat

In the PrimitiveTable you will find an entry primitiveFloatMultiply at index 50 of the array (the array index starts at 1, the primitive numbers at 0). This is the corresponding routine called by the virtual machine.