Jelajahi Sumber

feat: 设置all_free和all_static_类型

SongZihuan 4 tahun lalu
induk
melakukan
cfd83bb66f
6 mengubah file dengan 72 tambahan dan 8 penghapusan
  1. 3 1
      include/value.h
  2. 27 3
      ofunc/src/object.c
  3. 10 0
      ofunc/src/sys.c
  4. 27 1
      src/__run.c
  5. 2 2
      src/runcall.c
  6. 3 1
      src/runfile.c

+ 3 - 1
include/value.h

@@ -58,9 +58,11 @@ struct Value{
                     free_,  // 不包含任何隐式传递的参数
                     static_,  // 不包含self参数
                     object_static_,  // self参数不允许class
-                    class_static_,  // self参数允许一切father
+                    class_static_,  // self参数允许一切,但转换为类
+                    all_static_, // self参数允许一切
                     object_free_,  // 同object_static_但不包含func参数
                     class_free_,  // 同object_static_但不包含func参数
+                    all_free_,
                 } pt_type;
             } function_data;
         } function;

+ 27 - 3
ofunc/src/object.c

@@ -47,21 +47,45 @@ ResultType object_new_(OFFICAL_FUNCTIONSIG){
 ResultType object_repo_(OFFICAL_FUNCTIONSIG){
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
                            {.must=-1}};
-    char repo[200] = {};
+    char *repo;
+    char *name;
+    char *type;
+    size_t len;
+    LinkValue *name_value;
     setResultCore(result);
     parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return result->type;
     freeResult(result);
-    snprintf(repo, 200, "(object on %p)", ap[0].value->value);
+
+    name_value = findAttributes(inter->data.object_name, false, ap[0].value, inter);
+    if (name_value != NULL){
+        gc_addTmpLink(&name_value->gc_status);
+        name = getRepo(name_value, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        gc_freeTmpLink(&name_value->gc_status);
+        if (!CHECK_RESULT(result))
+            return result->type;
+        freeResult(result);
+    } else
+        name = "unknown";
+
+    if (ap[0].value->value->type == class)
+        type = "class";
+    else
+        type = "object";
+
+    len = memStrlen(name) + 26;
+    repo = memCalloc(len, sizeof(char ));
+    snprintf(repo, len, "(%s: %s on %p)", type, name, ap[0].value->value);
     setResultOperationBase(result, makeLinkValue(makeStringValue(repo, inter), belong, inter));
+    memFree(repo);
     return result->type;
 }
 
 void registeredObject(REGISTERED_FUNCTIONSIG){
     LinkValue *object = makeLinkValue(inter->data.object, inter->base_father, inter);
     NameFunc tmp[] = {{inter->data.object_new, object_new_, class_free_},
-                      {inter->data.object_repo, object_repo_, object_free_},
+                      {inter->data.object_repo, object_repo_, all_free_},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
     addStrVar("object", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));

+ 10 - 0
ofunc/src/sys.c

@@ -86,6 +86,14 @@ ResultType vm_objectfreemethod(OFFICAL_FUNCTIONSIG){
     return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), object_free_);
 }
 
+ResultType vm_allfreemethod(OFFICAL_FUNCTIONSIG){
+    return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), all_free_);
+}
+
+ResultType vm_allstaticmethod(OFFICAL_FUNCTIONSIG){
+    return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), all_static_);
+}
+
 void registeredSysFunction(REGISTERED_FUNCTIONSIG){
     NameFunc tmp[] = {{"super", vm_super, free_},
                       {"freemethod", vm_freemethod, free_},
@@ -94,6 +102,8 @@ void registeredSysFunction(REGISTERED_FUNCTIONSIG){
                       {"staticobjectmethod", vm_objectmethod, free_},
                       {"classmethod", vm_classfreemethod, free_},
                       {"objectmethod", vm_objectfreemethod, free_},
+                      {"simplemethod", vm_allfreemethod, free_},
+                      {"simplestaticmethod", vm_allstaticmethod, free_},
                       {NULL, NULL}};
     iterNameFunc(tmp, belong, CALL_INTER_FUNCTIONSIG_CORE(var_list));
 }

+ 27 - 1
src/__run.c

@@ -151,6 +151,20 @@ ResultType setFunctionArgument(Argument **arg, LinkValue *function_value, fline
             *arg = tmp;
             break;
         case class_static_:
+            tmp = makeValueArgument(function_value);
+            if (function_value->belong->value->type == class)
+                tmp->next = makeValueArgument(function_value->belong);
+            else if (function_value->value->object.inherit->value != NULL)
+                tmp->next = makeValueArgument(function_value->belong->value->object.inherit->value);
+            else {
+                tmp->next = *arg;
+                *arg = tmp;
+                break;
+            }
+            tmp->next->next = *arg;
+            *arg = tmp;
+            break;
+        case all_static_:
             tmp = makeValueArgument(function_value);
             tmp->next = makeValueArgument(function_value->belong);
             tmp->next->next = *arg;
@@ -167,7 +181,12 @@ ResultType setFunctionArgument(Argument **arg, LinkValue *function_value, fline
             *arg = tmp;
             break;
         case class_free_:
-            tmp = makeValueArgument(function_value->belong);
+            if (function_value->belong->value->type == class)
+                tmp = makeValueArgument(function_value->belong);
+            else if (function_value->value->object.inherit->value != NULL)
+                tmp = makeValueArgument(function_value->belong->value->object.inherit->value);
+            else
+                break;
             tmp->next = *arg;
             *arg = tmp;
             break;
@@ -178,6 +197,11 @@ ResultType setFunctionArgument(Argument **arg, LinkValue *function_value, fline
                 *arg = tmp;
             }
             break;
+        case all_free_:
+            tmp = makeValueArgument(function_value->belong);
+            tmp->next = *arg;
+            *arg = tmp;
+            break;
         default:
             break;
     }
@@ -303,9 +327,11 @@ char *getRepo(LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST
     LinkValue *_repo_ = findAttributes(inter->data.object_repo, false, value, inter);
     setResultCore(result);
     if (_repo_ != NULL){
+        gc_addTmpLink(&value->gc_status);
         gc_addTmpLink(&_repo_->gc_status);
         callBackCore(_repo_, NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_repo_->gc_status);
+        gc_freeTmpLink(&value->gc_status);
 
         if (!CHECK_RESULT(result))
             return NULL;

+ 2 - 2
src/runcall.c

@@ -29,7 +29,7 @@ ResultType setClass(INTER_FUNCTIONSIG) {
         tmp->value->object.var->next = var_backup;
         inter->data.default_pt_type = pt_type_bak;
 
-        if (!CHECK_RESULT(result))
+        if (result->type != yield_return && !CHECK_RESULT(result))
             goto error_;
         freeResult(result);
     }
@@ -227,7 +227,7 @@ ResultType callCFunction(LinkValue *function_value, Argument *arg, long int line
     of(CALL_OFFICAL_FUNCTION(arg, function_var, result, function_value->belong));
     if (result->type == function_return)
         result->type = operation_return;
-    else if (result->type != operation_return)
+    else if (result->type != operation_return && result->type != error_return)
         setResult(result, inter, function_value->belong);
 
     gc_freeze(inter, var_list, function_var, false);

+ 3 - 1
src/runfile.c

@@ -31,7 +31,9 @@ ResultType includeFile(INTER_FUNCTIONSIG) {
     }
 
     functionSafeInterStatement(CALL_INTER_FUNCTIONSIG(new_st, var_list, result, belong));
-    if (!CHECK_RESULT(result))
+    if (result->type == yield_return)
+        setResult(result, inter, belong);
+    else if (!CHECK_RESULT(result))
         setResultErrorSt(E_BaseException, NULL, false, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
     return_: