[svn:parrot] r47012 - in branches/gsoc_instrument: examples/library runtime/parrot/library/Instrument src/dynpmc
khairul at svn.parrot.org
khairul at svn.parrot.org
Wed May 26 05:37:26 UTC 2010
Author: khairul
Date: Wed May 26 05:37:25 2010
New Revision: 47012
URL: https://trac.parrot.org/parrot/changeset/47012
Log:
Removed duplicate functionality
Modified:
branches/gsoc_instrument/examples/library/tracer.pir
branches/gsoc_instrument/runtime/parrot/library/Instrument/Probe.pir
branches/gsoc_instrument/src/dynpmc/instrument.pmc
Modified: branches/gsoc_instrument/examples/library/tracer.pir
==============================================================================
--- branches/gsoc_instrument/examples/library/tracer.pir Wed May 26 04:32:06 2010 (r47011)
+++ branches/gsoc_instrument/examples/library/tracer.pir Wed May 26 05:37:25 2010 (r47012)
@@ -31,7 +31,7 @@
# each op.
probe = new ['Instrument';'Probe';'Catchall']
probe.'set_callback'('catchall_callback')
- #probe.'set_finalize'('catchall_finalize')
+ probe.'set_finalize'('catchall_finalize')
# Create a probe that will be called whenever the
# specified ops are encountered.
Modified: branches/gsoc_instrument/runtime/parrot/library/Instrument/Probe.pir
==============================================================================
--- branches/gsoc_instrument/runtime/parrot/library/Instrument/Probe.pir Wed May 26 04:32:06 2010 (r47011)
+++ branches/gsoc_instrument/runtime/parrot/library/Instrument/Probe.pir Wed May 26 05:37:25 2010 (r47012)
@@ -22,7 +22,7 @@
probe2.'set_finalize'('specific_finalize')
=head2 TODO
-1. Refactor, too much copy and paste for now.
+1. Rewrite in NQP
=cut
@@ -279,7 +279,7 @@
.sub 'enable' :method
.local pmc instr_attr, ops_u_attr, ops_p_attr, en_attr, cb_attr
- .local pmc it, key
+ .local pmc it, key, op_lib, op_eh
.local string msg, type, op_name
.local int op_num
@@ -289,6 +289,8 @@
en_attr = getattribute self, 'enabled'
cb_attr = getattribute self, 'callback'
+ op_lib = new ['OpLib']
+
# Check to see if we are already enabled.
if en_attr == 1 goto ENABLE_DONE
@@ -299,6 +301,11 @@
if type != 'Instrument' goto EXCEP
+ # Create a new exception handler for op lookups
+ op_eh = new ['ExceptionHandler']
+ set_addr op_eh, NON_EXISTENT_OP
+ push_eh op_eh
+
# Process the unprocessed ops in ops_u_attr.
# Because we simply dump in both integers
@@ -347,6 +354,9 @@
en_attr = 1
setattribute self, 'enabled', en_attr
+ # Pop the op lookup exception handler
+ pop_eh
+
.return()
@@ -362,9 +372,18 @@
# Lookup the op number from op_name
# This will return an array, so for each element
# in the array, insert it into ops_p_attr.
- .local pmc query_ret, op_lu_it, op_lu_cur
+ .local pmc query_ret, op_lu_it, op_lu_cur, op_obj
- query_ret = instr_attr.'op_query'(0, op_name)
+ query_ret = op_lib.'op_family'(op_name)
+ $I0 = defined query_ret
+ if $I0 goto OPS_LOOKUP_ITER
+
+ # Not short name.
+ op_obj = op_lib[op_name]
+ query_ret = new ['ResizablePMCArray']
+ push query_ret, op_obj
+
+OPS_LOOKUP_ITER:
op_lu_it = iter query_ret
OPS_LOOKUP_BEG:
@@ -381,6 +400,13 @@
goto UNPROC_LOOKUPED
+NON_EXISTENT_OP:
+ print 'Warning: Non-existant op "'
+ print op_name
+ say '".'
+
+ goto OPS_LOOKUP_END
+
.end
=item disable
Modified: branches/gsoc_instrument/src/dynpmc/instrument.pmc
==============================================================================
--- branches/gsoc_instrument/src/dynpmc/instrument.pmc Wed May 26 04:32:06 2010 (r47011)
+++ branches/gsoc_instrument/src/dynpmc/instrument.pmc Wed May 26 05:37:25 2010 (r47012)
@@ -335,150 +335,6 @@
/*
-=item C<void *op_query(INTVAL query_type, PMC *key :optional)>
-
-Performs a op query, based on the query_type.
-0: Lookup the op number given the ops' name. Returns an array of all the indexes with that name.
-1: Returns a hash with the key and data as in the op's op_info_t entry.
-2: Returns the op's full name.
-3: Returns the op's short name.
-4: Returns an array with the type of arguments the op expects.
-5: Returns the total number of ops in the op_lib.
-
-TODO: Create a .pasm file for the constants.
-
-=cut
-
-*/
-
- METHOD op_query (INTVAL query_type, PMC *key :optional) {
- PMC *res;
- Parrot_Instrument_attributes * const attr = PARROT_INSTRUMENT(SELF);
-
- /* Perform the required lookup */
- switch (query_type) {
- case OP_LOOKUP:
- {
- /* Given the name of the op, return its number.
- Name given can be either short or long name.
- Return value is in the form of a ResizableIntegerArray */
- int index;
- op_info_t *head = attr->supervised->op_info_table;
- STRING *name = VTABLE_get_string(INTERP, key);
- char const *c_name = Parrot_str_cstring(INTERP, name);
- res = Parrot_pmc_new(INTERP, enum_class_ResizableIntegerArray);
-
-
-
- /* Find the first index of the op. */
- index = attr->supervised->op_lib->op_code(attr->supervised, c_name, 0);
- if(index < 0) {
- index = attr->supervised->op_lib->op_code(attr->supervised, c_name, 1);
- }
-
- /* Check if long or short name lookups fail. */
- if(index < 0) {
- break;
- }
-
- /* Iterate onwards until the name does not match. */
- do {
-
- VTABLE_push_integer(INTERP, res, index);
- index++;
-
- } while (STREQ(c_name, head[index].name)
- || STREQ(c_name, head[index].full_name));
-
- break;
- }
-
- case OP_INFO:
- /* Returns a Hash with the op info as shown in
- the op_info_table */
- /* TODO */
- res = Parrot_pmc_new(INTERP, enum_class_Undef);
-
- break;
-
- case OP_FULLNAME:
- {
- /* Given the op number, return the full name of the op */
- size_t index;
- STRING *name;
- char const *c_name;
- index = VTABLE_get_integer(INTERP, key);
-
- if(index > attr->supervised->op_lib->op_count) {
- /* Error! Index given is out of range. */
- Parrot_ex_throw_from_c_args(
- INTERP, NULL, 1,
- "Op index out of range."
- );
- }
-
- c_name = attr->supervised->op_info_table[index].full_name;
- name = Parrot_str_new(INTERP, c_name, strlen(c_name));
- res = Parrot_pmc_new(INTERP, enum_class_String);
-
- VTABLE_set_string_native(INTERP, res, name);
-
- break;
- }
-
- case OP_NAME:
- {
- /* Given the op number, return the short name of the op */
- size_t index;
- STRING *name;
- char const *c_name;
- index = VTABLE_get_integer(INTERP, key);
-
- if(index > attr->supervised->op_lib->op_count) {
- /* Error! Index given is out of range. */
- Parrot_ex_throw_from_c_args(
- INTERP, NULL, 1,
- "Op index out of range."
- );
- }
-
- c_name = attr->supervised->op_info_table[index].name;
- name = Parrot_str_new(INTERP, c_name, strlen(c_name));
- res = Parrot_pmc_new(INTERP, enum_class_String);
-
- VTABLE_set_string_native(INTERP, res, name);
-
- break;
- }
-
- case OP_ARGS:
- /* Return a ResizablePMCArray with the types of arguments
- in order of how the op expects it. */
- /* TODO */
- res = Parrot_pmc_new(INTERP, enum_class_Undef);
-
- break;
-
- case OP_COUNT:
- {
- /* Return the total number of ops in the supervised
- ops table */
- INTVAL count;
- res = Parrot_pmc_new(INTERP, enum_class_Integer);
- count = attr->supervised->op_count;
- VTABLE_set_integer_native(INTERP, res, count);
-
- break;
- }
- default:
- res = Parrot_pmc_new(INTERP, enum_class_Undef);
- }
-
- RETURN(PMC* res);
- }
-
-/*
-
=item C<void *insert_op_hooks(PMC *hook_hash)>
Insert hooks based on what is given in hook_hash.
More information about the parrot-commits
mailing list