[svn:parrot] r47445 - in branches/gsoc_instrument: runtime/parrot/library/Instrument src/dynpmc src/pmc t/dynpmc

khairul at svn.parrot.org khairul at svn.parrot.org
Tue Jun 8 03:00:37 UTC 2010


Author: khairul
Date: Tue Jun  8 03:00:36 2010
New Revision: 47445
URL: https://trac.parrot.org/parrot/changeset/47445

Log:
Made codetest mostly happy, exposed data attribute of task pmc.

Modified:
   branches/gsoc_instrument/runtime/parrot/library/Instrument/Instrument.pir
   branches/gsoc_instrument/src/dynpmc/instrument.pmc
   branches/gsoc_instrument/src/pmc/task.pmc
   branches/gsoc_instrument/t/dynpmc/instrument.t

Modified: branches/gsoc_instrument/runtime/parrot/library/Instrument/Instrument.pir
==============================================================================
--- branches/gsoc_instrument/runtime/parrot/library/Instrument/Instrument.pir	Tue Jun  8 00:33:05 2010	(r47444)
+++ branches/gsoc_instrument/runtime/parrot/library/Instrument/Instrument.pir	Tue Jun  8 03:00:36 2010	(r47445)
@@ -9,7 +9,7 @@
 
    # Load the instrument dynpmc and required libraries.
    load_bytecode 'Instrument/Instrument.pbc'
-   
+
 =cut
 
 .include 'call_bits.pasm'
@@ -19,14 +19,7 @@
 .sub '__instrument_lib_init' :init :load :anon
     .local pmc lib
     load_bytecode 'P6object.pbc'
-    
-    #lib = loadlib 'instrument'
-    #$I0 = defined lib
-    #if $I0 goto END
-    
-    #die 'Could not load the instrument dynpmc'
 
-END:
     .return()
 .end
 

Modified: branches/gsoc_instrument/src/dynpmc/instrument.pmc
==============================================================================
--- branches/gsoc_instrument/src/dynpmc/instrument.pmc	Tue Jun  8 00:33:05 2010	(r47444)
+++ branches/gsoc_instrument/src/dynpmc/instrument.pmc	Tue Jun  8 03:00:36 2010	(r47445)
@@ -41,7 +41,7 @@
  * Extend the runcore_t struct to include a reference
  *  to the supervisor interpreter.
  */
- 
+
 typedef struct Instrument_runcore_t {
     STRING                  *name;
     int                      id;
@@ -50,7 +50,7 @@
     runcore_destroy_fn_type  destroy;
     runcore_prepare_fn_type  prepare_run;
     INTVAL                   flags;
-    
+
     /* End of common members */
     Parrot_Interp             supervisor_interp;
     PMC                      *supervisor_pmc;
@@ -59,21 +59,21 @@
 } Instrument_runcore_t;
 
 /* Runcore Function Prototypes */
-static void      Instrument_runcore_init (PARROT_INTERP, Parrot_Interp supervisor, PMC *instrument);
-static opcode_t *Instrument_runcore_runops (PARROT_INTERP, Parrot_runcore_t *runcore, opcode_t *pc);
-static void      Instrument_init_probes (Parrot_Interp supervisor, Parrot_Interp supervised);
+static void      Instrument_runcore_init(PARROT_INTERP, Parrot_Interp supervisor, PMC *instrument);
+static opcode_t *Instrument_runcore_runops(PARROT_INTERP, Parrot_runcore_t *runcore, opcode_t *pc);
+static void      Instrument_init_probes(Parrot_Interp supervisor, Parrot_Interp supervised);
 
 /* Helper prototype */
-static opcode_t *Instrument_fire_hooks (opcode_t *pc, PARROT_INTERP);
+static opcode_t *Instrument_fire_hooks(opcode_t *pc, PARROT_INTERP);
 
 /* Linked List operations */
-static probe_list_t *probe_list_create_list (PARROT_INTERP);
-static probe_node_t *probe_list_create_node (PARROT_INTERP);
-static void          probe_list_delete_node (PARROT_INTERP, probe_node_t *node);
-static void          probe_list_push (PARROT_INTERP, probe_list_t *list, PMC *item);
-static PMC          *probe_list_pop (PARROT_INTERP, probe_list_t *list);
-static PMC          *probe_list_remove (PARROT_INTERP, probe_list_t *list, probe_node_t *node);
-static probe_node_t *probe_list_find (PARROT_INTERP, probe_list_t *list, PMC *val);
+static probe_list_t *probe_list_create_list(PARROT_INTERP);
+static probe_node_t *probe_list_create_node(PARROT_INTERP);
+static void          probe_list_delete_node(PARROT_INTERP, probe_node_t *node);
+static void          probe_list_push(PARROT_INTERP, probe_list_t *list, PMC *item);
+static PMC          *probe_list_pop(PARROT_INTERP, probe_list_t *list);
+static PMC          *probe_list_remove(PARROT_INTERP, probe_list_t *list, probe_node_t *node);
+static probe_node_t *probe_list_find(PARROT_INTERP, probe_list_t *list, PMC *val);
 
 pmclass Instrument auto_attrs dynpmc provides hash {
     ATTR Parrot_Interp  supervised;  /* The interpreter running the code */
@@ -89,23 +89,23 @@
 
 */
 
-    VTABLE void init () {
+    VTABLE void init() {
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
-        
+
         /* Create the child interpreter PMC */
         attr->supervised  = Parrot_new(INTERP);
         attr->probes      = Parrot_pmc_new(INTERP, enum_class_Hash);
-        
+
         /* Initialize the runcore for the child interpreter */  
         Instrument_runcore_init(attr->supervised, INTERP, SELF);
-        
+
         /* Initialize the scheduler for the child interpreter */
         attr->supervised->scheduler = Parrot_pmc_new(interp, enum_class_Scheduler);
         attr->supervised->scheduler = VTABLE_share_ro(interp, attr->supervised->scheduler);
-        
+
         /* Prepare the child interpreter's op table for instrumentation */
         Instrument_init_probes(INTERP, attr->supervised);
-        
+
         /* Set self to destroy manually */
         PObj_custom_mark_destroy_SETALL(SELF);
     }
@@ -120,11 +120,11 @@
 
 */
 
-    VTABLE void destroy () {
+    VTABLE void destroy() {
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
-        
+
         /* TODO: Delete the linked list entries. */
-        
+
         /* Delete the supervised interpreter */
         Parrot_destroy(attr->supervised);
     }
@@ -139,9 +139,9 @@
 
 */
 
-    VTABLE void mark () {
+    VTABLE void mark() {
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
-        
+
         /* Mark attributes as alive */
         Parrot_gc_mark_PMC_alive_fun(INTERP, attr->probes);
     }
@@ -169,10 +169,10 @@
 
         /* probes: return the hash of probes */
         name = CONST_STRING(INTERP, "probes");
-        if(Parrot_str_equal(INTERP, name, item)) {
+        if (Parrot_str_equal(INTERP, name, item)) {
             return attr->probes;
         }
-        
+
         /* push to the supervised interpreter. */
         supervised_pmc = VTABLE_get_pmc_keyed_int(attr->supervised,
                                                   attr->supervised->iglobals,
@@ -190,7 +190,7 @@
 
 */
 
-    METHOD run (STRING file, PMC *args) {
+    METHOD run(STRING file, PMC *args) {
         PMC *entry_point;
         int argc = 0, status;
         char * default_argv[] = {NULL};
@@ -198,29 +198,38 @@
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
         PMC *probe_iter;
         int counter = 0;
-            
+
         /* If args is not null, is of type ResizableStringArray and has at
            least 1 element, process it so we can pass it to the child interpreter.
          */
-        if(!Parrot_pmc_is_null(INTERP, args)
+        if (!Parrot_pmc_is_null(INTERP, args)
            && VTABLE_type(INTERP, args) == enum_class_ResizableStringArray
            && VTABLE_get_integer(INTERP, args) > 0) {
-           
+
             /* Get the number of argument values */
             int count = VTABLE_get_integer(INTERP, args);
-            
+
             /* Allocate enough memory for the argv pointer array */
             argv = (char **) mem_gc_allocate_n_zeroed_typed(INTERP, count, char *);
-            
+
             /* Populate the argv array, updating argc in the process */
-            for(argc = 0; argc < count; argc++) {
+            for (argc = 0; argc < count; argc++) {
                 STRING *cur;
-                
+
                 cur = VTABLE_get_string_keyed_int(INTERP, args, argc);
                 argv[argc] = Parrot_str_to_cstring(INTERP, cur);
             }
         }
-        
+
+        /* TODO: Apparently, dynpmcs also have the same problem as dynops.
+                 I'm not sure why, but it seems that whenever 2 interps try
+                 to load the same dynpmc (at different times), something bad happens.
+                 Below is a hack as a temporary work around for that.
+        */
+        attr->supervised->vtables          = INTERP->vtables;
+        attr->supervised->n_vtable_max     = INTERP->n_vtable_max;
+        attr->supervised->n_vtable_alloced = INTERP->n_vtable_alloced;
+
         /* Begin Execution */
         status = imcc_run(attr->supervised,
                     Parrot_str_cstring(attr->supervised, file),
@@ -228,33 +237,33 @@
         if (status) {
             imcc_run_pbc(attr->supervised,
                          attr->supervised->output_file,
-                         argc,(const char **) argv);
+                         argc, (const char **) argv);
         }
-        
+
         /* Finalize the instruments */
         probe_iter = VTABLE_get_iter(INTERP, attr->probes);
-        while(VTABLE_get_bool(INTERP, probe_iter)) {
+        while (VTABLE_get_bool(INTERP, probe_iter)) {
             PMC *key, *probe, *finalize_sub;
-            
+
             /* For the current probe, get the finalize attribute. */
             key          = VTABLE_shift_pmc(INTERP, probe_iter);
             probe        = VTABLE_get_pmc_keyed(INTERP, attr->probes, key);
             finalize_sub = VTABLE_get_attr_str(INTERP, probe,
                                                CONST_STRING(INTERP, "$!finalize"));
-            
+
             /* If it is set, call that sub. */
-            if(!PMC_IS_NULL(finalize_sub)) {
+            if (!PMC_IS_NULL(finalize_sub)) {
                 Parrot_ext_call(INTERP, finalize_sub, "->");
             }
         }
-        
+
         /* We should free the cstrings allocated above if needed */
-        if(argc > 0) {
-            for(; argc > 0; argc--) {
+        if (argc > 0) {
+            for (; argc > 0; argc--) {
                 Parrot_str_free_cstring(argv[argc - 1]);
                 argv[argc - 1] = NULL;
             }
-            
+
             /* Free the memory allocated to hold the string pointers */
             mem_gc_free(INTERP, argv);
             argv = NULL;
@@ -273,37 +282,35 @@
 
 */
 
-    METHOD attach (PMC *obj) {
+    METHOD attach(PMC *obj) {
         PMC *enable_method, *id;
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
-    
+
         /* We do not care what type of object it is,
            as long as the object has the attributes $!instr_obj and $!identifier
            and the method enable. */
-        
+
         /* Set the instrument reference attribute of the object,
            and call its enable method. */
-        VTABLE_set_attr_str(
-            INTERP, obj,
-            CONST_STRING(INTERP, "$!instr_obj"),
-            SELF
-        );
-        
+        VTABLE_set_attr_str(INTERP, obj,
+                            CONST_STRING(INTERP, "$!instr_obj"),
+                            SELF);
+
         /* Find the enable method */
         enable_method = VTABLE_find_method(INTERP, obj, CONST_STRING(INTERP, "enable"));
-        if(PMC_IS_NULL(enable_method)) {
+        if (PMC_IS_NULL(enable_method)) {
             /* Error! Could not find the enable method. */
             Parrot_ex_throw_from_c_args(
                 INTERP, NULL, 1,
                 "Could not locate the method 'enable'."
             );
         }
-        
+
         /* Call the method.
            The first parameter to a method is the object itself.
            The enable method will be calling insert_op_hook to register the hooks. */
         Parrot_ext_call(INTERP, enable_method, "P->", obj);
-        
+
         /* Register the probe. */
         id = VTABLE_get_attr_str(INTERP, obj, CONST_STRING(INTERP, "$!identifier"));
         VTABLE_set_pmc_keyed(INTERP, attr->probes, id, obj);
@@ -319,25 +326,21 @@
 
 */
     
-    METHOD insert_op_hook (PMC *id, INTVAL op_num, PMC *hook) {
+    METHOD insert_op_hook(PMC *id, INTVAL op_num, PMC *hook) {
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
         Instrument_runcore_t *core = (Instrument_runcore_t *) attr->supervised->run_core;
         probe_list_t        **list = core->op_hooks;
         size_t               index = op_num;
-        
-        if(index >= attr->supervised->op_count) {
+
+        if (index >= attr->supervised->op_count) {
             /* Invalid op num */
-            Parrot_ex_throw_from_c_args(
-                INTERP, NULL, 1,
-                "Invalid op number %d.",
-                index
-            );
+            Parrot_ex_throw_from_c_args(INTERP, NULL, 1,"Invalid op number %d.", index);
         }
-        
-        if(list[index] == NULL) {
+
+        if (list[index] == NULL) {
             list[index] = probe_list_create_list(INTERP);
         }
-        
+
         probe_list_push(INTERP, list[index], hook);
     }
 
@@ -351,37 +354,31 @@
 
 */
     
-    METHOD remove_op_hook (PMC *id, INTVAL op_num, PMC *callback) {
+    METHOD remove_op_hook(PMC *id, INTVAL op_num, PMC *callback) {
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
         Instrument_runcore_t *core = (Instrument_runcore_t *) attr->supervised->run_core;
         probe_list_t        **list = core->op_hooks;
         probe_node_t         *node = NULL;
         size_t               index = op_num;
-        
-        if(index >= attr->supervised->op_count) {
+
+        if (index >= attr->supervised->op_count) {
             /* Invalid op num */
-            Parrot_ex_throw_from_c_args(
-                INTERP, NULL, 1,
-                "Invalid op number %d.",
-                index
-            );
+            Parrot_ex_throw_from_c_args(INTERP, NULL, 1,"Invalid op number %d.", index);
         }
-        
-        if(list[index] != NULL) {
+
+        if (list[index] != NULL) {
             node = probe_list_find(INTERP, list[index], callback);
-            
-            if(node != NULL) {
+
+            if (node != NULL) {
                 probe_list_remove(INTERP, list[index], node);
             }
         }
-        
-        if(node == NULL) {
+
+        if (node == NULL) {
             /* Callback was not found. */
-            Parrot_ex_throw_from_c_args(
-                INTERP, NULL, 1,
-                "Probe of '%S' not found in 'removal_op_hook'",
-                VTABLE_get_string(INTERP, id)
-            );
+            Parrot_ex_throw_from_c_args(INTERP, NULL, 1,
+                                        "Probe of '%S' not found in 'removal_op_hook'",
+                                        VTABLE_get_string(INTERP, id));
         }
     }
 
@@ -393,19 +390,19 @@
 =cut
 */
 
-    METHOD count_op_hooks (INTVAL op_num) {
+    METHOD count_op_hooks(INTVAL op_num) {
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
         Instrument_runcore_t *core = (Instrument_runcore_t *) attr->supervised->run_core;
         probe_list_t         *list = core->op_hooks[op_num];
         probe_node_t         *node = NULL;
         INTVAL               count = 0;
-        
+
         node = (list != NULL) ? list->head : NULL;
-        while(node != NULL) {
+        while (node != NULL) {
             count++;
             node = node->next;
         }
-        
+
         RETURN(INTVAL count);
     }
 
@@ -417,11 +414,11 @@
 =cut
 */
 
-    METHOD insert_op_catchall (PMC *id, PMC *callback) {
+    METHOD insert_op_catchall(PMC *id, PMC *callback) {
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
         Instrument_runcore_t *core = (Instrument_runcore_t *) attr->supervised->run_core;
         probe_list_t  *list = core->op_catchall;
-        
+
         probe_list_push(INTERP, list, callback);
     }
 
@@ -433,23 +430,21 @@
 =cut
 */
 
-    METHOD remove_op_catchall (PMC *id, PMC *callback) {
+    METHOD remove_op_catchall(PMC *id, PMC *callback) {
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
         Instrument_runcore_t *core = (Instrument_runcore_t *) attr->supervised->run_core;
         probe_list_t  *list = core->op_catchall;
         probe_node_t  *node = NULL;
-        
+
         node = probe_list_find(INTERP, list, callback);
-        
-        if(node == NULL) {
+
+        if (node == NULL) {
             /* Callback was not found. */
-            Parrot_ex_throw_from_c_args(
-                INTERP, NULL, 1,
-                "Probe of '%S' not found in 'removal_op_hook'",
-                VTABLE_get_string(INTERP, id)
-            );
+            Parrot_ex_throw_from_c_args(INTERP, NULL, 1,
+                                        "Probe of '%S' not found in 'removal_op_hook'",
+                                        VTABLE_get_string(INTERP, id));
         }
-        
+
         probe_list_remove(INTERP, list, node);
     }
 
@@ -461,19 +456,19 @@
 =cut
 */
 
-    METHOD count_op_catchalls () {
+    METHOD count_op_catchalls() {
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
         Instrument_runcore_t *core = (Instrument_runcore_t *) attr->supervised->run_core;
         probe_list_t         *list = core->op_catchall;
         probe_node_t         *node = NULL;
         INTVAL               count = 0;
-        
+
         node = list->head;
-        while(node != NULL) {
+        while (node != NULL) {
             count++;
             node = node->next;
         }
-        
+
         RETURN(INTVAL count);
     }
 
@@ -488,58 +483,64 @@
 =cut
 */
 
-    METHOD get_op_arg (INTVAL arg, INTVAL arg_type) {
+    METHOD get_op_arg(INTVAL arg, INTVAL arg_type) {
         Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
         PMC *ret, *cc, *key;
         arg_type_t type = (arg_type_t) arg_type;
 
         cc = CURRENT_CONTEXT(attr->supervised);
-        
-        switch(type) {
+
+        switch (type) {
           case PARROT_ARG_IC:            
             /* Integer constants are stored as part of the opcode
                in the packfile */
             ret = Parrot_pmc_new(INTERP, enum_class_Integer);
             VTABLE_set_integer_native(INTERP, ret, arg);
-            
+
             break;
           case PARROT_ARG_I:
             ret = Parrot_pmc_new(INTERP, enum_class_Integer);
-            VTABLE_set_integer_native(INTERP, ret, *Parrot_pcc_get_INTVAL_reg(attr->supervised, cc, arg));
+            VTABLE_set_integer_native(INTERP, ret,
+                                      *Parrot_pcc_get_INTVAL_reg(attr->supervised, cc, arg));
 
             break;
           case PARROT_ARG_NC:
             ret = Parrot_pmc_new(INTERP, enum_class_Float);
-            VTABLE_set_number_native(INTERP, ret, Parrot_pcc_get_num_constant_func(attr->supervised, cc, arg));
-            
+            VTABLE_set_number_native(INTERP, ret,
+                                     Parrot_pcc_get_num_constant_func(attr->supervised, cc, arg));
+
             break;
           case PARROT_ARG_N:
             ret = Parrot_pmc_new(INTERP, enum_class_Float);
-            VTABLE_set_number_native(INTERP, ret, *Parrot_pcc_get_FLOATVAL_reg(attr->supervised, cc, arg));
+            VTABLE_set_number_native(INTERP, ret,
+                                     *Parrot_pcc_get_FLOATVAL_reg(attr->supervised, cc, arg));
 
             break;
           case PARROT_ARG_PC:
             ret = Parrot_pcc_get_pmc_constant_func(attr->supervised, cc, arg);
-            
+
             break;
           case PARROT_ARG_P:
             ret = *Parrot_pcc_get_PMC_reg(attr->supervised, cc, arg);
-            
+
             break;
           case PARROT_ARG_SC:
             ret = Parrot_pmc_new(INTERP, enum_class_String);
-            VTABLE_set_string_native(INTERP, ret, Parrot_pcc_get_string_constant_func(attr->supervised, cc, arg));
-            
+            VTABLE_set_string_native(INTERP, ret,
+                                     Parrot_pcc_get_string_constant_func(attr->supervised,
+                                                                         cc, arg));
+
             break;
           case PARROT_ARG_S:
             ret = Parrot_pmc_new(INTERP, enum_class_String);
-            VTABLE_set_string_native(INTERP, ret, *Parrot_pcc_get_STRING_reg(attr->supervised, cc, arg));
+            VTABLE_set_string_native(INTERP, ret,
+                                     *Parrot_pcc_get_STRING_reg(attr->supervised, cc, arg));
 
             break;
           case PARROT_ARG_K:
             /* Key is PMC */
             ret = *Parrot_pcc_get_PMC_reg(attr->supervised, cc, arg);
-            
+
             break;
           case PARROT_ARG_KC:
             /* Key is String reg or String const */
@@ -549,25 +550,23 @@
           case PARROT_ARG_KI:
             /* Key is integer reg */
             ret = Parrot_pmc_new(INTERP, enum_class_Integer);
-            VTABLE_set_integer_native(INTERP, ret, *Parrot_pcc_get_INTVAL_reg(attr->supervised, cc, arg));
-            
+            VTABLE_set_integer_native(INTERP, ret,
+                                      *Parrot_pcc_get_INTVAL_reg(attr->supervised, cc, arg));
+
             break;
           case PARROT_ARG_KIC:
             /* Key is integer constant */
             ret = Parrot_pmc_new(INTERP, enum_class_Integer);
             VTABLE_set_integer_native(INTERP, ret, arg);
-          
+
             break;
           default:
-            Parrot_ex_throw_from_c_args(
-                INTERP, NULL, 1,
-                "Currently unhandled op arg type %d.", type
-            );
+            Parrot_ex_throw_from_c_args(INTERP, NULL, 1,
+                                        "Currently unhandled op arg type %d.", type );
         };
-        
+
         RETURN(PMC *ret);
     }
-
 }
 
 /*
@@ -588,13 +587,13 @@
 
     while (pc) {
         Parrot_pcc_set_pc(interp, CURRENT_CONTEXT(interp), pc);
-        
+
         /* TODO: This is a hack to get around dynops for now.
                  Since dynops are loaded by the child interpreter
                  and there is no easy way to get notification of that,
                  this will do for now.
         */
-        if(supervisor->op_func_table != interp->op_func_table) {
+        if (supervisor->op_func_table != interp->op_func_table) {
             Instrument_init_probes(supervisor, interp);
             
             supervisor->op_lib        = interp->op_lib;
@@ -602,23 +601,15 @@
             supervisor->op_func_table = interp->op_func_table;
             supervisor->op_info_table = interp->op_info_table;
         }
-        
-        if((pc - interp->code->base.data) == 45) {
-            PMC *mro, *def;
-            
-            //mro = 
-            //printf("%d\n");
-        }
-        
+
         Instrument_fire_hooks(pc, interp);
         DO_OP(pc, interp);
-        
+
         /* Force events */
         Parrot_cx_handle_tasks(interp, interp->scheduler);
     }
-    
+
     return pc;
-    
 }
 
 /*
@@ -628,19 +619,19 @@
 
 static
 void
-Instrument_runcore_init (PARROT_INTERP, Parrot_Interp supervisor, PMC *instrument) {
+Instrument_runcore_init(PARROT_INTERP, Parrot_Interp supervisor, PMC *instrument) {
     Instrument_runcore_t * const coredata =
         mem_gc_allocate_zeroed_typed(interp, Instrument_runcore_t);
-    
+
     /* Ensure the current loaded runcore is the slow core */
     Parrot_set_run_core(interp, PARROT_SLOW_CORE);
-    
+
     /* Copy the runcore entry for the PARROT_SLOW_CORE,
        and then make modifications to it.
        Copy so that we get the opinit function pointer.
     */
     mem_copy_n_typed(coredata, interp->run_core, 1, Parrot_runcore_t);
-    
+
     coredata->name                 = string_from_literal(interp, "instrument");
     coredata->runops             = Instrument_runcore_runops;
     coredata->prepare_run         = NULL;
@@ -650,12 +641,12 @@
     coredata->supervisor_pmc     = instrument;
     coredata->op_hooks           = NULL;
     coredata->op_catchall        = NULL;
-    
+
     PARROT_RUNCORE_FUNC_TABLE_SET((Parrot_runcore_t *)coredata);
-    
+
     Parrot_runcore_register(interp, (Parrot_runcore_t *) coredata);
-    
-    //Switch to this runcore.
+
+    /* Switch to this runcore. */
     Parrot_runcore_switch(interp, coredata->name);
 }
 
@@ -664,20 +655,20 @@
  * Probes are stored in the extended runcore_t.
  */
  
-static void Instrument_init_probes (Parrot_Interp supervisor, Parrot_Interp supervised) {
+static void Instrument_init_probes(Parrot_Interp supervisor, Parrot_Interp supervised) {
     Instrument_runcore_t    *core;
     INTVAL op_count;
-    
+
     core     = (Instrument_runcore_t *) supervised->run_core;
     op_count = supervised->op_count;
-    
+
     /* Create the probe list table */
-    if(!core->op_hooks) {
+    if (!core->op_hooks) {
         /* First time allocating. */
         core->op_hooks    = mem_gc_allocate_n_zeroed_typed(supervisor, op_count, probe_list_t *);
         core->op_catchall = probe_list_create_list(supervisor);
-        
-    } else {
+    }
+    else {
         /* Reallocate. */
         INTVAL old_count  = supervisor->op_count;
         core->op_hooks    = mem_gc_realloc_n_typed_zeroed(supervisor, core->op_hooks,
@@ -689,7 +680,7 @@
  * This will fire the probes.
  */
 
-static opcode_t *Instrument_fire_hooks (opcode_t *pc, PARROT_INTERP) {
+static opcode_t *Instrument_fire_hooks(opcode_t *pc, PARROT_INTERP) {
     /* If this stub is called, this op is instrumented. */
     probe_list_t *to_recall, *op_probes, *op_catchalls;
     probe_node_t *cur_probe;
@@ -697,17 +688,17 @@
     Parrot_Interp            supervisor;
     PMC                     *instrument, *op_data;
     INTVAL                   op_params, cur_op_param, pc_relative, done_catchalls;
-    
+
     core         = (Instrument_runcore_t *) interp->run_core;
     to_recall    = NULL; /* TODO: Implement probe recalls */
     op_probes    = core->op_hooks[*pc];
     op_catchalls = core->op_catchall;
     supervisor   = core->supervisor_interp;
     instrument   = core->supervisor_pmc;
-    
+
     /* Calculate the relative position of the pc. */
     pc_relative = pc - interp->code->base.data;
-    
+
     /* Grab the opcode params */
     /* TODO: Apparently some ops like set_args_pc have extra args.
              see src/runcore/trace.c line 312.
@@ -715,20 +706,20 @@
     op_params = interp->op_info_table[*pc].op_count;
     op_data   = Parrot_pmc_new(supervisor, enum_class_ResizableIntegerArray);
     cur_op_param = 0;
-    while(cur_op_param <= op_params) {
+    while (cur_op_param <= op_params) {
         VTABLE_push_integer(supervisor, op_data, pc[cur_op_param]);
         cur_op_param++;
     }
-    
+
     /* Execute any probes. */
     done_catchalls = 0;
     cur_probe = (op_catchalls != NULL) ? op_catchalls->head : NULL;
-    while(cur_probe != NULL || !done_catchalls) {
+    while (cur_probe != NULL || !done_catchalls) {
         PMC *callback;
         probe_node_t *next;
-    
+
         /* Switch to the specific probes if we are done with catchalls. */
-        if(cur_probe == NULL && !done_catchalls) {
+        if (cur_probe == NULL && !done_catchalls) {
             cur_probe = (op_probes != NULL) ? op_probes->head : NULL;
             done_catchalls = 1;
             continue;
@@ -737,13 +728,13 @@
         /* Fire the probe. */
         callback = cur_probe->list_obj;
         next     = cur_probe->next;
-        
-        if(!PMC_IS_NULL(callback)) {
+
+        if (!PMC_IS_NULL(callback)) {
             Parrot_ext_call(supervisor, callback, "IPP->", pc_relative, op_data, instrument);
         }
         cur_probe = next;
     }
-    
+
     /* Done */
     return pc;
 }
@@ -755,50 +746,50 @@
 /*
  * Creates a new list.
  */
-static probe_list_t *probe_list_create_list (PARROT_INTERP) {
+static probe_list_t *probe_list_create_list(PARROT_INTERP) {
     probe_list_t *list;
-    
+
     list = mem_gc_allocate_zeroed_typed(interp, probe_list_t);
-    
+
     list->head = NULL;
     list->tail = NULL;
-    
+
     return list;
 }
 
 /*
  * Creates a new list node.
  */
-static probe_node_t *probe_list_create_node (PARROT_INTERP) {
+static probe_node_t *probe_list_create_node(PARROT_INTERP) {
     probe_node_t *node;
-    
+
     node = mem_gc_allocate_zeroed_typed(interp, probe_node_t);
-    
+
     node->next     = NULL;
     node->prev     = NULL;
     node->list_obj = NULL;
-    
+
     return node;
 }
 
 /*
  * Deletes the node.
  */
-static void probe_list_delete_node (PARROT_INTERP, probe_node_t *node) {
-
+static void probe_list_delete_node(PARROT_INTERP, probe_node_t *node) {
     mem_gc_free(interp, node);
 }
 
 /*
  * Pushes item to the end of the list.
  */
-static void probe_list_push (PARROT_INTERP, probe_list_t *list, PMC *item) {
+static void probe_list_push(PARROT_INTERP, probe_list_t *list, PMC *item) {
     probe_node_t *node = probe_list_create_node(interp);
     node->list_obj     = item;
 
-    if(list->head == NULL) {
+    if (list->head == NULL) {
         list->head = list->tail = node;
-    } else {
+    }
+    else {
         node->prev       = list->tail;
         node->next       = NULL;
         list->tail->next = node;
@@ -809,23 +800,24 @@
 /*
  * Removes item at the end of the list.
  */
-static PMC * probe_list_pop (PARROT_INTERP, probe_list_t *list) {
+static PMC * probe_list_pop(PARROT_INTERP, probe_list_t *list) {
     PMC *item = PMCNULL;
     probe_node_t *node = list->tail;
-    
-    if(node != NULL) {
-        if(node == list->head) {
+
+    if (node != NULL) {
+        if (node == list->head) {
             list->head = list->tail = NULL;
-        } else {
+        }
+        else {
             list->tail       = node->prev;
             list->tail->next = NULL;
         }
-        
+
         item = node->list_obj;
-        
+
         probe_list_delete_node(interp, node);
     }
-    
+
     return item;
 }
 
@@ -833,38 +825,34 @@
  * Removes the given node. Used with probe_list_find.
  * Returns the item in that node.
  */
-static PMC * probe_list_remove (PARROT_INTERP, probe_list_t *list, probe_node_t *node) {
+static PMC * probe_list_remove(PARROT_INTERP, probe_list_t *list, probe_node_t *node) {
     PMC *item;
-    
-    if(node == list->head) {
-        list->head = node->next;
-    }
-    if(node == list->tail) {
-        list->tail = node->prev;
-    }
-    
-    if(node->prev != NULL) { node->prev->next = node->next; }
-    if(node->next != NULL) { node->next->prev = node->prev; }
-    
+
+    if (node == list->head) { list->head = node->next; }
+    if (node == list->tail) { list->tail = node->prev; }
+
+    if (node->prev != NULL) { node->prev->next = node->next; }
+    if (node->next != NULL) { node->next->prev = node->prev; }
+
     item = node->list_obj;
-    
+
     probe_list_delete_node(interp, node);
-    
+
     return item;
 }
 
 /*
  * Locates item within the list and returns the node.
  */
-static probe_node_t *probe_list_find (PARROT_INTERP, probe_list_t *list, PMC *val) {
+static probe_node_t *probe_list_find(PARROT_INTERP, probe_list_t *list, PMC *val) {
     probe_node_t *cur_node = list->head;
-    
-    while(cur_node != NULL) {
-        if(cur_node->list_obj == val) { return cur_node; }
-        
+
+    while (cur_node != NULL) {
+        if (cur_node->list_obj == val) { return cur_node; }
+
         cur_node = cur_node->next;
     }
-    
+
     return NULL;
 }
 
@@ -877,7 +865,7 @@
 */
 
 /*
- * Local Variables:
+ * Local variables:
  *   c-file-style: "parrot"
  * End:
  * vim: expandtab shiftwidth=4:

Modified: branches/gsoc_instrument/src/pmc/task.pmc
==============================================================================
--- branches/gsoc_instrument/src/pmc/task.pmc	Tue Jun  8 00:33:05 2010	(r47444)
+++ branches/gsoc_instrument/src/pmc/task.pmc	Tue Jun  8 03:00:36 2010	(r47445)
@@ -112,6 +112,12 @@
 
 =back
 
+=item C<data>
+
+Additional data for the task.
+
+=back
+
 =cut
 
 */
@@ -168,7 +174,9 @@
             core_struct->birthtime = 0.0;
 
         core_struct->codeblock = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "code"));
-        core_struct->interp = (Parrot_Interp)VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "data"));
+        core_struct->data      = VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "data"));
+        
+        core_struct->interp = (Parrot_Interp)VTABLE_get_pmc_keyed_str(INTERP, data, CONST_STRING(INTERP, "interp"));
     }
 
 /*
@@ -233,6 +241,9 @@
             value = Parrot_pmc_new(INTERP, enum_class_Float);
             VTABLE_set_number_native(INTERP, value, core_struct->birthtime);
         }
+        else if (Parrot_str_equal(INTERP, name, CONST_STRING(INTERP, "data"))) {
+            value = core_struct->data;
+        }
         else {
             value = PMCNULL;
         }

Modified: branches/gsoc_instrument/t/dynpmc/instrument.t
==============================================================================
--- branches/gsoc_instrument/t/dynpmc/instrument.t	Tue Jun  8 00:33:05 2010	(r47444)
+++ branches/gsoc_instrument/t/dynpmc/instrument.t	Tue Jun  8 03:00:36 2010	(r47445)
@@ -25,166 +25,166 @@
     test_attach()
     test_insert_and_remove_op_hook()
     test_insert_and_remove_op_catchall()
-    
+
     .return()
 .end
 
 .sub 'test_loadlib'
     .local pmc lib
-    
+
     lib = loadlib 'instrument'
     $I0 = defined lib
     ok($I0, 'Instrument dynpmc loaded')
-    
+
     .return()
     
 .end
 
 .sub 'test_instantiate'
     .local pmc instr
-    
+
     instr = new ['Instrument']
     $I0 = defined instr
     ok($I0, 'Instrument object instantiated')
-    
+
 .end
 
 .sub 'test_attach'    
     .local pmc mock_probe, instr
-    
+
     mock_probe = new ['MockProbe']
-    
+
     instr      = new ['Instrument']
     instr.'attach'(mock_probe)
-    
+
 .end
 
 .sub 'test_insert_and_remove_op_hook'
     # Plan: Test insertion and removal of hooks.
     .local pmc instr
     .local pmc stub1, stub2, fake_id
-    
+
     fake_id = box 'FakeProbeId'
     stub1   = get_global 'stub_1'
     stub2   = get_global 'stub_2'
-    
+
     instr = new ['Instrument']
 
     # Test insert and remove 1 hook on existing op (op 0 = noop).
     instr.'insert_op_hook'(fake_id, 0, stub1)
     $I0 = instr.'count_op_hooks'(0)
     is($I0, 1, 'Insertion successful')
-    
+
     instr.'remove_op_hook'(fake_id, 0, stub1)
     $I0 = instr.'count_op_hooks'(0)
     is($I0, 0, 'Removal successful')
-    
+
     # Test insert and removal 2 hooks on existing op.
     instr.'insert_op_hook'(fake_id, 0, stub1)
     instr.'insert_op_hook'(fake_id, 0, stub2)
     $I0 = instr.'count_op_hooks'(0)
     is($I0, 2, 'Insertion successful')
-    
+
     instr.'remove_op_hook'(fake_id, 0, stub1)
     $I0 = instr.'count_op_hooks'(0)
     is($I0, 1, 'Removal of probe 1 successful')
-    
+
     instr.'remove_op_hook'(fake_id, 0, stub2)
     $I0 = instr.'count_op_hooks'(0)
     is($I0, 0, 'Removal of probe 2 successful')
-    
+
     # Test insertion on a non-existent op. (Say, op 5000)
     .local pmc eh
     eh = new ['ExceptionHandler']
     set_addr eh, NON_EXIST_OP_OK
     push_eh eh
-  
+
     instr.'insert_op_hook'(fake_id, 5000, stub1)
 
     ok(0, 'Managed to insert probe for non-existent op.')
     goto NON_EXIST_OP_END
-    
+
   NON_EXIST_OP_OK:
-    
+
     ok(1, 'Detected non-existent op')
-    
+
   NON_EXIST_OP_END:
-    
+
     pop_eh
-  
+
     # Test removal of non-existent hook.
     eh = new ['ExceptionHandler']
     set_addr eh, NON_EXIST_PROBE_OK
     push_eh eh
-  
+
     instr.'remove_op_hook'(fake_id, 0, stub1)
 
     ok(0, 'Managed to remove non-existent probe.')
     goto NON_EXIST_PROBE_END
-    
+
   NON_EXIST_PROBE_OK:
-    
+
     ok(1, 'Detected non-existent probe')
-    
+
   NON_EXIST_PROBE_END:
-    
+
     pop_eh
-    
+
 .end
 
 .sub 'test_insert_and_remove_op_catchall'
     # Plan: Test insertion and removal of catchall probes.
     .local pmc instr
     .local pmc stub1, stub2, fake_id
-    
+
     fake_id = box 'FakeCatchallProbeId'
     stub1   = get_global 'stub_1'
     stub2   = get_global 'stub_2'
-    
+
     instr = new ['Instrument']
 
     # Test insert and remove 1 catchall.
     instr.'insert_op_catchall'(fake_id, stub1)
     $I0 = instr.'count_op_catchalls'()
     is($I0, 1, 'Insertion of catchall successful')
-    
+
     instr.'remove_op_catchall'(fake_id, stub1)
     $I0 = instr.'count_op_catchalls'()
     is($I0, 0, 'Removal of catchall successful')
-    
+
     # Test insert and removal 2 catchalls.
     instr.'insert_op_catchall'(fake_id, stub1)
     instr.'insert_op_catchall'(fake_id, stub2)
     $I0 = instr.'count_op_catchalls'()
     is($I0, 2, 'Insertion of catchalls successful')
-    
+
     instr.'remove_op_catchall'(fake_id, stub1)
     $I0 = instr.'count_op_catchalls'()
     is($I0, 1, 'Removal of catchall probe 1 successful')
-    
+
     instr.'remove_op_catchall'(fake_id, stub2)
     $I0 = instr.'count_op_catchalls'()
     is($I0, 0, 'Removal of catchall probe 2 successful')
-  
+
     # Test removal of non-existent catchall hook.
     .local pmc eh
     eh = new ['ExceptionHandler']
     set_addr eh, NON_EXIST_CATCHALL_OK
     push_eh eh
-  
+
     instr.'remove_op_catchall'(fake_id, stub1)
 
     ok(0, 'Managed to remove non-existent probe.')
     goto NON_EXIST_CATCHALL_END
-    
+
   NON_EXIST_CATCHALL_OK:
-    
+
     ok(1, 'Detected non-existent probe')
-    
+
   NON_EXIST_CATCHALL_END:
-    
+
     pop_eh
-    
+
 .end
 
 
@@ -215,16 +215,16 @@
 
 .sub 'enable' :method
     ok(1, 'Enable is called')
-    
+
     .local pmc instr_obj
     .local string instr_obj_type
     instr_obj = getattribute self, '$!instr_obj'
     $I0 = defined instr_obj
     ok($I0, 'Attribute instr_obj is defined')
-    
+
     instr_obj_type = typeof instr_obj
     is(instr_obj_type, 'Instrument', 'Attribute instr_obj is the correct type')
-    
+
     .return()
 .end
 


More information about the parrot-commits mailing list