[svn:parrot] r38541 - in branches/pmc_pct/compilers/pmc: src/emitter t
cotto at svn.parrot.org
cotto at svn.parrot.org
Thu May 7 21:11:21 UTC 2009
Author: cotto
Date: Thu May 7 21:11:20 2009
New Revision: 38541
URL: https://trac.parrot.org/parrot/changeset/38541
Log:
[pmcc] generate PARROT_FOO macro, plus a test for it and the ATTR wrapper struct
Modified:
branches/pmc_pct/compilers/pmc/src/emitter/pmc.pm
branches/pmc_pct/compilers/pmc/t/05-header.t
Modified: branches/pmc_pct/compilers/pmc/src/emitter/pmc.pm
==============================================================================
--- branches/pmc_pct/compilers/pmc/src/emitter/pmc.pm Thu May 7 19:15:37 2009 (r38540)
+++ branches/pmc_pct/compilers/pmc/src/emitter/pmc.pm Thu May 7 21:11:20 2009 (r38541)
@@ -23,11 +23,12 @@
'#ifndef ' ~ $guard ~ "\n",
'#define ' ~ $guard ~ "\n\n",
- self.generate_h_file_functions(),
+ self.generate_h_file_functions(), "\n",
- self.generate_attr_struct(),
+ self.generate_attr_struct(), "\n",
+
+ self.generate_casting_macro(), "\n",
- "\n",
'#endif /* ', $guard, " */ \n"
)
);
@@ -66,7 +67,6 @@
#=cut
method generate_attr_struct() {
- my $past := self.past;
my $struct_start;
my $struct_body;
@@ -88,6 +88,18 @@
return $struct_start ~ join('', @struct_members) ~ $struct_end;
}
+#=item C<generate_casting_macro>
+#
+#Generate a #define to simplify ATTR access
+#
+#=cut
+
+method generate_casting_macro() {
+
+ return
+ "#define PARROT_" ~ self.ucname ~ "(o) ((Parrot_" ~ self.name ~ "_attributes *) PMC_data(o))\n";
+}
+
#=item C<generate_c_file>
#
#Generate C file for PMC.
Modified: branches/pmc_pct/compilers/pmc/t/05-header.t
==============================================================================
--- branches/pmc_pct/compilers/pmc/t/05-header.t Thu May 7 19:15:37 2009 (r38540)
+++ branches/pmc_pct/compilers/pmc/t/05-header.t Thu May 7 21:11:20 2009 (r38541)
@@ -8,7 +8,7 @@
load_bytecode 'pmc.pbc'
.local int total
- plan(3)
+ plan(5)
.local string filename
filename = 't/data/class00.pmc'
@@ -21,6 +21,24 @@
$S0 = _slurp(filename)
check_one_header(filename, $S0, "'PMC * Parrot_Integer_instantiate(PARROT_INTERP, PMC *sig, PMC* init)'", "VTable method generated")
+ .local string attr_struct
+ filename = 't/data/class10.pmc'
+ $S0 = _slurp(filename)
+ attr_struct = <<'STRUCT'
+typedef struct Parrot_foo_attributes {
+\s*int\s+int_attribute[;]
+\s*PMC\*\s+pmc_attribute[;]
+} Parrot_foo_attributes[;]
+STRUCT
+ attr_struct = "attributes"
+ check_one_header(filename, $S0, attr_struct, "ATTR struct generated")
+
+ .local string attr_macro
+ attr_macro = '#define\sPARROT_FOO\(o\)\s\(\(Parrot_foo_attributes\s\*\)\sPMC_data\(o\)\)'
+ filename = "t/data/class10.pmc"
+ $S0 = _slurp(filename)
+ check_one_header(filename, $S0, attr_macro, "ATTR macro generated")
+
.end
# Check genrated header.
More information about the parrot-commits
mailing list