mirror of
https://codeberg.org/andyscott/marCsweep.git
synced 2024-11-09 13:50:51 -05:00
VM: added function and data declarations
This commit is contained in:
parent
b0585de84e
commit
d33e6c8e99
1 changed files with 53 additions and 0 deletions
53
vm.h
Normal file
53
vm.h
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
#ifndef VM_H
|
||||||
|
#define VM_H
|
||||||
|
|
||||||
|
#define STACK_MAX 1024
|
||||||
|
|
||||||
|
// Primitive types for garbage collection
|
||||||
|
enum garbageData {
|
||||||
|
GARBAGE_INT,
|
||||||
|
GARBAGE_PAIR,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Holds type and value data for the virtual machine
|
||||||
|
struct garbageObject {
|
||||||
|
enum garbageData type;
|
||||||
|
struct garbageObject *next;
|
||||||
|
|
||||||
|
union {
|
||||||
|
int value;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
struct garbageObject *head;
|
||||||
|
struct garbageObject *tail;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Virtual machine hold the stack to trace references
|
||||||
|
struct virtualMachine {
|
||||||
|
int stackSize;
|
||||||
|
struct garbageObject *head;
|
||||||
|
struct garbageObject *stack[STACK_MAX];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new garbageObject
|
||||||
|
struct garbageObject *initGarbage(struct virtualMachine *vm,
|
||||||
|
enum garbageData type);
|
||||||
|
|
||||||
|
// Create a new VM
|
||||||
|
struct virtualMachine *initVM();
|
||||||
|
|
||||||
|
// Generic function to push data onto the VM stack
|
||||||
|
void push(struct virtualMachine *vm, struct garbageObject *value);
|
||||||
|
|
||||||
|
// Pop data from the VM stack
|
||||||
|
struct garbageObject *pop(struct virtualMachine *vm);
|
||||||
|
|
||||||
|
// Push a GARBAGE_INT onto the VM stack
|
||||||
|
void pushInt(struct virtualMachine *vm, int value);
|
||||||
|
|
||||||
|
// Push a GARBAGE_PAIR onto the VM stack
|
||||||
|
struct garbageObject *pushPair(struct virtualMachine *vm);
|
||||||
|
|
||||||
|
#endif /* VM_H */
|
Loading…
Reference in a new issue