SEND Instruction - craterdog-archives/js-bali-virtual-machine GitHub Wiki
The SEND Instruction
The SEND
instruction causes the virtual processor to create a new task context for a
message with optional arguments being send to a target component. The new context is
either added to the top of the context stack if the target component is currently on the
component stack; or placed in the task bag to be handled by a separate task if the target
component is a document referenced by a citation that is on top of the component stack.
The modifier specifies whether or not the target component is a document and whether or
not there is a list of arguments residing on the component stack.
The operand contains an index value in the range 1..2047
of the message to be sent.
SEND message TO COMPONENT
The SEND
instruction with the TO COMPONENT
modifier sends the message identified by
the message operand to the component that is currently on top of the component stack.
The bytecode for this instruction has the form:
[11100xxx][xxxxxxxx] where xxxxxxxxxxx is the index of the message to be sent
The following pseudo-code defines this instruction:
component = task.components.pop()
message = context.messages.get(context.operand)
context.address = context.address + 1
task.contexts.push(context)
context = Context(component, message)
Example Context Before Execution
Example Context After Execution
SEND message TO COMPONENT WITH ARGUMENTS
The SEND
instruction with the TO COMPONENT WITH ARGUMENTS
modifier sends the message
identified by the message operand to the component that is currently on top of the component
passing the list of arguments that is the next component on the component stack.
The bytecode for this instruction has the form:
[11101xxx][xxxxxxxx] where xxxxxxxxxxx is the index of the message to be sent
The following pseudo-code defines this instruction:
arguments = task.components.pop()
component = task.components.pop()
message = context.messages.get(context.operand)
context.address = context.address + 1
task.contexts.push(context)
context = Context(component, message, arguments)
Example Context Before Execution
Example Context After Execution
SEND message TO DOCUMENT
The SEND
instruction with the TO DOCUMENT
modifier sends the message identified by
the message operand to the commited document that is named by the component that is
currently on top of the component stack. The message will be processed by a different
virtual processor. The bytecode for this instruction has the form:
[11110xxx][xxxxxxxx] where xxxxxxxxxxx is the index of the message to be sent
The following pseudo-code defines this instruction:
target = task.components.pop()
message = context.messages.get(context.operand)
document = repository.retrieveDocument(target)
task.tokens = task.tokens / 2
child = Task(task.account, task.tokens)
child.contexts.push(Context(document, message))
repository.postMessage('/bali/vm/tasks/v1', child)
task.components.push(child.tag)
context.address = context.address + 1
Example Context Before Execution
Example Context After Execution
SEND message TO DOCUMENT WITH ARGUMENTS
The SEND
instruction with the TO DOCUMENT WITH ARGUMENTS
modifier sends the message
identified by the message operand to the committed document that is named by the component
that is currently on top of the component passing the list of arguments that is the next
component on the component stack. The message will be processed by a different virtual
processor. The bytecode for this instruction has the form:
[11111xxx][xxxxxxxx] where xxxxxxxxxxx is the index of the message to be sent
The following pseudo-code defines this instruction:
arguments = task.components.pop()
target = task.components.pop()
message = context.messages.get(context.operand)
document = repository.retrieveDocument(target)
task.tokens = task.tokens / 2
child = Task(task.account, task.tokens)
child.contexts.push(Context(document, message, arguments))
repository.postMessage('/bali/vm/tasks/v1', child)
task.components.push(child.tag)
context.address = context.address + 1