env.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef AFUN_ENV
  2. #define AFUN_ENV
  3. #include "aFunCoreExport.h"
  4. #include "tool.hpp"
  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, **paf_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(const char *type, bool is_guard, void *data, af_Environment *env);
  15. DEFINE_DLC_SYMBOL(GuardianFunc);
  16. typedef void GuardianDestruct(const 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.hpp"
  23. #include "object.hpp"
  24. #include "var.hpp"
  25. /* 运行环境 创建与释放 */
  26. AFUN_CORE_EXPORT af_Environment *makeEnvironment(enum GcRunTime grt);
  27. AFUN_CORE_EXPORT bool freeEnvironment(af_Environment *env);
  28. AFUN_CORE_EXPORT af_Environment *deriveEnvironment(bool derive_tmp, bool derive_guardian, bool derive_lr, bool enable,
  29. af_Environment *base);
  30. /* 消息 创建与释放 */
  31. AFUN_CORE_EXPORT af_Message *makeMessage(const char *type, size_t size);
  32. AFUN_CORE_EXPORT af_Message *freeMessage(af_Message *msg);
  33. AFUN_CORE_EXPORT bool freeMessageCount(size_t count, af_Message *msg);
  34. AFUN_CORE_EXPORT af_Message *makeNORMALMessage(af_Object *obj, af_Environment *env);
  35. AFUN_CORE_EXPORT af_Message *makeERRORMessage(const char *type, const char *error, af_Environment *env);
  36. AFUN_CORE_EXPORT af_Message *makeERRORMessageFormat(const char *type, af_Environment *env, const char *format, ...);
  37. AFUN_CORE_EXPORT af_Message *makeIMPORTMessage(const char *mark, af_Object *obj, af_Environment *env);
  38. /* ErrorInfo 创建与释放 */
  39. AFUN_CORE_EXPORT af_ErrorInfo *makeErrorInfo(const char *type, const char *error, const char *note, FileLine line, FilePath path);
  40. AFUN_CORE_EXPORT void freeErrorInfo(af_ErrorInfo *ei, af_Environment *env);
  41. /* ImportInfo 创建与释放 */
  42. af_ImportInfo *makeImportInfo(const char *mark, af_Object *obj, af_Environment *env);
  43. void freeImportInfo(af_ImportInfo *ii, af_Environment *env);
  44. /* 运行环境 相关操作 */
  45. AFUN_CORE_EXPORT void enableEnvironment(af_Environment *env);
  46. AFUN_CORE_EXPORT void setGcMax(int32_t max, af_Environment *env);
  47. AFUN_CORE_EXPORT void setGcRun(enum GcRunTime grt, af_Environment *env);
  48. AFUN_CORE_EXPORT char setPrefix(size_t name, char prefix, af_Environment *env);
  49. AFUN_CORE_EXPORT void setCoreStop(af_Environment *env);
  50. AFUN_CORE_EXPORT void setCoreExit(int exit_code, af_Environment *env);
  51. AFUN_CORE_EXPORT void setCoreExitNotExitCode(af_Environment *env);
  52. AFUN_CORE_EXPORT void setCoreNormal(af_Environment *env);
  53. AFUN_CORE_EXPORT void setArgc(int argc, af_Environment *env);
  54. AFUN_CORE_EXPORT void setEnviromentExit_out(af_Environment *env);
  55. AFUN_CORE_EXPORT void waitForEnviromentExit(af_Environment *env);
  56. /* 消息 相关操作 */
  57. AFUN_CORE_EXPORT void pushMessageUp(af_Message *msg, af_Environment *env);
  58. AFUN_CORE_EXPORT void *popMessageUpData(const char *type, af_Environment *env);
  59. AFUN_CORE_EXPORT af_Message *popMessageUp(af_Environment *env);
  60. AFUN_CORE_EXPORT void *getMessageData(af_Message *msg);
  61. AFUN_CORE_EXPORT void pushMessageDown(af_Message *msg, af_Environment *env);
  62. AFUN_CORE_EXPORT af_Message *popMessageDown(const char *type, af_Environment *env);
  63. AFUN_CORE_EXPORT af_Message *getFirstMessage(af_Environment *env);
  64. /* 环境变量 相关操作 */
  65. AFUN_CORE_EXPORT void setEnvVarData(const char *name, const char *data, af_Environment *env);
  66. AFUN_CORE_EXPORT void setEnvVarNumber(const char *name, int32_t data, af_Environment *env);
  67. /* 顶层消息处理器 相关操作 */
  68. AFUN_CORE_EXPORT bool addTopMsgProcess(const char *type, DLC_SYMBOL(TopMsgProcessFunc) func, af_Environment *env);
  69. /* 顶层消息处理器 相关操作 */
  70. AFUN_CORE_EXPORT bool addGuardian(const char *type, bool always, bool derive, size_t size, DLC_SYMBOL(GuardianFunc) func,
  71. DLC_SYMBOL(GuardianDestruct) destruct, void **pdata, af_Environment *env);
  72. AFUN_CORE_EXPORT bool popGuardian(const char *type, af_Environment *env);
  73. /* LiteralRegex 相关操作 */
  74. AFUN_CORE_EXPORT bool pushLiteralRegex(const char *pattern, const char *func, bool in_protect, af_Environment *env);
  75. /* ErrorInfo 相关操作 */
  76. AFUN_CORE_EXPORT void fprintfErrorInfo(FILE *file, af_ErrorInfo *ei);
  77. AFUN_CORE_EXPORT void fprintfErrorInfoStderr(af_ErrorInfo *ei);
  78. AFUN_CORE_EXPORT void fprintfErrorInfoStdout(af_ErrorInfo *ei);
  79. /* ErrorBacktracking 相关操作 */
  80. AFUN_CORE_EXPORT void pushErrorBacktracking(FileLine line, FilePath file, const char *note, af_ErrorInfo *ei);
  81. /* GuardianList 相关操作 */
  82. AFUN_CORE_EXPORT void pushGuardianList(af_Object *obj, af_Object *func, paf_GuardianList &pal, af_Environment *env);
  83. /* 环境变量 属性访问 */
  84. AFUN_CORE_EXPORT char *findEnvVarData(const char *name, af_Environment *env);
  85. AFUN_CORE_EXPORT int32_t *findEnvVarNumber(const char *name, af_Environment *env);
  86. /* 运行环境 属性访问 */
  87. AFUN_CORE_EXPORT char getPrefix(size_t name, af_Environment *env);
  88. AFUN_CORE_EXPORT af_Object *getBaseObject(const char *name, af_Environment *env);
  89. AFUN_CORE_EXPORT af_VarSpace *getProtectVarSpace(af_Environment *env);
  90. AFUN_CORE_EXPORT int32_t getGcCount(af_Environment *env);
  91. AFUN_CORE_EXPORT int32_t getGcMax(af_Environment *env);
  92. AFUN_CORE_EXPORT enum GcRunTime getGcRun(af_Environment *env);
  93. AFUN_CORE_EXPORT int getArgc(af_Environment *env);
  94. AFUN_CORE_EXPORT af_Object *getCoreGlobal(af_Environment *env);
  95. AFUN_CORE_EXPORT af_Object *getGlobal(af_Environment *env);
  96. AFUN_CORE_EXPORT af_Object *getBelong(af_Environment *env);
  97. AFUN_CORE_EXPORT FilePath getActivityFile(af_Environment *env);
  98. AFUN_CORE_EXPORT FileLine getActivityLine(af_Environment *env);
  99. AFUN_CORE_EXPORT af_VarList *getRunVarSpaceList(af_Environment *env);
  100. AFUN_CORE_EXPORT int isCoreExit(af_Environment *env);
  101. AFUN_CORE_EXPORT bool getErrorStd(af_Environment *env);
  102. AFUN_CORE_EXPORT int32_t getCoreExitCode(af_Environment *env);
  103. AFUN_CORE_EXPORT af_Object *getActivityFunc(af_Environment *env);
  104. AFUN_CORE_EXPORT bool isEnviromentExit(af_Environment *env);
  105. AFUN_CORE_EXPORT size_t getEnviromentSonCount(af_Environment *env);
  106. /* ErrorInfo 属性访问 */
  107. AFUN_CORE_EXPORT char *getErrorType(af_ErrorInfo *ei);
  108. AFUN_CORE_EXPORT char *getError(af_ErrorInfo *ei);
  109. /* ImportInfo 属性访问 */
  110. AFUN_CORE_EXPORT char *getImportMark(af_ImportInfo *ii);
  111. AFUN_CORE_EXPORT af_Object *getImportObject(af_ImportInfo *ii, af_Environment *env);
  112. #endif //AFUN_ENV