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

bacek at svn.parrot.org bacek at svn.parrot.org
Sat May 2 03:40:38 UTC 2009


Author: bacek
Date: Sat May  2 03:40:20 2009
New Revision: 38434
URL: https://trac.parrot.org/parrot/changeset/38434

Log:
Add (totally incomplete) class_init generating

Modified:
   branches/pmc_pct/compilers/pmc/src/emitter/pmc.pir
   branches/pmc_pct/compilers/pmc/src/nodes.pir
   branches/pmc_pct/compilers/pmc/src/parser/actions.pm
   branches/pmc_pct/compilers/pmc/t/06-body.t

Modified: branches/pmc_pct/compilers/pmc/src/emitter/pmc.pir
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/emitter/pmc.pir	Fri May  1 23:41:15 2009	(r38433)
+++ branches/pmc_pct/compilers/pmc/src/emitter/pmc.pir	Sat May  2 03:40:20 2009	(r38434)
@@ -117,12 +117,12 @@
     .local string guard
     .local string name
 
-    name = past.'name'()
-    $S0 = 'uc'(name)
-
     $S0 = self.'generate_c_file_functions'(past)
     concat res, $S0
     
+    $S0 = self.'!generate_class_init'(past)
+    concat res, $S0
+    
     .return (res)
 .end
 
@@ -172,7 +172,6 @@
 .end
 
 
-
 =item C<!generate_signature>
 
 Generate full signature of vtable.
@@ -219,6 +218,48 @@
     .return ($S0)
 .end
 
+
+=item C<!generate_class_init>
+
+Generating class_init function
+
+=cut
+
+.sub '!generate_class_init' :method
+    .param pmc past
+    
+    .local string pmc_name
+    pmc_name = past.'name'()
+
+    .local pmc res
+
+    res = new 'ResizableStringArray'
+    push res, 'PARROT_EXPORT void '
+    push res, ' Parrot_'
+    push res, pmc_name
+    push res, '_class_init'
+    push res, '(PARROT_INTERP, int entry, int pass) '
+
+    push res, "\n{\n"
+
+    # Put generating of vtables here.
+
+    $P0 = past['class_init']
+    $I0 = defined $P0
+    unless $I0 goto no_init
+
+    push res, "/* class_init */\n"
+    $S0 = self.'!generate_body'($P0)
+    push res, $S0
+  no_init:
+
+    push res, "\n}\n"
+    
+
+    $S0 = join '', res
+    .return ($S0)
+.end
+
 =item C<!generate_body>
 
 Generate C function body from PAST.

Modified: branches/pmc_pct/compilers/pmc/src/nodes.pir
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/nodes.pir	Fri May  1 23:41:15 2009	(r38433)
+++ branches/pmc_pct/compilers/pmc/src/nodes.pir	Sat May  2 03:40:20 2009	(r38434)
@@ -44,9 +44,6 @@
     $P3 = new 'ResizableStringArray'
     res.'attr'('parents', $P3, 1)
 
-    $P4 = new 'Hash'
-    res.'attr'('class_init', $P4, 1)
-
     $P5 = new 'Hash'
     res.'attr'('vtables', $P5, 1)
 
@@ -135,13 +132,12 @@
     .local string name
     name = 'class_init'
 
-    $P0 = self.'attr'('class_init', 0, 0)
-    $I0 = exists $P0[name]
+    $I0 = exists self['class_init']
     unless $I0 goto add_method
     $S0 = "Duplicate class_init function: "
     die $S0
   add_method:
-    $P0[name] = method
+    self['class_init'] = method
     .return ()
 .end
 

Modified: branches/pmc_pct/compilers/pmc/src/parser/actions.pm
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/parser/actions.pm	Fri May  1 23:41:15 2009	(r38433)
+++ branches/pmc_pct/compilers/pmc/src/parser/actions.pm	Sat May  2 03:40:20 2009	(r38434)
@@ -66,7 +66,12 @@
 
 method class_init($/) {
     #say('class_init ' ~$<identifier>);
-    my $past := PAST::Block.new( :blocktype('declaration'), :node($/) );
+    my $past := PAST::Block.new( 
+        :blocktype('method'),
+        :returns('void'),
+        :node($/),
+        $<c_body>.ast
+    );
     make $past;
 }
 
@@ -76,11 +81,11 @@
         :name(~$<c_signature><identifier>),
         :blocktype('method'),
         :returns(~$<c_signature><c_type>),
-        :node($/)
+        :node($/),
+
+        $<c_body>.ast
     );
     $past<parameters> := $<c_signature><c_arguments>.ast;
-    #say(~$<c_body>);
-    $past.push($<c_body>.ast());
     make $past;
 }
 
@@ -89,11 +94,12 @@
     my $past := PAST::Block.new(
         :name(~$<identifier>),
         :blocktype('declaration'),
+        :returns('void'),           # PCC METHODS returns void
         :node($/),
-        PAST::Op.new(
-            :inline(~$<c_body>)
-        )
+
+        $<c_body>.ast
     );
+    #$past<parameters> := $<c_signature><c_arguments>.ast;
     make $past;
 }
 

Modified: branches/pmc_pct/compilers/pmc/t/06-body.t
==============================================================================
--- branches/pmc_pct/compilers/pmc/t/06-body.t	Fri May  1 23:41:15 2009	(r38433)
+++ branches/pmc_pct/compilers/pmc/t/06-body.t	Sat May  2 03:40:20 2009	(r38434)
@@ -8,7 +8,7 @@
 load_bytecode 'pmc.pbc'
     .local int total
 
-    plan(3)
+    plan(4)
 
     .local string filename
 
@@ -19,6 +19,8 @@
     check_one_file(filename, $S0, "'PMC * Parrot_Integer_instantiate(PARROT_INTERP, PMC *sig)'", "VTable method generated")
     check_one_file(filename, $S0, "'Integer.instantiate: unhandled initializer'", "VTable body generated")
 
+    $S0 = _slurp('t/data/class14.pmc')
+    check_one_file(filename, $S0, "'/* class_init_code; called for side effects */'", "class_init body preserved")
 .end
 
 # Check genrated header.
@@ -38,7 +40,7 @@
     emitter = new $P1
     emitter.'set_filename'(name)
     $S0 = emitter.'generate_c_file'($P0)
-    #say $S0
+    say $S0
     like($S0, pattern, message)
 .end
 


More information about the parrot-commits mailing list