chunk.h 900 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // Created by 李晓明 on 2023/6/14.
  3. //
  4. #ifndef CLOX__CHUNK_H_
  5. #define CLOX__CHUNK_H_
  6. #include "common.h"
  7. typedef enum {
  8. OP_RETURN,
  9. } OpCode;
  10. //============================================================================
  11. // Dynamic array of instructions 扩容步骤
  12. //1. Allocate a new array with more capacity.
  13. //2. Copy the existing elements from the old array to the new one.
  14. //3. Store the new capacity.
  15. //4. Delete the old array.
  16. //5. Update code to point to the new array.
  17. //6. Store the element in the new array now that there is room.
  18. //7. Update the count.
  19. //============================================================================
  20. typedef struct {
  21. int count; // 使用量
  22. int capacity; // 容量
  23. uint8_t *code;// unsigned char*
  24. } Chunk;
  25. void initChunk(Chunk *chunk);
  26. void freeChunk(Chunk* chunk);
  27. void writeChunk(Chunk *chunk, uint8_t byte);
  28. #endif//CLOX__CHUNK_H_