| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- /**
- ******************************************************************************
- * @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 "value.h"
- #define STACK_MAX 256
- typedef struct {
- Chunk *chunk;
- uint8_t *ip;
- Value stack[STACK_MAX];
- Value *stackTop; // 栈指针
- } VM;
- typedef enum {
- INTERPRET_OK,
- INTERPRET_COMPILE_ERROR,
- INTERPRET_RUNTIME_ERROR
- } InterpretResult;
- 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_
|