Newer
Older
Tardis / lang / vm.h
// SPDX-License-Identifier: MIT
// Copyright (c) 2023 John Watts and the LuminaSensum contributors

#ifndef VM_H
#define VM_H

#include "types.h"

// Creates a virtual machine
VmState vm_create(void);

// Destroys a virtual machine
void vm_destroy(VmState *state);

// Sets the value of a vm stack element
// index is relative to the current frame
// The object's reference is taken from the caller
void vm_stack_set(VmState state, int index, Object obj);

// Gets the value of a vm stack element
// index is relative to the current frame
// A new reference is created for the caller
Object vm_stack_get(VmState state, int index);

// Pushes an object to the top of the vm stack
// The object's reference is taken from the caller
void vm_stack_push(VmState state, Object obj);

// Pops a object from the top of the vm stack
// The object's reference is given to the caller
Object vm_stack_pop(VmState state);

// Drops a number of objects from the vm stack
void vm_stack_drop(VmState state, int count);

// Gets the depth of the current vm stack frame
int vm_stack_depth(VmState state);

// Creates a stack frame at arg_count offset from the top then calls an object
void vm_call(VmState state, Object obj, const char *name, int arg_count);

// Queues a call to be scheduled on next return to vm_call
void vm_tailcall(VmState state, Object obj, const char *name);

#endif