Permalink
Browse files

merge auto_attrs branch into trunk

git-svn-id: https://svn.parrot.org/parrot/trunk@40628 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information...
1 parent 90df100 commit 5a7584e8a572f59d5e082592df47ffbf2f14dbe5 @NotFound NotFound committed Aug 18, 2009
Showing with 213 additions and 678 deletions.
  1. +23 −1 lib/Parrot/Pmc2c/PMCEmitter.pm
  2. +4 −0 lib/Parrot/Vtable.pm
  3. +2 −5 src/dynpmc/dynlexpad.pmc
  4. +1 −1 src/dynpmc/foo.pmc
  5. +1 −1 src/dynpmc/foo2.pmc
  6. +1 −1 src/dynpmc/rotest.pmc
  7. +10 −0 src/gc/api.c
  8. +34 −0 src/pmc.c
  9. +3 −19 src/pmc/arrayiterator.pmc
  10. +1 −1 src/pmc/boolean.pmc
  11. +4 −22 src/pmc/callsignature.pmc
  12. +4 −18 src/pmc/capture.pmc
  13. +4 −20 src/pmc/class.pmc
  14. +1 −9 src/pmc/codestring.pmc
  15. +1 −14 src/pmc/complex.pmc
  16. +2 −5 src/pmc/continuation.pmc
  17. +15 −23 src/pmc/cpointer.pmc
  18. +13 −0 src/pmc/default.pmc
  19. +6 −19 src/pmc/exception.pmc
  20. +2 −3 src/pmc/exceptionhandler.pmc
  21. +1 −23 src/pmc/exporter.pmc
  22. +2 −6 src/pmc/filehandle.pmc
  23. +1 −7 src/pmc/fixedbooleanarray.pmc
  24. +1 −7 src/pmc/fixedfloatarray.pmc
  25. +1 −6 src/pmc/fixedintegerarray.pmc
  26. +2 −6 src/pmc/fixedpmcarray.pmc
  27. +1 −10 src/pmc/fixedstringarray.pmc
  28. +1 −19 src/pmc/float.pmc
  29. +3 −19 src/pmc/hashiterator.pmc
  30. +1 −37 src/pmc/hashiteratorkey.pmc
  31. +2 −5 src/pmc/integer.pmc
  32. +2 −23 src/pmc/key.pmc
  33. +2 −13 src/pmc/lexpad.pmc
  34. +1 −7 src/pmc/managedstruct.pmc
  35. +1 −1 src/pmc/multisub.pmc
  36. +1 −23 src/pmc/nci.pmc
  37. +3 −19 src/pmc/orderedhashiterator.pmc
  38. +10 −2 src/pmc/parrotinterpreter.pmc
  39. +1 −6 src/pmc/parrotlibrary.pmc
  40. +4 −5 src/pmc/pmcproxy.pmc
  41. +2 −19 src/pmc/pointer.pmc
  42. +1 −1 src/pmc/resizablebooleanarray.pmc
  43. +1 −18 src/pmc/resizablefloatarray.pmc
  44. +1 −17 src/pmc/resizableintegerarray.pmc
  45. +1 −5 src/pmc/resizablepmcarray.pmc
  46. +1 −20 src/pmc/resizablestringarray.pmc
  47. +2 −7 src/pmc/retcontinuation.pmc
  48. +4 −20 src/pmc/role.pmc
  49. +2 −5 src/pmc/scheduler.pmc
  50. +4 −20 src/pmc/schedulermessage.pmc
  51. +4 −5 src/pmc/sockaddr.pmc
  52. +2 −4 src/pmc/socket.pmc
  53. +2 −22 src/pmc/string.pmc
  54. +2 −20 src/pmc/stringhandle.pmc
  55. +3 −23 src/pmc/stringiterator.pmc
  56. +5 −23 src/pmc/task.pmc
  57. +2 −5 src/pmc/timer.pmc
  58. +0 −1 src/pmc/undef.pmc
  59. +1 −37 src/pmc/unmanagedstruct.pmc
@@ -464,7 +464,8 @@ sub vtable_decl {
NULL, /* mro */
NULL, /* attribute_defs */
NULL, /* ro_variant_vtable */
- $methlist
+ $methlist,
+ 0 /* attr size */
};
ENDOFCODE
return $cout;
@@ -640,6 +641,7 @@ EOC
vt_${k} = Parrot_${classname}_${k}_get_vtable(interp);
vt_${k}->base_type = $enum_name;
vt_${k}->flags = $k_flags;
+
vt_${k}->attribute_defs = attr_defs;
vt_${k}->base_type = entry;
@@ -761,13 +763,31 @@ sub update_vtable_func {
my $classname = $self->name;
my $export = $self->is_dynamic ? 'PARROT_DYNEXT_EXPORT ' : 'PARROT_EXPORT';
+ # Sets the attr_size field:
+ # If the auto_attrs flag is set, use the current data,
+ # else check if this PMC has init or init_pmc vtable functions,
+ # setting it to 0 in that case, and keeping the value from the
+ # parent otherwise.
+ my $set_attr_size = '';
+ if ( @{$self->attributes} && $self->{flags}{auto_attrs} ) {
+ $set_attr_size .= "sizeof(Parrot_${classname}_attributes)";
+ }
+ else {
+ $set_attr_size .= "0" if exists($self->{has_method}{init}) ||
+ exists($self->{has_method}{init_pmc});
+ }
+ $set_attr_size = " vt->attr_size = " . $set_attr_size . ";\n"
+ if $set_attr_size ne '';
+
my $vtable_updates = '';
for my $name ( @{ $self->vtable->names } ) {
if (exists $self->{has_method}{$name}) {
$vtable_updates .= " vt->$name = Parrot_${classname}_${name};\n";
}
}
+ $vtable_updates .= $set_attr_size;
+
$cout .= <<"EOC";
$export
@@ -793,6 +813,8 @@ EOC
}
}
+ $vtable_updates .= $set_attr_size;
+
$cout .= <<"EOC";
$export
View
@@ -186,6 +186,10 @@ EOF
$struct .= " $entry->[1]_method_t $entry->[1];\n";
}
+ $struct .= <<'EOF';
+ UINTVAL attr_size; /* Size of the attributes struct */
+EOF
+
$struct .= "} _vtable;\n";
return $struct;
View
@@ -19,7 +19,7 @@ lexicals at runtime.
*/
-pmclass DynLexPad dynpmc provides lexpad need_ext {
+pmclass DynLexPad dynpmc provides lexpad need_ext auto_attrs {
ATTR Hash *hash;
ATTR PMC *init; /* the PMC used to initialize this DynLexPad */
@@ -42,8 +42,7 @@ lexinfo.
Hash *hash;
Parrot_DynLexPad_attributes *attrs =
- mem_allocate_zeroed_typed(Parrot_DynLexPad_attributes);
- PMC_data(SELF) = attrs;
+ (Parrot_DynLexPad_attributes *) PMC_data(SELF);
if (VTABLE_elements(interp, lexinfo)) {
attrs->init = pmc_new_init(interp, enum_class_LexPad, lexinfo);
@@ -188,8 +187,6 @@ Return the LexInfo PMC, if any or a Null PMC.
parrot_hash_destroy(interp, PARROT_DYNLEXPAD(SELF)->hash);
PARROT_DYNLEXPAD(SELF)->hash = NULL;
}
- mem_sys_free(PMC_data(SELF));
- PMC_data(SELF) = NULL;
}
/*
View
@@ -8,7 +8,7 @@
* proper inheritance - for testing only
*/
-pmclass Foo dynpmc group foo_group provides scalar extends Integer {
+pmclass Foo dynpmc group foo_group provides scalar extends Integer auto_attrs {
VTABLE INTVAL get_integer() {
return 42;
View
@@ -8,7 +8,7 @@
* proper inheritance - for testing only
*/
-pmclass Foo2 dynpmc group foo_group provides scalar extends Foo {
+pmclass Foo2 dynpmc group foo_group provides scalar extends Foo auto_attrs {
VTABLE INTVAL get_integer() {
INTVAL i = SUPER();
View
@@ -8,7 +8,7 @@
* generation. For testing only.
*/
-pmclass ROTest dynpmc provides scalar extends Integer {
+pmclass ROTest dynpmc provides scalar extends Integer auto_attrs {
VTABLE void set_integer_native(INTVAL value) :read {
}
VTABLE INTVAL get_integer() :write {
View
@@ -374,6 +374,16 @@ Parrot_gc_free_pmc_header(PARROT_INTERP, ARGMOD(PMC *pmc))
if (PObj_active_destroy_TEST(pmc))
VTABLE_destroy(interp, pmc);
+ if (PMC_data(pmc) && pmc->vtable->attr_size) {
+#if 0
+ mem_sys_free(PMC_data(pmc));
+ PMC_data(pmc) = NULL;
+#else
+ Parrot_gc_free_pmc_attributes(interp, pmc, pmc->vtable->attr_size);
+#endif
+ }
+ PARROT_ASSERT(NULL == PMC_data(pmc));
+
if (PObj_is_PMC_EXT_TEST(pmc))
Parrot_gc_free_pmc_ext(interp, pmc);
View
@@ -241,6 +241,24 @@ pmc_reuse_no_init(PARROT_INTERP, ARGIN(PMC *pmc), INTVAL new_type,
/* Set the right vtable */
pmc->vtable = new_vtable;
+ if (PMC_data(pmc) && pmc->vtable->attr_size) {
+#if 0
+ mem_sys_free(PMC_data(pmc));
+#else
+ Parrot_gc_free_pmc_attributes(interp, pmc, pmc->vtable->attr_size);
+#endif
+ }
+
+ if (new_vtable->attr_size) {
+#if 0
+ PMC_data(pmc) = mem_sys_allocate_zeroed(new_vtable->attr_size);
+#else
+ Parrot_gc_allocate_pmc_attributes(interp, pmc, pmc->vtable->attr_size);
+#endif
+}
+ else
+ PMC_data(pmc) = NULL;
+
return pmc;
}
@@ -361,6 +379,14 @@ pmc_reuse_check_pmc_ext(PARROT_INTERP, ARGMOD(PMC * pmc),
/* Do we have an extension area? */
INTVAL const has_ext = (PObj_is_PMC_EXT_TEST(pmc) && pmc->pmc_ext);
+ if (PMC_data(pmc) && pmc->vtable->attr_size) {
+#if 0
+ mem_sys_free(PMC_data(pmc));
+#else
+ Parrot_gc_free_pmc_attributes(interp, pmc, pmc->vtable->attr_size);
+#endif
+ }
+
/* Do we need one? */
if (flags & VTABLE_PMC_NEEDS_EXT) {
/* If we need an ext area, go allocate one */
@@ -465,6 +491,14 @@ get_new_pmc_header(PARROT_INTERP, INTVAL base_type, UINTVAL flags)
pmc = Parrot_gc_new_pmc_header(interp, flags);
pmc->vtable = vtable;
+ if (vtable->attr_size) {
+#if 0
+ PMC_data(pmc) = mem_sys_allocate_zeroed(vtable->attr_size);
+#else
+ Parrot_gc_allocate_pmc_attributes(interp, pmc, pmc->vtable->attr_size);
+#endif
+ }
+
#if GC_VERBOSE
if (Interp_flags_TEST(interp, PARROT_TRACE_FLAG)) {
/* XXX make a more verbose trace flag */
View
@@ -51,7 +51,7 @@ to avoid this caveat.
*/
-pmclass ArrayIterator extends Iterator no_ro {
+pmclass ArrayIterator extends Iterator no_ro auto_attrs {
ATTR PMC *array; /* the array which this Iterator iterates */
ATTR INTVAL pos; /* Current position of iterator for forward iterator */
/* Previous position of iterator for reverse iterator */
@@ -86,34 +86,18 @@ Defaults iteration mode to iterate from start.
VTABLE void init_pmc(PMC *array) {
Parrot_ArrayIterator_attributes * const attrs =
- mem_allocate_zeroed_typed(Parrot_ArrayIterator_attributes);
+ (Parrot_ArrayIterator_attributes *) PMC_data(SELF);
attrs->array = array;
- PMC_data(SELF) = attrs;
- PObj_custom_mark_destroy_SETALL(SELF);
+ PObj_custom_mark_SET(SELF);
/* by default, iterate from start */
SELF.set_integer_native(ITERATE_FROM_START);
}
/*
-=item C<void destroy()>
-
-destroys this PMC
-
-=cut
-
-*/
-
- VTABLE void destroy() {
- mem_sys_free(PMC_data(SELF));
- PMC_data(SELF) = NULL;
- }
-
-/*
-
=item C<void mark()>
Marks the current idx/key and the aggregate as live.
View
@@ -21,7 +21,7 @@ it doesn't morph to other types. Only its value is changed.
*/
-pmclass Boolean extends Integer provides boolean provides scalar {
+pmclass Boolean extends Integer provides boolean provides scalar auto_attrs {
/*
View
@@ -27,7 +27,7 @@ information for a multiple dispatch call.
if (!PARROT_CAPTURE(obj)->hash) \
PARROT_CAPTURE(obj)->hash = pmc_new((i), enum_class_Hash);
-pmclass CallSignature extends Capture need_ext provides array provides hash {
+pmclass CallSignature extends Capture need_ext auto_attrs provides array provides hash {
ATTR PMC *returns; /* Result PMCs, if they were passed with the call */
ATTR PMC *type_tuple; /* Cached argument types for multiple dispatch */
ATTR STRING *short_sig; /* Simple string signature args & returns */
@@ -44,16 +44,10 @@ Initializes a newly created CallSignature object.
VTABLE void init() {
Parrot_CallSignature_attributes * const sig_struct =
- mem_allocate_typed(Parrot_CallSignature_attributes);
- PMC_data(SELF) = sig_struct;
- sig_struct->short_sig = NULL;
+ (Parrot_CallSignature_attributes *) PMC_data(SELF);
+ SUPER();
sig_struct->type_tuple = PMCNULL;
sig_struct->returns = PMCNULL;
- sig_struct->array = NULL;
- sig_struct->hash = NULL;
- sig_struct->data_size = CAPTURE_DATA_SIZE;
- PObj_active_destroy_SET(SELF);
- PObj_custom_mark_SET(SELF);
}
/*
@@ -182,29 +176,17 @@ Mark any referenced strings and PMCs.
*/
VTABLE void mark() {
- PMC ** const data = PMC_data_typed(SELF, PMC **);
Parrot_CallSignature_attributes * const attrs = PARROT_CALLSIGNATURE(SELF);
if (attrs) {
-
- if (attrs->array)
- Parrot_gc_mark_PObj_alive(interp, (PObj*)attrs->array);
- if (attrs->hash)
- Parrot_gc_mark_PObj_alive(interp, (PObj*)attrs->hash);
if (attrs->returns)
Parrot_gc_mark_PObj_alive(interp, (PObj*)attrs->returns);
if (attrs->type_tuple)
Parrot_gc_mark_PObj_alive(interp, (PObj*)attrs->type_tuple);
if (attrs->short_sig)
Parrot_gc_mark_PObj_alive(interp, (PObj*)attrs->short_sig);
}
-
- if (data) {
- INTVAL i;
- for (i = attrs->data_size - 1; i >= 0; --i)
- if (data[i])
- Parrot_gc_mark_PObj_alive(interp, (PObj *)data[i]);
- }
+ SUPER();
}
View
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2008, Parrot Foundation.
+Copyright (C) 2001-2009, Parrot Foundation.
$Id$
=head1 NAME
@@ -26,7 +26,7 @@ These are the vtable functions for the Capture PMC.
if (!PARROT_CAPTURE(obj)->hash) \
PARROT_CAPTURE(obj)->hash = pmc_new((i), enum_class_Hash);
-pmclass Capture need_ext {
+pmclass Capture need_ext auto_attrs {
ATTR PMC *array;
ATTR PMC *hash;
ATTR INTVAL data_size;
@@ -37,31 +37,17 @@ pmclass Capture need_ext {
Initializes the Capture instance.
-=item C<void destroy()>
-
-Free structures.
-
=cut
*/
VTABLE void init() {
- Parrot_Capture_attributes *capture = mem_allocate_typed(Parrot_Capture_attributes);
- PMC_data(SELF) = capture;
- capture->array = NULL;
- capture->hash = NULL;
+ Parrot_Capture_attributes *capture =
+ (Parrot_Capture_attributes *) PMC_data(SELF);
capture->data_size = CAPTURE_DATA_SIZE;
- PObj_active_destroy_SET(SELF);
PObj_custom_mark_SET(SELF);
}
- VTABLE void destroy() {
- if (PARROT_CAPTURE(SELF)) {
- mem_sys_free(PARROT_CAPTURE(SELF));
- PMC_data(SELF) = NULL;
- }
- }
-
/*
=item C<PMC *clone()>
Oops, something went wrong.

0 comments on commit 5a7584e

Please sign in to comment.