[svn:parrot] r49709 - branches/opmap_aware_pmcs/src/pmc
cotto at svn.parrot.org
cotto at svn.parrot.org
Thu Oct 28 04:55:32 UTC 2010
Author: cotto
Date: Thu Oct 28 04:55:31 2010
New Revision: 49709
URL: https://trac.parrot.org/parrot/changeset/49709
Log:
[pmc] move get_pointer to PackfileBytecodeSegment, finish (untested) implementation
Modified:
branches/opmap_aware_pmcs/src/pmc/packfilebytecodesegment.pmc
branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc
Modified: branches/opmap_aware_pmcs/src/pmc/packfilebytecodesegment.pmc
==============================================================================
--- branches/opmap_aware_pmcs/src/pmc/packfilebytecodesegment.pmc Thu Oct 28 02:36:44 2010 (r49708)
+++ branches/opmap_aware_pmcs/src/pmc/packfilebytecodesegment.pmc Thu Oct 28 04:55:31 2010 (r49709)
@@ -26,6 +26,8 @@
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */
+#include "pmc/pmc_packfileopmap.h"
+
pmclass PackfileBytecodeSegment auto_attrs extends PackfileSegment{
ATTR PMC *ops; /* RIA of executable opcodes */
ATTR PMC *op_map; /* OpMap PMC */
@@ -63,8 +65,7 @@
*/
VTABLE void mark() {
- Parrot_PackfileBytecodeSegment_attributes * attrs =
- PARROT_PACKFILESEGMENT(SELF);
+ Parrot_PackfileBytecodeSegment_attributes * attrs = PARROT_PACKFILESEGMENT(SELF);
Parrot_gc_mark_PMC_alive(INTERP, attrs->op_map);
Parrot_gc_mark_PMC_alive(INTERP, attrs->ops);
@@ -73,6 +74,113 @@
/*
+=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, "oplib_name");
+ STRING *lib_ops = CONST_STRING(INTERP, "lib_ops");
+ opcode_t *cursor;
+ Parrot_PackfileBytecodeSegment_attributes *attrs =
+ PMC_data_typed(SELF, Parrot_PackfileBytecodeSegment_attributes*);
+ Parrot_PackfileOpMap_attributes *map_attrs =
+ PMC_data_typed(attrs->op_map, Parrot_PackfileOpMap_attributes*);
+ PackFile_ByteCode *bc_seg =
+ mem_gc_allocate_zeroed_typed(INTERP, PackFile_ByteCode);
+
+
+ bc_seg_size = 0;
+
+ // TODO: calculate this while building bc segment for better efficiency
+ bc_seg_size += VTABLE_elements(INTERP, attrs->ops);
+
+
+ /* op count and number of libraries */
+ bc_seg_size += 2;
+ lib_count = VTABLE_elements(INTERP, map_attrs->op_maps);
+ for (i = 0; i < lib_count; i++) {
+ char *lib_name_cstring;
+ PMC *op_map = VTABLE_get_pmc_keyed_int(INTERP, map_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)));
+ }
+
+ bc_seg->base.type = PF_BYTEC_SEG;
+ bc_seg->base.size = bc_seg_size;
+ bc_seg->base.data = (opcode_t *) mem_sys_allocate(bc_seg_size);
+ cursor = bc_seg->base.data;
+
+ /* write bytecode bytes to segment */
+ // TODO: use something more efficient than this, e.g. StringBuilder
+ for (i = 0; i < VTABLE_elements(INTERP, attrs->ops); i++) {
+ *cursor++ = VTABLE_get_integer_keyed_int(INTERP, attrs->ops, i);
+ }
+
+ /* write number of ops, number of libs */
+ *cursor++ = map_attrs->op_count;
+ *cursor++ = VTABLE_elements(INTERP, map_attrs->op_maps);
+
+ /* for each lib */
+ for (i = 0; i < VTABLE_elements(INTERP, map_attrs->op_maps); i++) {
+ char *lib_name_cstring;
+ PMC *op_map = VTABLE_get_pmc_keyed_int(INTERP, map_attrs->op_maps, i);
+ PMC *oplib = VTABLE_get_pmc_keyed_str(INTERP, op_map, CONST_STRING(INTERP, "oplib"));
+ PMC *lib_ops = VTABLE_get_pmc_keyed_str(INTERP, op_map, CONST_STRING(INTERP, "lib_ops"));
+ PMC *table_ops = VTABLE_get_pmc_keyed_str(INTERP, op_map, CONST_STRING(INTERP, "table_ops"));
+ INTVAL j, version_major, version_minor, version_patch, opmap_count;
+
+ /* write lib name (PF_store_cstring) */
+ lib_name_cstring = Parrot_str_to_cstring(INTERP,
+ VTABLE_get_string_keyed_str(INTERP, op_map, oplib_name));
+ cursor = PF_store_cstring(cursor, lib_name_cstring);
+ mem_sys_free(lib_name_cstring);
+
+ /* major, minor, patch */
+ Parrot_pcc_invoke_method_from_c_args(INTERP, oplib, CONST_STRING(INTERP, "version_major"),
+ "->I", &version_major);
+ Parrot_pcc_invoke_method_from_c_args(INTERP, oplib, CONST_STRING(INTERP, "version_minor"),
+ "->I", &version_minor);
+ Parrot_pcc_invoke_method_from_c_args(INTERP, oplib, CONST_STRING(INTERP, "version_patch"),
+ "->I", &version_patch);
+
+ *cursor++ = version_major;
+ *cursor++ = version_minor;
+ *cursor++ = version_patch;
+
+ /* write number of mappings */
+ opmap_count = map_attrs->op_count;
+ *cursor++ = opmap_count;
+
+ /* for each mapping */
+ for (j = 0; j < opmap_count; j++) {
+ *cursor++ = VTABLE_get_integer_keyed_int(INTERP, table_ops, j);
+ *cursor++ = VTABLE_get_integer_keyed_int(INTERP, lib_ops, j);
+ }
+
+ }
+ }
+/*
+
=item C<void destroy()>
Destroy anything in this segment that need destroying.
@@ -83,8 +191,7 @@
VTABLE void destroy() {
Parrot_PackfileBytecodeSegment_attributes * attrs =
- PARROT_PACKFILESEGMENT(SELF);
-
+ PARROT_PACKFILEBYTECODESEGMENT(SELF);
VTABLE_destroy(INTERP, attrs->op_map);
VTABLE_destroy(INTERP, attrs->ops);
SUPER();
@@ -102,8 +209,10 @@
*/
METHOD void load_lib(STRING *lib_name) {
- /* delegate to OpMap */
-
+ Parrot_PackfileBytecodeSegment_attributes * attrs =
+ PARROT_PACKFILEBYTECODESEGMENT(SELF);
+ Parrot_pcc_invoke_method_from_c_args(INTERP, SELF, CONST_STRING(INTERP, "load_lib"),
+ "S->", lib_name);
}
Modified: branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc
==============================================================================
--- branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc Thu Oct 28 02:36:44 2010 (r49708)
+++ branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc Thu Oct 28 04:55:31 2010 (r49709)
@@ -44,7 +44,7 @@
VTABLE void init() {
PMC *core_ops_info, *core_ops_pmc;
- STRING *oplib_name, *lib_ops, *table_ops;
+ STRING *oplib_name, *oplib_str, *lib_ops, *table_ops, *core_ops_str;
Parrot_PackfileOpMap_attributes *attrs =
PMC_data_typed(SELF, Parrot_PackfileOpMap_attributes*);
@@ -54,17 +54,23 @@
core_ops_pmc = Parrot_pmc_new(INTERP, enum_class_String);
VTABLE_set_string_native(INTERP, core_ops_pmc, CONST_STRING(INTERP, PARROT_CORE_OPLIB_NAME));
- lib_ops = CONST_STRING(INTERP, "lib_ops");
- table_ops = CONST_STRING(INTERP, "table_ops");
- oplib_name = CONST_STRING(INTERP, "oplib_name");
+ lib_ops = CONST_STRING(INTERP, "lib_ops");
+ table_ops = CONST_STRING(INTERP, "table_ops");
+ oplib_name = CONST_STRING(INTERP, "oplib_name");
+ oplib_str = CONST_STRING(INTERP, "oplib");
+ core_ops_str = CONST_STRING(INTERP, "core_ops");
core_ops_info = Parrot_pmc_new(INTERP, enum_class_Hash);
- VTABLE_set_pmc_keyed_str(INTERP, core_ops_info, oplib_name,
+ VTABLE_set_pmc_keyed_str(INTERP, core_ops_info, oplib_name, core_ops_pmc);
+ VTABLE_set_pmc_keyed_str(INTERP, core_ops_info, oplib_str,
Parrot_pmc_new_init(INTERP, enum_class_OpLib, core_ops_pmc));
VTABLE_set_pmc_keyed_str(INTERP, core_ops_info, lib_ops,
Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray));
VTABLE_set_pmc_keyed_str(INTERP, core_ops_info, table_ops,
Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray));
+ VTABLE_set_pmc_keyed_str(INTERP, core_ops_info, oplib_str,
+ Parrot_pmc_new_init
+ );
VTABLE_push_pmc(INTERP, attrs->op_maps, core_ops_info);
SUPER();
@@ -130,6 +136,7 @@
return SELF.get_integer_keyed(pmc_key);
}
+
/*
=item C<void mark()>
@@ -185,78 +192,6 @@
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>
@@ -270,7 +205,7 @@
/* check if the library has been loaded */
PMC *op_maps, *ops_info, *oplib, *lib_name_pmc;
INTVAL i, op_map_count;
- STRING *oplib_name, *lib_ops, *table_ops;
+ STRING *oplib_name, *lib_ops, *table_ops, *oplib_str;
Parrot_PackfileOpMap_attributes *attrs;
oplib_name = CONST_STRING(INTERP, "oplib_name");
@@ -300,14 +235,17 @@
lib_ops = CONST_STRING(INTERP, "lib_ops");
table_ops = CONST_STRING(INTERP, "table_ops");
+ oplib_str = CONST_STRING(INTERP, "oplib");
ops_info = Parrot_pmc_new(INTERP, enum_class_Hash);
- VTABLE_set_pmc_keyed_str(INTERP, ops_info, oplib_name,
+ VTABLE_set_pmc_keyed_str(INTERP, ops_info, oplib_name, lib_name_pmc);
+ VTABLE_set_pmc_keyed_str(INTERP, ops_info, oplib_str,
Parrot_pmc_new_init(INTERP, enum_class_OpLib, lib_name_pmc));
VTABLE_set_pmc_keyed_str(INTERP, ops_info, lib_ops,
Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray));
VTABLE_set_pmc_keyed_str(INTERP, ops_info, table_ops,
Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray));
+ VTABLE_set_pmc_keyed_str(INTERP, ops_info, oplib_str, oplib);
VTABLE_push_pmc(INTERP, attrs->op_maps, ops_info);
RETURN (INTVAL 1);
More information about the parrot-commits
mailing list