[svn:parrot] r48033 - in branches/gsoc_instrument: runtime/parrot/library/Instrument src/dynpmc
khairul at svn.parrot.org
khairul at svn.parrot.org
Wed Jul 7 16:53:00 UTC 2010
Author: khairul
Date: Wed Jul 7 16:53:00 2010
New Revision: 48033
URL: https://trac.parrot.org/parrot/changeset/48033
Log:
Fixed code issues raised by cotto (missed EventDispatcher.nqp).
Modified:
branches/gsoc_instrument/runtime/parrot/library/Instrument/EventDispatcher.nqp
branches/gsoc_instrument/src/dynpmc/instrumentgc.pmc
branches/gsoc_instrument/src/dynpmc/instrumentvtable.pmc
Modified: branches/gsoc_instrument/runtime/parrot/library/Instrument/EventDispatcher.nqp
==============================================================================
--- branches/gsoc_instrument/runtime/parrot/library/Instrument/EventDispatcher.nqp Wed Jul 7 16:31:38 2010 (r48032)
+++ branches/gsoc_instrument/runtime/parrot/library/Instrument/EventDispatcher.nqp Wed Jul 7 16:53:00 2010 (r48033)
@@ -21,9 +21,7 @@
=end
class Instrument::EventDispatcher is EventHandler {
- has $!evt_category;
- has $!evt_subtype;
- has $!evt_fulltype;
+ has %!callbacks;
=begin
@@ -60,9 +58,7 @@
=end
method _self_init () {
- $!evt_category := Q:PIR { %r = new ['Hash'] };
- $!evt_subtype := Q:PIR { %r = new ['Hash'] };
- $!evt_fulltype := Q:PIR { %r = new ['Hash'] };
+ %!callbacks := {};
Q:PIR {
$P0 = get_global 'handler'
@@ -98,29 +94,8 @@
=end
method register ($event, $callback) {
- my $tokens := pir::split__PSS('::', $event);
- my $count := pir::set__IP($tokens);
- if $count > 3 || $count < 1 {
- die('Invalid Instrument event: ' ~ $event ~ "\n"
- ~ 'Expected between 1 to 3 tokens when split with \'::\'.');
- }
-
- my $list;
-
- if $count == 3 {
- # Assume callback is for an exact event.
- $list := get_list($!evt_fulltype, $event);
- }
- elsif $count == 2 {
- # Assume callback is for a subtype event.
- $list := get_list($!evt_subtype, $event);
- }
- elsif $count == 1 {
- # Assume callback is for a category event.
- $list := get_list($!evt_category, $event);
- }
-
- $list.push($callback);
+ my @list := get_list(%!callbacks, $event);
+ @list.push($callback);
};
=begin
@@ -134,34 +109,14 @@
=end
method deregister ($event, $callback) {
- my $tokens := pir::split__PSS('::', $event);
- my $count := pir::set__IP($tokens);
- if $count > 3 || $count < 1 {
- die('Invalid Instrument event: ' ~ $event ~ "\n"
- ~ 'Expected between 1 to 3 tokens when split with \'::\'.');
- }
-
- my $list;
+ my @list := get_list(%!callbacks, $event);
- if $count == 3 {
- # Assume callback is for an exact event.
- $list := get_list($!evt_fulltype, $event);
- }
- elsif $count == 2 {
- # Assume callback is for a subtype event.
- $list := get_list($!evt_subtype, $event);
- }
- elsif $count == 1 {
- # Assume callback is for a category event.
- $list := get_list($!evt_category, $event);
- }
-
- # Look for $callback in $list.
+ # Look for $callback in @list.
my $found := 0;
my $index := 0;
- for $list {
+ for @list {
if pir::defined__IP($_) && $_ eq $callback {
- pir::delete_p_k($list, $index);
+ pir::delete_p_k(@list, $index);
$found := 1;
break;
}
@@ -185,21 +140,18 @@
=end
method get_handlers ($event) {
- my $tokens := pir::split__PSS('::', $event);
+ my @tokens := pir::split__PSS('::', $event);
# Get the lists and join them into 1 big list.
- my $key := Q:PIR { %r = new ['ResizablePMCArray'] };
- my $list := Q:PIR { %r = new ['ResizablePMCArray'] };
- my $hashes := [$!evt_category, $!evt_subtype, $!evt_fulltype];
- my $index := 0;
-
- for $tokens {
- $key.push($_);
- $list.append(get_list($hashes[$index], pir::join__SSP('::', $key)));
- $index++;
+ my @key := ();
+ my @list := ();
+
+ for @tokens {
+ @key.push($_);
+ @list.append(get_list(%!callbacks, pir::join__SSP('::', @key)));
}
- return $list;
+ return @list;
}
=begin
@@ -210,14 +162,14 @@
to dispatch the events to all the appropriate handler(s) registered
with it.
+TODO: Update gc and vtable generator scripts before updating this.
+
=cut
=end
sub handler ($handler, $task) {
- my $evt_category := pir::getattribute__PPS($handler, '$!evt_category');
- my $evt_subtype := pir::getattribute__PPS($handler, '$!evt_subtype');
- my $evt_fulltype := pir::getattribute__PPS($handler, '$!evt_fulltype');
+ my %callbacks := pir::getattribute__PPS($handler, '%!callbacks');
# Get the required subkeys.
my $data := pir::getattribute__PPS($task, "data");
@@ -226,16 +178,16 @@
my $fulltype := pir::set_p_p_kc__PPS($data, 'event_fulltype');
# Get the lists and join them into 1 big list.
- my $key := [$category];
- my $list := Q:PIR { %r = new ['ResizablePMCArray'] };
- $list.append(get_list($evt_category, $category));
- $key.push($subtype);
- $list.append(get_list($evt_subtype, pir::join__SSP('::', $key)));
- $key.push($fulltype);
- $list.append(get_list($evt_fulltype, pir::join__SSP('::', $key)));
+ my @key := [$category];
+ my @list := ();
+ @list.append(get_list(%callbacks, $category));
+ @key.push($subtype);
+ @list.append(get_list(%callbacks, pir::join__SSP('::', @key)));
+ @key.push($fulltype);
+ @list.append(get_list(%callbacks, pir::join__SSP('::', @key)));
# Call the callbacks.
- for $list {
+ for @list {
$_($data);
}
};
@@ -252,19 +204,15 @@
=end
- sub get_list ($hash, $key) {
- my $list := Q:PIR {
- find_lex $P0, '$hash'
- find_lex $P1, '$key'
- %r = $P0[$P1]
- };
+ sub get_list (%hash, $key) {
+ my @list := %hash{$key};
- if !pir::defined__IP($list) {
- $list := Q:PIR { %r = new ['ResizablePMCArray'] };
- pir::set_p_k_p($hash, $key, $list);
+ if !pir::defined__IP(@list) {
+ @list := ();
+ %hash{$key} := @list;
}
- return $list;
+ return @list;
};
};
Modified: branches/gsoc_instrument/src/dynpmc/instrumentgc.pmc
==============================================================================
--- branches/gsoc_instrument/src/dynpmc/instrumentgc.pmc Wed Jul 7 16:31:38 2010 (r48032)
+++ branches/gsoc_instrument/src/dynpmc/instrumentgc.pmc Wed Jul 7 16:53:00 2010 (r48033)
@@ -69,6 +69,7 @@
} InstrumentGC_Subsystem;
/* Prototypes for stub functions. */
+/* BEGIN gc prototypes */
PMC* stub_allocate_pmc_header(PARROT_INTERP, UINTVAL flags);
void* stub_allocate_pmc_attributes(PARROT_INTERP, PMC *pmc);
void* stub_allocate_memory_chunk(PARROT_INTERP, size_t size);
@@ -100,6 +101,7 @@
void stub_mark_special(PARROT_INTERP, PMC *pmc);
void stub_pmc_needs_early_collection(PARROT_INTERP, PMC *pmc);
void stub_init_pool(PARROT_INTERP, struct Fixed_Size_Pool *pool);
+/* END gc prototypes */
/* Prototypes for helper functions. */
void raise_gc_event(PARROT_INTERP, Parrot_Interp supervised, STRING *event, PMC *data);
@@ -403,6 +405,7 @@
* 3. Raise an event denoting that the function has been accessed.
*/
+/* BEGIN gc stubs */
/*
* Allocations
*/
@@ -1133,6 +1136,8 @@
return;
}
+/* END gc stubs */
+
/*
* Helper functions
*/
@@ -1184,6 +1189,7 @@
void build_gc_func_hash(PARROT_INTERP,
Hash *instr_hash, Hash *orig_hash, Hash *entry_hash,
InstrumentGC_Subsystem *gc_instr, GC_Subsystem *gc_orig) {
+ /* BEGIN gc mappings */
/* Build the pointer hash to the stubs. */
parrot_hash_put(interp, instr_hash, CONST_STRING(interp, "finalize_gc_system"),
stub_finalize_gc_system);
@@ -1375,6 +1381,7 @@
&(gc_instr->block_sweep));
parrot_hash_put(interp, entry_hash, CONST_STRING(interp, "unblock_sweep"),
&(gc_instr->unblock_sweep));
+ /* END gc mappings */
}
/*
Modified: branches/gsoc_instrument/src/dynpmc/instrumentvtable.pmc
==============================================================================
--- branches/gsoc_instrument/src/dynpmc/instrumentvtable.pmc Wed Jul 7 16:31:38 2010 (r48032)
+++ branches/gsoc_instrument/src/dynpmc/instrumentvtable.pmc Wed Jul 7 16:53:00 2010 (r48033)
@@ -23,6 +23,7 @@
#include "pmc_instrument.h"
/* Stub Prototypes */
+/* BEGIN: vtable_prototypes */
static PMC* stub_vtable_absolute(PARROT_INTERP, PMC* pmc, PMC* dest);
static PMC* stub_vtable_add(PARROT_INTERP, PMC* pmc, PMC* value, PMC* dest);
static void stub_vtable_add_attribute(PARROT_INTERP, PMC* pmc, STRING* name, PMC* type);
@@ -210,6 +211,7 @@
static void stub_vtable_unshift_pmc(PARROT_INTERP, PMC* pmc, PMC* value);
static void stub_vtable_unshift_string(PARROT_INTERP, PMC* pmc, STRING* value);
static void stub_vtable_visit(PARROT_INTERP, PMC* pmc, PMC* info);
+/* END vtable_prototypes */
/* Helper Prototypes. */
void raise_vtable_event(PARROT_INTERP, Parrot_Interp supervised, PMC *pmc, PMC *data, STRING *type);
@@ -368,6 +370,7 @@
void build_vtable_hashes(PARROT_INTERP, Hash *orig, Hash *instr, Hash *stub,
_vtable *orig_vtable, _vtable *instr_vtable) {
+ /* BEGIN vtable mappings */
/* Build mappings for name -> original function.vtable entry */
parrot_hash_put(interp, orig, CONST_STRING(interp, "absolute"),
orig_vtable->absolute);
@@ -1491,12 +1494,14 @@
parrot_hash_put(interp, stub, CONST_STRING(interp, "visit"),
stub_vtable_visit);
}
+ /* END vtable mappings */
}
/*
* Stubs
*/
+/* BEGIN vtable stubs */
static
PMC* stub_vtable_absolute(PARROT_INTERP, PMC* pmc, PMC* dest) {
PMC *instr_vt, *data;
@@ -5500,6 +5505,7 @@
return;
}
+/* END vtable stubs */
/*
* Local variables:
More information about the parrot-commits
mailing list