[svn:parrot] r38535 - in branches/pmc_pct/compilers/pmc/src: . emitter
cotto at svn.parrot.org
cotto at svn.parrot.org
Thu May 7 11:45:21 UTC 2009
Author: cotto
Date: Thu May 7 11:45:21 2009
New Revision: 38535
URL: https://trac.parrot.org/parrot/changeset/38535
Log:
[pmcc] generate (non-inheriting) ATTR wrapper structs in headers
Modified:
branches/pmc_pct/compilers/pmc/src/emitter/pmc.pm
branches/pmc_pct/compilers/pmc/src/nodes.pir
Modified: branches/pmc_pct/compilers/pmc/src/emitter/pmc.pm
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/emitter/pmc.pm Thu May 7 11:12:01 2009 (r38534)
+++ branches/pmc_pct/compilers/pmc/src/emitter/pmc.pm Thu May 7 11:45:21 2009 (r38535)
@@ -25,6 +25,8 @@
self.generate_h_file_functions(),
+ self.generate_attr_struct(),
+
"\n",
'#endif /* ', $guard, " */ \n"
)
@@ -57,6 +59,35 @@
join('', @res_builder);
}
+#=item C<generate_attr_struct>
+#
+#Generate a C declaration for the ATTR wrapper struct
+#
+#=cut
+
+method generate_attr_struct() {
+ my $past := self.past;
+
+ my $struct_start;
+ my $struct_body;
+ my $struct_end;
+
+ $struct_start :=
+ "\n/* " ~ self.name ~ " PMC's underlying struct. */\n" ~
+ "typedef struct Parrot_" ~ self.name ~ "_attributes {\n";
+
+ my @attrs := self.attrs;
+ my @struct_members;
+
+ for @attrs {
+ @struct_members.push(" " ~ $_<type> ~ " " ~ $_<name> ~ ";\n");
+ }
+
+ $struct_end := "} Parrot_" ~ self.name ~ "_attributes;\n";
+
+ return $struct_start ~ join('', @struct_members) ~ $struct_end;
+}
+
#=item C<generate_c_file>
#
#Generate C file for PMC.
@@ -115,7 +146,9 @@
join('', @res);
}
-
+method attrs() {
+ self.past.attrs;
+}
method vtables() {
self.past.vtables;
Modified: branches/pmc_pct/compilers/pmc/src/nodes.pir
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/nodes.pir Thu May 7 11:12:01 2009 (r38534)
+++ branches/pmc_pct/compilers/pmc/src/nodes.pir Thu May 7 11:45:21 2009 (r38535)
@@ -50,7 +50,7 @@
$P1 = new 'Hash'
res.'attr'('methods', $P1, 1)
- $P1 = new 'Hash'
+ $P1 = new 'ResizablePMCArray'
res.'attr'('attrs', $P1, 1)
$P1 = new 'ResizableStringArray'
@@ -109,6 +109,16 @@
.tailcall self.'attr'('provides',0,0)
.end
+=item C<attrs>
+
+Get PMC ATTRs.
+
+=cut
+
+.sub 'attrs' :method
+ .tailcall self.'attr'('attrs',0,0)
+.end
+
=item C<set_trait>
@@ -194,13 +204,25 @@
.param string name
.param string type
- $P0 = self.'attr'('attrs', 0, 0)
- $I0 = exists $P0[name]
- unless $I0 goto add_method
+ .local pmc it, attrs, attr
+
+ attrs = self.'attr'('attrs', 0, 0)
+ it = iter attrs
+ iter_start:
+ unless it goto add_method
+ $P0 = shift it
+ $S0 = $P0['name']
+ $I0 = cmp $S0, name
+ if $I0 goto iter_start
+
$S0 = concat "Duplicate ATTR: ", name
die $S0
+
add_method:
- $P0[name] = type
+ attr = new 'Hash'
+ attr['type'] = type
+ attr['name'] = name
+ push attrs, attr
.return ()
.end
More information about the parrot-commits
mailing list