Просмотр исходного кода

feat: 修改callFuncBody的签名

SongZihuan 3 лет назад
Родитель
Сommit
ea1a38e359

+ 15 - 1
include/core/func.h

@@ -22,7 +22,21 @@ enum af_FuncInfoEmbedded {
 #include "code.h"
 #include "object.h"
 
-typedef struct af_FuncBody *callFuncBody(void *mark, af_Environment *env);
+typedef struct CallFuncInfo CallFuncInfo;
+struct CallFuncInfo {
+    void *mark;
+    af_Object *belong;
+    af_Object *func;
+    struct af_VarSpaceListNode *var_list;
+
+    enum af_BlockType call_type;
+    bool is_gc_call;
+    bool is_literal;
+    bool is_obj_func;
+    bool is_macro_call;
+};
+
+typedef struct af_FuncBody *callFuncBody(CallFuncInfo *info, af_Environment *env);
 NEW_DLC_SYMBOL(callFuncBody, callFuncBody);
 
 /* af_ArgCodeList 创建与释放 */

+ 2 - 1
include/core/info/obj_api.h

@@ -21,7 +21,8 @@ typedef void objectAPIFunc();  // 位于object.h (所有Object API函数指针
 typedef void TopMsgProcessFunc(af_Message *msg, bool is_gc, af_Environment *env);  // 位于env.h
 
 /* 回调C函数 */
-typedef struct af_FuncBody *callFuncBody(void *mark, af_Environment *env);  // 位于env.h
+typedef struct CallFuncInfo CallFuncInfo;
+typedef struct af_FuncBody *callFuncBody(CallFuncInfo *info, af_Environment *env);  // 位于env.h
 
 /* 定义Object的函数签名 */
 /*

+ 17 - 1
src/core/env.c

@@ -1017,6 +1017,19 @@ bool setFuncActivityAddVar(af_Environment *env){
     return true;
 }
 
+static void initCallFuncInfo(CallFuncInfo *cfi, af_Environment *env) {
+    cfi->mark = env->activity->mark;
+    cfi->belong = env->activity->belong;
+    cfi->func = env->activity->func;
+    cfi->var_list = env->activity->var_list;  // 传var_list而非vsl
+
+    cfi->call_type = env->activity->call_type;
+    cfi->is_gc_call = env->activity->is_gc_call;
+    cfi->is_literal = env->activity->is_literal;
+    cfi->is_obj_func = env->activity->is_obj_func;
+    cfi->is_macro_call = env->activity->is_macro_call;
+}
+
 /*
  * 函数名: setFuncActivityToNormal
  * 目标: 获取下一步需要运行的结果
@@ -1038,7 +1051,10 @@ int setFuncActivityToNormal(af_Environment *env){  // 获取函数的函数体
     env->activity->body_next = body->next;
     switch (body->type) {
         case func_body_c: {
-            af_FuncBody *new = GET_SYMBOL(body->c_func)(env->activity->mark, env);
+            CallFuncInfo cfi;
+            initCallFuncInfo(&cfi, env);
+
+            af_FuncBody *new = GET_SYMBOL(body->c_func)(&cfi, env);
             activity->process_msg_first++;  // 处理C函数通过msg_down返回的结果
             pushDynamicFuncBody(new, body);
             activity->body_next = body->next;  // 添加新元素后要重新设定body_next的位置

+ 1 - 1
src/core/object.c

@@ -27,7 +27,7 @@ static af_ObjectData * makeObjectData_Pri(char *id, bool free_api, af_ObjectAPI
     af_ObjectData *od = calloc(1, sizeof(af_ObjectData));
     od->base = base_obj;
     base_obj->data = od;
-    od->id = strCopy(id == NULL ? "Unknow" : id);
+    od->id = strCopy(id == NULL ? "Unknown" : id);
 
     od->api = api;
     od->free_api = free_api;

+ 1 - 1
src/runtime/aFunTool/base/quit.c

@@ -33,7 +33,7 @@ static bool funcVarList(char *id, af_Object *obj, af_VarSpaceListNode **vsl, voi
     return true;
 }
 
-static af_FuncBody *funcBody(void *mark, af_Environment *env) {
+static af_FuncBody *funcBody(CallFuncInfo *cfi, af_Environment *env) {
     env->core->exit_code = 0;
     env->core->status = core_exit;
     pushMessageDown(makeNORMALMessage(getGlobal(env)), env);

+ 2 - 16
src/runtime/aFunTool/base/str_obj.c

@@ -50,17 +50,8 @@ static void strFuncInit(char *id, af_Object *obj, ObjectStrFunc *data, af_Enviro
     data->api = makeAPIFromList(api_list);
 }
 
-typedef struct strFuncMark strFuncMark;
-struct strFuncMark {
-    af_Object *obj;
-};
-
 static bool strFuncArgCodeList(char *id, af_Object *obj, af_ArgCodeList **acl, af_Code *code, void **mark, af_Environment *env) {
     *acl = NULL;
-    *mark = calloc(1, sizeof(strFuncMark));
-
-    strFuncMark *sfm = *mark;
-    sfm->obj = obj;
     return true;
 }
 
@@ -75,8 +66,8 @@ static bool strFuncVarList(char *id, af_Object *obj, af_VarSpaceListNode **vsl,
     return true;
 }
 
-static af_FuncBody *strFuncBody(strFuncMark *mark, af_Environment *env) {
-    af_Object *obj = mark->obj;
+static af_FuncBody *strFuncBody(CallFuncInfo *cfi, af_Environment *env) {
+    af_Object *obj = cfi->func;
     ObjectStrFunc *osf = getObjectData(obj);
     af_Object *str = makeObject((char *)string_id, false, osf->api, false, NULL, makeInherit(obj), env);
     af_Message *msg = makeNORMALMessage(str);
@@ -92,10 +83,6 @@ static bool strFuncGetInfo(char *id, af_Object *obj, af_FuncInfo **fi, af_Code *
     return true;
 }
 
-static void strFuncFreeMark(char *id, af_Object *obj, strFuncMark *mark) {
-    free(mark);
-}
-
 static void strFuncDestruct(char *id, af_Object *obj, ObjectStrFunc *data, af_Environment *env) {
     if (EQ_STR(id, string_func_id)) {
         freeObjectAPI(data->api);
@@ -112,7 +99,6 @@ void makeStrFunc(af_Object *visitor, af_VarSpace *vs, af_Environment *env) {
             {.name="obj_funcGetVarList", .func=strFuncVarList, .dlc=NULL},
             {.name="obj_funcGetArgList", .func=strFuncArgList, .dlc=NULL},
             {.name="obj_funcGetInfo", .func=strFuncGetInfo, .dlc=NULL},
-            {.name="obj_funcFreeMask", .func=strFuncFreeMark, .dlc=NULL},
             {.name=NULL}
     };
 

+ 1 - 1
test/export/main.c

@@ -77,7 +77,7 @@ void literalSet(char *str, void *data, af_Object *obj, af_Environment *env) {
     printf("literalSet(): str = %s\n", str);
 }
 
-af_FuncBody *testFunc(int *mark, af_Environment *env) {  // 测试用函数
+af_FuncBody *testFunc(CallFuncInfo *cfi, af_Environment *env) {  // 测试用函数
     printf("testFunc(): I am testFunc\n");
     af_Object *obj;
 

+ 23 - 23
test/src/run_code.c

@@ -76,7 +76,7 @@ void literalSet(char *id, af_Object *obj, void *data, char *str, af_Environment
     printf("literalSet(): str = %s\n", str);
 }
 
-af_FuncBody *testFunc(int *mark, af_Environment *env) {  // 测试用函数
+af_FuncBody *testFunc(CallFuncInfo *cfi, af_Environment *env) {  // 测试用函数
     printf("testFunc(): I am testFunc\n");
     af_Object *obj;
 
@@ -108,7 +108,7 @@ void freeMark(char *id, af_Object *obj, int *mark) {
     free(mark);
 }
 
-af_FuncBody *testFunc2(int *mark, af_Environment *env) {  // 测试用函数
+af_FuncBody *testFunc2(CallFuncInfo *cfi, af_Environment *env) {  // 测试用函数
     printf("testFunc2(): I am testFunc2\n");
     af_Object *obj;
 
@@ -173,7 +173,7 @@ bool getInfo3(char *id, af_Object *obj, af_FuncInfo **fi, af_Code *code, void *m
     return true;
 }
 
-af_FuncBody *testFunc4(int *mark, af_Environment *env) {  // 测试用函数
+af_FuncBody *testFunc4(CallFuncInfo *cfi, af_Environment *env) {  // 测试用函数
     printf("testFunc4(): I am testFunc4\n");
     af_Object *obj;
 
@@ -198,7 +198,7 @@ bool getInfo4(char *id, af_Object *obj, af_FuncInfo **fi, af_Code *code, void *m
     return true;
 }
 
-af_FuncBody *testFunc9(int *mark, af_Environment *env) {  // 测试用函数
+af_FuncBody *testFunc9(CallFuncInfo *cfi, af_Environment *env) {  // 测试用函数
     af_Object *obj;
     af_FuncBody *fb;
     obj = makeObject("obj", true, makeObjectAPI(), true, NULL, NULL, env);
@@ -222,7 +222,7 @@ bool getInfo9(char *id, af_Object *obj, af_FuncInfo **fi, af_Code *code, void *m
     return true;
 }
 
-af_FuncBody *testFunc8(int *mark, af_Environment *env) {  // 测试用函数
+af_FuncBody *testFunc8(CallFuncInfo *cfi, af_Environment *env) {  // 测试用函数
     af_Object *obj;
     obj = makeObject("obj", true, makeObjectAPI(), true, NULL, NULL, env);
     pushMessageDown(makeNORMALMessage(obj), env);
@@ -231,7 +231,7 @@ af_FuncBody *testFunc8(int *mark, af_Environment *env) {  // 测试用函数
     return NULL;
 }
 
-af_FuncBody *testFunc7(int *mark, af_Environment *env) {  // 测试用函数
+af_FuncBody *testFunc7(CallFuncInfo *cfi, af_Environment *env) {  // 测试用函数
     af_Object *obj;
     obj = makeObject("func", true, makeObjectAPI(), true, NULL, NULL, env);
     pushMessageDown(makeNORMALMessage(obj), env);
@@ -248,7 +248,7 @@ bool getInfo7(char *id, af_Object *obj, af_FuncInfo **fi, af_Code *code, void *m
     return true;
 }
 
-af_FuncBody *testFunc6(int *mark, af_Environment *env) {  // 测试用函数
+af_FuncBody *testFunc6(CallFuncInfo *cfi, af_Environment *env) {  // 测试用函数
     af_Object *obj;
     af_Object *des;
     obj = makeObject("func", true, makeObjectAPI(), true, NULL, NULL, env);
@@ -300,7 +300,7 @@ bool getInfo6(char *id, af_Object *obj, af_FuncInfo **fi, af_Code *code, void *m
     return true;
 }
 
-af_FuncBody *testFunc5(int *mark, af_Environment *env) {  // 测试用函数
+af_FuncBody *testFunc5(CallFuncInfo *cfi, af_Environment *env) {  // 测试用函数
     af_Object *obj;
     af_Object *des;
     obj = makeObject("func", true, makeObjectAPI(), true, NULL, NULL, env);
@@ -874,7 +874,7 @@ int main() {
 
     {  // 正常程序
         printf("TAG A:\n");
-        af_Code *bt1 = makeElementCode("object", 0, 1, "taga.aun");
+        af_Code *bt1 = makeElementCode("object", 0, 1, "Taga.aun");
         af_Code *bt2 = makeElementCode("data", ',', 0, NULL);
         pushCode(&bt1, bt2);
 
@@ -892,7 +892,7 @@ int main() {
 
     {  // 宏函数
         printf("TAG L:\n");
-        af_Code *bt1 = makeElementCode("object", 0, 1, "tagl.aun");
+        af_Code *bt1 = makeElementCode("object", 0, 1, "Tagl.aun");
 
         af_Code *bt3 = makeElementCode("func2", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
@@ -909,7 +909,7 @@ int main() {
 
     {  // 尾调递归优化
         printf("TAG B:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "tagb.aun");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagb.aun");
         af_Code *bt2 = makeElementCode("object", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
@@ -924,7 +924,7 @@ int main() {
 
     {  // 尾调递归优化2
         printf("TAG C:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "tagc.aun");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagc.aun");
 
         runCodeFromMemory(bt1, env);
         freeAllCode(bt1);
@@ -933,7 +933,7 @@ int main() {
 
     {  // 测试类前缀调用
         printf("TAG D:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "tagd.aun");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagd.aun");
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
@@ -956,7 +956,7 @@ int main() {
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, "tage.aun", NULL);
+        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, "Tage.aun", NULL);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
@@ -973,7 +973,7 @@ int main() {
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, "tagf.aun", NULL);
+        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, "Tagf.aun", NULL);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
@@ -990,7 +990,7 @@ int main() {
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, "tagg.aun", NULL);
+        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, "Tagg.aun", NULL);
 
         runCodeFromMemory(bt5, env);
         freeAllCode(bt5);
@@ -1004,7 +1004,7 @@ int main() {
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, "tagh.aun", NULL);
+        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, "Tagh.aun", NULL);
 
         runCodeFromMemory(bt5, env);
         freeAllCode(bt5);
@@ -1014,7 +1014,7 @@ int main() {
     {  // 双层尾调递归优化 (函数内调用函数)
         printf("TAG I:\n");
         af_Code *bt2 = makeElementCode("func3", 0, 1, NULL);
-        af_Code *bt3 = makeBlockCode(curly, bt2, 0, 1, "tagi.aun", NULL);
+        af_Code *bt3 = makeBlockCode(curly, bt2, 0, 1, "Tagi.aun", NULL);
 
         af_Code *bt4 = makeElementCode("func3", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt4, 0, 1, NULL, NULL);
@@ -1030,7 +1030,7 @@ int main() {
 
     {  // 对象函数的调用
         printf("TAG J:\n");
-        af_Code *bt1 = makeElementCode("func4", 0, 1, "tagj.aun");
+        af_Code *bt1 = makeElementCode("func4", 0, 1, "Tagj.aun");
         af_Code *bt2 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
@@ -1041,7 +1041,7 @@ int main() {
 
     {  // 变量引用调用
         printf("TAG K:\n");
-        af_Code *bt1 = makeElementCode("func4", '\'', 1, "tagk.aun");
+        af_Code *bt1 = makeElementCode("func4", '\'', 1, "Tagk.aun");
         af_Code *bt2 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
@@ -1052,7 +1052,7 @@ int main() {
 
     {  // 对象函数的调用 (尾调递归优化)
         printf("TAG L:\n");
-        af_Code *bt1 = makeElementCode("func4", 0, 1, "tagl.aun");
+        af_Code *bt1 = makeElementCode("func4", 0, 1, "Tagl.aun");
 
         runCodeFromMemory(bt1, env);
         freeAllCode(bt1);
@@ -1130,7 +1130,7 @@ int main() {
 
     {  // 导入式运行
         printf("TAG R:\n");
-        af_Code *bt1 = makeElementCode("object", 0, 1, "tagr.aun");
+        af_Code *bt1 = makeElementCode("object", 0, 1, "Tagr.aun");
         af_Code *bt2 = makeElementCode("data", ',', 0, NULL);
         pushCode(&bt1, bt2);
 
@@ -1148,7 +1148,7 @@ int main() {
 
     {
         printf("TAG S: STRING\n");
-        int exit_code = runCodeFromString("object\ndata\n{func}\nglobal\n", "tags-string.aun", NULL, env);
+        int exit_code = runCodeFromString("object\ndata\n{func}\nglobal\n", "Tags-string.aun", NULL, env);
         printf("exit code = %d\n\n", exit_code);
     }