Permalink
Browse files

use static scoping to get at NCI funcs

  • Loading branch information...
1 parent e94468d commit 46a0d960f10b887d817027a59261257a3a4d174e @plobsing committed Aug 7, 2010
Showing with 65 additions and 53 deletions.
  1. +65 −53 src/deepclone.winxed
View
@@ -1,13 +1,20 @@
#! winxed
+$include_const 'hash_key_type.pasm';
+
const int VISIT_FREEZE_NORMAL = 0x04; // 0x00 | 0x04;
const int VISIT_THAW_NORMAL = 0x05; // 0x01 | 0x04;
-const int Hash_key_type_pointer = 4;
+// static var nci = {};
+function nci[anon, immediate] () {
+ return {};
+}
function onload[anon, load] () {
+ using static nci;
+
var core_nci_funcs = {
- "Parrot_pmc_new_noinit" : "PJI",
+ "Parrot_pmc_new_noinit" : "PJi",
"Parrot_PMC_visit" : "vJPP",
"Parrot_PMC_freeze" : "vJPP",
"Parrot_PMC_thaw" : "vJPP",
@@ -16,8 +23,8 @@ function onload[anon, load] () {
var lib = null;
for (string name in core_nci_funcs) {
string sig = core_nci_funcs[name];
- var nci = dlfunc(lib, name, sig);
- ${ set_hll_global name, nci };
+ var func = dlfunc(lib, name, sig);
+ nci[name] = func;
}
/*
@@ -26,17 +33,18 @@ function onload[anon, load] () {
*
* XXX Don't do this at home!
*/
- var my_lib = loadlib("deepclonehelper");
+ var my_lib = loadlib("libdeepclonehelper");
var my_nci_funcs = {
- "pmc_addr" : "IJP",
+ "pmc_addr" : "iJP",
"pmc_get_meta" : "PJP",
"pmc_set_meta" : "vJPP",
- "pmc_typenum" : "IJP"
+ "pmc_typenum" : "iJP"
};
+
for (string name in my_nci_funcs) {
string sig = my_nci_funcs[name];
- var nci = dlfunc(my_lib, name, sig);
- ${ set_hll_global name, nci };
+ var func = dlfunc(my_lib, name, sig);
+ nci[name] = func;
}
}
@@ -50,52 +58,48 @@ class DeepClone {
var str_queue;
var pmc_queue;
- function init_pmc[vtable] (var orig) {
+ function set_pmc[vtable] (var orig) {
self.todo = new 'ResizablePMCArray'();
- // XXX winxed constant expansion bug
- // self.seen = new 'Hash'(Hash_key_type_pointer);
- self.seen = new 'Hash'(4);
+ self.seen = new 'Hash'();
+ // XXX can't create (ptr => pmc) hashes in HLLs
+ // self.seen.set_key_type(Hash_key_type_ptr);
+ self.seen.set_key_type(Hash_key_type_int);
self.state = new 'Integer'();
self.int_queue = new 'ResizableIntegerArray'();
self.num_queue = new 'ResizableFloatArray'();
self.str_queue = new 'ResizableStringArray'();
self.pmc_queue = new 'ResizablePMCArray'();
- ${ push self.todo, orig };
+ var todo = self.todo;
+ ${ push todo, orig };
}
function get_pmc[vtable] () {
- using Parrot_PMC_visit;
- using Parrot_PMC_freeze;
- using Parrot_PMC_thaw;
- using Parrot_PMC_thawfinish;
- using pmc_get_meta;
- using pmc_set_meta;
- using pmc_addr;
+ using static nci;
for (int i = 0; i < self.todo; i++) {
var orig = self.todo[i];
- var meta = pmc_get_meta(orig);
+ var meta = nci['pmc_get_meta'](orig);
self.state = VISIT_FREEZE_NORMAL;
- Parrot_PMC_visit(orig, self);
- Parrot_PMC_freeze(orig, self);
+ nci['Parrot_PMC_visit'](orig, self);
+ nci['Parrot_PMC_freeze'](orig, self);
self.push_pmc(meta);
- int addr = pmc_addr(orig);
+ int addr = nci['pmc_addr'](orig);
var dup = self.seen[addr];
self.state = VISIT_THAW_NORMAL;
- Parrot_PMC_visit(dup, self);
- Parrot_PMC_thaw(dup, self);
- pmc_set_meta(dup, self.shift_pmc());
+ nci['Parrot_PMC_visit'](dup, self);
+ nci['Parrot_PMC_thaw'](dup, self);
+ nci['pmc_set_meta'](dup, self.shift_pmc());
}
for (int i = 0; i < self.todo; i++) {
- var dup = self.seen[pmc_addr(self.todo[i])];
- Parrot_PMC_thawfinish(dup, self);
+ var dup = self.seen[nci['pmc_addr'](self.todo[i])];
+ nci['Parrot_PMC_thawfinish'](dup, self);
}
- return self.todo[0];
+ return self.seen[nci['pmc_addr'](self.todo[0])];
}
function get_integer[vtable] () {
@@ -104,63 +108,71 @@ class DeepClone {
}
function push_pmc[vtable] (var v) {
- using pmc_addr;
- int addr = pmc_addr(v);
+ using static nci;
+ int addr = nci['pmc_addr'](v);
var dup;
- int i;
- ${ isnull i, v };
- if (i) {
+ int nullp;
+ ${ isnull nullp, v };
+ if (nullp) {
dup = null;
}
- else if (exists(self.seen[addr])) {
- dup = self.seen[addr];
- }
else {
- using pmc_typenum;
- using Parrot_pmc_new_noinit;
- int i = pmc_typenum(v);
- dup = Parrot_pmc_new_noinit(i);
- self.seen[addr] = dup;
- ${ push self.todo, v };
+ dup = self.seen[addr];
+ ${ isnull nullp, dup };
+ if (nullp) {
+ int i = nci['pmc_typenum'](v);
+ dup = nci['Parrot_pmc_new_noinit'](i);
+ self.seen[addr] = dup;
+ var todo = self.todo;
+ ${ push todo, v };
+ }
}
- ${ push self.pmc_queue, dup };
+ var pmc_queue = self.pmc_queue;
+ ${ push pmc_queue, dup };
}
function shift_pmc[vtable] () {
var v;
- ${ shift v, self.pmc_queue };
+ var pmc_queue = self.pmc_queue;
+ ${ shift v, pmc_queue };
return v;
}
function push_integer[vtable] (int v) {
- ${ push self.int_queue, v };
+ var int_queue = self.int_queue;
+ ${ push int_queue, v };
}
function shift_integer[vtable] () {
int v;
- ${ shift v, self.int_queue };
+ var int_queue = self.int_queue;
+ ${ shift v, int_queue };
return v;
}
function push_float[vtable] (float v) {
- ${ push self.num_queue, v };
+ var num_queue = self.num_queue;
+ ${ push num_queue, v };
}
function shift_float[vtable] () {
float v;
- ${ shift v, self.num_queue };
+ var num_queue = self.num_queue;
+ ${ shift v, num_queue };
return v;
}
function push_string[vtable] (string v) {
- ${ push self.str_queue, v };
+ var str_queue = self.str_queue;
+ ${ push str_queue, v };
}
function shift_string[vtable] () {
string v;
- ${ shift v, self.str_queue };
+ var str_queue = self.str_queue;
+ ${ shift v, str_queue };
return v;
}
}

0 comments on commit 46a0d96

Please sign in to comment.