function sum([int] data) => int: int r = 0 for item in data: r = r + item return rThis function is compiled into the following WyIL bytecode:
function sum([int] data) => int: body: const %1 = 0 : int assign %2 = %0 : [int] forall %3 in %2 () : [int] assign %4 = %1 : int add %1 = %4, %3 : int return %1 : int
Here, we can see that every bytecode is associated with one (or more) types. These types are inferred by the compiler during type propagation.
Each bytecode has a binary format which identifies the opcode, registers used and pool items used (e.g. names, constants, etc). The generic organisation of a bytecode is as follows:
+--------+-----------+------------+ | opcode | registers | pool items | +--------+-----------+------------+
The opcode is currently always 1 byte, whilst the remainder varies between instructions. Many bytecodes assign to a target register and read values from operand registers. Such bytecodes are organised as follows:
+--------+--------+----------+------------+ | opcode | target | operands | pool items | +--------+--------+----------+------------+@author David J. Pearce
|
|
|
|
|
|