env.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef AFUN_ENV
  2. #define AFUN_ENV
  3. #include "aFunCoreExport.h"
  4. #include "tool.h"
  5. #include "prefix_macro.h"
  6. typedef struct af_Environment af_Environment;
  7. typedef struct af_Message af_Message;
  8. typedef struct af_ErrorInfo af_ErrorInfo;
  9. typedef struct af_ImportInfo af_ImportInfo;
  10. typedef struct af_GuardianList af_GuardianList;
  11. /* 顶层消息处理器的处理函数 DLC */
  12. typedef void TopMsgProcessFunc(af_Message *msg, bool is_top, af_Environment *env);
  13. DEFINE_DLC_SYMBOL(TopMsgProcessFunc);
  14. typedef af_GuardianList *GuardianFunc(char *type, bool is_guard, void *data, af_Environment *env);
  15. DEFINE_DLC_SYMBOL(GuardianFunc);
  16. typedef void GuardianDestruct(char *type, void *data, af_Environment *env);
  17. DEFINE_DLC_SYMBOL(GuardianDestruct);
  18. enum GcRunTime {
  19. grt_always = 0, // 总是运行
  20. grt_count, // 累计式运行
  21. };
  22. #include "code.h"
  23. #include "object.h"
  24. #include "var.h"
  25. /* 运行环境 创建与释放 */
  26. AFUN_CORE_EXPORT af_Environment *makeEnvironment(enum GcRunTime grt);
  27. AFUN_CORE_EXPORT void freeEnvironment(af_Environment *env);
  28. /* 消息 创建与释放 */
  29. AFUN_CORE_EXPORT af_Message *makeMessage(char *type, size_t size);
  30. AFUN_CORE_EXPORT af_Message *freeMessage(af_Message *msg);
  31. AFUN_CORE_EXPORT bool freeMessageCount(size_t count, af_Message *msg);
  32. AFUN_CORE_EXPORT af_Message *makeNORMALMessage(af_Object *obj);
  33. AFUN_CORE_EXPORT af_Message *makeERRORMessage(char *type, char *error, af_Environment *env);
  34. AFUN_CORE_EXPORT af_Message *makeERRORMessageFormat(char *type, af_Environment *env, const char *format, ...);
  35. AFUN_CORE_EXPORT af_Message *makeIMPORTMessage(char *mark, af_Object *obj);
  36. /* ErrorInfo 创建与释放 */
  37. AFUN_CORE_EXPORT af_ErrorInfo *makeErrorInfo(char *type, char *error, char *note, FileLine line, FilePath path);
  38. AFUN_CORE_EXPORT void freeErrorInfo(af_ErrorInfo *ei);
  39. /* ImportInfo 创建与释放 */
  40. af_ImportInfo *makeImportInfo(char *mark, af_Object *obj);
  41. void freeImportInfo(af_ImportInfo *ii);
  42. /* 运行环境 相关操作 */
  43. AFUN_CORE_EXPORT void enableEnvironment(af_Environment *env);
  44. AFUN_CORE_EXPORT void setGcMax(int32_t max, af_Environment *env);
  45. AFUN_CORE_EXPORT void setGcRun(enum GcRunTime grt, af_Environment *env);
  46. AFUN_CORE_EXPORT char setPrefix(size_t name, char prefix, af_Environment *env);
  47. AFUN_CORE_EXPORT void setCoreStop(af_Environment *env);
  48. AFUN_CORE_EXPORT void setCoreExit(int exit_code, af_Environment *env);
  49. AFUN_CORE_EXPORT void setCoreNormal(af_Environment *env);
  50. /* 消息 相关操作 */
  51. AFUN_CORE_EXPORT void pushMessageUp(af_Message *msg, af_Environment *env);
  52. AFUN_CORE_EXPORT void *popMessageUpData(char *type, af_Environment *env);
  53. AFUN_CORE_EXPORT af_Message *popMessageUp(af_Environment *env);
  54. AFUN_CORE_EXPORT void *getMessageData(af_Message *msg);
  55. AFUN_CORE_EXPORT void pushMessageDown(af_Message *msg, af_Environment *env);
  56. AFUN_CORE_EXPORT af_Message *popMessageDown(char *type, af_Environment *env);
  57. AFUN_CORE_EXPORT af_Message *getFirstMessage(af_Environment *env);
  58. /* 环境变量 相关操作 */
  59. AFUN_CORE_EXPORT void setEnvVarData(char *name, char *data, af_Environment *env);
  60. AFUN_CORE_EXPORT void setEnvVarNumber(char *name, int32_t data, af_Environment *env);
  61. /* 顶层消息处理器 相关操作 */
  62. AFUN_CORE_EXPORT bool addTopMsgProcess(char *type, DLC_SYMBOL(TopMsgProcessFunc) func, af_Environment *env);
  63. /* 顶层消息处理器 相关操作 */
  64. AFUN_CORE_EXPORT bool addGuardian(char *type, bool always, size_t size, DLC_SYMBOL(GuardianFunc) func,
  65. DLC_SYMBOL(GuardianDestruct) destruct, void **pdata, af_Environment *env);
  66. AFUN_CORE_EXPORT bool popGuardian(char *type, af_Environment *env);
  67. /* LiteralRegex 相关操作 */
  68. AFUN_CORE_EXPORT bool pushLiteralRegex(char *pattern, char *func, bool in_protect, af_Environment *env);
  69. /* ErrorInfo 相关操作 */
  70. AFUN_CORE_EXPORT void fprintfErrorInfo(FILE *file, af_ErrorInfo *ei);
  71. AFUN_CORE_EXPORT void fprintfErrorInfoStderr(af_ErrorInfo *ei);
  72. AFUN_CORE_EXPORT void fprintfErrorInfoStdout(af_ErrorInfo *ei);
  73. /* ErrorBacktracking 相关操作 */
  74. AFUN_CORE_EXPORT void pushErrorBacktracking(FileLine line, FilePath file, char *note, af_ErrorInfo *ei);
  75. /* GuardianList 相关操作 */
  76. af_GuardianList **pushGuardianList(af_Object *func, af_GuardianList **pgl);
  77. /* 环境变量 属性访问 */
  78. AFUN_CORE_EXPORT char *findEnvVarData(char *name, af_Environment *env);
  79. /* 运行环境 属性访问 */
  80. AFUN_CORE_EXPORT char getPrefix(size_t name, af_Environment *env);
  81. AFUN_CORE_EXPORT af_Object *getBaseObject(char *name, af_Environment *env);
  82. AFUN_CORE_EXPORT af_VarSpace *getProtectVarSpace(af_Environment *env);
  83. AFUN_CORE_EXPORT int32_t getGcCount(af_Environment *env);
  84. AFUN_CORE_EXPORT int32_t getGcMax(af_Environment *env);
  85. AFUN_CORE_EXPORT enum GcRunTime getGcRun(af_Environment *env);
  86. AFUN_CORE_EXPORT af_Object *getCoreGlobal(af_Environment *env);
  87. AFUN_CORE_EXPORT af_Object *getGlobal(af_Environment *env);
  88. AFUN_CORE_EXPORT af_Object *getBelong(af_Environment *env);
  89. AFUN_CORE_EXPORT FilePath getActivityFile(af_Environment *env);
  90. AFUN_CORE_EXPORT FileLine getActivityLine(af_Environment *env);
  91. AFUN_CORE_EXPORT af_VarSpaceListNode *getRunVarSpaceList(af_Environment *env);
  92. AFUN_CORE_EXPORT int isCoreExit(af_Environment *env);
  93. AFUN_CORE_EXPORT bool getErrorStd(af_Environment *env);
  94. /* 消息 属性访问 */
  95. AFUN_CORE_EXPORT af_Object *getMsgNormalData(af_Message *msg);
  96. AFUN_CORE_EXPORT af_ErrorInfo *getMsgErrorInfo(af_Message *msg);
  97. AFUN_CORE_EXPORT af_ImportInfo *getMsgImportInfo(af_Message *msg);
  98. /* ErrorInfo 属性访问 */
  99. AFUN_CORE_EXPORT char *getErrorType(af_ErrorInfo *ei);
  100. AFUN_CORE_EXPORT char *getError(af_ErrorInfo *ei);
  101. /* ImportInfo 属性访问 */
  102. AFUN_CORE_EXPORT char *getImportMark(af_ImportInfo *ii);
  103. AFUN_CORE_EXPORT af_Object *getImportObject(af_ImportInfo *ii);
  104. #endif //AFUN_ENV