[svn:parrot] r39715 - in branches/pmc_pct/compilers/pmcc: . src src/emitter src/parser
cotto at svn.parrot.org
cotto at svn.parrot.org
Mon Jun 22 13:03:41 UTC 2009
Author: cotto
Date: Mon Jun 22 13:03:32 2009
New Revision: 39715
URL: https://trac.parrot.org/parrot/changeset/39715
Log:
[pmcc] add some initial code to generate ro variant vtables
Modified:
branches/pmc_pct/compilers/pmcc/pmcc.pir
branches/pmc_pct/compilers/pmcc/src/builtins.pir
branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm
branches/pmc_pct/compilers/pmcc/src/nodes.pir
branches/pmc_pct/compilers/pmcc/src/parser/actions.pm
Modified: branches/pmc_pct/compilers/pmcc/pmcc.pir
==============================================================================
--- branches/pmc_pct/compilers/pmcc/pmcc.pir Mon Jun 22 12:37:32 2009 (r39714)
+++ branches/pmc_pct/compilers/pmcc/pmcc.pir Mon Jun 22 13:03:32 2009 (r39715)
@@ -26,7 +26,7 @@
#add an extra stage to generate the c, h and dump files
$P0.'addstage'('generate_files', 'after'=>'past')
- $P0.'addstage'('read_dump', 'before'=>'past')
+ #$P0.'addstage'('read_dump', 'before'=>'parse')
$P1 = split ' ', 'e=s vtdump|d=s pmc_path|p=s help|h target=s dumper=s trace|t=s encoding=s output|o=s combine version|v'
setattribute $P0, '@cmdoptions', $P1
@@ -76,6 +76,22 @@
.param pmc past
.param pmc adverbs :slurpy :named
+ .local string vtdump_filename, vtdump_str
+ .local pmc vtdump
+
+ vtdump_filename = '../../vtable.frozen'
+ #$P0 = getstderr
+ #print $P0, "Error: no vtable.freeze specified."
+ $P0 = new ['FileHandle']
+ vtdump_str = $P0.'readall'(vtdump_filename)
+ vtdump = thaw vtdump_str
+
+ set_global ['PMC';'Class'], '%vtdump', vtdump
+
+ load_bytecode 'JSON.pbc'
+ #$S0 = _json(vtdump,1)
+ #say $S0
+
.return (past, adverbs :flat :named)
.end
Modified: branches/pmc_pct/compilers/pmcc/src/builtins.pir
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/builtins.pir Mon Jun 22 12:37:32 2009 (r39714)
+++ branches/pmc_pct/compilers/pmcc/src/builtins.pir Mon Jun 22 13:03:32 2009 (r39715)
@@ -131,6 +131,25 @@
.return ($S0)
.end
+.sub 'json'
+ .param pmc p
+ load_bytecode 'JSON.pbc'
+ $S0 = _json(p, 1)
+ .return ($S0)
+.end
+
+.sub 'thaw'
+ .param string filename
+
+ .local string frozen
+ .local pmc pio
+ pio = new ['FileHandle']
+ frozen = pio.'readall'(filename)
+ $P0 = thaw frozen
+ .return ($P0)
+
+.end
+
# Extend various Parrot's PMCs to play nicely with NQP.
.namespace ['Hash']
Modified: branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm Mon Jun 22 12:37:32 2009 (r39714)
+++ branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm Mon Jun 22 13:03:32 2009 (r39715)
@@ -522,7 +522,16 @@
method generate_get_vtable_func() {
my @res;
my @other_parents := self.past.parents;
- my $first_parent := @other_parents.shift;
+ my $parent_count := elements(@other_parents);
+ my $first_parent;
+
+ if ($parent_count == 0) {
+ $first_parent := 'default';
+ }
+ else {
+ $first_parent := @other_parents.shift;
+ }
+ say("first parent is "~$first_parent);
@res.push('PARROT_EXPORT');
@res.push('PARROT_CANNOT_RETURN_NULL');
@@ -570,8 +579,21 @@
@res.push('');
@res.push(' return vt;');
@res.push("}");
+ @res.push('');
+ @res.push('');
#XXX: needs implementation for variant vtable functions
+ @res.push('PARROT_EXPORT');
+ @res.push('VTABLE *Parrot_'~ self.name ~"_ro_update_vtable(VTABLE *vt) {");
+
+ for (self.past.vtables{'ro'}) {
+ @res.push(' vt->'~$_~' = Parrot_'~self.name~'_'~$_~';');
+ }
+ @res.push('');
+ @res.push(' return vt;');
+ @res.push("}");
+ @res.push('');
+
join("\n", at res);
}
Modified: branches/pmc_pct/compilers/pmcc/src/nodes.pir
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/nodes.pir Mon Jun 22 12:37:32 2009 (r39714)
+++ branches/pmc_pct/compilers/pmcc/src/nodes.pir Mon Jun 22 13:03:32 2009 (r39715)
@@ -48,6 +48,9 @@
res.'attr'('vtables', $P1, 1)
$P1 = new 'Hash'
+ res.'attr'('vtdump', $P1, 1)
+
+ $P1 = new 'Hash'
res.'attr'('methods', $P1, 1)
# Multis are Hash of Arrays. name -> implementation*
@@ -96,6 +99,16 @@
.tailcall self.'attr'('vtables',0,0)
.end
+=item C<vtudmp>
+
+Get PMC vtable dump hash.
+
+=cut
+
+.sub 'vtdump' :method
+ .tailcall self.'attr'('vtdump',0,0)
+.end
+
=item C<methods>
Get PMC methods.
@@ -245,6 +258,19 @@
.return ()
.end
+
+=item C<set_vtdump>
+
+Store the thawed vtable.tbl dump in this PMC.
+
+=cut
+
+.sub 'set_vtdump' :method
+ .param pmc vtdump
+ .tailcall self.'attrs'('vtdump', vtdump, 1)
+.end
+
+
=item C<add_vtable>
Add a VTABLE function to this PMC's default vtable.
Modified: branches/pmc_pct/compilers/pmcc/src/parser/actions.pm
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/parser/actions.pm Mon Jun 22 12:37:32 2009 (r39714)
+++ branches/pmc_pct/compilers/pmcc/src/parser/actions.pm Mon Jun 22 13:03:32 2009 (r39715)
@@ -28,7 +28,7 @@
else {
# TODO Set c_header and c_coda
#XXX: is this the best place to set up variant vtables?
- #$?PMC.create_variant_vtables();
+ $?PMC.create_variant_vtable();
make $?PMC;
}
}
More information about the parrot-commits
mailing list