/** ****************************************************************************** * @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 "chunk.h" #include "table.h" #define STACK_MAX 256 typedef struct { Chunk *chunk; uint8_t *ip; Value stack[STACK_MAX]; Value *stackTop;// 栈指针 Table globals; Table strings; // 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_