txlyre 2 天之前
父节点
当前提交
eea706da35
共有 1 个文件被更改,包括 22 次插入1 次删除
  1. 22 1
      qic.c

+ 22 - 1
qic.c

@@ -1047,6 +1047,8 @@ struct _node_t {
 
   size_t fi;
   size_t pos;
+
+  int flag;
 };
 typedef struct _node_t node_t;
 
@@ -2393,8 +2395,11 @@ node_t *parse_stmt(list_t *tokens, size_t *pos) {
   }
 
   node_t *n = parse_expr(tokens, pos);
-  if (n->tag == N_MVAR)
+  if (n->tag == N_MVAR) {
+    n->flag = 1;
+
     return n;
+  }
 
   return NODE1(EXPRSTMT, n);
 }
@@ -3476,6 +3481,17 @@ node_t *mf_isExpr(list_t *t) {
   return a->tag > N_EXPRS_BEGIN && a->tag < N_EXPRS_END? YES: NULL;
 }
 
+node_t *mf_isList(list_t *t) {
+  if (t->length != 1)
+    return NULL;
+
+  node_t *a = t->data[0];
+  if (!a)
+    return NULL;
+
+  return a->tag == N_LIST? YES: NULL;
+}
+
 node_t *mf_newList(list_t *t) {
   for (size_t i = 0; i < t->length; i++)
     if (!t->data[i])
@@ -3489,6 +3505,8 @@ struct {
   node_t *(*handler)(list_t *);
 } METAFUNCS[] = {
   { "isExpr", mf_isExpr },
+  { "isList", mf_isList },
+
   { "newList", mf_newList },
 
   { NULL, NULL }
@@ -4682,6 +4700,9 @@ void compile_node(buffer_t *gbuf, buffer_t *buf, list_t *ctx, table_t *ltab, int
       if (!n)
         COMPILE_ERROR("undefined macro variable: '%s'", node->t);
 
+      if (node->flag)
+        n = node1(N_EXPRSTMT, n);
+
       compile_node(gbuf, buf, ctx, ltab, lstk, sstk, lbl, n);
     } break;