[svn:parrot] r49683 - in branches/opmap_aware_pmcs: . src/pmc

cotto at svn.parrot.org cotto at svn.parrot.org
Tue Oct 26 19:17:14 UTC 2010


Author: cotto
Date: Tue Oct 26 19:17:13 2010
New Revision: 49683
URL: https://trac.parrot.org/parrot/changeset/49683

Log:
[pmc] initial versions, mostly stub code with some untested implementations

Added:
   branches/opmap_aware_pmcs/src/pmc/packfilebytecodesegment.pmc
   branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc
Modified:
   branches/opmap_aware_pmcs/MANIFEST

Modified: branches/opmap_aware_pmcs/MANIFEST
==============================================================================
--- branches/opmap_aware_pmcs/MANIFEST	Tue Oct 26 11:50:55 2010	(r49682)
+++ branches/opmap_aware_pmcs/MANIFEST	Tue Oct 26 19:17:13 2010	(r49683)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Thu Oct 21 03:36:17 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Tue Oct 26 19:04:40 2010 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -1416,9 +1416,11 @@
 src/pmc/packfile.pmc                                        []
 src/pmc/packfileannotation.pmc                              []
 src/pmc/packfileannotations.pmc                             []
+src/pmc/packfilebytecodesegment.pmc                         []
 src/pmc/packfileconstanttable.pmc                           []
 src/pmc/packfiledebug.pmc                                   []
 src/pmc/packfiledirectory.pmc                               []
+src/pmc/packfileopmap.pmc                                   []
 src/pmc/packfilerawsegment.pmc                              []
 src/pmc/packfilesegment.pmc                                 []
 src/pmc/parrotinterpreter.pmc                               []

Added: branches/opmap_aware_pmcs/src/pmc/packfilebytecodesegment.pmc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/opmap_aware_pmcs/src/pmc/packfilebytecodesegment.pmc	Tue Oct 26 19:17:13 2010	(r49683)
@@ -0,0 +1,160 @@
+/*
+Copyright (C) 2001-2008, Parrot Foundation.
+$Id$
+
+=head1 NAME
+
+src/pmc/packfilebytecodesegment.pmc - PackfileBytecodeSegment PMC
+
+=head1 DESCRIPTION
+
+This class implements a PackfileBytecode class, providing a PMC-based interface
+for bytecode creation and manipulation.
+
+See packfile.pmc for the toplevel Packfile interface; see PDD13 for the design
+spec.
+
+=head2 Methods
+
+=over 4
+
+=cut
+
+*/
+
+/* HEADERIZER HFILE: none */
+/* HEADERIZER BEGIN: static */
+/* HEADERIZER END: static */
+
+pmclass PackfileBytecodeSegment auto_attrs extends PackfileSegment{
+    ATTR PMC  *ops;    /* RIA of executable opcodes */
+    ATTR PMC  *op_map; /* OpMap PMC */
+
+
+
+/*
+
+=item C<void init()>
+
+Initialize PackfileBytecodeSegment.
+
+=cut
+
+*/
+    VTABLE void init() {
+        Parrot_PackfileBytecodeSegment_attributes * attrs =
+                PMC_data_typed(SELF, Parrot_PackfileBytecodeSegment_attributes*);
+
+        attrs->op_map = Parrot_pmc_new(INTERP, enum_class_PackfileOpMap);
+        attrs->ops    = Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray);
+
+        PObj_custom_mark_SET(SELF);
+        SUPER();
+    }
+
+/*
+
+=item C<void mark()>
+
+Marks the object as live.
+
+=cut
+
+*/
+
+    VTABLE void mark() {
+        Parrot_PackfileBytecodeSegment_attributes * attrs =
+                PARROT_PACKFILESEGMENT(SELF);
+
+        Parrot_gc_mark_PMC_alive(INTERP, attrs->op_map);
+        Parrot_gc_mark_PMC_alive(INTERP, attrs->ops);
+        SUPER();
+    }
+
+/*
+
+=item C<void destroy()>
+
+Destroy anything in this segment that need destroying.
+
+=cut
+
+*/
+
+    VTABLE void destroy() {
+        Parrot_PackfileBytecodeSegment_attributes * attrs =
+                PARROT_PACKFILESEGMENT(SELF);
+
+        VTABLE_destroy(INTERP, attrs->op_map);
+        VTABLE_destroy(INTERP, attrs->ops);
+        SUPER();
+    }
+
+/*
+
+=item C<void load_lib()>
+
+Load a dynop library so that ops contained in that library can be used in this
+bytecode segment.
+
+=cut
+
+*/
+
+    METHOD void load_lib(STRING *lib_name) {
+        /* delegate to OpMap */
+
+    }
+
+
+/*
+
+=over 4
+
+=item Packfile Interface Methods 
+
+=back 4
+
+=item C<STRING *pack()>
+
+Serialize the segment.
+
+=cut
+
+*/
+    METHOD pack() {
+        Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_UNIMPLEMENTED,
+                                    "PackfileBytecodeSegment.pack() not implemented yet.");
+    }
+
+
+/*
+
+=item C<void unpack(STRING *data)>
+
+Unpack a serialized segment string.
+
+=cut
+
+*/
+    METHOD unpack(STRING *data) {
+        Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_UNIMPLEMENTED,
+                                    "PackfileBytecodeSegment.unpack() not implemented yet.");
+    }
+
+/*
+
+=back
+
+=cut
+
+*/
+
+}
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Added: branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/opmap_aware_pmcs/src/pmc/packfileopmap.pmc	Tue Oct 26 19:17:13 2010	(r49683)
@@ -0,0 +1,260 @@
+/*
+Copyright (C) 2001-2010, Parrot Foundation.
+$Id$
+
+=head1 NAME
+
+src/pmc/packfileopmap.pmc - Packfile Debug Segment PMC
+
+=head1 DESCRIPTION
+
+This class implements a PackfileOpMap, which provides a map between op
+numbers in a bytecode segment and the libraries and offsets within those
+libraries that the ops come from.
+
+=head2 Vtable functions
+
+=over 4
+
+=cut
+
+*/
+
+#include "pmc/pmc_parrotlibrary.h"
+
+/* HEADERIZER HFILE: none */
+/* HEADERIZER BEGIN: static */
+/* HEADERIZER END: static */
+
+
+pmclass PackfileOpMap extends PackfileSegment auto_attrs {
+    ATTR PMC    *op_maps;   /* RPA of Hashes of op lib maps */
+    ATTR PMC    *map_cache; /* Hash mapping full op names to numbers */
+    ATTR INTVAL  op_count;  /* number of mapped ops*/
+
+/*
+
+=item C<init>
+
+Create empty PackfileOpMap for a given op library.
+
+=cut
+
+*/
+
+    VTABLE void init() {
+        PMC *core_ops_info, *core_ops_pmc;
+        STRING *oplib_name, *lib_ops, *table_ops;
+        Parrot_PackfileOpMap_attributes *attrs =
+            PMC_data_typed(SELF, Parrot_PackfileOpMap_attributes*);
+        
+        attrs->op_maps    = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
+        attrs->map_cache  = Parrot_pmc_new(INTERP, enum_class_Hash);
+        attrs->op_count   = 0;
+
+        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");
+
+        core_ops_info = Parrot_pmc_new(INTERP, enum_class_Hash);
+        VTABLE_set_pmc_keyed_str(INTERP, core_ops_info, oplib_name,
+                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_push_pmc(INTERP, attrs->op_maps, core_ops_info);
+
+        SUPER();
+    }
+
+/*
+
+=item C<get_integer_keyed>
+
+Return the integer which maps to the given op, if any.  If the op is not
+already in the map, a new map will be created.
+
+=cut
+
+*/
+
+    VTABLE INTVAL get_integer_keyed(PMC *key) {
+        STRING *key_str, *oplib_str;
+        PMC    *map_cache, *op_maps;
+        INTVAL  op_map_count, i;
+
+        GET_ATTR_map_cache(INTERP, SELF, map_cache);
+
+        if (VTABLE_exists_keyed(INTERP, map_cache, key)) {
+            return VTABLE_get_integer_keyed(INTERP, map_cache, key);
+        }
+
+        key_str = key_string(INTERP, key);
+        oplib_str = CONST_STRING(INTERP, "oplib");
+        GET_ATTR_op_maps(INTERP, SELF, op_maps);
+        op_map_count = VTABLE_elements(INTERP, op_maps);
+        for (i = 0; i < op_map_count; i++) {
+            PMC *op_map = VTABLE_get_pmc_keyed_int(INTERP, op_maps, i);
+            PMC *oplib  = VTABLE_get_pmc_keyed_str(INTERP, op_map, oplib_str);
+            INTVAL op_num = VTABLE_get_integer_keyed(INTERP, oplib, key);
+
+            /* we found the op */
+            if (op_num > -1) {
+                PMC *table_ops, *lib_ops;
+                STRING *table_ops_str, *lib_ops_str;
+                INTVAL op_count;
+
+                table_ops_str = CONST_STRING(INTERP, "table_ops");
+                lib_ops_str   = CONST_STRING(INTERP, "lib_ops");
+
+                table_ops = VTABLE_get_pmc_keyed_str(INTERP, op_map, table_ops_str);
+                lib_ops   = VTABLE_get_pmc_keyed_str(INTERP, op_map, lib_ops_str);
+
+                GET_ATTR_op_count(INTERP, SELF, op_count);
+
+                VTABLE_set_integer_keyed(INTERP, map_cache, key, op_count);
+                VTABLE_push_integer(INTERP, table_ops, op_count);
+                VTABLE_push_integer(INTERP, lib_ops, op_num);
+
+                return op_num;
+            }
+        }
+        return -1;
+    }
+
+    VTABLE INTVAL get_integer_keyed_str(STRING *str_key) {
+        PMC *pmc_key = key_new_string(INTERP, str_key);
+        return SELF.get_integer_keyed(pmc_key);
+    }
+
+
+/*
+
+=item C<void mark()>
+
+Marks the object as live.
+
+=cut
+
+*/
+
+    VTABLE void mark() {
+        Parrot_PackfileOpMap_attributes *attrs =
+            PMC_data_typed(SELF, Parrot_PackfileOpMap_attributes*);
+        VTABLE_mark(INTERP, attrs->op_maps);
+        VTABLE_mark(INTERP, attrs->map_cache);
+
+        SUPER();
+    }
+
+
+/*
+
+=item C<void destroy()>
+
+Clean up anything used by this PMC.
+
+=cut
+
+*/
+
+    VTABLE void destroy() {
+        Parrot_PackfileOpMap_attributes *attrs =
+            PMC_data_typed(SELF, Parrot_PackfileOpMap_attributes*);
+        VTABLE_destroy(INTERP, attrs->op_maps);
+        VTABLE_destroy(INTERP, attrs->map_cache);
+
+        SUPER();
+    }
+
+
+/*
+
+=item C<INTVAL get_integer()>
+
+Get the number of filename mappings.
+
+=cut
+
+*/
+
+    VTABLE INTVAL get_integer() {
+        INTVAL op_count;
+        GET_ATTR_op_count(INTERP, SELF, op_count);
+        return op_count;
+    }
+
+/*
+
+=item C<METHOD load_lib>
+
+Ensure that an op library is loaded and accessible to this OpMap.
+
+=cut
+
+*/
+    METHOD load_lib(STRING *lib_name) {
+        /* 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;
+        Parrot_PackfileOpMap_attributes *attrs;
+
+        oplib_name = CONST_STRING(INTERP, "oplib_name");
+
+        GET_ATTR_op_maps(INTERP, SELF, op_maps);
+        op_map_count = VTABLE_elements(INTERP, op_maps);
+
+        for (i = 0; i < op_map_count; i++) {
+            PMC *map = VTABLE_get_pmc_keyed_int(INTERP, op_maps, i);
+            if (Parrot_str_equal(INTERP, lib_name, 
+                        VTABLE_get_string_keyed_str(INTERP, map, oplib_name))) {
+                RETURN (INTVAL 1);
+            }
+        }
+
+        /* create a new OpLib etc */
+        lib_name_pmc = Parrot_pmc_new(INTERP, enum_class_String);
+        VTABLE_set_string_native(INTERP, lib_name_pmc, lib_name);
+        oplib = Parrot_pmc_new_init(INTERP, enum_class_OpLib, lib_name_pmc);
+
+        if (!VTABLE_get_bool(INTERP, oplib)) {
+            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_LIBRARY_ERROR,
+                    "Couldn't load op library '%Ss'.", lib_name);
+        }
+
+        attrs = PMC_data_typed(SELF, Parrot_PackfileOpMap_attributes*);
+        
+        lib_ops   = CONST_STRING(INTERP, "lib_ops");
+        table_ops = CONST_STRING(INTERP, "table_ops");
+
+        ops_info = Parrot_pmc_new(INTERP, enum_class_Hash);
+        VTABLE_set_pmc_keyed_str(INTERP, ops_info, oplib_name,
+                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_push_pmc(INTERP, attrs->op_maps, ops_info);
+    }
+
+}
+
+
+/*
+
+=back
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */


More information about the parrot-commits mailing list