[svn:parrot] r49704 - branches/opmap_aware_pmcs/src/pmc
cotto at svn.parrot.org
cotto at svn.parrot.org
Wed Oct 27 22:50:22 UTC 2010
Author: cotto
Date: Wed Oct 27 22:50:22 2010
New Revision: 49704
URL: https://trac.parrot.org/parrot/changeset/49704
Log:
[pmc] implement size calculation in get_pointer; filling in the data is nyi
Modified:
branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc
Modified: branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc
==============================================================================
--- branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc Wed Oct 27 22:49:42 2010 (r49703)
+++ branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc Wed Oct 27 22:50:22 2010 (r49704)
@@ -130,7 +130,6 @@
return SELF.get_integer_keyed(pmc_key);
}
-
/*
=item C<void mark()>
@@ -170,7 +169,6 @@
SUPER();
}
-
/*
=item C<INTVAL get_integer()>
@@ -187,6 +185,78 @@
return op_count;
}
+
+/*
+
+=item C<void *get_pointer()>
+
+Return a pointer to a PackFile_ByteCode* built from this PMC's data.
+
+=cut
+
+*/
+
+ VTABLE void *get_pointer() {
+ INTVAL i, bc_seg_size, lib_count;
+ STRING *oplib_name = CONST_STRING(INTERP, "const_string");
+ STRING *lib_ops = CONST_STRING(INTERP, "lib_ops");
+ Parrot_PackfileOpMap_attributes *attrs =
+ PMC_data_typed(SELF, Parrot_PackfileOpMap_attributes*);
+ PackFile_ByteCode *bc_seg =
+ mem_gc_allocate_zeroed_typed(INTERP, PackFile_ByteCode);
+
+ bc_seg->base.type = PF_BYTEC_SEG;
+
+ /* figure out size of bytecode segment (->data) */
+ // should calculate this while building bc segment
+
+ /* op count and number of libraries */
+ bc_seg_size = 2;
+ lib_count = VTABLE_elements(INTERP, attrs->op_maps);
+ for (i = 0; i < lib_count; i++) {
+ char *lib_name_cstring;
+ PMC *op_map = VTABLE_get_pmc_keyed_int(INTERP, attrs->op_maps, i);
+
+ /* length of lib name as a cstring, plus padding */
+ lib_name_cstring = Parrot_str_to_cstring(INTERP,
+ VTABLE_get_string_keyed_str(INTERP, op_map, oplib_name));
+ bc_seg_size += PF_size_cstring(lib_name_cstring);
+ mem_sys_free(lib_name_cstring);
+
+ /* 3 for major, minor, patch */
+ bc_seg_size += 3;
+
+ /* 1 for number of ops */
+ bc_seg_size += 1;
+
+ /* 2*number of ops */
+ bc_seg_size += (2 * VTABLE_elements(INTERP,
+ VTABLE_get_pmc_keyed_str(INTERP, op_map, lib_ops)));
+ }
+
+
+ /* allocate space for ->data */
+
+ /* write bytecode bytes to ->data */
+
+ /* write number of ops, number of libs */
+
+ /* for each lib */
+
+ /* write lib name (PF_store_cstring) */
+
+ /* major, minor, patch */
+
+ /* write number of mappings */
+
+ /* for each mapping */
+
+ /* write table_ops[n] */
+
+ /* write lib_ops[n] */
+
+ }
+
/*
=item C<METHOD load_lib>
@@ -239,6 +309,8 @@
VTABLE_set_pmc_keyed_str(INTERP, ops_info, table_ops,
Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray));
VTABLE_push_pmc(INTERP, attrs->op_maps, ops_info);
+
+ RETURN (INTVAL 1);
}
}
More information about the parrot-commits
mailing list