SongZihuan 3 лет назад
Родитель
Сommit
70218e74eb
3 измененных файлов с 33 добавлено и 3 удалено
  1. 3 0
      include/prefix_macro.h
  2. 9 0
      src/core/code.c
  3. 21 3
      src/core/env.c

+ 3 - 0
include/prefix_macro.h

@@ -5,6 +5,9 @@
 #ifndef AFUN__PREFIX_MACRO_H
 #define AFUN__PREFIX_MACRO_H
 
+#define LV_PREFIX ",`'"  /* 字面量和变量前缀 */
+#define B_PREFIX "%^&'`,<?>"  /* 括号前缀 */
+
 // 作为顶层代码,以及'()运行时
 #define V_QUOTE           (0)  /* 变量前缀: 引用 */
 

+ 9 - 0
src/core/code.c

@@ -29,6 +29,9 @@ static af_Code *makeCode(char prefix, FileLine line, FilePath path) {
 }
 
 af_Code *makeLiteralCode(char *literal_data, char *func, bool in_protect, char prefix, FileLine line, FilePath path) {
+    if (prefix != NUL && strchr(LV_PREFIX, prefix) == NULL)
+        prefix = NUL;
+
     af_Code *bt = makeCode(prefix, line, path);
     bt->type = literal;
     bt->literal.literal_data = strCopy(literal_data);
@@ -39,6 +42,9 @@ af_Code *makeLiteralCode(char *literal_data, char *func, bool in_protect, char p
 
 
 af_Code *makeVariableCode(char *var, char prefix, FileLine line, FilePath path) {
+    if (prefix != NUL && strchr(LV_PREFIX, prefix) == NULL)
+        prefix = NUL;
+
     af_Code *bt = makeCode(prefix, line, path);
     bt->type = variable;
     bt->variable.name = strCopy(var);
@@ -73,6 +79,9 @@ af_Code *makeBlockCode(enum af_BlockType type, af_Code *element, char prefix, Fi
     if (next == NULL)
         next = &tmp;
 
+    if (prefix != NUL && strchr(B_PREFIX, prefix) == NULL)
+        prefix = NUL;
+
     countElement(element, &elements, &count, next);
     bt = makeCode(prefix, line, path);
     bt->type = block;

+ 21 - 3
src/core/env.c

@@ -64,9 +64,22 @@ static void freeCore(af_Environment *env) {
 }
 
 char setPrefix(size_t name, char prefix, af_Environment *env) {
-    char old = env->core->prefix[name];
-    if (name >= PREFIX_SIZE || prefix == NUL)
+    if (name >= PREFIX_SIZE)
         return NUL;
+    switch (name) {
+        case V_QUOTE:
+            if (prefix != NUL && strchr(LV_PREFIX, prefix) == NULL)
+                prefix = NUL;
+            break;
+        case B_EXEC:
+        case B_EXEC_FIRST:
+            if (prefix != NUL && strchr(B_PREFIX, prefix) == NULL)
+                prefix = NUL;
+            break;
+        default:
+            break;
+    }
+    char old = env->core->prefix[name];
     env->core->prefix[name] = prefix;
     return old;
 }
@@ -558,8 +571,13 @@ bool pushFuncActivity(af_Code *bt, af_Environment *env) {
 
     env->activity->call_type = env->activity->bt_top->block.type;
     env->activity->status = act_func;
-    if (env->activity->call_type == parentheses)  // 对于类前缀调用, 已经获得func的实际值了
+    if (env->activity->call_type == parentheses) { // 对于类前缀调用, 已经获得func的实际值了
+        if (parentheses_call == NULL) {
+            pushMessageDown(makeMessage("ERROR-STR", 0), env);
+            return false;
+        }
         return setFuncActivityToArg(parentheses_call, env);
+    }
     return true;
 }