| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /**
- ******************************************************************************
- * @file : vm.h
- * @author : simon
- * @brief : hand it a chunk of code—literally a Chunk—and it runs it
- * @attention : None
- * @date : 2023/8/17
- ******************************************************************************
- */
- #ifndef CLOX__VM_H_
- #define CLOX__VM_H_
- #include "compiler.h"
- #include "object.h"
- #include "table.h"
- #define FRAMES_MAX 64
- #define STACK_MAX (FRAMES_MAX * UINT8_COUNT)
- typedef struct {
- ObjClosure *closure;
- uint8_t *ip;
- Value *slots;
- } CallFrame;
- typedef struct VM {
- CallFrame frames[FRAMES_MAX];
- int frameCount;
- Value stack[STACK_MAX];
- Value *stackTop;// 栈指针
- Table globals;
- Table strings;//
- ObjUpvalue *openUpvalues;
- Obj *objects;// 管理分配的 heap 内存
- } VM;
- typedef enum {
- INTERPRET_OK,
- INTERPRET_COMPILE_ERROR,
- INTERPRET_RUNTIME_ERROR
- } InterpretResult;
- extern VM vm;
- void initVM();
- void freeVM();
- /// \brief interpret 执行指令
- /// \param source 源代码
- /// \return InterpretResult
- InterpretResult interpret(const char *source);
- void push(Value value);
- Value pop();
- #endif//CLOX__VM_H_
|