浏览代码

feat: 删除不必要的导出函数

SongZihuan 3 年之前
父节点
当前提交
70b0d9cac3

+ 243 - 0
include/core/README

@@ -0,0 +1,243 @@
+aFun-core 的导出函数
+==================
+此处记录了aFun-Core模块导出的所有函数, 以及对应结构体解释
+
+core_init:
+* aFunCoreInit 初始化 全局应用程序
+
+
+code:
+af_Code 表示语法结构
+af_BlockType 表示block类型的枚举体 (公开)
+因为需要af_Code不能轻易修改, 因此不完全公开
+
+创建与释放:
+* makeElementCode
+* makeBlockCode
+* freeAllCode
+
+相关操作:
+* connectCode  [不会修改现有代码的结构, 只是在末尾追加内容]
+* copyCode
+* writeAllCode
+* readAllCode
+* codeToStr
+
+属性访问:
+* getCodeNext
+* getCodeBlockElement
+* getCodeType  [未存在]
+* getCodeBlockType  [未存在]
+* getCodePrefix  [未存在]
+* getCodeEndCount  [未存在]
+* getCodeElementData  [未存在]
+* getCodeBlockType  [未存在]
+* getCodeBlockElements  [未存在]
+
+
+func.h
+af_ArgCodeList  表示参数计算表, 已经计算结果
+af_ArgList  表示参数赋值表
+af_FuncBody  函数体信息 [无访问的必要性]
+af_FuncInfo  函数信息 [无访问的必要性]
+
+创建与释放
+* makeArgCodeList
+* freeAllArgCodeList
+* makeArgList
+* freeAllArgList
+
+* makeCodeFuncBody
+* makeImportFuncBody
+* makeCFuncBody
+* makeDynamicFuncBody
+* freeFuncBody
+* freeAllFuncBody
+* makeFuncInfo
+* freeFuncInfo
+
+相关操作
+* pushArgCodeList
+* pushArgList
+* pushFuncBody  [未存在]
+* makeCFuncBodyToFuncInfo
+* makeCodeFuncBodyToFuncInfo
+* makeImportFuncBodyToFuncInfo
+* makeDynamicFuncBodyToFuncInfo
+
+属性访问
+* getArgCodeListNext  [未存在]
+* getArgListNext  [未存在]
+* getArgCodeListResult
+* getArgCodeListData
+* getArgCodeListRunInFunc  [未存在]
+
+
+gc.h
+GcList 记录自定义的gc链接信息 [无访问的必要性]
+
+创建与释放
+* makeGcList
+* freeAllGcList
+
+相关操作
+* pushGcList
+* gc_addObjectReference
+* gc_addVarReference
+* gc_addVarSpaceReference
+* gc_delObjectReference
+* gc_delVarReference
+* gc_delVarSpaceReference
+
+属性访问
+* gc_getObjectReference  [未存在]
+* gc_getVarReference  [未存在]
+* gc_getVarSpaceReference  [未存在]
+
+
+object.h
+af_Object 描述一个对象
+af_Inherit 描述继承关系
+af_ObjectAPI 描述API
+
+创建与释放
+* makeObject
+* makeInherit
+* freeAllInherit
+* makeObjectAPI
+* freeObjectAPI
+
+相关操作
+* objectSetAllowInherit
+* setObjectAttributes
+* addAPI
+* addAPIToObject
+* pushInherit  [未定义]
+
+属性访问
+* getObjectID  [未定义]
+* getObjectData
+* getObjectAPI   [未定义]
+* getBelongObject
+* getInherit  (副本) [未定义]
+* findObjectAttributes
+* checkPosterity
+* getInheritObject  [未定义]
+* getInheritVarSpace  [未定义]
+* findAPI
+* findObjectAPI
+* getAPICount  [未定义]
+
+
+parser.h
+af_Parser 描述解释器
+
+创建与释放:
+* makeParser
+* freeParser
+* makeParserByString
+* makeParserByFile
+* makeParserByStdin  [未定义]
+
+相关操作:
+* parserCode
+* initParser
+
+
+run.h
+相关操作:
+* iterCode
+
+var.h
+af_Var 描述一个变量
+af_VarSpace 描述一个变量空间
+af_VarSpaceListNode 描述变量空间链
+
+创建与释放:
+* makeVar
+* makeVarSpace
+* makeVarSpaceList
+* freeAllVarSpaceList
+* freeVarSpaceListCount
+
+相关操作
+* addVarNode
+* addVarToVarSpace
+* makeVarToVarSpace
+* addVarToVarSpaceList
+* makeVarToVarSpaceList
+* makeVarToProtectVarSpace
+* delVarFromVarSpace
+* delVarFromVarList
+* setVarToVarSpace
+* setVarToVarList
+* pushNewVarList
+* setVarPermison  [未定义]
+* setVarSpacePermison  [未定义]
+* setVarSpaceProtect  [未定义]
+
+属性访问
+* getVarNode  [未定义]
+* findVarFromVarSpace
+* findVarFromVarList
+* getVarSpaceFromList
+
+
+env.h
+af_Environment 描述运行环境
+af_Message 描述消息传递
+af_ErrorInfo 描述错误信息
+
+创建与释放
+* makeEnvironment
+* freeEnvironment
+* makeMessage
+* freeMessage
+* freeMessageCount
+* makeNORMALMessage
+* makeERRORMessage
+* makeERRORMessageFormate
+* makeErrorInfo
+* freeErrorInfo
+
+相关操作
+* enableEnvironment
+* setPrefix
+* addVarToProtectVarSpace
+* setCoreStop
+* setCoreExit
+* setCoreNormal
+* pushMessageUp
+* popMessageUpData
+* popMessageUp
+* pushMessageDown
+* popMessageDown
+* setEnvVar
+* addTopMsgProcess
+* pushLiteralRegex
+* fprintfErrorInfo
+* pushErrorBacktracking
+* setGcMax  [未定义]
+* setGcRun  [未定义]
+
+属性访问
+* getPrefix
+* getBaseObject
+* getProtectVarSpace
+* getMessageData
+* getFirstMessage
+* getCoreSttaus  [未定义]
+* getGcCount  [未定义]
+* getGcMax  [未定义]
+* getGcRun  [未定义]
+* getCoreGlobal  [未定义]
+* getGlobal (会涉及import)  [未定义]
+* getBelong  [未定义]
+* getActivityType  [未定义]
+* getActivityFile  [未定义]
+* getActivityLine  [未定义]
+* findEnvVar
+* getMsgNormalData  [未定义]
+* getMsgErrorInfo  [未定义]
+* getErrorType  [未定义]
+* getMsgError  [未定义]

+ 10 - 3
include/core/code.h

@@ -6,6 +6,13 @@
 #define CODE_STR_MAX_SIZE (50)
 typedef struct af_Code af_Code;
 
+typedef long CodeInt;  // Code uint
+
+enum af_CodeType {
+    code_element = 0,
+    code_block,  // 括号
+};
+
 /* 括号类型 */
 enum af_BlockType {
     parentheses = '(',  // 小括号
@@ -22,12 +29,12 @@ AFUN_CORE_EXPORT af_Code *makeBlockCode(enum af_BlockType type, af_Code *element
 AFUN_CORE_EXPORT void freeAllCode(af_Code *bt);
 
 /* 代码块操作函数 */
-AFUN_CORE_EXPORT af_Code *connectCode(af_Code **base, af_Code *next);
+AFUN_CORE_EXPORT af_Code *pushCode(af_Code **base, af_Code *next);
 AFUN_CORE_EXPORT af_Code *copyCode(af_Code *base, FilePath *path);
 
 /* 代码块属性获取函数 */
-AFUN_CORE_EXPORT bool getCodeBlockNext(af_Code *bt, af_Code **next);
-AFUN_CORE_EXPORT void printCode(af_Code *bt);
+AFUN_CORE_EXPORT af_Code *getCodeNext(af_Code *bt);
+AFUN_CORE_EXPORT af_Code *getCodeElement(af_Code *bt);
 AFUN_CORE_EXPORT char *codeToStr(af_Code *code, int n);
 
 /* 代码块IO函数 */

+ 5 - 8
include/core/env.h

@@ -21,15 +21,15 @@ enum GcRunTime {
 #include "object.h"
 #include "var.h"
 
-/* 前缀管理函数 */
-AFUN_CORE_EXPORT char getPrefix(size_t name, af_Environment *env);
-AFUN_CORE_EXPORT char setPrefix(size_t name, char prefix, af_Environment *env);
-
 /* 运行环境函数 */
 AFUN_CORE_EXPORT af_Environment *makeEnvironment(enum GcRunTime grt);
 AFUN_CORE_EXPORT void enableEnvironment(af_Environment *env);
 AFUN_CORE_EXPORT void freeEnvironment(af_Environment *env);
 
+/* 前缀管理函数 */
+AFUN_CORE_EXPORT char getPrefix(size_t name, af_Environment *env);
+AFUN_CORE_EXPORT char setPrefix(size_t name, char prefix, af_Environment *env);
+
 /* 保护空间管理函数 */
 AFUN_CORE_EXPORT bool addVarToProtectVarSpace(af_Var *var, af_Environment *env);
 AFUN_CORE_EXPORT af_Object *getBaseObject(char *name, af_Environment *env);
@@ -43,7 +43,6 @@ AFUN_CORE_EXPORT void setCoreNormal(af_Environment *env);
 /* 消息创建与释放函数 */
 AFUN_CORE_EXPORT af_Message *makeMessage(char *type, size_t size);
 AFUN_CORE_EXPORT af_Message *freeMessage(af_Message *msg);
-AFUN_CORE_EXPORT void freeAllMessage(af_Message *msg);
 AFUN_CORE_EXPORT bool freeMessageCount(size_t count, af_Message *msg);
 
 /* 消息管理函数 */
@@ -51,7 +50,6 @@ AFUN_CORE_EXPORT void pushMessageUp(af_Message *msg, af_Environment *env);
 AFUN_CORE_EXPORT void *popMessageUpData(char *type, af_Environment *env);
 AFUN_CORE_EXPORT af_Message *popMessageUp(af_Environment *env);
 AFUN_CORE_EXPORT void *getMessageData(af_Message *msg);
-AFUN_CORE_EXPORT void connectMessage(af_Message **base, af_Message *msg);
 
 /* 消息工具函数 */
 AFUN_CORE_EXPORT af_Message *makeNORMALMessage(af_Object *obj);
@@ -68,8 +66,7 @@ AFUN_CORE_EXPORT void setEnvVar(char *name, char *data, af_Environment *env);
 AFUN_CORE_EXPORT char *findEnvVar(char *name, af_Environment *env);
 
 /* 顶层消息处理器管理函数 */
-AFUN_CORE_EXPORT void addTopMsgProcess(char *type, DLC_SYMBOL(TopMsgProcessFunc) func, af_Environment *env);
-AFUN_CORE_EXPORT bool changeTopMsgProcess(char *type, DLC_SYMBOL(TopMsgProcessFunc) func, af_Environment *env);
+AFUN_CORE_EXPORT bool addTopMsgProcess(char *type, DLC_SYMBOL(TopMsgProcessFunc) func, af_Environment *env);
 
 /* LiteralRegex操作函数 */
 AFUN_CORE_EXPORT bool pushLiteralRegex(char *pattern, char *func, bool in_protect, af_Environment *env);

+ 8 - 13
include/core/func.h

@@ -5,10 +5,6 @@ typedef struct af_ArgList af_ArgList;
 typedef struct af_FuncInfo af_FuncInfo;
 typedef struct af_FuncBody af_FuncBody;
 
-#include "aFunCoreExport.h"
-#include "code.h"
-#include "object.h"
-
 enum af_FuncInfoScope {
     normal_scope = 0,
     inline_scope,
@@ -22,31 +18,30 @@ enum af_FuncInfoEmbedded {
     super_embedded,  // 超内嵌函数
 };
 
-typedef struct af_FuncBody *callFuncBody(void *make, af_Environment *env);
-DEFINE_DLC_SYMBOL(callFuncBody);
+#include "aFunCoreExport.h"
+#include "code.h"
+#include "object.h"
+
+typedef struct af_FuncBody *callFuncBody(void *mark, af_Environment *env);
+NEW_DLC_SYMBOL(callFuncBody, callFuncBody);
 
 /* af_ArgCodeList 创建与释放 */
 AFUN_CORE_EXPORT af_ArgCodeList *makeArgCodeList(af_Code *code, size_t size, bool free_code, bool run_in_func);
-AFUN_CORE_EXPORT af_ArgCodeList *freeArgCodeList(af_ArgCodeList *acl);
 AFUN_CORE_EXPORT void freeAllArgCodeList(af_ArgCodeList *acl);
 
 /* af_ArgCodeList 操作函数 */
 AFUN_CORE_EXPORT af_ArgCodeList **pushArgCodeList(af_ArgCodeList **base, af_ArgCodeList *new);
-AFUN_CORE_EXPORT af_ArgCodeList **pushNewArgCodeList(af_ArgCodeList **base, af_Code *code, size_t size, bool free_code,
-                                                     bool run_in_func);
+
+/* af_ArgCodeList 属性获取 */
 AFUN_CORE_EXPORT void *getArgCodeListData(af_ArgCodeList *acl);
 AFUN_CORE_EXPORT af_Object *getArgCodeListResult(af_ArgCodeList *acl);
 
 /* af_ArgList 创建与释放 */
 AFUN_CORE_EXPORT af_ArgList *makeArgList(char *name, af_Object *obj);
-AFUN_CORE_EXPORT af_ArgList *freeArgList(af_ArgList *al);
 AFUN_CORE_EXPORT void freeAllArgList(af_ArgList *al);
 
 /* af_ArgList 操作函数 */
 AFUN_CORE_EXPORT af_ArgList **pushArgList(af_ArgList **base, af_ArgList *new);
-AFUN_CORE_EXPORT af_ArgList **pushNewArgList(af_ArgList **base, char *name, af_Object *obj);
-
-AFUN_CORE_EXPORT bool runArgList(af_ArgList *al, af_VarSpaceListNode *vsl, af_Environment *env);
 
 /* FuncBody 创建与释放 */
 AFUN_CORE_EXPORT af_FuncBody *makeCodeFuncBody(af_Code *code, bool free_code, char **msg_type);

+ 3 - 11
include/core/gc.h

@@ -5,7 +5,6 @@
 #include "var.h"
 
 typedef struct af_GcList af_GcList;
-typedef struct gc_DestructList gc_DestructList;
 enum af_GcListType {
     glt_obj = 1,
     glt_vs,
@@ -24,17 +23,13 @@ enum af_GcListType {
                                af_Var *: gc_delVarReference, \
                                af_VarSpace *: gc_delVarSpaceReference))(obj))
 
-/* gc_DestructList 释放函数*/
-AFUN_CORE_EXPORT void freeAllDestructList(gc_DestructList *dl);
+/* GcList 创建与释放 */
+AFUN_CORE_EXPORT af_GcList *makeGcList(enum af_GcListType type, void *data);
+AFUN_CORE_EXPORT void freeAllGcList(af_GcList *gl);
 
 /* GcList 操作函数 */
 AFUN_CORE_EXPORT af_GcList *pushGcList(enum af_GcListType type, void *data, af_GcList *base);
 
-/* gc 对象新增函数 */
-AFUN_CORE_EXPORT void gc_addObject(af_Object *obj, af_Environment *env);
-AFUN_CORE_EXPORT void gc_addVar(af_Var *obj, af_Environment *env);
-AFUN_CORE_EXPORT void gc_addVarSpace(af_VarSpace *obj, af_Environment *env);
-
 /* gc Reference 管理函数 */
 AFUN_CORE_EXPORT void gc_addObjectReference(af_Object *obj);
 AFUN_CORE_EXPORT void gc_addVarReference(af_Var *obj);
@@ -43,7 +38,4 @@ AFUN_CORE_EXPORT void gc_delObjectReference(af_Object *obj);
 AFUN_CORE_EXPORT void gc_delVarReference(af_Var *obj);
 AFUN_CORE_EXPORT void gc_delVarSpaceReference(af_VarSpace *obj);
 
-/* gc 运行时函数 */
-AFUN_CORE_EXPORT void resetGC(af_Environment *env);
-
 #endif //AFUN_GC

+ 2 - 3
include/core/object.h

@@ -17,7 +17,6 @@ DEFINE_DLC_SYMBOL(objectAPIFunc);
 /* 对象创建与释放函数 */
 AFUN_CORE_EXPORT af_Object *makeObject(char *id, bool free_api, af_ObjectAPI *api, bool allow_inherit, af_Object *belong,
                       af_Inherit *inherit, af_Environment *env);
-AFUN_CORE_EXPORT void freeObject(af_Object *obj, af_Environment *env);
 
 /* 对象属性获取函数 */
 AFUN_CORE_EXPORT void *getObjectData(af_Object *obj);
@@ -30,8 +29,8 @@ AFUN_CORE_EXPORT bool setObjectAttributes(char *name, char p_self, char p_poster
 
 /* 对象继承关系函数 */
 AFUN_CORE_EXPORT af_Inherit *makeInherit(af_Object *obj);
-AFUN_CORE_EXPORT af_Inherit *freeInherit(af_Inherit *ih);
 AFUN_CORE_EXPORT void freeAllInherit(af_Inherit *ih);
+
 AFUN_CORE_EXPORT bool checkPosterity(af_Object *base, af_Object *posterity);
 
 /* API表 创建与释放 */
@@ -43,6 +42,6 @@ AFUN_CORE_EXPORT int addAPI(DLC_SYMBOL(objectAPIFunc) func, char *api_name, af_O
 AFUN_CORE_EXPORT void *findAPI(char *api_name, af_ObjectAPI *api);
 
 /* 对象API函数 */
-AFUN_CORE_EXPORT void *findObjectAPI(char *api_name, af_Object *obj);
 AFUN_CORE_EXPORT int addAPIToObject(DLC_SYMBOL(objectAPIFunc) func, char *api_name, af_Object *obj);
+AFUN_CORE_EXPORT void *findObjectAPI(char *api_name, af_Object *obj);
 #endif //AFUN_OBJECT

+ 0 - 2
include/core/parser.h

@@ -17,8 +17,6 @@ AFUN_CORE_EXPORT af_Parser *makeParserByFile(FilePath path, FILE *error);
 
 /* Parser 操作函数 */
 AFUN_CORE_EXPORT af_Code *parserCode(af_Parser *parser);
-AFUN_CORE_EXPORT af_TokenType getTokenFromLexical(char **text, af_Parser *parser);
-AFUN_CORE_EXPORT void *getParserData(af_Parser *parser);
 AFUN_CORE_EXPORT void initParser(af_Parser *parser);
 
 #endif //AFUN_PARSER_H

+ 0 - 1
include/core/run.h

@@ -6,5 +6,4 @@
 
 /* 代码运行工具 */
 AFUN_CORE_EXPORT bool iterCode(af_Code *code, af_Environment *env);
-AFUN_CORE_EXPORT bool iterDestruct(int deep, af_Environment *env);
 #endif //AFUN_RUN_H

+ 0 - 4
include/core/var.h

@@ -11,14 +11,12 @@ typedef struct af_VarSpaceListNode af_VarSpaceListNode;
 
 /* 变量创建与释放 */
 AFUN_CORE_EXPORT af_Var *makeVar(char *name, char p_self, char p_posterity, char p_external, af_Object *obj, af_Environment *env);
-AFUN_CORE_EXPORT void freeVar(af_Var *var, af_Environment *env);
 
 /* 变量值管理 */
 AFUN_CORE_EXPORT void addVarNode(af_Var var, af_Object *obj, char *id);
 
 /* 变量空间创建与释放 */
 AFUN_CORE_EXPORT af_VarSpace *makeVarSpace(af_Object *belong, char p_self, char p_posterity, char p_external, af_Environment *env);
-AFUN_CORE_EXPORT void freeVarSpace(af_VarSpace *vs, af_Environment *env);
 
 /* 变量定义函数 */
 AFUN_CORE_EXPORT bool addVarToVarSpace(af_Var *var, af_Object *visitor, af_VarSpace *vs);
@@ -44,7 +42,6 @@ AFUN_CORE_EXPORT bool setVarToVarList(char *name, af_Object *obj, af_Object *vis
 
 /* 变量空间链的创建与释放 */
 AFUN_CORE_EXPORT af_VarSpaceListNode *makeVarSpaceList(af_VarSpace *vs);
-AFUN_CORE_EXPORT af_VarSpaceListNode *freeVarSpaceList(af_VarSpaceListNode *vsl);
 AFUN_CORE_EXPORT void freeAllVarSpaceList(af_VarSpaceListNode *vsl);
 AFUN_CORE_EXPORT bool freeVarSpaceListCount(size_t count, af_VarSpaceListNode *vsl);
 
@@ -53,6 +50,5 @@ AFUN_CORE_EXPORT af_VarSpace *getVarSpaceFromList(af_VarSpaceListNode *vsl);
 
 /* 变量空间链管理 */
 AFUN_CORE_EXPORT af_VarSpaceListNode *pushNewVarList(af_Object *belong, af_VarSpaceListNode *base, af_Environment *env);
-AFUN_CORE_EXPORT af_VarSpaceListNode *popLastVarList(af_VarSpaceListNode *base);
 
 #endif //AFUN_VAR

+ 1 - 0
include/tool/str.h

@@ -18,6 +18,7 @@
 AFUN_TOOL_EXPORT char *charToStr(char ch);
 AFUN_TOOL_EXPORT char *strCopy(const char *str);
 AFUN_TOOL_EXPORT wchar_t *wstrCopy(const wchar_t *str);
+AFUN_TOOL_EXPORT wchar_t *wstrExpansion(wchar_t *str, size_t size, bool free_old);
 AFUN_TOOL_EXPORT char *strJoin(char *first, char *second, bool free_first, bool free_last);
 AFUN_TOOL_EXPORT char *strJoin_(char *first, char *second, bool free_first, bool free_last);
 AFUN_TOOL_EXPORT wchar_t *wstrJoin(wchar_t *first, wchar_t *second, bool free_first, bool free_last);

+ 2 - 10
src/core/__code.h

@@ -8,25 +8,17 @@
 #include "tool.h"
 #include "code.h"
 
-typedef unsigned int CodeUint;  // Code uint
-
-enum af_CodeType {
-    code_element = 0,
-    code_block,  // 括号
-};
-
-
 struct af_Code {  // 一个 Code 的结构体
     enum af_CodeType type;
     char prefix;  // 前缀
-    CodeUint code_end;  // 记录block的end
+    CodeInt code_end;  // 记录block的end
     union {
         struct {
             char *data;
         } element;
 
         struct {
-            CodeUint elements;  // 元素个数
+            CodeInt elements;  // 元素个数 (主要作用是检查是否为空)
             enum af_BlockType type;  // 括号类型
         } block;
     };

+ 5 - 0
src/core/__env.h

@@ -234,4 +234,9 @@ AFUN_CORE_NO_EXPORT bool checkLiteralCode(char *literal, char **func, bool *in_p
 /* 顶层消息处理器 处理函数 */
 AFUN_CORE_NO_EXPORT void runTopMessageProcess(bool is_gc, af_Environment *env);
 
+/* 消息创建与释放函数 */
+AFUN_CORE_NO_EXPORT void freeAllMessage(af_Message *msg);
+
+/* 消息管理函数 */
+AFUN_CORE_NO_EXPORT void connectMessage(af_Message **base, af_Message *msg);
 #endif //AFUN_ENV_H_

+ 3 - 3
src/core/__func.h

@@ -24,9 +24,6 @@ struct af_ArgList {
     struct af_ArgList *next;
 };
 
-typedef struct af_FuncBody *callFuncBody(void *mark, af_Environment *env);
-NEW_DLC_SYMBOL(callFuncBody, callFuncBody);
-
 struct af_FuncBody {
     enum af_FuncBodyType {
         func_body_c = 0,  // 回调C函数
@@ -63,4 +60,7 @@ struct af_FuncInfo {
 /* FuncInfo 操作函数 */
 AFUN_CORE_NO_EXPORT bool pushDynamicFuncBody(af_FuncBody *new, af_FuncBody *body);
 
+/* ArgList 操作函数 */
+AFUN_CORE_NO_EXPORT bool runArgList(af_ArgList *al, af_VarSpaceListNode *vsl, af_Environment *env);
+
 #endif //AFUN_FUNC_H_

+ 14 - 7
src/core/__gc.h

@@ -91,19 +91,20 @@ struct gc_DestructList {
                                af_Var *: gc_delVarReference, \
                                af_VarSpace *: gc_delVarSpaceReference))(obj))
 
-/* gc 对象新增函数 : 涉及af_ObjectData 不对外公开 */
+/* gc 对象新增函数 */
+AFUN_CORE_NO_EXPORT void gc_addObject(af_Object *obj, af_Environment *env);
+AFUN_CORE_NO_EXPORT void gc_addVar(af_Var *obj, af_Environment *env);
+AFUN_CORE_NO_EXPORT void gc_addVarSpace(af_VarSpace *obj, af_Environment *env);
 AFUN_CORE_NO_EXPORT void gc_addObjectData(struct af_ObjectData *obj, af_Environment *env);
-
-/* gc Reference 管理函数 : 涉及af_ObjectData 不对外公开 */
-AFUN_CORE_NO_EXPORT void gc_addObjectDataReference(af_ObjectData *obj);
-AFUN_CORE_NO_EXPORT void gc_delObjectDataReference(af_ObjectData *obj);
-
-/* gc 对象新增函数 : 涉及af_Core不对外公开 */
 AFUN_CORE_NO_EXPORT void gc_addObjectDataByCore(struct af_ObjectData *obj, af_Core *core);
 AFUN_CORE_NO_EXPORT void gc_addObjectByCore(struct af_Object *obj, af_Core *core);
 AFUN_CORE_NO_EXPORT void gc_addVarByCore(struct af_Var *obj, af_Core *core);
 AFUN_CORE_NO_EXPORT void gc_addVarSpaceByCore(struct af_VarSpace *obj, af_Core *core);
 
+/* gc Reference 管理函数 : 涉及af_ObjectData 不对外公开 */
+AFUN_CORE_NO_EXPORT void gc_addObjectDataReference(af_ObjectData *obj);
+AFUN_CORE_NO_EXPORT void gc_delObjectDataReference(af_ObjectData *obj);
+
 /* gc 操控函数 : gc的启动由解释器完全管理 */
 AFUN_CORE_NO_EXPORT void gc_RunGC(af_Environment *env);
 AFUN_CORE_NO_EXPORT pgc_DestructList checkAllDestruct(af_Environment *env, pgc_DestructList pdl);
@@ -112,4 +113,10 @@ AFUN_CORE_NO_EXPORT void gc_freeAllValue(af_Environment *env);
 /* gc 信息函数 */
 AFUN_CORE_NO_EXPORT void printGCByCode(af_Core *core);
 
+/* gc_DestructList 释放函数*/
+AFUN_CORE_NO_EXPORT void freeAllDestructList(gc_DestructList *dl);
+
+/* gc 运行时函数 */
+AFUN_CORE_NO_EXPORT void resetGC(af_Environment *env);
+
 #endif //AFUN_GC_H_

+ 3 - 0
src/core/__object.h

@@ -59,6 +59,9 @@ struct af_Inherit {
     struct af_Inherit *next;
 };
 
+/* 对象创建与释放函数 */
+AFUN_CORE_NO_EXPORT void freeObject(af_Object *obj, af_Environment *env);
+
 /* ObjectData 属性获取函数 */
 AFUN_CORE_NO_EXPORT af_Object *findObjectAttributesByObjectData(char *name, af_Object *visitor, af_ObjectData *od);
 

+ 3 - 0
src/core/__parser.h

@@ -60,4 +60,7 @@ struct af_Syntactic {
     char *text;
 };
 
+/* Parser 操作函数 */
+AFUN_CORE_EXPORT af_TokenType getTokenFromLexical(char **text, af_Parser *parser);
+
 #endif //AFUN_PARSER_H_

+ 7 - 0
src/core/__run.h

@@ -0,0 +1,7 @@
+#ifndef AFUN_RUN_H_
+#define AFUN_RUN_H_
+#include "run.h"
+
+AFUN_CORE_NO_EXPORT bool iterDestruct(int deep, af_Environment *env);
+
+#endif //AFUN_RUN_H_

+ 3 - 0
src/core/__var.h

@@ -42,12 +42,15 @@ struct af_VarSpaceListNode {  // 变量链
     struct af_VarSpaceListNode *next;
 };
 
+
 /* 变量空间创建与释放 */
 AFUN_CORE_NO_EXPORT af_VarSpace *makeVarSpaceByCore(af_Object *belong, char p_self, char p_posterity, char p_external, af_Core *core);
+AFUN_CORE_NO_EXPORT void freeVarSpace(af_VarSpace *vs, af_Environment *env);
 AFUN_CORE_NO_EXPORT void freeVarSpaceByCore(af_VarSpace *vs, af_Core *core);
 
 /* 变量创建与释放 */
 AFUN_CORE_NO_EXPORT af_Var *makeVarByCore(char *name, char p_self, char p_posterity, char p_external, af_Object *obj, af_Core *core);
+AFUN_CORE_NO_EXPORT void freeVar(af_Var *var, af_Environment *env);
 AFUN_CORE_NO_EXPORT void freeVarByCore(af_Var *var, af_Core *core);
 
 #endif //AFUN_VAR_H_

+ 33 - 27
src/core/code.c

@@ -14,7 +14,7 @@ static af_Code *makeCode(char prefix, FileLine line, FilePath path);
 static af_Code *freeCode(af_Code *bt);
 
 /* Code 操作函数 */
-static bool countElement(af_Code *element, CodeUint *elements, af_Code **next);
+static bool countElement(af_Code *element, CodeInt *elements, af_Code **next);
 
 /* Code IO函数 */
 static bool readCode(af_Code **bt, FILE *file);
@@ -26,8 +26,8 @@ struct af_BlockEnd {
     struct af_BlockEnd *next;
 };
 static bool checkElementData(char *data);
-static char *codeToStr_(af_Code *code, CodeUint *layer, struct af_BlockEnd **bn);
-static char *codeEndToStr(CodeUint code_end, CodeUint *layer, struct af_BlockEnd **bn);
+static char *codeToStr_(af_Code *code, CodeInt *layer, struct af_BlockEnd **bn);
+static char *codeEndToStr(CodeInt code_end, CodeInt *layer, struct af_BlockEnd **bn);
 
 static af_Code *makeCode(char prefix, FileLine line, FilePath path) {
     af_Code *bt = calloc(1, sizeof(af_Code));
@@ -52,8 +52,8 @@ af_Code *makeElementCode(char *var, char prefix, FileLine line, FilePath path) {
  * 函数名: countElement
  * 目标: 统计元素个数(不包括元素的子元素)
  */
-static bool countElement(af_Code *element, CodeUint *elements, af_Code **next) {
-    CodeUint layer = 0;
+static bool countElement(af_Code *element, CodeInt *elements, af_Code **next) {
+    CodeInt layer = 0;
 
     for (*elements = 0; element != NULL; *next = element, element = element->next) {
         if (layer == 0)
@@ -72,7 +72,7 @@ static bool countElement(af_Code *element, CodeUint *elements, af_Code **next) {
 af_Code *makeBlockCode(enum af_BlockType type, af_Code *element, char prefix, FileLine line, FilePath path, af_Code **next) {
     af_Code *bt = NULL;
     af_Code *tmp = NULL;  // 保存最后一个code的地址
-    CodeUint elements = 0;
+    CodeInt elements = 0;
 
     if (next == NULL)
         next = &tmp;
@@ -93,7 +93,7 @@ af_Code *makeBlockCode(enum af_BlockType type, af_Code *element, char prefix, Fi
     return bt;
 }
 
-af_Code *connectCode(af_Code **base, af_Code *next) {
+af_Code *pushCode(af_Code **base, af_Code *next) {
     while ((*base) != NULL)
         base = &((*base)->next);
     *base = next;
@@ -153,23 +153,29 @@ void freeAllCode(af_Code *bt) {
         bt = freeCode(bt);
 }
 
-bool getCodeBlockNext(af_Code *bt, af_Code **next) {
-    if (bt->block.elements == 0) {
-        *next = bt->next;
-        return true;
+af_Code *getCodeNext(af_Code *bt) {
+    if (bt->type == code_element || bt->block.elements == 0) {
+        return bt->next;
     }
 
-    CodeUint count = 1;
-    bt = bt->next;
-    for (NULL; count > 0; bt = bt->next) {
-        if (bt == NULL)
-            return false;
-        if (bt->type == code_block)
-            count++;
-        count = count - bt->code_end;
+    CodeInt layer = 1;
+    bt = bt->next;  // 跳过第一个code_block
+    while (layer > 0) {
+        if (bt->type == code_block && bt->block.elements != 0)
+            layer++;
+        layer = layer - bt->code_end;
+        bt = bt->next;
     }
-    *next = bt;
-    return true;
+
+    if (layer == 0)  // 当layer小于0时, 认为已经无next, 即连续跳出了多层
+        return bt;
+    return NULL;
+}
+
+af_Code *getCodeElement(af_Code *bt) {
+    if (bt->type == code_element || bt->block.elements == 0)
+        return NULL;
+    return bt->next;
 }
 
 #define Done(write) do{if(!(write)){return false;}}while(0)
@@ -290,7 +296,7 @@ static bool checkElementData(char *data) {
  * 函数名: codeEndToStr
  * 目标: 转换element或开括号为字符串
  */
-static char *codeToStr_(af_Code *code, CodeUint *layer, struct af_BlockEnd **bn) {
+static char *codeToStr_(af_Code *code, CodeInt *layer, struct af_BlockEnd **bn) {
     char *re = charToStr(code->prefix);
     if (code->type == code_element) {
         if (checkElementData(code->element.data)) {  // 需要|xx xx|语法
@@ -344,7 +350,7 @@ static char *codeToStr_(af_Code *code, CodeUint *layer, struct af_BlockEnd **bn)
  * 函数名: codeEndToStr
  * 目标: 转换收尾括号为字符串
  */
-static char *codeEndToStr(CodeUint code_end, CodeUint *layer, struct af_BlockEnd **bn) {
+static char *codeEndToStr(CodeInt code_end, CodeInt *layer, struct af_BlockEnd **bn) {
     char *re = NEW_STR(code_end);
     for (size_t i = 0; code_end > 0; code_end--, i++) {
         if (*bn == NULL)
@@ -367,7 +373,7 @@ static char *codeEndToStr(CodeUint code_end, CodeUint *layer, struct af_BlockEnd
 char *codeToStr(af_Code *code, int n) {
     char *re = strCopy(NULL);
     struct af_BlockEnd *bn = NULL;
-    CodeUint layer = 0;
+    CodeInt layer = 0;
 
     for (NULL; code != NULL && layer >= 0 && (n > 0 || n == -1); code = code->next) {
         if (strlen(re) >= CODE_STR_MAX_SIZE) {
@@ -399,14 +405,14 @@ void printCode(af_Code *bt) {
         layer = layer - bt->code_end;
         switch (bt->type) {
             case code_element:
-                printf("element: [prefix (%c)] [end %d] [data '%s']\n", bt->prefix, bt->code_end, bt->element.data);
+                printf("element: [prefix (%c)] [end %ld] [data '%s']\n", bt->prefix, bt->code_end, bt->element.data);
                 break;
             case code_block:
                 layer++;
-                printf("code: [prefix (%c)] [end %d] [type %c] [elements %d]\n", bt->prefix, bt->code_end, bt->block.type, bt->block.elements);
+                printf("code: [prefix (%c)] [end %ld] [type %c] [elements %ld]\n", bt->prefix, bt->code_end, bt->block.type, bt->block.elements);
                 break;
             default:
-                printf("Unknown: [prefix (%c)] [end %d] [type %d]\n", bt->prefix, bt->code_end, bt->type);
+                printf("Unknown: [prefix (%c)] [end %ld] [type %d]\n", bt->prefix, bt->code_end, bt->type);
                 break;
         }
     }

+ 10 - 23
src/core/env.c

@@ -1,7 +1,7 @@
 #include "aFunCore.h"
 #include "__env.h"
 #include "__global_obj.h"
-#include "run.h"
+#include "__run.h"
 
 /* Core 创建和释放 */
 static af_Core *makeCore(enum GcRunTime grt);
@@ -645,20 +645,15 @@ static af_TopMsgProcess *findTopMsgProcessFunc(char *type, af_Environment *env)
     return NULL;
 }
 
-void addTopMsgProcess(char *type, DLC_SYMBOL(TopMsgProcessFunc) func,
+bool addTopMsgProcess(char *type, DLC_SYMBOL(TopMsgProcessFunc) func,
                       af_Environment *env) {
-    af_TopMsgProcess *mp = makeTopMsgProcess(type, func);
-    mp->next = env->process;
-    env->process = mp;
-}
-
-bool changeTopMsgProcess(char *type, DLC_SYMBOL(TopMsgProcessFunc) func,
-                         af_Environment *env) {
     af_TopMsgProcess *mp = findTopMsgProcessFunc(type, env);
-    if (mp == NULL)
+    if (mp != NULL)
         return false;
-    FREE_SYMBOL(mp->func);
-    mp->func = COPY_SYMBOL(func, TopMsgProcessFunc);
+
+    mp = makeTopMsgProcess(type, func);
+    mp->next = env->process;
+    env->process = mp;
     return true;
 }
 
@@ -702,11 +697,7 @@ static bool isInfixFunc(af_Code *code, af_Environment *env) {
 
 bool pushExecutionActivity(af_Code *bt, bool return_first, af_Environment *env) {
     af_Code *next;
-    if (!getCodeBlockNext(bt, &next)) {
-        pushMessageDown(makeERRORMessage(SYNTAX_ERROR, SYNTAX_ERROR_INFO"1", env), env);
-        return false;
-    }
-
+    next = getCodeNext(bt);
     if (bt->type != code_block || bt->block.elements == 0) {
         pushMessageDown(makeERRORMessage(SYNTAX_ERROR, NOT_CODE_INFO, env), env);
         return false;
@@ -728,11 +719,7 @@ bool pushFuncActivity(af_Code *bt, af_Environment *env) {
     af_Object *parentheses_call = env->activity->parentheses_call;
     env->activity->parentheses_call = NULL;
 
-    if (!getCodeBlockNext(bt, &next)) {
-        pushMessageDown(makeERRORMessage(SYNTAX_ERROR, SYNTAX_ERROR_INFO"2", env), env);
-        return false;
-    }
-
+    next = getCodeNext(bt);
     switch (bt->block.type) {
         case curly:
             if (bt->block.elements == 0) {
@@ -749,7 +736,7 @@ bool pushFuncActivity(af_Code *bt, af_Environment *env) {
                     func = code;
                     break;
                 }
-                if (!getCodeBlockNext(bt, &code))
+                if ((code = getCodeNext(bt)) == NULL)
                     break;
             }
             if (func == NULL) {

+ 2 - 16
src/core/func.c

@@ -19,7 +19,7 @@ af_ArgCodeList *makeArgCodeList(af_Code *code, size_t size, bool free_code, bool
     return acl;
 }
 
-af_ArgCodeList *freeArgCodeList(af_ArgCodeList *acl) {
+static af_ArgCodeList *freeArgCodeList(af_ArgCodeList *acl) {
     af_ArgCodeList *next = acl->next;
     free(acl->info);
     if (acl->free_code)
@@ -45,13 +45,6 @@ af_ArgCodeList **pushArgCodeList(af_ArgCodeList **base, af_ArgCodeList *new) {
     return base;
 }
 
-af_ArgCodeList **pushNewArgCodeList(af_ArgCodeList **base, af_Code *code, size_t size, bool free_code, bool run_in_func) {
-    while (*base != NULL)
-        base = &((*base)->next);
-    *base = makeArgCodeList(code, size, free_code, run_in_func);
-    return &((*base)->next);
-}
-
 void *getArgCodeListData(af_ArgCodeList *acl) {
     return acl->info;
 }
@@ -68,7 +61,7 @@ af_ArgList *makeArgList(char *name, af_Object *obj) {
     return arg_list;
 }
 
-af_ArgList *freeArgList(af_ArgList *al) {
+static af_ArgList *freeArgList(af_ArgList *al) {
     af_ArgList *next = al->next;
     free(al->name);
     if (al->obj != NULL)
@@ -92,13 +85,6 @@ af_ArgList **pushArgList(af_ArgList **base, af_ArgList *new) {
     return base;
 }
 
-af_ArgList **pushNewArgList(af_ArgList **base, char *name, af_Object *obj) {
-    while (*base != NULL)
-        base = &((*base)->next);
-    *base = makeArgList(name, obj);
-    return &((*base)->next);
-}
-
 bool runArgList(af_ArgList *al, af_VarSpaceListNode *vsl, af_Environment *env){
     for (NULL; al != NULL; al = al->next) {
         if (!makeVarToVarSpaceList(al->name, 3, 3, 3, al->obj, vsl,

+ 2 - 4
src/core/gc.c

@@ -71,11 +71,9 @@ static pgc_DestructList pushDestructList(af_ObjectData *od, af_Object *func, pgc
 
 /* gcList 函数 */
 /* gcList 创建与释放函数 */
-static af_GcList *makeGcList(enum af_GcListType type, void *data);
 static af_GcList *freeGcList(af_GcList *gl);
-static void freeAllGcList(af_GcList *gl);
 
-static af_GcList *makeGcList(enum af_GcListType type, void *data) {
+af_GcList *makeGcList(enum af_GcListType type, void *data) {
     af_GcList *gl = calloc(1, sizeof(af_GcList));
     gl->type = type;
     gl->data = data;
@@ -88,7 +86,7 @@ static af_GcList *freeGcList(af_GcList *gl) {
     return next;
 }
 
-static void freeAllGcList(af_GcList *gl) {
+void freeAllGcList(af_GcList *gl) {
     while (gl != NULL)
         gl = freeGcList(gl);
 }

+ 1 - 1
src/core/global_obj.c

@@ -10,7 +10,7 @@ static void initData(af_Object *obj, af_VarSpace **data, af_Environment *env) {
 }
 
 static void freeData(af_Object *obj, af_VarSpace **data, af_Environment *env) {
-    freeVarSpace(*data, env);
+    // 无操作
 }
 
 static af_GcList *getGcList(char *id, void *data) {

+ 1 - 1
src/core/object.c

@@ -151,7 +151,7 @@ af_Inherit *makeInherit(af_Object *obj) {
     return ih;
 }
 
-af_Inherit *freeInherit(af_Inherit *ih) {
+static af_Inherit *freeInherit(af_Inherit *ih) {
     af_Inherit *next = ih->next;  // vs一定是被gc托管的
     free(ih);
     return next;

+ 0 - 4
src/core/parser.c

@@ -29,10 +29,6 @@ void freeParser(af_Parser *parser) {
     free(parser);
 }
 
-void *getParserData(af_Parser *parser) {
-    return getReaderData(parser->reader);
-}
-
 void initParser(af_Parser *parser) {
     initReader(parser->reader);
 }

+ 1 - 1
src/core/run.c

@@ -1,7 +1,7 @@
 #include <assert.h>
 #include "aFunCore.h"
 
-#include "run.h"
+#include "__run.h"
 #include "__env.h"
 
 /* 工具函数: 初始化类型 */

+ 3 - 3
src/core/syntactic.c

@@ -152,7 +152,7 @@ static af_Code *codeList(size_t deep, af_Parser *parser) {
                 goBackToken(parser);
                 code_list = codePrefix(deep, parser);
                 if (code_list != NULL)
-                    pre = &(connectCode(pre, code_list)->next);
+                    pre = &(pushCode(pre, code_list)->next);
                 break;
 
             case TK_ELEMENT_SHORT:
@@ -163,7 +163,7 @@ static af_Code *codeList(size_t deep, af_Parser *parser) {
                 goBackToken(parser);
                 code_list = code(deep, NUL, parser);
                 if (code_list != NULL)
-                    pre = &(connectCode(pre, code_list)->next);
+                    pre = &(pushCode(pre, code_list)->next);
                 break;
             case TK_ERROR:
                 freeAllCode(re);
@@ -192,7 +192,7 @@ static af_Code *codeListEnd(af_Parser *parser) {
         case TK_LC:
             goBackToken(parser);
             code_list = codeList(0, parser);
-            connectCode(pre, code_list);
+            pushCode(pre, code_list);
 
             getToken(parser);
             switch (parser->syntactic->token) {

+ 1 - 5
src/core/var.c

@@ -146,7 +146,7 @@ af_VarSpaceListNode *makeVarSpaceList(af_VarSpace *vs) {
     return vsl;
 }
 
-af_VarSpaceListNode *freeVarSpaceList(af_VarSpaceListNode *vsl){
+static af_VarSpaceListNode *freeVarSpaceList(af_VarSpaceListNode *vsl){
     af_VarSpaceListNode *next = vsl->next;
     free(vsl);
     return next;
@@ -422,7 +422,3 @@ af_VarSpaceListNode *pushNewVarList(af_Object *belong, af_VarSpaceListNode *base
     new->next = base;
     return new;
 }
-
-af_VarSpaceListNode *popLastVarList(af_VarSpaceListNode *base) {
-    return freeVarSpaceList(base);
-}

+ 31 - 32
src/main.c

@@ -38,7 +38,6 @@ void initData3(af_Object *obj, af_VarSpace **data, af_Environment *env) {
 
 void freeData3(af_Object *obj, af_VarSpace **data, af_Environment *env) {
     printf("freeData(): *data = %p\n", *data);
-    freeVarSpace(*data, env);
 }
 
 af_GcList *getGcList3(char *id, void *data) {
@@ -878,14 +877,14 @@ int main() {
         printf("TAG A:\n");
         af_Code *bt1 = makeElementCode("object", 0, 1, "Unknown");
         af_Code *bt2 = makeElementCode("data", ',', 0, "Unknown");
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
-        connectCode(&bt2, bt5);
+        pushCode(&bt2, bt5);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -898,10 +897,10 @@ int main() {
 
         af_Code *bt3 = makeElementCode("func2", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
-        connectCode(&bt1, bt5);
+        pushCode(&bt1, bt5);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -913,11 +912,11 @@ int main() {
         printf("TAG B:\n");
         af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
         af_Code *bt2 = makeElementCode("object", 0, 1, NULL);
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
-        connectCode(&bt2, bt5);
+        pushCode(&bt2, bt5);
 
         iterCode(bt5, env);
         freeAllCode(bt1);
@@ -937,14 +936,14 @@ int main() {
         printf("TAG D:\n");
         af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         af_Code *bt5 = makeBlockCode(parentheses, NULL, 0, 1, NULL, NULL);
-        connectCode(&bt2, bt5);
+        pushCode(&bt2, bt5);
 
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -956,12 +955,12 @@ int main() {
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt3, bt4);
+        pushCode(&bt3, bt4);
 
         af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, NULL, NULL);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt5, env);
         freeAllCode(bt5);
@@ -973,12 +972,12 @@ int main() {
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt3, bt4);
+        pushCode(&bt3, bt4);
 
         af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, NULL, NULL);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt5, env);
         freeAllCode(bt5);
@@ -990,7 +989,7 @@ int main() {
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt3, bt4);
+        pushCode(&bt3, bt4);
 
         af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, NULL, NULL);
 
@@ -1004,7 +1003,7 @@ int main() {
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt3, bt4);
+        pushCode(&bt3, bt4);
 
         af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, NULL, NULL);
 
@@ -1020,10 +1019,10 @@ int main() {
 
         af_Code *bt4 = makeElementCode("func3", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt4, 0, 1, NULL, NULL);
-        connectCode(&bt3, bt5);
+        pushCode(&bt3, bt5);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt3, env);
         freeAllCode(bt3);
@@ -1034,7 +1033,7 @@ int main() {
         printf("TAG N:\n");
         af_Code *bt1 = makeElementCode("func4", 0, 1, NULL);
         af_Code *bt2 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1045,7 +1044,7 @@ int main() {
         printf("TAG O:\n");
         af_Code *bt1 = makeElementCode("func4", '\'', 1, NULL);
         af_Code *bt2 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1080,8 +1079,8 @@ int main() {
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt1, bt3);
-        connectCode(&bt3, bt4);
+        pushCode(&bt1, bt3);
+        pushCode(&bt3, bt4);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1095,7 +1094,7 @@ int main() {
         af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagR.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt1, bt3);
+        pushCode(&bt1, bt3);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1109,7 +1108,7 @@ int main() {
         af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "TagS.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt1, bt3);
+        pushCode(&bt1, bt3);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1123,7 +1122,7 @@ int main() {
         af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagX.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt1, bt3);
+        pushCode(&bt1, bt3);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1139,7 +1138,7 @@ int main() {
         af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "TagT.error.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt1, bt3);
+        pushCode(&bt1, bt3);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1151,10 +1150,10 @@ int main() {
         af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
 
         af_Code *bt5 = makeBlockCode(curly, NULL, 0, 1, NULL, NULL);
-        connectCode(&bt1, bt5);
+        pushCode(&bt1, bt5);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1166,7 +1165,7 @@ int main() {
         af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
         af_Code *bt2 = makeElementCode("object2", 0, 1, NULL);
 
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1179,7 +1178,7 @@ int main() {
         af_Code *bt2 = makeElementCode("func8", 0, 2, NULL);
         af_Code *bt1 = makeElementCode("global", 0, 1, "TagV.error.af");
 
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1193,7 +1192,7 @@ int main() {
         af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagW.error.af", NULL);
 
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt1, bt3);
+        pushCode(&bt1, bt3);
 
         iterCode(bt1, env);
         freeAllCode(bt1);

+ 14 - 0
src/tool/string.c

@@ -31,6 +31,20 @@ wchar_t *wstrCopy(const wchar_t *str){
     return tmp;
 }
 
+/*
+ * 函数名: wstrExpansion
+ * 目标: 把wstr复制到新的空间, 并拓展其大小
+ */
+wchar_t *wstrExpansion(wchar_t *str, size_t size, bool free_old) {
+    size_t base_len = WSTR_LEN(str);
+    wchar_t *tmp = NEW_WSTR(base_len + size);
+    if (base_len != 0)
+        wcscpy(tmp, str);
+    if (free_old)
+        free(str);
+    return tmp;
+}
+
 /*
  * 函数名: strJoin
  * 目标: 拼接两个字符串

+ 3 - 7
test/src/byte_code.c

@@ -9,11 +9,11 @@ int main() {
     af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
     af_Code *bt4 = makeElementCode("var2", 0, 1, NULL);
 
-    connectCode(&bt1, bt2);
-    connectCode(&bt3, bt4);
+    pushCode(&bt1, bt2);
+    pushCode(&bt3, bt4);
 
     af_Code *bt5 = makeBlockCode(parentheses, bt3, 0, 1, NULL, NULL);
-    connectCode(&bt2, bt5);
+    pushCode(&bt2, bt5);
 
     FILE *file = fopen("test.afb", "wb");
     if (file == NULL) {
@@ -40,10 +40,6 @@ int main() {
     }
     fclose(file);
 
-    printf("out:\n");
-    printCode(bt1);
-    printf("in:\n");
-    printCode(get);
     freeAllCode(bt1);
     freeAllCode(get);
     return EXIT_SUCCESS;

+ 0 - 1
test/src/env_init.c

@@ -25,7 +25,6 @@ void initData3(af_Object *obj, af_VarSpace **data, af_Environment *env) {
 
 void freeData3(af_Object *obj, af_VarSpace **data, af_Environment *env) {
     printf("freeData(): *data = %p\n", *data);
-    freeVarSpace(*data, env);
 }
 
 af_GcList *getGcList3(char *id, void *data) {

+ 1 - 0
test/src/lexical.c

@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include "aFun.h"
+#include "../../src/core/__parser.h"
 
 char *str = "Hello_var\n"
             "10 20.32 100var\n"

+ 31 - 32
test/src/run_code.c

@@ -38,7 +38,6 @@ void initData3(af_Object *obj, af_VarSpace **data, af_Environment *env) {
 
 void freeData3(af_Object *obj, af_VarSpace **data, af_Environment *env) {
     printf("freeData(): *data = %p\n", *data);
-    freeVarSpace(*data, env);
 }
 
 af_GcList *getGcList3(char *id, void *data) {
@@ -878,14 +877,14 @@ int main() {
         printf("TAG A:\n");
         af_Code *bt1 = makeElementCode("object", 0, 1, "Unknown");
         af_Code *bt2 = makeElementCode("data", ',', 0, "Unknown");
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
-        connectCode(&bt2, bt5);
+        pushCode(&bt2, bt5);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -898,10 +897,10 @@ int main() {
 
         af_Code *bt3 = makeElementCode("func2", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
-        connectCode(&bt1, bt5);
+        pushCode(&bt1, bt5);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -913,11 +912,11 @@ int main() {
         printf("TAG B:\n");
         af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
         af_Code *bt2 = makeElementCode("object", 0, 1, NULL);
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
-        connectCode(&bt2, bt5);
+        pushCode(&bt2, bt5);
 
         iterCode(bt5, env);
         freeAllCode(bt1);
@@ -937,14 +936,14 @@ int main() {
         printf("TAG D:\n");
         af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         af_Code *bt5 = makeBlockCode(parentheses, NULL, 0, 1, NULL, NULL);
-        connectCode(&bt2, bt5);
+        pushCode(&bt2, bt5);
 
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -956,12 +955,12 @@ int main() {
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt3, bt4);
+        pushCode(&bt3, bt4);
 
         af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, NULL, NULL);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt5, env);
         freeAllCode(bt5);
@@ -973,12 +972,12 @@ int main() {
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt3, bt4);
+        pushCode(&bt3, bt4);
 
         af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, NULL, NULL);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt5, env);
         freeAllCode(bt5);
@@ -990,7 +989,7 @@ int main() {
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt3, bt4);
+        pushCode(&bt3, bt4);
 
         af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, NULL, NULL);
 
@@ -1004,7 +1003,7 @@ int main() {
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt3, bt4);
+        pushCode(&bt3, bt4);
 
         af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, NULL, NULL);
 
@@ -1020,10 +1019,10 @@ int main() {
 
         af_Code *bt4 = makeElementCode("func3", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt4, 0, 1, NULL, NULL);
-        connectCode(&bt3, bt5);
+        pushCode(&bt3, bt5);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt3, env);
         freeAllCode(bt3);
@@ -1034,7 +1033,7 @@ int main() {
         printf("TAG N:\n");
         af_Code *bt1 = makeElementCode("func4", 0, 1, NULL);
         af_Code *bt2 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1045,7 +1044,7 @@ int main() {
         printf("TAG O:\n");
         af_Code *bt1 = makeElementCode("func4", '\'', 1, NULL);
         af_Code *bt2 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1080,8 +1079,8 @@ int main() {
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt1, bt3);
-        connectCode(&bt3, bt4);
+        pushCode(&bt1, bt3);
+        pushCode(&bt3, bt4);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1095,7 +1094,7 @@ int main() {
         af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagR.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt1, bt3);
+        pushCode(&bt1, bt3);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1109,7 +1108,7 @@ int main() {
         af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "TagS.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt1, bt3);
+        pushCode(&bt1, bt3);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1123,7 +1122,7 @@ int main() {
         af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagX.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt1, bt3);
+        pushCode(&bt1, bt3);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1139,7 +1138,7 @@ int main() {
         af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "TagT.error.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
-        connectCode(&bt1, bt3);
+        pushCode(&bt1, bt3);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1151,10 +1150,10 @@ int main() {
         af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
 
         af_Code *bt5 = makeBlockCode(curly, NULL, 0, 1, NULL, NULL);
-        connectCode(&bt1, bt5);
+        pushCode(&bt1, bt5);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt5, bt6);
+        pushCode(&bt5, bt6);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1166,7 +1165,7 @@ int main() {
         af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
         af_Code *bt2 = makeElementCode("object2", 0, 1, NULL);
 
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1179,7 +1178,7 @@ int main() {
         af_Code *bt2 = makeElementCode("func8", 0, 2, NULL);
         af_Code *bt1 = makeElementCode("global", 0, 1, "TagV.error.af");
 
-        connectCode(&bt1, bt2);
+        pushCode(&bt1, bt2);
 
         iterCode(bt1, env);
         freeAllCode(bt1);
@@ -1193,7 +1192,7 @@ int main() {
         af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagW.error.af", NULL);
 
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
-        connectCode(&bt1, bt3);
+        pushCode(&bt1, bt3);
 
         iterCode(bt1, env);
         freeAllCode(bt1);

+ 0 - 2
test/src/syntactic.c

@@ -21,7 +21,6 @@ int main() {
 void test1(void) {
     af_Parser *parser = makeParserByString(str, false, stderr);
     af_Code *code = parserCode(parser);
-    printCode(code);
     freeParser(parser);
     freeAllCode(code);
 }
@@ -42,7 +41,6 @@ void test2(void) {
 
     af_Parser *parser = makeParserByFile(path, stderr);
     af_Code *code = parserCode(parser);
-    printCode(code);
     freeParser(parser);
     freeAllCode(code);
 }