[svn:parrot] r39785 - in branches/pmc_pct/compilers/pmcc/src: . emitter parser
cotto at svn.parrot.org
cotto at svn.parrot.org
Thu Jun 25 23:47:17 UTC 2009
Author: cotto
Date: Thu Jun 25 23:47:17 2009
New Revision: 39785
URL: https://trac.parrot.org/parrot/changeset/39785
Log:
[pmcc] finish code to emit class_init, now for cleanup
Modified:
branches/pmc_pct/compilers/pmcc/src/builtins.pir
branches/pmc_pct/compilers/pmcc/src/emitter/c.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
branches/pmc_pct/compilers/pmcc/src/parser/grammar.pg
Modified: branches/pmc_pct/compilers/pmcc/src/builtins.pir
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/builtins.pir Thu Jun 25 22:49:12 2009 (r39784)
+++ branches/pmc_pct/compilers/pmcc/src/builtins.pir Thu Jun 25 23:47:17 2009 (r39785)
@@ -147,7 +147,11 @@
frozen = pio.'readall'(filename)
$P0 = thaw frozen
.return ($P0)
+.end
+.sub 'die'
+ .param string msg
+ die msg
.end
# Extend various Parrot's PMCs to play nicely with NQP.
Modified: branches/pmc_pct/compilers/pmcc/src/emitter/c.pir
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/emitter/c.pir Thu Jun 25 22:49:12 2009 (r39784)
+++ branches/pmc_pct/compilers/pmcc/src/emitter/c.pir Thu Jun 25 23:47:17 2009 (r39785)
@@ -45,10 +45,8 @@
.param pmc pmclass
.param pmc past
.local string res
- res = "{\n"
$S0 = self.'!generate_children_body_part'(pmclass, past)
concat res, $S0
- concat res, "}\n"
.return (res)
.end
Modified: branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm Thu Jun 25 22:49:12 2009 (r39784)
+++ branches/pmc_pct/compilers/pmcc/src/emitter/pmc.pm Thu Jun 25 23:47:17 2009 (r39785)
@@ -311,6 +311,18 @@
=cut
method generate_c_code($past) {
+
+ my %vtables := thaw('../../vtable.frozen');
+ #make sure there aren't any misnamed VTABLE functions
+ for self.past.vtables{'default'} {
+ if !%vtables{$_} {
+ #XXX: check that the return type and parameter types are good too
+ #XXX: show a nicer message that points to the failure
+ die("Found an invalid vtable function '"~$_~"'. Perhaps you misnamed it?");
+ }
+ }
+
+
self.pre_method_gen();
my $res :=
self.past<c_header> ~ "\n\n"
@@ -385,12 +397,6 @@
@res.push( self.generate_multis() );
@res.push( self.generate_passes() );
- my $past := self.past;
- if ($past<class_init>) {
- @res.push("/* class_init */\n");
- @res.push(PMC::Emitter::C.new().emit($past, $past<class_init>));
- }
-
@res.push("\n}\n");
join('', @res);
}
@@ -521,16 +527,16 @@
@res.push(' } /* pass 2 */');
@res.push(' else {');
- my $hll := self.past.hll();
+ my $hll := self.past.traits{'hll'};
- if $hll ne '' && elements(self.past.maps()) {
+ if $hll ne '' && elements(self.past.maps) {
@res.push(' {');
@res.push(' /* Register this PMC as a HLL mapping */');
@res.push(' const INTVAL pmc_id = Parrot_get_HLL_id( interp, CONST_STRING_GEN(interp, "'~$hll~'"));');
@res.push(' if (pmc_id > 0) {');
- for self.past.maps() {
+ for self.past.maps {
@res.push(' Parrot_register_HLL_type( interp, pmc_id, enum_class_'~$_~', entry);');
}
@@ -539,18 +545,33 @@
@res.push('');
}
- @res.push(' /* set up MRO and _namespace */');
- @res.push(' {');
- @res.push(' VTABLE * const vt = interp->vtables[entry];');
- @res.push(' vt->mro = Parrot_'~self.name~'_get_mro(interp, PMCNULL);');
- @res.push(' if (vt->ro_variant_vtable)');
- @res.push(' vt->ro_variant_vtable->mro = vt->mro;');
- @res.push(' }');
+ @res.push(' /* set up MRO and _namespace */');
+ @res.push(' {');
+ @res.push(' VTABLE * const vt = interp->vtables[entry];');
+ @res.push(' vt->mro = Parrot_'~self.name~'_get_mro(interp, PMCNULL);');
+ @res.push(' if (vt->ro_variant_vtable)');
+ @res.push(' vt->ro_variant_vtable->mro = vt->mro;');
+ @res.push(' }');
@res.push('');
- @res.push(' Parrot_create_mro(interp, entry);');
+ @res.push(' Parrot_create_mro(interp, entry);');
+ for self.past.methods {
+ @res.push(' register_raw_nci_method_in_ns(interp, entry, F2DPTR(Parrot_'~self.name~'_nci_'~$_~'), CONST_STRING_GEN(interp, "'~$_~'"));');
+ if self.past.methods{$_}{'attrs'}{'write'} {
+ @res.push(' Parrot_mark_method_writes(interp, entry, "nci_'~$_~'");');
+ }
+ }
+ @res.push('');
- @res.push('}');
+ if self.past.class_init {
+ @res.push(' /* class_init */');
+ @res.push(' {');
+ @res.push(PMC::Emitter::C.new().emit(self.past, self.past.class_init));
+ #@res.push(self.past.class_init);
+ @res.push(' }');
+ }
+
+ @res.push(' }');
join("\n", @res);
}
@@ -575,7 +596,6 @@
else {
$first_parent := @other_parents.shift;
}
- say("first parent is "~$first_parent);
@res.push('PARROT_EXPORT');
@res.push('PARROT_CANNOT_RETURN_NULL');
Modified: branches/pmc_pct/compilers/pmcc/src/nodes.pir
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/nodes.pir Thu Jun 25 22:49:12 2009 (r39784)
+++ branches/pmc_pct/compilers/pmcc/src/nodes.pir Thu Jun 25 23:47:17 2009 (r39785)
@@ -42,6 +42,9 @@
# Initialize various attributes
$P1 = new ['ResizableStringArray']
+ res.'attr'('does', $P1, 1)
+
+ $P1 = new ['ResizableStringArray']
res.'attr'('parents', $P1, 1)
$P1 = new ['Hash']
@@ -66,15 +69,22 @@
$P1 = new ['Hash']
res.'attr'('traits', $P1, 1)
- $P1 = new ['String']
- res.'attr'('hll', $P1, 1)
-
$P1 = new ['ResizableStringArray']
res.'attr'('maps', $P1, 1)
.return (res)
.end
+=item C<does>
+
+How does this PMC act?.
+
+=cut
+
+.sub 'does' :method
+ .tailcall self.'attr'('does',0,0)
+.end
+
=item C<parents>
Get PMC parents.
@@ -165,20 +175,6 @@
.tailcall self.'attr'('traits',0,0)
.end
-=item hll
-
-Get PMC hll name.
-
-=cut
-
-.sub 'hll' :method
- .tailcall self.'attr'('hll',0,0)
-.end
-
-.sub 'set_hll' :method
- .param pmc name
- .tailcall self.'attr'('hll',name,1)
-.end
.sub 'maps' :method
.tailcall self.'attr'('maps',0,0)
Modified: branches/pmc_pct/compilers/pmcc/src/parser/actions.pm
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/parser/actions.pm Thu Jun 25 22:49:12 2009 (r39784)
+++ branches/pmc_pct/compilers/pmcc/src/parser/actions.pm Thu Jun 25 23:47:17 2009 (r39785)
@@ -44,23 +44,30 @@
our $?PMC;
if $key eq 'does' {
+ $?PMC.does.push(~$<identifier>);
}
elsif $key eq 'group' {
+ #XXX: only one group is possible
+ #XXX: only valid for dynpmcs
+ $?PMC.traits{'group'} := ~$<identifier>;
}
elsif $key eq 'hll' {
- $?PMC.set_hll(~$<identifier>);
+ #XXX: only one HLL is possible
+ $?PMC.traits{'hll'} := ~$<identifier>;
}
elsif $key eq 'provides' {
- $?PMC.provides().push(~$<identifier>);
+ $?PMC.provides.push(~$<identifier>);
}
elsif $key eq 'extends' {
- $?PMC.parents().push(~$<identifier>);
+ #XXX: some sanity checking here would probably be advisable
+ $?PMC.parents.push(~$<identifier>);
$?PMC.thaw_pmc_attrs(~$<identifier>);
}
elsif $key eq 'maps' {
- $?PMC.maps().push(~$<identifier>);
+ $?PMC.maps.push(~$<identifier>);
}
elsif $key eq 'lib' {
+ $?PMC.traits{'lib'} := ~$<identifier>;
}
else {
$?PMC.traits{$key} := 1;
@@ -137,25 +144,42 @@
$<c_body>.ast
);
$past<parameters> := $<c_signature><c_arguments>.ast;
+
+ my %attrs;
+ for $<method_attr> {
+ %attrs{~$_<identifier>} := 1;
+ }
+ $past<attrs> := %attrs;
+
make $past;
}
method method($/) {
#say('METHOD ' ~$<identifier>);
+ my $method_body := $<c_body>.ast;
+
my $past := PAST::Block.new(
:name(~$<identifier>),
:blocktype('declaration'),
:returns('void'), # PCC METHODS returns void
:node($/),
- $<c_body>.ast
+ $method_body
);
#$past<parameters> := $<c_signature><c_arguments>.ast;
+
+ my %attrs;
+ for $<method_attr> {
+ %attrs{~$_<identifier>} := 1;
+ }
+ $past<attrs> := %attrs;
+
make $past;
}
method multi($/) {
#say('MULTI ' ~$<identifier>);
+
my $past := PAST::Block.new(
:name(~$<c_signature><identifier>),
:blocktype('method'),
@@ -201,6 +225,12 @@
$past<long_signature> := join(',', @long_sig);
$past<full_name> := "multi_" ~ $past.name ~ "_" ~ join('_', @long_sig);
+ my %attrs;
+ for $<method_attr> {
+ %attrs{~$_<identifier>} := 1;
+ }
+ $past<attrs> := %attrs;
+
make $past;
}
Modified: branches/pmc_pct/compilers/pmcc/src/parser/grammar.pg
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/parser/grammar.pg Thu Jun 25 22:49:12 2009 (r39784)
+++ branches/pmc_pct/compilers/pmcc/src/parser/grammar.pg Thu Jun 25 23:47:17 2009 (r39785)
@@ -118,22 +118,26 @@
rule method {
'METHOD' :: [
- [ <identifier> '(' <parrot_c_arguments> ')' <c_body> ]
+ [ <identifier> '(' <parrot_c_arguments> ')' <method_attr>* <c_body> ]
| <.panic: "Unexpected METHOD content">
]
{*}
}
rule vtable {
- 'VTABLE' :: <c_signature> <c_body>
+ 'VTABLE' :: <c_signature> <method_attr>* <c_body>
{*}
}
rule multi {
- 'MULTI' :: <c_signature> <c_body>
+ 'MULTI' :: <c_signature> <method_attr>* <c_body>
{*}
}
+rule method_attr {
+ ':' <identifier>
+}
+
# Nested list of something
rule c_body {
'{' <c_body_statement>* '}' {*}
More information about the parrot-commits
mailing list