# New Ticket Created by Bob Diertens # Please include the string: [perl #29502] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=29502 >
Hi, I found the following two bugs with the use of macro's in IMC. The first bug has to do with nested macro calls that use the same name as parameter. -------- .macro Test(X) print .X print "\n" .endm .macro XTest(X) .Test(.X) .endm .sub _Main .XTest("hi") end .end -------- Expansion of .X results in an endless loop. The reason for this is that arguments of a macro call are expanded not at the call but later on, and the lookup finds a value .X for which the lookup finds .X and so on. The second bug has to do with a local label as argument of a macro call. -------- .macro Test(X) print "Test label arg\n" goto .X .endm .macro XTest() .Test(.$end) .local $end: .endm .sub _Main .XTest() end .end -------- This results in the following PASM code. -------- _Main: print "Test label arg\n" branch local__XTest__end__3 local__XTest__end__1: end -------- Again, this is due to the fact that arguments of macro calls are expanded at a later stage. Here, the label gets the wrong frame number (3 instead of 1). The patch provided here as attachment solves both bugs. It puts some code in the function expand_macro that expands the arguments of the macro.
Index: imcc/imcc.l =================================================================== RCS file: /cvs/public/parrot/imcc/imcc.l,v retrieving revision 1.98 diff -u -r1.98 imcc.l --- imcc/imcc.l 7 May 2004 18:43:34 -0000 1.98 +++ imcc/imcc.l 11 May 2004 10:54:04 -0000 @@ -723,6 +723,10 @@ struct macro_t *m; const char *expansion; int start_cond; + int i; + char *current; + char *s; + int len; union { const void * __c_ptr; void * __ptr; @@ -778,6 +782,27 @@ "Macro '%s' requires %d arguments, but %d given", m->name, m->params.num_param, frame->expansion.num_param); } + + /* expand arguments */ + for (i = 0; i < frame->expansion.num_param; i ++) { + current = frame->expansion.name[i]; + if (current[0] == '.') { /* parameter of outer macro */ + s = find_macro_param(current + 1); + if (s) { + frame->expansion.name[i] = strdup(s); + free(current); + } + } else { + len = strlen(current) - 1; + if (current[len] == '$') { /* local label */ + current[len] = '\0'; + s = mem_sys_allocate(len + 1 + 10); + sprintf(s, "%s%d", current, frames->label); + frame->expansion.name[i] = s; + free(current); + } + } + } line = m->line; scan_string(frame, m->expansion);