Bläddra i källkod

修复了point运算符的bug

SongZihuan 5 år sedan
förälder
incheckning
b3f7444125
6 ändrade filer med 13 tillägg och 8 borttagningar
  1. 2 1
      README.md
  2. 1 1
      inter/cfunc.c
  3. 2 2
      inter/interpreter.c
  4. 1 0
      paser/lexical.c
  5. 5 3
      paser/syntax.c
  6. 2 1
      paser/token.h

+ 2 - 1
README.md

@@ -56,6 +56,7 @@ return x n  函数返回值x,返回n层
 * 虚解包,允许语法:a,b,\* = 1,2,3,4,5,6。也支持形参表,但不支持实参表。
 * 使用function定义静态方法(def)可以定义auto方法(如果是class内则定义为action方法,否则定义为def方法)。
 * 优先级bug:调用类方法只能用(xxx.zzz)()的方式,为优先级错误[已经修复]。
-* 使用cls来定义类方法,并且使用类调用对象方法的时候不会填入self
+* 使用cls来定义类方法,并且使用类调用对象方法的时候不会填入self。
+* 使用点运算符读取成员的时候会越界访问外部变量。[已经修复]
 ## 关于GWARF
 最后更新时间 : 2020年05月05日 广州

+ 1 - 1
inter/cfunc.c

@@ -311,7 +311,7 @@ class_object *make_object(var_list *the_var, var_list *father_var_list){
         append_by_var_list(class_tmp->the_var, father_var_list);  // int、double、str等内置类需要继承gobject类
     }
 
-    class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  // make class var list with out var
+    // class_tmp->out_var = copy_var_list(the_var);  // make class var list with out var
     return class_tmp;
 }
 

+ 2 - 2
inter/interpreter.c

@@ -485,7 +485,7 @@ GWARF_result read_statement(statement *the_statement, var_list *the_var, var_lis
                 }
             }
 
-            class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  //TODO::class_tmp->out_var = copy_var_list(the_var);
+            class_tmp->out_var = copy_var_list(the_var);  //TODO::class_tmp->out_var = copy_var_list(the_var);
             // 执行done
             statement *tmp = the_statement->code.set_class.done;
             GWARF_result result;
@@ -924,7 +924,7 @@ GWARF_result import_func(statement *the_statement, var_list *the_var){
     
     class_object *class_tmp = malloc(sizeof(class_object));
     class_tmp->the_var = new_the_var;  // make class var list
-    class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  // make class var list with out var
+    class_tmp->out_var = copy_var_list(the_var);  // make class var list with out var
 
     import_result.value.value.class_value = class_tmp;
     assignment_statement_core(the_statement->code.import_class.var, the_var, the_var, import_result, true);

+ 1 - 0
paser/lexical.c

@@ -174,6 +174,7 @@ int paser(int *index, p_status *status){
         match_text(p, global_paser[SVAR_PASER], "$");
         match_text(p, global_paser[FUNC_PASER], "function");
         match_text(p, global_paser[CLS_PASER], "cls");
+        match_text(p, global_paser[ACTION_PASER], "action");
 
         *index = check_list(global_paser, p, status);  // 检查解析结果
 

+ 5 - 3
paser/syntax.c

@@ -127,7 +127,7 @@ void command(p_status *old_status, token_node *list){  // 多项式
         get_stop_token(status, list);
         push_statement(statement_base, new_token);
     }
-    else if(left.type == DEF_PASER || left.type == FUNC_PASER || left.type == CLASS_PASER || left.type == CLS_PASER){
+    else if(left.type == DEF_PASER || left.type == FUNC_PASER || left.type == CLASS_PASER || left.type == CLS_PASER || left.type == ACTION_PASER){
         fprintf(status_log, "[info][grammar]  (command)back one token to (def_class)\n");
         back_one_token(list, left);
         get_base_token(&status, list, def_class, new_token);
@@ -451,7 +451,7 @@ void def_class(p_status *status, token_node *list){
     parameter *p_list;
 
     def_t = pop_node(list);
-    if(def_t.type == DEF_PASER || def_t.type == FUNC_PASER || def_t.type == CLASS_PASER || def_t.type == CLS_PASER){
+    if(def_t.type == DEF_PASER || def_t.type == FUNC_PASER || def_t.type == CLASS_PASER || def_t.type == CLS_PASER || def_t.type == ACTION_PASER){
         p_status new_status;
         new_status = *status;
         new_status.not_match_tuple = true;
@@ -490,7 +490,7 @@ void def_class(p_status *status, token_node *list){
         }
 
         statement *def_tmp =  make_statement();
-        if(def_t.type == DEF_PASER || def_t.type == FUNC_PASER || def_t.type == CLS_PASER){
+        if(def_t.type == DEF_PASER || def_t.type == FUNC_PASER || def_t.type == CLS_PASER || def_t.type == ACTION_PASER){
             def_tmp->type = def;
             def_tmp->code.def.var = name_t.data.statement_value;
             def_tmp->code.def.parameter_list = p_list;
@@ -504,6 +504,8 @@ void def_class(p_status *status, token_node *list){
                 break;
                 case FUNC_PASER:
                 def_tmp->code.def.type = function;
+                case ACTION_PASER:
+                def_tmp->code.def.type = action;
                 break;
             }
         }

+ 2 - 1
paser/token.h

@@ -3,7 +3,7 @@
 
 #include "../inter/interpreter.h"
 
-#define MAX_PASER_SIZE 87
+#define MAX_PASER_SIZE 88
 #define INT_PASER 0
 #define DOUBLE_PASER 1
 #define ENTER_PASER 2
@@ -91,6 +91,7 @@
 #define SVAR_PASER 84
 #define FUNC_PASER 85
 #define CLS_PASER 86
+#define ACTION_PASER 87
 
 // 获取并返回一个token
 #define get_pop_token(status,list,new_token) \