develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35843 - in trunk/compilers/pirc: src t

From:
kjs
Date:
January 20, 2009 15:28
Subject:
[svn:parrot] r35843 - in trunk/compilers/pirc: src t
Message ID:
20090120232810.B0305CB9AE@x12.develooper.com
Author: kjs
Date: Tue Jan 20 15:28:09 2009
New Revision: 35843

Modified:
   trunk/compilers/pirc/src/bcgen.c
   trunk/compilers/pirc/src/pircompunit.c
   trunk/compilers/pirc/src/piremit.c
   trunk/compilers/pirc/t/stmts.t

Log:
[pirc] fix something with debug segment creation, fix auto-declaration of "self" for :vtables and :methods, and add a test for :method calls.

Modified: trunk/compilers/pirc/src/bcgen.c
==============================================================================
--- trunk/compilers/pirc/src/bcgen.c	(original)
+++ trunk/compilers/pirc/src/bcgen.c	Tue Jan 20 15:28:09 2009
@@ -438,9 +438,11 @@
 */
 void
 create_debugsegment(bytecode * const bc, size_t size, char const * const file) {
+    /* create a new debug segment; Parrot_new_debug_seg() automatically stores
+     * away any currently existing debug segment.
+     */
     bc->debug_seg = Parrot_new_debug_seg(bc->interp, bc->interp->code, size);
 
-
     Parrot_debug_add_mapping(bc->interp, bc->debug_seg, bc->instr_counter, file);
 }
 

Modified: trunk/compilers/pirc/src/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/src/pircompunit.c	(original)
+++ trunk/compilers/pirc/src/pircompunit.c	Tue Jan 20 15:28:09 2009
@@ -188,6 +188,9 @@
     else {
         CURRENT_SUB(lexer)->info.vtable_index = vtable_index;
         SET_FLAG(lexer->subs->flags, PIRC_SUB_FLAG_VTABLE);
+
+        /* :vtable methods have an automatic "self" parameter */
+        add_param(lexer, PMC_TYPE, "self");
     }
 }
 
@@ -226,6 +229,9 @@
         CURRENT_SUB(lexer)->methodname = CURRENT_SUB(lexer)->info.subname;
 
     SET_FLAG(lexer->subs->flags, PIRC_SUB_FLAG_METHOD);
+
+    /* :methods have an automatic "self" parameter */
+    add_param(lexer, PMC_TYPE, "self");
 }
 
 /*
@@ -266,8 +272,7 @@
 set_sub_flag(lexer_state * const lexer, sub_flag flag)>
 
 Set a subroutine flag on the current sub. The C<flag> parameter may encode
-multiple flags. If it encodes the C<:vtable> or C<:method> flag, an extra
-parameter named C<self> is added to the current subroutine.
+multiple flags.
 
 =cut
 
@@ -277,9 +282,6 @@
     /* set the specified flag in the current subroutine */
     SET_FLAG(CURRENT_SUB(lexer)->flags, flag);
 
-    /* if the sub is a method or a :vtable method, then also add a "self" parameter */
-    if (TEST_FLAG(flag, (PIRC_SUB_FLAG_VTABLE | PIRC_SUB_FLAG_METHOD)))
-        add_param(lexer, PMC_TYPE, "self");
 }
 
 /*

Modified: trunk/compilers/pirc/src/piremit.c
==============================================================================
--- trunk/compilers/pirc/src/piremit.c	(original)
+++ trunk/compilers/pirc/src/piremit.c	Tue Jan 20 15:28:09 2009
@@ -876,8 +876,7 @@
 
     /* create debug segment */
     /* XXX is this the right size? */
-    create_debugsegment(lexer->bc, lexer->codesize, iter->sourceline, lexer->filename);
-
+    create_debugsegment(lexer->bc, lexer->codesize, lexer->filename);
 
     do {
         emit_pbc_instr(lexer, iter);

Modified: trunk/compilers/pirc/t/stmts.t
==============================================================================
--- trunk/compilers/pirc/t/stmts.t	(original)
+++ trunk/compilers/pirc/t/stmts.t	Tue Jan 20 15:28:09 2009
@@ -3,7 +3,7 @@
 # $Id$
 
 use lib "../../lib";
-use Parrot::Test tests => 4;
+use Parrot::Test tests => 5;
 
 pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "a simple sub call - no params");
 .sub main
@@ -73,6 +73,26 @@
 OUTPUT
 
 
+
+pirc_2_pasm_is(<<'CODE', <<'OUTPUT', "method call");
+.sub main
+    .local pmc cl, obj, meth
+    cl  = newclass "Foo"
+    obj = new "Foo"
+    obj.'hi'()
+.end
+
+.namespace ["Foo"]
+.sub hi :method
+    say "ok"
+.end
+
+
+CODE
+ok
+OUTPUT
+
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About