Initial commit
This commit is contained in:
commit
b2edca2cb4
25 changed files with 3590 additions and 0 deletions
49
vm.h
Normal file
49
vm.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#ifndef clox_vm_h
|
||||
#define clox_vm_h
|
||||
|
||||
#include "object.h"
|
||||
#include "table.h"
|
||||
#include "value.h"
|
||||
|
||||
#define FRAMES_MAX 64
|
||||
#define STACK_MAX (FRAMES_MAX * UINT8_COUNT)
|
||||
|
||||
typedef struct {
|
||||
ObjClosure* closure;
|
||||
uint8_t* ip;
|
||||
Value* slots;
|
||||
} CallFrame;
|
||||
|
||||
typedef struct {
|
||||
CallFrame frames[FRAMES_MAX];
|
||||
int frameCount;
|
||||
Value stack[STACK_MAX];
|
||||
Value* stackTop;
|
||||
Table globals;
|
||||
Table strings;
|
||||
ObjString* initString;
|
||||
ObjUpvalue* openUpvalues;
|
||||
size_t bytesAllocated;
|
||||
size_t nextGC;
|
||||
Obj* objects;
|
||||
int grayCount;
|
||||
int grayCapacity;
|
||||
Obj** grayStack;
|
||||
} VM;
|
||||
|
||||
typedef enum {
|
||||
INTERPRET_OK,
|
||||
INTERPRET_COMPILE_ERROR,
|
||||
INTERPRET_RUNTIME_ERROR,
|
||||
} InterpretResult;
|
||||
|
||||
extern VM vm;
|
||||
|
||||
void initVM();
|
||||
void freeVM();
|
||||
InterpretResult interpret(const char* source);
|
||||
void push(Value value);
|
||||
Value pop();
|
||||
|
||||
#endif // clox_vm_h
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue