changeset 924:bd9bd4ba2f1c

ignore global non function macro in function and do replace eager
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 13 Apr 2014 10:14:38 +0900
parents 080d87432ff3
children 4e73a22327a8
files mc-macro.c test/macro.c
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mc-macro.c	Fri Apr 11 20:02:17 2014 +0900
+++ b/mc-macro.c	Sun Apr 13 10:14:38 2014 +0900
@@ -131,6 +131,10 @@
            if (t[-2]!='\n') putchar('\n');
         }
 #endif
+        while (macro_history!=0) {
+            int i = cadr(macro_history); free_glist2(macro_history); macro_history = i;
+        }
+        macro_history = car(macro_history_save);
         // evaluate generated result again
         macrop=macro_eval(macrop,macropp,macro_history,0);
         cheap = reset_cheap(&scheap);
@@ -142,6 +146,7 @@
         cheap->ptr[0] =0;
         cheap = increment_cheap(cheap,&macropp);
     }
+
     cheap = reset_cheap(&scheap);
     // genrated macro will be overwrited by cheap, but it's OK, again
     if (before && lsrc) printf("## after %s\n",macropp);
@@ -1087,16 +1092,16 @@
             default:
                 if (prev_concat) {
                     prev_concat = 0;
-                    macro = nptrm->u.nm;
+                    macro = nptrm->nm;
                 } else if (next_concat(c,body)) {
                     prev_concat = 1;
-                    macro = nptrm->u.nm;
+                    macro = nptrm->nm;
                 }  
                 if (macro==0 || !macro[0]) 
                     macro = nptrm->nm;
                 goto skip;
             case MACRO:
-                if (neqname(nptrm->nm,macro)) {
+                if (!local_only && neqname(nptrm->nm,macro)) {
                     if (macro[0]==0)  {
                         if (string_flag) {
                             string_flag = 0;
@@ -1111,6 +1116,7 @@
                     expand = (char **)&(scaddr(macrop));
                     break;
                 }
+                if (local_only) mconcat = 1;
                 macro = nptrm->nm;
 skip:
             case LMACRO:
--- a/test/macro.c	Fri Apr 11 20:02:17 2014 +0900
+++ b/test/macro.c	Sun Apr 13 10:14:38 2014 +0900
@@ -139,6 +139,7 @@
     printf("#0107:%s\n",stringify(aho));
     printf("#0108:%s\n",init_str);
     printf("#0109:%d\n",names2(4));
+    printf("#0110:%d\n",name_hoge(names(4,hoge)));
 /*
     printf("#0103:%d\n",(3 +a));
     printf("#0104:%d\n",(3 +a));