diff --git a/lang/func.c b/lang/func.c index 82bfd32..395d51e 100644 --- a/lang/func.c +++ b/lang/func.c @@ -21,6 +21,7 @@ (void)obj; int arg_count = vm_stack_depth(state); abort_if(arg_count != 1, "func_add called with more than 1 argument"); + // For now just call bytecode_run bytecode_run(state); } diff --git a/lang/object.h b/lang/object.h index e42008b..dfb04df 100644 --- a/lang/object.h +++ b/lang/object.h @@ -19,9 +19,13 @@ *calls; // Points to array terminated by call with NULL name }; +// Creates an object with a class and allocated private data Object object_create(struct object_class *class, int priv_size); + +// Retrieves private data for an object with a specified class char *object_priv(Object object, struct object_class *class); +// Creates a placeholder object for use when no object is present Object object_none(void); // Adds a reference to an object diff --git a/lang/types.h b/lang/types.h index 1dfebae..2e7668b 100644 --- a/lang/types.h +++ b/lang/types.h @@ -4,7 +4,10 @@ #ifndef TYPES_H #define TYPES_H +// Opaque type for an object typedef void *Object; + +// Opaque type for the VM state typedef void *VmState; #endif diff --git a/lang/vm.h b/lang/vm.h index 76c8914..052c7d4 100644 --- a/lang/vm.h +++ b/lang/vm.h @@ -6,16 +6,37 @@ #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); #endif