SongZihuan 4 жил өмнө
parent
commit
d691810676
6 өөрчлөгдсөн 132 нэмэгдсэн , 92 устгасан
  1. 4 2
      include/run.h
  2. 6 6
      src/parameter.c
  3. 6 6
      src/runbranch.c
  4. 2 2
      src/runcall.c
  5. 1 1
      src/runfile.c
  6. 113 75
      src/runoperation.c

+ 4 - 2
include/run.h

@@ -68,6 +68,8 @@ ResultType importFile(INTER_FUNCTIONSIG);
 ResultType fromImportFile(INTER_FUNCTIONSIG);
 
 ResultType pointAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST);
-ResultType assCore(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST);
-
+ResultType listAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST);
+ResultType assCore(Statement *name, LinkValue *value, bool check_aut, INTER_FUNCTIONSIG_NOT_ST);
+ResultType downAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST);
+ResultType varAss(Statement *name, LinkValue *value, bool check_aut, INTER_FUNCTIONSIG_NOT_ST);
 #endif //VIRTUALMATH_RUN_H

+ 6 - 6
src/parameter.c

@@ -233,7 +233,7 @@ ResultType defaultParameter(Parameter **function_ad, NUMBER_TYPE *num, INTER_FUN
 
         value = result->value;
         freeResult(result);
-        assCore(function->data.name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        assCore(function->data.name, value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         if (!run_continue(result))
             goto return_;
     }
@@ -262,7 +262,7 @@ ResultType argumentToVar(Argument **call_ad, NUMBER_TYPE *num, INTER_FUNCTIONSIG
             continue;
         }
         freeResult(result);
-        assCore(call->data.name, call->data.value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        assCore(call->data.name, call->data.value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         if (!run_continue(result))
             goto return_;
     }
@@ -338,7 +338,7 @@ ResultType parameterFromVar(Parameter **function_ad, VarList *function_var, NUMB
 
         not_return:
         freeResult(result);
-        assCore(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(function_var, result, belong));
+        assCore(name, value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(function_var, result, belong));
 
         if (!run_continue(result)) {
             *function_ad = function;
@@ -373,7 +373,7 @@ ResultType argumentToParameter(Argument **call_ad, Parameter **function_ad, VarL
 
     for (PASS; call != NULL && function != NULL && (call->type == value_arg) && function->type != args_par; call = call->next, function = function->next){
         Statement *name = function->type == value_par ? function->data.value : function->data.name;
-        assCore(name, call->data.value, CALL_INTER_FUNCTIONSIG_NOT_ST(function_var, result, belong));
+        assCore(name, call->data.value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(function_var, result, belong));
         if (!run_continue(result))
             goto return_;
         freeResult(result);
@@ -562,7 +562,7 @@ ResultType setParameterCore(long int line, char *file, Argument *call, Parameter
             }
             case mul_par: {
                 LinkValue *tmp = makeLinkValue(makeListValue(&call, inter, value_tuple), belong, inter);
-                assCore(function->data.value, tmp, CALL_INTER_FUNCTIONSIG_NOT_ST(function_var, result, belong));
+                assCore(function->data.value, tmp, false, CALL_INTER_FUNCTIONSIG_NOT_ST(function_var, result, belong));
                 returnResult(result);
                 function = function->next;
                 break;
@@ -572,7 +572,7 @@ ResultType setParameterCore(long int line, char *file, Argument *call, Parameter
                 returnResult(result);
                 freeResult(result);
 
-                assCore(function->data.value, tmp, CALL_INTER_FUNCTIONSIG_NOT_ST(function_var, result, belong));
+                assCore(function->data.value, tmp, false, CALL_INTER_FUNCTIONSIG_NOT_ST(function_var, result, belong));
                 returnResult(result);
                 function = function->next;
                 break;

+ 6 - 6
src/runbranch.c

@@ -120,7 +120,7 @@ ResultType ifBranch(INTER_FUNCTIONSIG) {
             condition_value = result->value;
             freeResult(result);
             if (if_list->var != NULL) {
-                assCore(if_list->var, condition_value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+                assCore(if_list->var, condition_value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                 if (!run_continue(result)){
                     set_result = false;
                     goto not_else;
@@ -259,7 +259,7 @@ ResultType whileBranch(INTER_FUNCTIONSIG) {
         condition_value = result->value;
         freeResult(result);
         if (while_list->var != NULL){
-            assCore(while_list->var, condition_value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            assCore(while_list->var, condition_value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             if (!run_continue(result)){
                 set_result = false;
                 goto not_else;
@@ -428,7 +428,7 @@ ResultType forBranch(INTER_FUNCTIONSIG) {
             element = result->value;
             result->value = NULL;
             freeResult(result);
-            assCore(for_list->var, element, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            assCore(for_list->var, element, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             gc_freeTmpLink(&element->gc_status);
             if (!run_continue(result)){
                 set_result = false;
@@ -594,7 +594,7 @@ ResultType withBranch(INTER_FUNCTIONSIG) {
             new = pushVarList(var_list, inter);
             enter_value = result->value;
             freeResult(result);
-            assCore(with_list->var, enter_value, CALL_INTER_FUNCTIONSIG_NOT_ST(new, result, belong));
+            assCore(with_list->var, enter_value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(new, result, belong));
             if (!run_continue(result)) {
                 set_result = false;
                 popVarList(new);
@@ -743,7 +743,7 @@ ResultType tryBranch(INTER_FUNCTIONSIG) {
     error_value = result->value;
     freeResult(result);
     if (except_list->var != NULL){
-        assCore(except_list->var, error_value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        assCore(except_list->var, error_value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         if (!run_continue(result)){
             set_result = false;
             goto not_else;
@@ -989,7 +989,7 @@ ResultType runLabel(INTER_FUNCTIONSIG) {
     freeResult(result);
     var_list = pushVarList(var_list, inter);
     if (st->u.label_.as != NULL)
-        assCore(st->u.label_.as, goto_value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        assCore(st->u.label_.as, goto_value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     gc_freeTmpLink(&goto_value->gc_status);
     if (st->u.label_.as != NULL && !run_continue(result))
         goto return_;

+ 2 - 2
src/runcall.c

@@ -38,7 +38,7 @@ ResultType setClass(INTER_FUNCTIONSIG) {
         freeResult(result);
     }
 
-    assCore(st->u.set_class.name, tmp, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    assCore(st->u.set_class.name, tmp, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (run_continue(result))
         setResult(result, inter, belong);
 
@@ -70,7 +70,7 @@ ResultType setFunction(INTER_FUNCTIONSIG) {
         result->value = NULL;
         freeResult(result);
     }
-    assCore(st->u.set_function.name, tmp, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    assCore(st->u.set_function.name, tmp, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!run_continue(result))
         goto error_;
     setResult(result, inter, belong);

+ 1 - 1
src/runfile.c

@@ -106,7 +106,7 @@ ResultType importFile(INTER_FUNCTIONSIG) {
         import_value = makeLinkValue(import_obj, belong, inter);
     }
     if (st->u.import_file.as != NULL)
-        assCore(st->u.import_file.as, import_value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        assCore(st->u.import_file.as, import_value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     else
         addStrVar(splitDir(file_dir), true, import_value, belong, CALL_INTER_FUNCTIONSIG_CORE(var_list));
     setResult(result, inter, belong);

+ 113 - 75
src/runoperation.c

@@ -116,10 +116,14 @@ ResultType assOperation(INTER_FUNCTIONSIG) {
         Value *function_value = NULL;
         LinkValue *tmp = NULL;
         function_var = copyVarList(var_list, false, inter);
-        function_value = makeVMFunctionValue(st->u.operation.right, st->u.operation.left->u.call_function.parameter,
-                                             function_var, inter);
+        {
+            Statement *return_st = makeReturnStatement(st->u.operation.right, st->line, st->code_file);
+            function_value = makeVMFunctionValue(return_st, st->u.operation.left->u.call_function.parameter, function_var, inter);
+            return_st->u.return_code.value = NULL;
+            freeStatement(return_st);
+        }
         tmp = makeLinkValue(function_value, belong, inter);
-        assCore(st->u.operation.left->u.call_function.function, tmp, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        assCore(st->u.operation.left->u.call_function.function, tmp, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     }
     else{
         if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.operation.right, var_list, result, belong)))
@@ -127,92 +131,126 @@ ResultType assOperation(INTER_FUNCTIONSIG) {
         value = result->value;
 
         freeResult(result);
-        assCore(st->u.operation.left, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        assCore(st->u.operation.left, value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     }
     return result->type;
 }
 
-ResultType assCore(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST){
+ResultType assCore(Statement *name, LinkValue *value, bool check_aut, INTER_FUNCTIONSIG_NOT_ST){
     setResultCore(result);
     gc_addTmpLink(&value->gc_status);
 
-    if (name->type == base_list && name->u.base_list.type == value_tuple){
-        Parameter *pt = NULL;
-        Argument *call = NULL;
-        Statement *tmp_st = makeBaseLinkValueStatement(value, name->line, name->code_file);
-
-        pt = makeArgsParameter(tmp_st);
-        call = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-        if (!run_continue(result)) {
-            freeArgument(call, false);
-            freeParameter(pt, true);
-            goto return_;
-        }
+    if (name->type == base_list && name->u.base_list.type == value_tuple)
+        listAss(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    else if (name->type == slice_ && name->u.slice_.type == SliceType_down_)
+        downAss(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    else if (name->type == operation && name->u.operation.OperationType == OPT_POINT)
+        pointAss(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    else
+        varAss(name, value, check_aut, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
-        freeResult(result);
-        setParameterCore(name->line, name->code_file, call, name->u.base_list.list, var_list, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-        if (run_continue(result)){
-            Argument *tmp = call;
-            LinkValue *new_value = makeLinkValue(makeListValue(&tmp, inter, value_tuple), belong, inter);
-            freeResult(result);
-            setResultOperation(result, new_value);
+    gc_freeTmpLink(&value->gc_status);
+    return result->type;
+}
+
+ResultType varAss(Statement *name, LinkValue *value, bool check_aut, INTER_FUNCTIONSIG_NOT_ST) {
+    char *str_name = NULL;
+    int int_times = 0;
+    LinkValue *var_value = NULL;
+    getVarInfo(&str_name, &int_times, CALL_INTER_FUNCTIONSIG(name, var_list, result, belong));
+    if (!run_continue(result)) {
+        memFree(str_name);
+        return result->type;
+    }
+    var_value = copyLinkValue(value, inter);
+    if (name->aut != auto_aut)
+        var_value->aut = name->aut;
+    if (check_aut) {
+        LinkValue *tmp = findFromVarList(str_name, int_times, 2, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+        if (tmp != NULL) {
+            if ((value->aut == public_aut || value->aut == auto_aut) && (tmp->aut != public_aut && tmp->aut != auto_aut)) {
+                setResultErrorSt(result, inter, "PermissionsException", "Wrong Permissions: access variables as public",
+                                 name, belong, true);
+                goto return_;
+            }
+            else if ((value->aut == protect_aut) && (tmp->aut == private_aut)) {
+                setResultErrorSt(result, inter, "PermissionsException",
+                                 "Wrong Permissions: access variables as protect", name, belong, true);
+                goto return_;
+            }
+            else
+                goto set_var;
+        } else
+            set_var: addFromVarList(str_name, result->value, int_times, var_value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+    } else {
+        if (name->aut != auto_aut) {
+            LinkValue *tmp = findFromVarList(str_name, int_times, 2, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+            if (tmp != NULL)
+                tmp->aut = name->aut;
         }
-        freeArgument(call, false);
-        freeParameter(pt, true);
+        addFromVarList(str_name, result->value, int_times, var_value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
     }
-    else if (name->type == slice_ && name->u.slice_.type == SliceType_down_){
-        LinkValue *iter = NULL;
-        LinkValue *_down_assignment_ = NULL;
-        Parameter *pt = name->u.slice_.index;
-        if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(name->u.slice_.element, var_list, result, belong)))
-            goto return_;
-        iter = result->value;
-        result->value = NULL;
+    freeResult(result);
+    result->type = operation_return;
+    result->value = value;
+    gc_addTmpLink(&result->value->gc_status);
+
+    return_:
+    memFree(str_name);
+    return result->type;
+}
+
+ResultType listAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST) {
+    Parameter *pt = NULL;
+    Argument *call = NULL;
+    Statement *tmp_st = makeBaseLinkValueStatement(value, name->line, name->code_file);
+
+    pt = makeArgsParameter(tmp_st);
+    call = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    if (!run_continue(result))
+        goto return_;
+
+    freeResult(result);
+    setParameterCore(name->line, name->code_file, call, name->u.base_list.list, var_list, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    if (run_continue(result)){
+        Argument *tmp = call;
+        LinkValue *new_value = makeLinkValue(makeListValue(&tmp, inter, value_tuple), belong, inter);
         freeResult(result);
-        _down_assignment_ = findAttributes("__down_assignment__", false, iter, inter);
-        if (_down_assignment_ != NULL){
-            Argument *arg = makeValueArgument(value);
-            gc_addTmpLink(&_down_assignment_->gc_status);
-            arg->next = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-            if (!run_continue(result))
-                goto daerror_;
-
-            freeResult(result);
-            callBackCore(_down_assignment_, arg, name->line, name->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-
-            daerror_:
-            freeArgument(arg, true);
-            gc_freeTmpLink(&_down_assignment_->gc_status);
-        }
-        else
-            setResultErrorSt(result, inter, "TypeException", "Don't find __down_assignment__", name, belong, true);
-        gc_freeTmpLink(&iter->gc_status);
+        setResultOperation(result, new_value);
     }
-    else if (name->type == operation && name->u.operation.OperationType == OPT_POINT)
-        pointAss(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    else{
-        char *str_name = NULL;
-        int int_times = 0;
-        LinkValue *var_value = NULL;
-        getVarInfo(&str_name, &int_times, CALL_INTER_FUNCTIONSIG(name, var_list, result, belong));
-        if (!run_continue(result)) {
-            memFree(str_name);
-            return result->type;
-        }
-        var_value = copyLinkValue(value, inter);
-        if (var_value->aut == auto_aut)
-            var_value->aut = name->aut;
-        addFromVarList(str_name, result->value, int_times, var_value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
-        memFree(str_name);
+    return_:
+    freeArgument(call, false);
+    freeParameter(pt, true);
+    return result->type;
+}
+
+ResultType downAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST) {
+    LinkValue *iter = NULL;
+    LinkValue *_down_assignment_ = NULL;
+    Parameter *pt = name->u.slice_.index;
+    if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(name->u.slice_.element, var_list, result, belong)))
+        return result->type;
+    iter = result->value;
+    result->value = NULL;
+    freeResult(result);
+    _down_assignment_ = findAttributes("__down_assignment__", false, iter, inter);
+    if (_down_assignment_ != NULL){
+        Argument *arg = makeValueArgument(value);
+        gc_addTmpLink(&_down_assignment_->gc_status);
+        arg->next = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        if (!run_continue(result))
+            goto daerror_;
+
         freeResult(result);
+        callBackCore(_down_assignment_, arg, name->line, name->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
-        result->type = operation_return;
-        result->value = value;
-        gc_addTmpLink(&result->value->gc_status);
+        daerror_:
+        freeArgument(arg, true);
+        gc_freeTmpLink(&_down_assignment_->gc_status);
     }
-
-    return_:
-    gc_freeTmpLink(&value->gc_status);
+    else
+        setResultErrorSt(result, inter, "TypeException", "Don't find __down_assignment__", name, belong, true);
+    gc_freeTmpLink(&iter->gc_status);
     return result->type;
 }
 
@@ -229,7 +267,7 @@ ResultType pointAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST)
     if (name->u.operation.right->type == OPERATION && name->u.operation.right->u.operation.OperationType == OPT_POINT)
         pointAss(name->u.operation.right, value, CALL_INTER_FUNCTIONSIG_NOT_ST(object, result, belong));
     else
-        assCore(name->u.operation.right, value, CALL_INTER_FUNCTIONSIG_NOT_ST(object, result, belong));
+        assCore(name->u.operation.right, value, true, CALL_INTER_FUNCTIONSIG_NOT_ST(object, result, belong));
     gc_freeze(inter, var_list, object, false);
 
     freeResult(&left);