cvsuser 04/03/11 06:02:49
Modified: imcc imcc.l imcc.y symreg.c symreg.h
imcc/t/syn objects.t
Log:
PIR meth call syntax - 5
Revision Changes Path
1.89 +10 -1 parrot/imcc/imcc.l
Index: imcc.l
===================================================================
RCS file: /cvs/public/parrot/imcc/imcc.l,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -w -r1.88 -r1.89
--- imcc.l 11 Mar 2004 13:17:00 -0000 1.88
+++ imcc.l 11 Mar 2004 14:02:44 -0000 1.89
@@ -194,6 +194,7 @@
".pcc_end_yield" return(PCC_END_YIELD);
"prototyped" return(PROTOTYPED);
"non_prototyped" return(NON_PROTOTYPED);
+"method" return(METHOD);
<emit,INITIAL>"@MAIN" return(MAIN);
<emit,INITIAL>"@LOAD" return(LOAD);
<emit,INITIAL>"@IMMEDIATE" return(IMMEDIATE);
@@ -206,7 +207,7 @@
<emit,INITIAL>".namespace" return(NAMESPACE);
".endnamespace" return(ENDNAMESPACE);
".field" return(FIELD);
-".method" return(METHOD);
+".method" return(DOT_METHOD);
".local" return(LOCAL);
".global" return(GLOBAL);
".const" return(CONST);
@@ -365,6 +366,14 @@
valp->sr = r;
return VAR;
}
+ if (cur_unit && cur_unit->instructions &&
+ !strcmp(yytext, "self") &&
+ (r = cur_unit->instructions->r[1])) {
+ if (r->pcc_sub && r->pcc_sub->pragma & P_METHOD)
+ valp->s = str_dup("P2");
+ return REG;
+ }
+
}
valp->s = str_dup(yytext);
return(!is_def && is_op(interp, valp->s) ? PARROT_OP : IDENTIFIER);
1.124 +4 -3 parrot/imcc/imcc.y
Index: imcc.y
===================================================================
RCS file: /cvs/public/parrot/imcc/imcc.y,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -w -r1.123 -r1.124
--- imcc.y 11 Mar 2004 13:17:00 -0000 1.123
+++ imcc.y 11 Mar 2004 14:02:44 -0000 1.124
@@ -242,7 +242,7 @@
%token <t> PRAGMA
%token <t> CALL GOTO ARG FLATTEN_ARG IF UNLESS END SAVEALL RESTOREALL
%token <t> NEW NEWSUB NEWCLOSURE NEWCOR NEWCONT
-%token <t> NAMESPACE ENDNAMESPACE CLASS ENDCLASS FIELD METHOD
+%token <t> NAMESPACE ENDNAMESPACE CLASS ENDCLASS FIELD DOT_METHOD
%token <t> SUB SYM LOCAL CONST
%token <t> INC DEC GLOBAL_CONST
%token <t> SHIFT_LEFT SHIFT_RIGHT INTV FLOATV STRINGV PMCV OBJECTV DEFINED LOG_XOR
@@ -251,7 +251,7 @@
%token <t> COMMA ESUB
%token <t> PCC_BEGIN PCC_END PCC_CALL PCC_SUB PCC_BEGIN_RETURN PCC_END_RETURN
%token <t> PCC_BEGIN_YIELD PCC_END_YIELD NCI_CALL
-%token <t> PROTOTYPED NON_PROTOTYPED MAIN LOAD IMMEDIATE POSTCOMP
+%token <t> PROTOTYPED NON_PROTOTYPED MAIN LOAD IMMEDIATE POSTCOMP METHOD
%token <s> LABEL
%token <t> EMIT EOM
%token <s> IREG NREG SREG PREG IDENTIFIER STRINGC INTC FLOATC REG MACRO ENDM
@@ -429,7 +429,7 @@
;
method_decl:
- METHOD IDENTIFIER IDENTIFIER '\n'
+ DOT_METHOD IDENTIFIER IDENTIFIER '\n'
{
Method * meth;
Symbol * sym = new_symbol($2);
@@ -551,6 +551,7 @@
| MAIN { $$ = P_MAIN; }
| IMMEDIATE { $$ = P_IMMEDIATE; }
| POSTCOMP { $$ = P_POSTCOMP; }
+ | METHOD { $$ = P_METHOD; }
;
pcc_call:
1.47 +2 -2 parrot/imcc/symreg.c
Index: symreg.c
===================================================================
RCS file: /cvs/public/parrot/imcc/symreg.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -w -r1.46 -r1.47
--- symreg.c 11 Mar 2004 13:17:00 -0000 1.46
+++ symreg.c 11 Mar 2004 14:02:44 -0000 1.47
@@ -328,7 +328,7 @@
* add namespace to sub if any
* */
static char *
-add_ns(SymReg *r, char *name)
+add_ns(char *name)
{
int len, l;
char *ns_name;
@@ -361,7 +361,7 @@
return r;
}
if (uniq == U_add_uniq_sub)
- name = add_ns(r, name);
+ name = add_ns(name);
if (uniq && (r = _get_sym(hsh, name)) &&
r->type == VTADDRESS &&
1.43 +1 -0 parrot/imcc/symreg.h
Index: symreg.h
===================================================================
RCS file: /cvs/public/parrot/imcc/symreg.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -w -r1.42 -r1.43
--- symreg.h 11 Mar 2004 13:17:00 -0000 1.42
+++ symreg.h 11 Mar 2004 14:02:44 -0000 1.43
@@ -125,6 +125,7 @@
P_NON_PROTOTYPED = 0x00, /* must be 0 */
P_PROTOTYPED = 0x01, /* must be 1 */
P_NONE = 0x04,
+ P_METHOD = 0x08,
P_MAIN = PObj_private4_FLAG, /* s. packfile.c ... */
P_LOAD = PObj_private5_FLAG,
1.4 +35 -5 parrot/imcc/t/syn/objects.t
Index: objects.t
===================================================================
RCS file: /cvs/public/parrot/imcc/t/syn/objects.t,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- objects.t 11 Mar 2004 13:17:08 -0000 1.3
+++ objects.t 11 Mar 2004 14:02:49 -0000 1.4
@@ -1,13 +1,12 @@
#!perl
use strict;
-use TestCompiler tests => 5;
+use TestCompiler tests => 6;
##############################
# Parrot Calling Conventions
output_is(<<'CODE', <<'OUT', "meth call syntax");
-.namespace [ "Foo" ]
.sub _main
.local pmc class
@@ -20,6 +19,8 @@
print "done\n"
end
.end
+
+.namespace [ "Foo" ]
.sub _meth
print "in meth\n"
.end
@@ -30,7 +31,6 @@
OUT
output_is(<<'CODE', <<'OUT', "meth call syntax m.o(arg)");
-.namespace [ "Foo" ]
.sub _main
.local pmc class
.local pmc obj
@@ -43,6 +43,8 @@
print "done\n"
end
.end
+
+.namespace [ "Foo" ]
.sub _meth
.param pmc s
print "in meth\n"
@@ -55,7 +57,6 @@
OUT
output_is(<<'CODE', <<'OUT', "meth call ret = o.m(arg)");
-.namespace [ "Foo" ]
.sub _main
.local pmc class
.local pmc obj
@@ -68,6 +69,8 @@
print $S0
end
.end
+
+.namespace [ "Foo" ]
.sub _meth
.param pmc s
print "in meth\n"
@@ -83,7 +86,6 @@
OUT
output_is(<<'CODE', <<'OUT', "meth call syntax");
-.namespace [ "Foo" ]
.sub _main
.local pmc class
.local pmc obj
@@ -101,6 +103,7 @@
print "done\n"
end
.end
+.namespace [ "Foo" ]
.sub _meth
print "in meth\n"
.end
@@ -152,3 +155,30 @@
done
OUT
+output_is(<<'CODE', <<'OUT', "meth call syntax - method, self");
+
+.sub _main
+ .local pmc class
+ .local pmc obj
+ newclass class, "Foo"
+ find_type $I0, "Foo"
+ new obj, $I0
+ obj._meth()
+ print "done\n"
+ end
+.end
+
+.namespace [ "Foo" ]
+.sub _meth method
+ print "in meth\n"
+ isa $I0, self, "Foo"
+ if $I0, ok
+ print "not "
+ok:
+ print "ok\n"
+.end
+CODE
+in meth
+ok
+done
+OUT