Author: chromatic
Date: Sat Jul 26 14:24:16 2008
New Revision: 29775

Modified:
   trunk/compilers/imcc/imcc.l
   trunk/compilers/imcc/imclexer.c
   trunk/compilers/imcc/pcc.c
   trunk/t/compilers/imcc/syn/objects.t

Log:
[IMCC] Made :vtable sub attribute imply the existence of a "self" PMC, which
refers to the invoking PMC.  Many occurrences of :method on vtable subs can go
away now.  See RT #47674 (and thanks to Andrew Whitworth for most of this
patch).

Modified: trunk/compilers/imcc/imcc.l
==============================================================================
--- trunk/compilers/imcc/imcc.l (original)
+++ trunk/compilers/imcc/imcc.l Sat Jul 26 14:24:16 2008
@@ -552,13 +552,14 @@
                 return VAR;
             }
 
-            if (IMCC_INFO(interp)->cur_unit &&
-                IMCC_INFO(interp)->cur_unit->instructions &&
-                (r = IMCC_INFO(interp)->cur_unit->instructions->symregs[0]) &&
-                r->pcc_sub)
+            if (IMCC_INFO(interp)->cur_unit
+            &&  IMCC_INFO(interp)->cur_unit->instructions
+            && (r = IMCC_INFO(interp)->cur_unit->instructions->symregs[0])
+            &&  r->pcc_sub)
             {
-                if ((r->pcc_sub->pragma & P_METHOD) &&
-                    !strcmp(yytext, "self")) {
+                if (((r->pcc_sub->pragma & P_METHOD)
+                ||   (IMCC_INFO(interp)->cur_unit->is_vtable_method))
+                &&   !strcmp(yytext, "self")) {
                     valp->sr = mk_ident(interp, "self", 'P');
                     IMCC_INFO(interp)->cur_unit->type |= IMC_HAS_SELF;
                     return VAR;

Modified: trunk/compilers/imcc/imclexer.c
==============================================================================
--- trunk/compilers/imcc/imclexer.c     (original)
+++ trunk/compilers/imcc/imclexer.c     Sat Jul 26 14:24:16 2008
@@ -30,7 +30,7 @@
 #define FLEX_SCANNER
 #define YY_FLEX_MAJOR_VERSION 2
 #define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 35
+#define YY_FLEX_SUBMINOR_VERSION 34
 #if YY_FLEX_SUBMINOR_VERSION > 0
 #define FLEX_BETA
 #endif
@@ -75,6 +75,7 @@
 typedef unsigned char flex_uint8_t; 
 typedef unsigned short int flex_uint16_t;
 typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
 
 /* Limits of integral types. */
 #ifndef INT8_MIN
@@ -105,8 +106,6 @@
 #define UINT32_MAX             (4294967295U)
 #endif
 
-#endif /* ! C99 */
-
 #endif /* ! FLEXINT_H */
 
 #ifdef __cplusplus
@@ -214,6 +213,13 @@
 
 #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
 
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ * Given that the standard has decreed that size_t exists since 1989,
+ * I guess we can afford to depend on it. Manoj.
+ */
+
 #ifndef YY_TYPEDEF_YY_SIZE_T
 #define YY_TYPEDEF_YY_SIZE_T
 typedef size_t yy_size_t;
@@ -2770,7 +2776,7 @@
 
 
 
-#line 2774 "compilers/imcc/imclexer.c"
+#line 2780 "compilers/imcc/imclexer.c"
 
 #define INITIAL 0
 #define emit 1
@@ -2924,7 +2930,7 @@
        if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
                { \
                int c = '*'; \
-               size_t n; \
+               int n; \
                for ( n = 0; n < max_size && \
                             (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
                        buf[n] = (char) c; \
@@ -3029,7 +3035,7 @@
             return 0;
         }
 
-#line 3033 "compilers/imcc/imclexer.c"
+#line 3039 "compilers/imcc/imclexer.c"
 
        if ( !yyg->yy_init )
                {
@@ -3933,13 +3939,14 @@
                 return VAR;
             }
 
-            if (IMCC_INFO(interp)->cur_unit &&
-                IMCC_INFO(interp)->cur_unit->instructions &&
-                (r = IMCC_INFO(interp)->cur_unit->instructions->symregs[0]) &&
-                r->pcc_sub)
+            if (IMCC_INFO(interp)->cur_unit
+            &&  IMCC_INFO(interp)->cur_unit->instructions
+            && (r = IMCC_INFO(interp)->cur_unit->instructions->symregs[0])
+            &&  r->pcc_sub)
             {
-                if ((r->pcc_sub->pragma & P_METHOD) &&
-                    !strcmp(yytext, "self")) {
+                if (((r->pcc_sub->pragma & P_METHOD)
+                ||   (IMCC_INFO(interp)->cur_unit->is_vtable_method))
+                &&   !strcmp(yytext, "self")) {
                     valp->sr = mk_ident(interp, "self", 'P');
                     IMCC_INFO(interp)->cur_unit->type |= IMC_HAS_SELF;
                     return VAR;
@@ -3953,32 +3960,32 @@
        YY_BREAK
 case 121:
 YY_RULE_SETUP
-#line 573 "compilers/imcc/imcc.l"
+#line 574 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, FLOATC);
        YY_BREAK
 case 122:
 YY_RULE_SETUP
-#line 574 "compilers/imcc/imcc.l"
+#line 575 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, INTC);
        YY_BREAK
 case 123:
 YY_RULE_SETUP
-#line 575 "compilers/imcc/imcc.l"
+#line 576 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, INTC);
        YY_BREAK
 case 124:
 YY_RULE_SETUP
-#line 576 "compilers/imcc/imcc.l"
+#line 577 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, INTC);
        YY_BREAK
 case 125:
 YY_RULE_SETUP
-#line 577 "compilers/imcc/imcc.l"
+#line 578 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, INTC);
        YY_BREAK
 case 126:
 YY_RULE_SETUP
-#line 579 "compilers/imcc/imcc.l"
+#line 580 "compilers/imcc/imcc.l"
 {
         valp->s = str_dup(yytext);
 
@@ -3991,7 +3998,7 @@
        YY_BREAK
 case 127:
 YY_RULE_SETUP
-#line 589 "compilers/imcc/imcc.l"
+#line 590 "compilers/imcc/imcc.l"
 {
         valp->s = str_dup(yytext);
 
@@ -4001,7 +4008,7 @@
        YY_BREAK
 case 128:
 YY_RULE_SETUP
-#line 596 "compilers/imcc/imcc.l"
+#line 597 "compilers/imcc/imcc.l"
 {
         macro_frame_t *frame;
 
@@ -4033,7 +4040,7 @@
        YY_BREAK
 case 129:
 YY_RULE_SETUP
-#line 625 "compilers/imcc/imcc.l"
+#line 626 "compilers/imcc/imcc.l"
 {
         /* charset:"..." */
         valp->s = str_dup(yytext);
@@ -4044,7 +4051,7 @@
        YY_BREAK
 case 130:
 YY_RULE_SETUP
-#line 633 "compilers/imcc/imcc.l"
+#line 634 "compilers/imcc/imcc.l"
 {
         if (valp) (valp)->s = yytext;
         if (IMCC_INFO(interp)->state->pasm_file)
@@ -4055,7 +4062,7 @@
        YY_BREAK
 case 131:
 YY_RULE_SETUP
-#line 641 "compilers/imcc/imcc.l"
+#line 642 "compilers/imcc/imcc.l"
 {
         if (valp) (valp)->s = yytext;
         if (IMCC_INFO(interp)->state->pasm_file)
@@ -4066,7 +4073,7 @@
        YY_BREAK
 case 132:
 YY_RULE_SETUP
-#line 649 "compilers/imcc/imcc.l"
+#line 650 "compilers/imcc/imcc.l"
 {
         if (valp) (valp)->s = yytext;
         if (IMCC_INFO(interp)->state->pasm_file)
@@ -4077,7 +4084,7 @@
        YY_BREAK
 case 133:
 YY_RULE_SETUP
-#line 657 "compilers/imcc/imcc.l"
+#line 658 "compilers/imcc/imcc.l"
 {
         if (valp) (valp)->s = yytext;
         if (IMCC_INFO(interp)->state->pasm_file)
@@ -4088,7 +4095,7 @@
        YY_BREAK
 case 134:
 YY_RULE_SETUP
-#line 665 "compilers/imcc/imcc.l"
+#line 666 "compilers/imcc/imcc.l"
 {
         IMCC_fataly(interp, E_SyntaxError,
             "'%s' is not a valid register name", yytext);
@@ -4096,19 +4103,19 @@
        YY_BREAK
 case 135:
 YY_RULE_SETUP
-#line 671 "compilers/imcc/imcc.l"
+#line 672 "compilers/imcc/imcc.l"
 /* skip */;
        YY_BREAK
 case 136:
 YY_RULE_SETUP
-#line 673 "compilers/imcc/imcc.l"
+#line 674 "compilers/imcc/imcc.l"
 {
         /* catch all except for state macro */
         return yytext[0];
     }
        YY_BREAK
 case YY_STATE_EOF(emit):
-#line 678 "compilers/imcc/imcc.l"
+#line 679 "compilers/imcc/imcc.l"
 {
         BEGIN(INITIAL);
 
@@ -4121,18 +4128,18 @@
     }
        YY_BREAK
 case YY_STATE_EOF(INITIAL):
-#line 689 "compilers/imcc/imcc.l"
+#line 690 "compilers/imcc/imcc.l"
 yyterminate();
        YY_BREAK
 case 137:
 YY_RULE_SETUP
-#line 691 "compilers/imcc/imcc.l"
+#line 692 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, ENDM);
        YY_BREAK
 case 138:
 /* rule 138 can match eol */
 YY_RULE_SETUP
-#line 693 "compilers/imcc/imcc.l"
+#line 694 "compilers/imcc/imcc.l"
 {
         IMCC_INFO(interp)->line++;
         DUP_AND_RET(valp, '\n');
@@ -4140,12 +4147,12 @@
        YY_BREAK
 case 139:
 YY_RULE_SETUP
-#line 698 "compilers/imcc/imcc.l"
+#line 699 "compilers/imcc/imcc.l"
 return LABEL;
        YY_BREAK
 case 140:
 YY_RULE_SETUP
-#line 700 "compilers/imcc/imcc.l"
+#line 701 "compilers/imcc/imcc.l"
 {
 
         if (yylex(valp,yyscanner,interp) != LABEL)
@@ -4171,7 +4178,7 @@
        YY_BREAK
 case 141:
 YY_RULE_SETUP
-#line 723 "compilers/imcc/imcc.l"
+#line 724 "compilers/imcc/imcc.l"
 {
         if (valp) {
             const size_t len = strlen(IMCC_INFO(interp)->cur_macro_name) + 
yyleng + 12;
@@ -4188,39 +4195,39 @@
        YY_BREAK
 case 142:
 YY_RULE_SETUP
-#line 737 "compilers/imcc/imcc.l"
+#line 738 "compilers/imcc/imcc.l"
 /* skip leading ws */;
        YY_BREAK
 case 143:
 YY_RULE_SETUP
-#line 738 "compilers/imcc/imcc.l"
+#line 739 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, ' ');
        YY_BREAK
 case 144:
 YY_RULE_SETUP
-#line 739 "compilers/imcc/imcc.l"
+#line 740 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, IDENTIFIER);
        YY_BREAK
 case 145:
 YY_RULE_SETUP
-#line 740 "compilers/imcc/imcc.l"
+#line 741 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, MACRO);
        YY_BREAK
 case 146:
 YY_RULE_SETUP
-#line 741 "compilers/imcc/imcc.l"
+#line 742 "compilers/imcc/imcc.l"
 DUP_AND_RET(valp, yytext[0]);
        YY_BREAK
 case YY_STATE_EOF(macro):
-#line 742 "compilers/imcc/imcc.l"
+#line 743 "compilers/imcc/imcc.l"
 yyterminate();
        YY_BREAK
 case 147:
 YY_RULE_SETUP
-#line 744 "compilers/imcc/imcc.l"
+#line 745 "compilers/imcc/imcc.l"
 ECHO;
        YY_BREAK
-#line 4224 "compilers/imcc/imclexer.c"
+#line 4231 "compilers/imcc/imclexer.c"
 case YY_STATE_EOF(pod):
 case YY_STATE_EOF(cmt1):
 case YY_STATE_EOF(cmt2):
@@ -5422,7 +5429,7 @@
 
 #define YYTABLES_NAME "yytables"
 
-#line 744 "compilers/imcc/imcc.l"
+#line 745 "compilers/imcc/imcc.l"
 
 
 

Modified: trunk/compilers/imcc/pcc.c
==============================================================================
--- trunk/compilers/imcc/pcc.c  (original)
+++ trunk/compilers/imcc/pcc.c  Sat Jul 26 14:24:16 2008
@@ -313,12 +313,13 @@
     SymReg      *regs[2];
 
     /* if this sub is a method, unshift 'self' as first param */
-    if (sub->pcc_sub->pragma & P_METHOD) {
+    if ((unit->type & IMC_HAS_SELF) || (sub->pcc_sub->pragma & P_METHOD)) {
         SymReg *self = get_sym(interp, "self");
         if (!self) {
             self       = mk_symreg(interp, "self", 'P');
             self->type = VTIDENTIFIER;
         }
+
         unshift_self(sub, self);
     }
 

Modified: trunk/t/compilers/imcc/syn/objects.t
==============================================================================
--- trunk/t/compilers/imcc/syn/objects.t        (original)
+++ trunk/t/compilers/imcc/syn/objects.t        Sat Jul 26 14:24:16 2008
@@ -1,5 +1,5 @@
 #!perl
-# Copyright (C) 2001-2005, The Perl Foundation.
+# Copyright (C) 2001-2008, The Perl Foundation.
 # $Id$
 
 use strict;
@@ -7,7 +7,7 @@
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
 use Parrot::Config;
-use Parrot::Test tests => 12;
+use Parrot::Test tests => 13;
 
 ##############################
 # ".namespace" sanity
@@ -329,6 +329,35 @@
 done
 OUT
 
+pir_output_is( <<'CODE', <<'OUT', ":vtable implies self (see RT #47674)" );
+.sub 'main' :main
+    $P1 = newclass "Foo"
+    $P2 = new "Foo"
+    $S1 = $P2
+    print $S1
+.end
+
+.namespace [ "Foo" ]
+
+.sub 'get_string' :vtable
+    self.'bar'()
+    .return ("stringy thingy\n")
+.end
+
+.sub bar :method
+    print "called bar\n"
+.end
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4: :ft=pir
+CODE
+called bar
+stringy thingy
+OUT
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4

Reply via email to