[svn:parrot] r38019 - branches/packfile_revamp/src/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Fri Apr 10 05:33:39 UTC 2009
Author: bacek
Date: Fri Apr 10 05:33:39 2009
New Revision: 38019
URL: https://trac.parrot.org/parrot/changeset/38019
Log:
Reimplement PackfileRawSegment to use own stored data.
Modified:
branches/packfile_revamp/src/pmc/packfilerawsegment.pmc
Modified: branches/packfile_revamp/src/pmc/packfilerawsegment.pmc
==============================================================================
--- branches/packfile_revamp/src/pmc/packfilerawsegment.pmc Fri Apr 10 05:33:15 2009 (r38018)
+++ branches/packfile_revamp/src/pmc/packfilerawsegment.pmc Fri Apr 10 05:33:39 2009 (r38019)
@@ -27,7 +27,92 @@
#include "parrot/parrot.h"
pmclass PackfileRawSegment extends PackfileSegment {
+ /* ResizableIntegerArray of opcodes */
+ ATTR PMC *opcodes;
+/*
+
+=item C<init>
+
+Create empty PackfileRawSegment.
+
+=cut
+
+*/
+
+ VTABLE void init() {
+ Parrot_PackfileRawSegment_attributes * attrs =
+ mem_allocate_zeroed_typed(Parrot_PackfileRawSegment_attributes);
+
+ attrs->opcodes = pmc_new(interp, enum_class_ResizableIntegerArray);
+
+ PObj_custom_mark_destroy_SETALL(SELF);
+ PMC_data(SELF) = attrs;
+ }
+
+/*
+
+=item C<void mark()>
+
+Marks the object as live.
+
+=cut
+
+*/
+
+ VTABLE void mark() {
+ Parrot_PackfileRawSegment_attributes * attrs =
+ PARROT_PACKFILERAWSEGMENT(SELF);
+
+ if (attrs->opcodes)
+ pobject_lives(interp, (PObj *)attrs->opcodes);
+ }
+
+/*
+
+=item C<void destroy()>
+
+Destroys the PMC and frees all allocated memory.
+
+=cut
+
+*/
+
+ VTABLE void destroy() {
+ Parrot_PackfileRawSegment_attributes * attrs =
+ PARROT_PACKFILERAWSEGMENT(SELF);
+
+ if (attrs) {
+ mem_sys_free(attrs);
+ PMC_data(SELF) = NULL;
+ }
+ }
+
+
+
+/*
+
+=item C<set_pointer>
+
+Initialize PackfileRawSegment from PackFile_Segment
+
+=cut
+
+*/
+
+ VTABLE void set_pointer(void * pointer) {
+ const PackFile_Segment const * pfseg =
+ (const PackFile_Segment const *)pointer;
+ PMC * opcodes = PARROT_PACKFILERAWSEGMENT(SELF)->opcodes;
+ size_t i;
+
+ /* copy data to own array */
+ VTABLE_set_integer_native(interp, opcodes, pfseg->op_count);
+ /* Not very efficient... */
+ for (i = 0; i < pfseg->op_count; ++i) {
+ VTABLE_set_integer_keyed_int(interp, opcodes, i, pfseg->data[i]);
+ }
+ }
/*
@@ -39,8 +124,8 @@
*/
VTABLE INTVAL elements() {
- PackFile_Segment *pfseg = PMC_data_typed(SELF, PackFile_Segment *);
- return pfseg->size;
+ return VTABLE_elements(interp,
+ PARROT_PACKFILERAWSEGMENT(SELF)->opcodes);
}
@@ -54,11 +139,8 @@
*/
VTABLE INTVAL get_integer_keyed_int(INTVAL key) {
- PackFile_Segment *pfseg = PMC_data_typed(SELF, PackFile_Segment *);
- if (key < 0 || (UINTVAL)key >= pfseg->size)
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_OUT_OF_BOUNDS,
- "Requested data out of range.");
- return pfseg->data[key];
+ return VTABLE_get_integer_keyed_int(interp,
+ PARROT_PACKFILERAWSEGMENT(SELF)->opcodes, key);
}
@@ -72,7 +154,8 @@
*/
VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+ VTABLE_set_integer_keyed_int(interp,
+ PARROT_PACKFILERAWSEGMENT(SELF)->opcodes, key, value);
}
More information about the parrot-commits
mailing list