Skip to content

Instruction Set

Nick Pope edited this page Jun 24, 2013 · 26 revisions

Each instruction can take several forms, indicated in each section below detailing the function of each instruction. $<dest> refers to a variable called dest, with <> indicating where a custom name/value should be inserted. The use of square brackets [] means it is optional, so [$] would mean that a parameter can be a variable or a constant value.

Example

A simple summation example, it iterates over an array of items and returns the integer sum of them.

get $size $t1 size  ; Get the size attribute of object $t1 and put into $size variable.
cpy $i 0            ; Initialise $i to 0
cpy $sum 0          ; Initialise $sum to 0

:loop               ; Start of loop label
get $x $t1 $i       ; Read the value of index $i in object $t1 into variable $x
add $sum $sum $x    ; Add $x to $sum and put into $sum
inc $i              ; Increment $i by 1
jlt :loop $i $size  ; If $i < $size then jump back to :loop

ret $sum            ; Return the contents of $sum

Variables

All variables are preceded by a $. There can be up to 255 variables, none of which needs to be declared before first use. Using a variable that has not been defined or defining the value of variable and never using it will generate warnings in the assembler.

There are 3 special variables: $t1, $t2 and $h. These correspond to the hyperarc that is the subject of the definition being evaluated. For example, $t1 would be the "object", $t2 the "attribute" and $h the current (old) value under and object interpretation of the hypergraph.

The VM Instructions

NID Manipulations

add

Add two numeric NIDs together and put result into dest, or add one value to dest.

add $<dest> [$]<a> [$]<b>
add $<dest> [$]<value>

sub

Subtract two numeric NIDs (b from a) and put result into dest.

sub $<dest> [$]<a> [$]<b>
sub $<dest> [$]<value>

div

div $<dest> [$]<a> [$]<b>
div $<dest> [$]<value>

mul

mul $<dest> [$]<a> [$]<b>
mul $<dest> [$]<value>

shl

Shift value left by n bits and put into dest.

shl $<dest> [$]<value> [$]<n>
shl $<dest> [$]<n>

shr

Shift value right by n bits and put into dest.

shr $<dest> [$]<value> [$]<n>
shr $<dest> [$]<n>

and

and $<dest> [$]<a> [$]<b>
and $<dest> [$]<value>

or

or $<dest> [$]<a> [$]<b>
or $<dest> [$]<value>

xor

xor $<dest> [$]<a> [$]<b>
xor $<dest> [$]<value>

neg

neg $<dest> [$]<value>
neg $<dest>

inc

inc $<value>

dec

dec $<value>

clr

Sets value to null.

clr $<value>

int

Convert value to an integer and put into dest.

int $<dest> [$]<value>
int $<dest>

flt

Convert value to a float and put into dest.

flt $<dest> [$]<value>
flt $<dest>

Data

cpy

Copy a value from source into dest.

cpy $<dest> [$]<source>

const

const <NAME> <value>

ret

Return value.

ret [$]<value>

Branching

jmp

jmp :<label>

jeq

jeq :<label> [$]<a> [$]<b>

jne

jne :<label> [$]<a> [$]<b>

jle

jle :<label> [$]<a> [$]<b>

jge

jge :<label> [$]<a> [$]<b>

jlt

jlt :<label> [$]<a> [$]<b>

jgt

jgt :<label> [$]<a> [$]<b>

Hypergraph Access

get

Read a single value from the t1 t2 HARC into dest.

get $<dest> [$]<t1> [$]<t2>

def

Define the HARC t1 t2 as value. The value may be a constant or definition.

def [$]<t1> [$]<t2> [$]<value>

dep

Add a dependency where a1 a2 depends upon b1 b2.

dep [$]<a1> [$]<a2> [$]<b1> [$]<b2>
dep [$]<a> [$]<b>

new

Create a new NID in dest which matches the kind NID.

new $<dest> [$]<kind>
new $<dest>

del

Delete the HARC t1 t2.

del [$]<t1> [$]<t2>

Calling

call $<result> [$]<func> [$]<param>*

Call an external function where xfunc is a string name for the function.

callx $<result> <xfunc> [$]<param>*

Register an agent using script with associated data item.

agent [$]<script> [$]<data>

High Level

path

Follow a path through the graph, starting at element and putting the result into dest. Elements may be repeated any number of times and are separated by dots. The pathd form also adds dependencies to the HARC whose definition this corresponds to ($t1 and $t2).

path $<dest> [$]<element>[.]*
pathd $<dest> [$]<element>[.]*

clone

sclone
dclone

jisa

jisa :<label> [$]<value> [$]<pattern>

jisnt

jisnt :<label> [$]<value> [$]<pattern>

Clone this wiki locally