[svn:parrot] r38416 - in branches/pmc_pct/compilers/pmc: src src/parser t

cotto at svn.parrot.org cotto at svn.parrot.org
Fri May 1 09:47:07 UTC 2009


Author: cotto
Date: Fri May  1 09:47:05 2009
New Revision: 38416
URL: https://trac.parrot.org/parrot/changeset/38416

Log:
[pmc_pct] add (not-quite-working) code to emit a class_init function prototype

Modified:
   branches/pmc_pct/compilers/pmc/src/nodes.pir
   branches/pmc_pct/compilers/pmc/src/parser/actions.pm
   branches/pmc_pct/compilers/pmc/src/pmc_emitter.pir
   branches/pmc_pct/compilers/pmc/t/04-header.t

Modified: branches/pmc_pct/compilers/pmc/src/nodes.pir
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/nodes.pir	Thu Apr 30 22:12:56 2009	(r38415)
+++ branches/pmc_pct/compilers/pmc/src/nodes.pir	Fri May  1 09:47:05 2009	(r38416)
@@ -45,13 +45,16 @@
     res.'attr'('parents', $P3, $I0)
 
     $P4 = new 'Hash'
-    res.'attr'('vtables', $P4, $I0)
+    res.'attr'('class_init', $P4, 0)
 
     $P5 = new 'Hash'
-    res.'attr'('methods', $P5, $I0)
+    res.'attr'('vtables', $P5, $I0)
 
-    $P6 = new 'ResizableStringArray'
-    res.'attr'('provides', $P6, $I0)
+    $P6 = new 'Hash'
+    res.'attr'('methods', $P6, $I0)
+
+    $P7 = new 'ResizableStringArray'
+    res.'attr'('provides', $P7, $I0)
 
     .return (res)
 .end
@@ -66,6 +69,16 @@
     .tailcall self.'attr'('parents',0,0)
 .end
 
+=item C<class_init>
+
+Get PMC vtable class_init, if any.
+
+=cut
+
+.sub 'class_init' :method
+    .tailcall self.'attr'('class_init',0,0)
+.end
+
 =item C<vtables>
 
 Get PMC vtable methods.
@@ -110,6 +123,28 @@
     .tailcall self.'attr'(name, value, has_value)
 .end
 
+=item C<add_class_init>
+
+Add a class_init function to PMC.
+
+=cut
+
+.sub 'add_class_init' :method
+    .param pmc method
+
+    .local string name
+    name = 'class_init'
+
+    $P0 = self.'attr'('class_init', 0, 0)
+    $I0 = exists $P0[name]
+    unless $I0 goto add_method
+    $S0 = "Duplicate class_init function: "
+    die $S0
+  add_method:
+    $P0[name] = method
+    .return ()
+.end
+
 =item C<add_vtable>
 
 Add VTABLE method to PMC.
@@ -150,6 +185,7 @@
     .return ()
 .end
 
+
 =head1 COPYRIGHT
 
 Copyright (C) 2009, Parrot Foundation.

Modified: branches/pmc_pct/compilers/pmc/src/parser/actions.pm
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/parser/actions.pm	Thu Apr 30 22:12:56 2009	(r38415)
+++ branches/pmc_pct/compilers/pmc/src/parser/actions.pm	Fri May  1 09:47:05 2009	(r38416)
@@ -53,7 +53,10 @@
 
     #say("body_part: " ~$key);
     my $m := $/{$key}.ast;
-    if $key eq 'vtable' {
+    if $key eq 'class_init' {
+        $?PMC.add_class_init($m);
+    }
+    elsif $key eq 'vtable' {
         $?PMC.add_vtable($m.name, $m);
     }
     elsif $key eq 'method' {
@@ -61,6 +64,12 @@
     }
 }
 
+method class_init($/) {
+    #say('class_init ' ~$<identifier>);
+    my $past := PAST::Block.new( :blocktype('declaration'), :node($/) );
+    make $past;
+}
+
 method vtable($/) {
     #say('VABLE ' ~$<c_signature><identifier>);
     my $past := PAST::Block.new( 

Modified: branches/pmc_pct/compilers/pmc/src/pmc_emitter.pir
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/pmc_emitter.pir	Thu Apr 30 22:12:56 2009	(r38415)
+++ branches/pmc_pct/compilers/pmc/src/pmc_emitter.pir	Fri May  1 09:47:05 2009	(r38416)
@@ -66,7 +66,7 @@
     .param pmc past
     .local string res
     .local pmc vtable_info, vtable_hash
-    .local pmc vtables, it, entry
+    .local pmc vtables, it, entry, class_init
     .local string pmc_name, vtable_name
 
     pmc_name = past.'name'()
@@ -74,6 +74,16 @@
     $P0 = get_hll_global ['PMC'; 'VTableInfo'], 'vtable_hash'
     vtable_hash = $P0()
     
+    class_init = self.'!class_init'(past)
+    $I0 = elements class_init
+    unless $I0 == 1 goto vtables_loop
+
+    concat res, "void Parrot_"
+    concat res, pmc_name
+    concat res, "_class_init(PARROT_INTERP, int, int);\n" 
+
+  vtables_loop:  
+
     vtables = self.'!vtables'(past)
 
     it = iter vtables
@@ -106,6 +116,11 @@
     .return (res)
 .end
 
+.sub '!class_init' :method
+    .param pmc past
+    .tailcall past.'class_init'()
+.end
+
 .sub '!vtables' :method
     .param pmc past
     .tailcall past.'vtables'()

Modified: branches/pmc_pct/compilers/pmc/t/04-header.t
==============================================================================
--- branches/pmc_pct/compilers/pmc/t/04-header.t	Thu Apr 30 22:12:56 2009	(r38415)
+++ branches/pmc_pct/compilers/pmc/t/04-header.t	Fri May  1 09:47:05 2009	(r38416)
@@ -40,7 +40,7 @@
     emitter = new $P1
     emitter.'set_filename'(name)
     $S0 = emitter.'generate_h_file'($P0)
-    #say $S0
+    say $S0
     like($S0, pattern, message)
 .end
 


More information about the parrot-commits mailing list