code.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef AFUN_BYTECODE
  2. #define AFUN_BYTECODE
  3. #include <stdio.h>
  4. #include "aFunCoreExport.h"
  5. #define CODE_STR_MAX_SIZE (50)
  6. typedef struct af_Code af_Code;
  7. typedef long CodeInt; // Code int
  8. typedef long CodeUint; // Code uint TODO-szh 在code结构体使用该函数
  9. enum af_CodeType {
  10. code_element = 0,
  11. code_block, // 括号
  12. };
  13. /* 括号类型 */
  14. enum af_BlockType {
  15. parentheses = '(', // 小括号
  16. brackets = '[', // 中括号
  17. curly = '{', // 大括号
  18. };
  19. /* 代码块 创建与释放 */
  20. AFUN_CORE_EXPORT af_Code *makeElementCode(char *var, char prefix, FileLine line, FilePath path);
  21. AFUN_CORE_EXPORT af_Code *makeBlockCode(enum af_BlockType type, af_Code *element, char prefix,
  22. FileLine line, FilePath path, af_Code **next);
  23. AFUN_CORE_EXPORT void freeAllCode(af_Code *bt);
  24. /* 代码块 相关操作 */
  25. AFUN_CORE_EXPORT af_Code *pushCode(af_Code **base, af_Code *next);
  26. AFUN_CORE_EXPORT af_Code *copyAllCode(af_Code *base, FilePath *path);
  27. AFUN_CORE_EXPORT af_Code *copyCode(af_Code *base, FilePath *path);
  28. AFUN_CORE_EXPORT bool writeAllCode(af_Code *bt, FilePath path);
  29. AFUN_CORE_EXPORT bool readAllCode(af_Code **bt, FilePath path);
  30. /* 代码块 属性访问 */
  31. AFUN_CORE_EXPORT af_Code *getCodeNext(af_Code *bt);
  32. AFUN_CORE_EXPORT af_Code *getCodeElement(af_Code *bt);
  33. AFUN_CORE_EXPORT char *codeToStr(af_Code *code, int n);
  34. AFUN_CORE_EXPORT enum af_CodeType getCodeType(af_Code *code);
  35. AFUN_CORE_EXPORT enum af_BlockType getCodeBlockType(af_Code *code);
  36. AFUN_CORE_EXPORT char getCodePrefix(af_Code *code);
  37. AFUN_CORE_EXPORT CodeInt getCodeEndCount(af_Code *code);
  38. AFUN_CORE_EXPORT char *getCodeElementData(af_Code *code);
  39. AFUN_CORE_EXPORT CodeInt getCodeElementCount(af_Code *code);
  40. #endif //AFUN_BYTECODE