Permalink
Browse files

Switch QAST over to associative_delegate.

  • Loading branch information...
jnthn committed Feb 9, 2013
1 parent 02e8737 commit 865484191d1ac0a0b7b5d78f734d820ba18e1bb2
Showing with 9 additions and 36 deletions.
  1. +8 −36 src/QAST/Node.nqp
  2. +1 −0 src/QAST/VM.nqp
View
@@ -2,8 +2,8 @@ class QAST::Node {
# For children.
has @!array is positional_delegate;
- # For annotations, lazily allocated.
- has %!hash;
+ # For annotations.
+ has %!hash is associative_delegate;
has $!node;
has $!returns;
@@ -12,6 +12,7 @@ class QAST::Node {
method new(*@children, *%options) {
my $new := self.CREATE();
nqp::bindattr($new, QAST::Node, '@!array', @children);
+ nqp::bindattr($new, QAST::Node, '%!hash', nqp::hash());
for %options {
nqp::findmethod($new, $_.key)($new, $_.value);
}
@@ -50,41 +51,12 @@ class QAST::Node {
self.set_compile_time_value($value);
}
+ method hash() { %!hash }
method list() { @!array }
- method pop() { nqp::pop(self.list) }
- method push($value) { nqp::push(self.list, $value) }
- method shift() { nqp::shift(self.list) }
- method unshift($value) { nqp::unshift(self.list, $value) }
-
- method hash() {
- nqp::isnull(%!hash) ?? %!hash !! nqp::hash()
- }
- method ($key) is parrot_vtable('get_pmc_keyed_str') {
- nqp::isnull(%!hash) ?? NQPMu !! %!hash{$key}
- }
- method ($key) is parrot_vtable('get_pmc_keyed') {
- nqp::isnull(%!hash) ?? NQPMu !! %!hash{$key}
- }
- method ($key, $value) is parrot_vtable('set_pmc_keyed_str') {
- %!hash := nqp::hash() if nqp::isnull(%!hash);
- %!hash{$key} := $value;
- }
- method ($key, $value) is parrot_vtable('set_pmc_keyed') {
- %!hash := nqp::hash() if nqp::isnull(%!hash);
- %!hash{$key} := $value;
- }
- method ($key) is parrot_vtable('exists_keyed_str') {
- nqp::isnull(%!hash) ?? 0 !! nqp::existskey(%!hash, $key)
- }
- method ($key) is parrot_vtable('exists_keyed') {
- nqp::isnull(%!hash) ?? 0 !! nqp::existskey(%!hash, $key)
- }
- method ($key) is parrot_vtable('delete_keyed_str') {
- nqp::deletekey(%!hash, $key) unless nqp::isnull(%!hash)
- }
- method ($key) is parrot_vtable('delete_keyed') {
- nqp::deletekey(%!hash, $key) unless nqp::isnull(%!hash)
- }
+ method pop() { nqp::pop(@!array) }
+ method push($value) { nqp::push(@!array, $value) }
+ method shift() { nqp::shift(@!array) }
+ method unshift($value) { nqp::unshift(@!array, $value) }
my %uniques;
method unique($prefix) {
View
@@ -4,6 +4,7 @@ class QAST::VM is QAST::Node {
method new(*@children, *%alternatives) {
my $obj := nqp::create(self);
nqp::bindattr($obj, QAST::Node, '@!array', @children);
+ nqp::bindattr($obj, QAST::Node, '%!hash', nqp::hash());
nqp::bindattr($obj, QAST::VM, '%!alternatives', %alternatives);
$obj
}

0 comments on commit 8654841

Please sign in to comment.