CALL Instruction - craterdog-archives/js-bali-virtual-machine GitHub Wiki
The CALL Instruction
The CALL
instruction causes an intrinsic function to be executed by the virtual machine
using 0..3
components from the component stack as arguments. The result of the function
replaces the arguments on top of the component stack. The number of arguments passed to
the function depends on the specified modifier:
The operand contains an index value in the range 1..154
of the intrinsic function to
called. Additional intrinsic functions may be added in the future.
CALL function
The CALL
instruction without a modifier calls the intrinsic function identified by
the function operand. The result of the function is placed on top of the component stack.
The bytecode for this instruction has the form:
[11000xxx][xxxxxxxx] where xxxxxxxxxxx is the index of the intrinsic function to be called
The following pseudo-code defines this instruction:
result = processor.intrinsics.call(context.operand)
task.components.push(result)
context.address = context.address + 1
Example Context Before Execution
Example Context After Execution
CALL function WITH 1 ARGUMENT
The CALL
instruction with the WITH 1 ARGUMENT
modifier calls the intrinsic function
identified by the function operand passing the top component on the component stack as the
argument to the function. The result of the function replaces the argument on top of the
component stack. The bytecode for this instruction has the form:
[11001xxx][xxxxxxxx] where xxxxxxxxxxx is the index of the intrinsic function to be called
The following pseudo-code defines this instruction:
argument = task.components.pop()
result = processor.intrinsics.call(context.operand, argument)
task.components.push(result)
context.address = context.address + 1
Example Context Before Execution
Example Context After Execution
CALL function WITH 2 ARGUMENTS
The CALL
instruction with the WITH 2 ARGUMENTS
modifier calls the intrinsic function
identified by the function operand passing the top two components on the component stack as the
arguments to the function. The result of the function replaces the arguments on top of the
component stack. The bytecode for this instruction has the form:
[11010xxx][xxxxxxxx] where xxxxxxxxxxx is the index of the intrinsic function to be called
The following pseudo-code defines this instruction:
argument2 = task.components.pop()
argument1 = task.components.pop()
result = processor.intrinsics.call(context.operand, argument1, argument2)
task.components.push(result)
context.address = context.address + 1
Example Context Before Execution
Example Context After Execution
CALL function WITH 3 ARGUMENTS
The CALL
instruction with the WITH 3 ARGUMENTS
modifier calls the intrinsic function
identified by the function operand passing the top three components on the component stack as
the arguments to the function. The result of the function replaces the arguments on top of
the component stack. The bytecode for this instruction has the form:
[11011xxx][xxxxxxxx] where xxxxxxxxxxx is the index of the intrinsic function to be called
The following pseudo-code defines this instruction:
argument3 = task.components.pop()
argument2 = task.components.pop()
argument1 = task.components.pop()
result = processor.intrinsics.call(context.operand, argument1, argument2, argument3)
task.components.push(result)
context.address = context.address + 1