Răsfoiți Sursa

函数静态空间

SongZihuan 5 ani în urmă
părinte
comite
728458e6aa
4 a modificat fișierele cu 19 adăugiri și 29 ștergeri
  1. 1 0
      README.md
  2. 16 29
      inter/interpreter.c
  3. 1 0
      inter/interpreter.h
  4. 1 0
      paser/syntax.c

+ 1 - 0
README.md

@@ -58,5 +58,6 @@ return x n  函数返回值x,返回n层
 * 优先级bug:调用类方法只能用(xxx.zzz)()的方式,为优先级错误[已经修复]。
 * 优先级bug:调用类方法只能用(xxx.zzz)()的方式,为优先级错误[已经修复]。
 * 使用cls来定义类方法,并且使用类调用对象方法的时候不会填入self。
 * 使用cls来定义类方法,并且使用类调用对象方法的时候不会填入self。
 * 使用点运算符读取成员的时候会越界访问外部变量。[已经修复]
 * 使用点运算符读取成员的时候会越界访问外部变量。[已经修复]
+* 设置了函数静态空间,允许对函数使用point运算符
 ## 关于GWARF
 ## 关于GWARF
 最后更新时间 : 2020年05月05日 广州
 最后更新时间 : 2020年05月05日 广州

+ 16 - 29
inter/interpreter.c

@@ -345,6 +345,9 @@ GWARF_result read_statement(statement *the_statement, var_list *the_var, var_lis
             else if(base_the_var.type == OBJECT_value){
             else if(base_the_var.type == OBJECT_value){
                 return_value = traverse((the_statement->code).point.child_var, base_the_var.value.object_value->the_var, false);
                 return_value = traverse((the_statement->code).point.child_var, base_the_var.value.object_value->the_var, false);
             }
             }
+            else if(base_the_var.type == FUNC_value){
+                return_value = traverse((the_statement->code).point.child_var, base_the_var.value.func_value->self, false);
+            }
             else{  // 其他类型
             else{  // 其他类型
                 goto the_break;
                 goto the_break;
             }
             }
@@ -405,6 +408,8 @@ GWARF_result read_statement(statement *the_statement, var_list *the_var, var_lis
             func_tmp->done = the_statement->code.def.done;
             func_tmp->done = the_statement->code.def.done;
             func_tmp->parameter_list = the_statement->code.def.parameter_list;
             func_tmp->parameter_list = the_statement->code.def.parameter_list;
             func_tmp->the_var = copy_var_list(the_var);
             func_tmp->the_var = copy_var_list(the_var);
+            func_tmp->self = make_var_base(make_hash_var());
+
             func_tmp->type = customize;  // func by user
             func_tmp->type = customize;  // func by user
             if((the_login_var != the_var && the_statement->code.def.type == auto_func) || the_statement->code.def.type == action){  // 定义为类方法
             if((the_login_var != the_var && the_statement->code.def.type == auto_func) || the_statement->code.def.type == action){  // 定义为类方法
                 func_tmp->is_class = action;
                 func_tmp->is_class = action;
@@ -430,6 +435,7 @@ GWARF_result read_statement(statement *the_statement, var_list *the_var, var_lis
             func_tmp->done = the_statement->code.lambda_func.done;
             func_tmp->done = the_statement->code.lambda_func.done;
             func_tmp->parameter_list = the_statement->code.lambda_func.parameter_list;
             func_tmp->parameter_list = the_statement->code.lambda_func.parameter_list;
             func_tmp->the_var = copy_var_list(the_var);
             func_tmp->the_var = copy_var_list(the_var);
+            func_tmp->self = make_var_base(make_hash_var());
             func_tmp->type = customize;  // func by user
             func_tmp->type = customize;  // func by user
             func_tmp->is_class = auto_func;
             func_tmp->is_class = auto_func;
             func_tmp->is_lambda = true;
             func_tmp->is_lambda = true;
@@ -1810,7 +1816,7 @@ GWARF_result assignment_statement_core(statement *the_statement, var_list *the_v
         value.base_name = left;
         value.base_name = left;
     }
     }
     else if(the_statement->type == point){  // 通过point赋值
     else if(the_statement->type == point){  // 通过point赋值
-        GWARF_result tmp_result = traverse(the_statement->code.point.base_var, login_var, false);  // 不用取value
+        GWARF_result tmp_result = traverse(the_statement->code.point.base_var, the_var, false);  // 不用取value
         if(is_error(&tmp_result)){  // Name Error错误
         if(is_error(&tmp_result)){  // Name Error错误
             // puts("STOP:: Name No Found!");
             // puts("STOP:: Name No Found!");
             return tmp_result;
             return tmp_result;
@@ -1819,40 +1825,21 @@ GWARF_result assignment_statement_core(statement *the_statement, var_list *the_v
             return tmp_result;
             return tmp_result;
         }
         }
         GWARF_value base_the_var = tmp_result.value;  // 不用取value
         GWARF_value base_the_var = tmp_result.value;  // 不用取value
-        if((the_statement->code.point.child_var)->type == base_var){
-            char *left = (the_statement->code.point.child_var)->code.base_var.var_name;
-            int from = 0;
-            if((the_statement->code.point.child_var)->code.base_var.from == NULL){
-                from = 0;
-            }
-            else{
-                GWARF_result tmp_result, tmp_object = traverse((the_statement->code.point.child_var)->code.base_var.from, the_var, false);
-                if(is_error(&tmp_object)){  // Name Error错误
-                    // puts("STOP:: Name No Found!");
-                    return tmp_object;
-                }
-                else if(is_space(&tmp_object)){
-                    return tmp_object;
-                }
-                tmp_result = get__value__(&(tmp_object.value), the_var);  // 从object中提取value
-                if(tmp_result.value.type == INT_value){
-                    from = tmp_result.value.value.int_value;
-                }
-                else if(tmp_result.value.type == NUMBER_value){
-                    from = (int)tmp_result.value.value.double_value;
-                }
-                else{
-                    from = 0;
-                }
-            }
-            value = assignment_func(left, right_result, base_the_var.value.object_value->the_var, from);
+        if(base_the_var.type == CLASS_value){
+            value = assignment_statement(the_statement->code.point.child_var, the_var, base_the_var.value.class_value->the_var, right_result);
+        }
+        else if(base_the_var.type == OBJECT_value){
+            value = assignment_statement(the_statement->code.point.child_var, the_var, base_the_var.value.object_value->the_var, right_result);
+        }
+        else if(base_the_var.type == FUNC_value){
+            value = assignment_statement(the_statement->code.point.child_var, the_var, base_the_var.value.func_value->self, right_result);
         }
         }
         else{
         else{
             goto the_else;
             goto the_else;
         }
         }
     }
     }
     else if(the_statement->type == down){  // 通过down赋值
     else if(the_statement->type == down){  // 通过down赋值
-        GWARF_result tmp_result = traverse(the_statement->code.down.base_var, login_var, false), get;  // 不用取value
+        GWARF_result tmp_result = traverse(the_statement->code.down.base_var, the_var, false), get;  // 不用取value
         if(is_error(&tmp_result)){  // Name Error错误
         if(is_error(&tmp_result)){  // Name Error错误
             // puts("STOP:: Name No Found!");
             // puts("STOP:: Name No Found!");
             return tmp_result;
             return tmp_result;

+ 1 - 0
inter/interpreter.h

@@ -483,6 +483,7 @@ typedef struct func{
     struct parameter *parameter_list;  // def parameter
     struct parameter *parameter_list;  // def parameter
     struct statement *done;  // def to do
     struct statement *done;  // def to do
     struct var_list *the_var;  // func会记录the_var,因为不同地方调用var如果var链不统一那就会很乱
     struct var_list *the_var;  // func会记录the_var,因为不同地方调用var如果var链不统一那就会很乱
+    struct var_list *self;  // func会记录自己的self信息(可以类似于class和object那样调用),对于setup func会合并到the_var中
     int is_class;
     int is_class;
     bool is_lambda;
     bool is_lambda;
 } func;
 } func;

+ 1 - 0
paser/syntax.c

@@ -504,6 +504,7 @@ void def_class(p_status *status, token_node *list){
                 break;
                 break;
                 case FUNC_PASER:
                 case FUNC_PASER:
                 def_tmp->code.def.type = function;
                 def_tmp->code.def.type = function;
+                break;
                 case ACTION_PASER:
                 case ACTION_PASER:
                 def_tmp->code.def.type = action;
                 def_tmp->code.def.type = action;
                 break;
                 break;