Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
[PATCH] expanding arguments of macro's
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bob Diertens  
View profile  
 More options May 11 2004, 7:10 am
Newsgroups: perl.perl6.internals
From: bugs-par...@netlabs.develooper.com (Bob Diertens)
Date: Tue, 11 May 2004 04:10:44 -0700
Local: Tues, May 11 2004 7:10 am
Subject: [perl #29502] [PATCH] expanding arguments of macro's

# 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.

[ expand_macro_args.patch 1K ]
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);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Leopold Toetsch  
View profile  
 More options May 11 2004, 10:59 am
Newsgroups: perl.perl6.internals
From: l...@toetsch.at (Leopold Toetsch)
Date: Tue, 11 May 2004 16:59:16 +0200
Local: Tues, May 11 2004 10:59 am
Subject: Re: [perl #29502] [PATCH] expanding arguments of macro's

Bob Diertens <bugs-par...@netlabs.develooper.com> wrote:
> I found the following two bugs with the use of macro's in IMC.

Good. Thanks, applied.
leo

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »