API

MACRO UTILS

Generic access to stack
   STK_OBJ(thread, pos)
New stack stack object (over top)
   STK_NEW(thread)
Top of stack
   STK_TOP(thread)
Second element of stack
   STK_SND(thread)
Third element of stack
   STK_TRD(thread)
Fourth element of stack
   STK_FTH(thread)
Swap top/second elements of stack
   STK_SWAP(thread)
Drop top of stack
   STK_DROP(thread)
Drop 2 top elements of stack
   STK_DROP2(thread)
Drop 3 top elements of stack
   STK_DROP3(thread)
Drop second element of stack
   STKDROPSND(thread)
Drop second and third element of stack
   STKDROPST(thread)
Drop second, third and fourth element of stack
   STKDROPSTF(thread)
Heap object by reference
   HEAP_OBJ(ref)
Create a new variable pointer referenced heap object
   NEW_HEAP_REF(_refobj_, ref)

VM INTERNALS

Run a single cycle of the vm
   void vm_step(vm_thread_t **thread, vm_program_t program);
Create new thread
   void vm_create_thread(vm_thread_t **thread);
Destroy thread
   void vm_destroy_thread(vm_thread_t **thread);
Push value
   void vm_push(vm_thread_t **thread, vm_value_t value);
Pop value
   vm_value_t vm_pop(vm_thread_t **thread);
Drop elements n elements from stack
   vm_errors_t vm_drop_n(vm_thread_t **thread, uint32_t qty);
Push frame (for call)
   void vm_push_frame(vm_thread_t **thread, uint8_t nargs);
Pop frame (for return from call)
   void vm_pop_frame(vm_thread_t **thread);
Read byte from program
   uint8_t vm_read_byte(vm_thread_t **thread, vm_program_t program, uint32_t *pc);
Read 16 bit integer from program
   int16_t vm_read_i16(vm_thread_t **thread, vm_program_t program, uint32_t *pc);
Read 16 bit unsigned integer from program
   uint16_t vm_read_u16(vm_thread_t **thread, vm_program_t program, uint32_t *pc);
Read 32 bit integer from program
   int32_t vm_read_i32(vm_thread_t **thread, vm_program_t program, uint32_t *pc);
Read 32 bit unsigned integer from program
   uint32_t vm_read_u32(vm_thread_t **thread, vm_program_t program, uint32_t *pc);
Read 32 bit float from program
   float vm_read_f32(vm_thread_t **thread, vm_program_t program, uint32_t *pc);

HEAP

Create heap
   vm_heap_t* vm_heap_create(uint32_t size);
Destroy heap
   void vm_heap_destroy(vm_heap_t *heap, vm_thread_t **thread);
Save new value in an empty space on heap
   uint32_t vm_heap_save(vm_heap_t *heap, vm_heap_object_t value, uint32_t **gc_mark);
Retrieve heap object
   vm_heap_object_t* vm_heap_load(vm_heap_t *heap, uint32_t pos);
Set value on occupied heap object
   bool vm_heap_set(vm_heap_t *heap, vm_heap_object_t value, uint32_t pos);
Mark as free a heap object
   void vm_heap_free(vm_heap_t *heap, uint32_t pos);
Check free mark status of gc heap object
   bool vm_heap_isgc(vm_heap_t *heap, uint32_t pos, uint32_t *gc_mark);
Check allocated mark of heap object
   bool vm_heap_isallocated(vm_heap_t *heap, uint32_t pos);
Check if heap object is static
   bool vm_heap_isstatic(vm_heap_t *heap, uint32_t pos);
Mark as free all gc mark objects
   void vm_heap_gc_collect(vm_heap_t *heap, uint32_t **gc_mark, bool free_mark, vm_thread_t **thread);
Create new gc mark
   uint32_t* vm_heap_new_gc_mark(vm_heap_t *heap);
Liberate all memory allocated in heap from not used upper objects
   void vm_heap_shrink(vm_heap_t *heap);