__env.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef AFUN__ENV_H
  2. #define AFUN__ENV_H
  3. #include "macro.h"
  4. #include "tool.h"
  5. typedef struct af_Core af_Core;
  6. typedef struct af_Activity af_Activity;
  7. typedef struct af_EnvVarSpace af_EnvVarSpace;
  8. typedef struct af_EnvVar af_EnvVar;
  9. typedef struct af_TopMsgProcess af_TopMsgProcess;
  10. #include "env.h"
  11. #include "__object.h"
  12. #include "__var.h"
  13. #include "__code.h"
  14. #include "__gc.h"
  15. #define ENV_VAR_HASH_SIZE (8)
  16. typedef uint16_t ActivityCount;
  17. typedef void TopMsgProcessFunc(af_Message *msg, af_Environment *env);
  18. NEW_DLC_SYMBOL(TopMsgProcessFunc, TopMsgProcessFunc);
  19. struct af_Core { // 解释器核心
  20. // GC基本信息
  21. struct af_ObjectData *gc_ObjectData;
  22. struct af_Object *gc_Object;
  23. struct af_Var *gc_Var;
  24. struct af_VarSpace *gc_VarSpace;
  25. // 基本对象信息
  26. struct af_Object *global; // 顶级属对象
  27. struct af_Object *object; // 顶级继承对象
  28. // 保护空间
  29. bool in_init; // 是否在初始化模式
  30. struct af_VarSpace *protect; // 顶级保护变量空间
  31. char prefix[PREFIX_SIZE]; // 前缀
  32. };
  33. struct af_Message {
  34. char *type; // 消息类型
  35. void *msg; // 信息内容
  36. size_t size;
  37. struct af_Message *next;
  38. };
  39. struct af_Activity { // 活动记录器
  40. struct af_Activity *prev; // 上一个活动记录器
  41. enum af_ActivityStatus {
  42. act_func = 0,
  43. act_arg,
  44. act_normal,
  45. } status;
  46. struct af_Message *msg_down; // 被调用者向调用者传递信息
  47. struct af_Message *msg_up; // 调用者向被调用者传递信息
  48. ActivityCount msg_up_count; // msg_up 添加的个数
  49. char **msg_type; // 一个包含字符串的列表, 记录了需要处理的`msg`类型的数组
  50. struct af_VarSpaceListNode *var_list; // 变量空间
  51. ActivityCount new_vs_count; // 需要释放的空间数
  52. struct af_Object *belong; // 属对象 (belong通常为func的belong)
  53. struct af_Object *func; // 函数本身
  54. struct af_Code *bt_top; // 最顶层设置为NULL, 函数调用设置为block, (bt_start的上一个元素)
  55. struct af_Code *bt_start; // 代码的起始位置 (block的第一个元素)
  56. struct af_Code *bt_next; // 指示代码下一步要运行的位置
  57. bool return_first; // 顺序执行, 获取第一个返回结果
  58. struct af_Object *return_obj; // 调用者向被调用者传递信息
  59. // 函数调用专项
  60. bool must_common_arg; // 强制普通参数
  61. bool not_strict; // 非严格调用
  62. };
  63. struct af_TopMsgProcess { // 顶层msg处理器
  64. char *type;
  65. DLC_SYMBOL(TopMsgProcessFunc) func; // 在 env.h 中定义
  66. struct af_TopMsgProcess *next;
  67. };
  68. struct af_EnvVar { // 环境变量
  69. char *name;
  70. char *data;
  71. struct af_EnvVar *next;
  72. };
  73. struct af_EnvVarSpace { // 环境变量
  74. struct af_EnvVar *(var[ENV_VAR_HASH_SIZE]);
  75. };
  76. struct af_Environment { // 运行环境
  77. struct af_Core *core;
  78. struct af_EnvVarSpace *esv;
  79. struct af_Activity *activity;
  80. struct af_TopMsgProcess *process;
  81. };
  82. af_Object *getBaseObjectFromCore(char *name, af_Core *core);
  83. bool pushExecutionActivity(af_Code *bt, bool return_first, af_Environment *env);
  84. bool pushFuncActivity(af_Code *bt, af_Environment *env);
  85. void popActivity(af_Message *msg, af_Environment *env);
  86. bool setFuncActivityToArg(af_Object *func, af_Environment *env);
  87. bool setFuncActivityAddVar(af_VarSpaceListNode *vsl, bool new_vsl, bool is_protect, char **msg_type, af_Environment *env);
  88. bool setFuncActivityToNormal(af_Code *bt, af_Environment *env);
  89. #endif //AFUN__ENV_H