Next: , Previous: , Up: The Poke Language   [Contents][Index]


20.13 Assembler

Poke provides two ways to execute PVM assembler instructions: an asm expression and an asm statement.

asm statements take the following form:

asm (template [: outputs [: inputs]])

where template is the written form of a PVM assembler program, outputs a comma separated list of l-values ans inputs a comma separated list of expressions.

Before the assembler program in template is executed, the inputs (if any) are pushed on the stack. After the assembler program is executed, it is expected to have left the same number of elements on the stack than outputs specified. These values are then assigned to the outputs, in reverse order.

Example:

var result = 0;
asm ("addi; nip2" : result : 10, 20);

After the execution of the asm statement above, the value 30 is stored in the variable result.

asm expressions take the form:

asm type: (template [: inputs])

where type is a simple type specifier and template and inputs have the same meaning than in asm statements. A single output is always expected to be generated on the stack, of type type.

Example:

(poke) asm int: ("addi; nip2" : 10, 20) + 2
32

In both asm statements and expressions the compiler generates code that tries to determine whether the execution of the assembler code results in the original stack being underflown or overflown. If this is found to happen an exception E_stack is raised.

E_stack is also raised in case an asm statement or expression leaves a non-representable PVM value as an output. This is for example the case of PVM_NULL, which can’t be represented in Poke.

Note however that the above mentioned tests are not perfect, and it is generally possible to crash the system using asm statements or expressions.


Next: , Previous: , Up: The Poke Language   [Contents][Index]