Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some BUILDPLAN handling updates.

  • Loading branch information...
commit af76e6d66d2c1bec2f9c48992eba5861d434c297 1 parent b36616b
@jnthn jnthn authored
Showing with 55 additions and 7 deletions.
  1. +3 −1 src/Perl6/Metamodel/BUILDPLAN.pm
  2. +52 −6 src/core/Mu.pm
View
4 src/Perl6/Metamodel/BUILDPLAN.pm
@@ -9,7 +9,9 @@ role Perl6::Metamodel::BUILDPLAN {
# nested array is an "op" representing the task to perform:
# 0 code = call specified BUILD method
# 1 class name attr_name = try to find initialization value
- # 2 class attr_name code = call default value closure if needed
+ # 2 class name attr_name = try to find initialization value, or set nqp::list()
+ # 3 class name attr_name = try to find initialization value, or set nqp::hash()
+ # 4 class attr_name code = call default value closure if needed
method create_BUILDPLAN($obj) {
# First, we'll create the build plan for just this class.
my @plan;
View
58 src/core/Mu.pm
@@ -75,12 +75,13 @@ my class Mu {
my int $i = 0;
while nqp::islt_i($i, $count) {
my $task := nqp::atpos($build_plan, $i);
+ my int $code = nqp::atpos_i($task, 0);
$i = nqp::add_i($i, 1);
- if nqp::iseq_i(nqp::atpos_i($task, 0), 0) {
+ if nqp::iseq_i($code, 0) {
# Custom BUILD call.
nqp::atpos($task, 1)(self, |%attrinit);
}
- elsif nqp::iseq_i(nqp::atpos_i($task, 0), 1) {
+ elsif nqp::iseq_i($code, 1) {
# See if we have a value to initialize this attr
# with.
my $key_name := nqp::p6box_s(nqp::atpos_s($task, 2));
@@ -92,7 +93,29 @@ my class Mu {
nqp::atpos($task, 3)) = nqp::p6decont(%attrinit{$key_name});
}
}
- elsif nqp::iseq_i(nqp::atpos_i($task, 0), 4) {
+ elsif nqp::iseq_i($code, 2) {
+ my $key_name := nqp::p6box_s(nqp::atpos_s($task, 2));
+ if %attrinit.exists($key_name) {
+ nqp::getattr(self, nqp::atpos($task, 1),
+ nqp::atpos_s($task, 3)) = nqp::p6decont(%attrinit{$key_name});
+ }
+ else {
+ nqp::bindattr(self, nqp::atpos($task, 1),
+ nqp::atpos_s($task, 3), nqp::list())
+ }
+ }
+ elsif nqp::iseq_i($code, 3) {
+ my $key_name := nqp::p6box_s(nqp::atpos_s($task, 2));
+ if %attrinit.exists($key_name) {
+ nqp::getattr(self, nqp::atpos($task, 1),
+ nqp::atpos_s($task, 3)) = nqp::p6decont(%attrinit{$key_name});
+ }
+ else {
+ nqp::bindattr(self, nqp::atpos($task, 1),
+ nqp::atpos_s($task, 3), nqp::hash())
+ }
+ }
+ elsif nqp::iseq_i($code, 4) {
unless nqp::attrinited(self, nqp::atpos($task, 1), nqp::atpos_s($task, 2)) {
my $attr := nqp::getattr(self, nqp::atpos($task, 1), nqp::atpos_s($task, 2));
$attr = nqp::atpos($task, 3)(self, $attr);
@@ -112,12 +135,13 @@ my class Mu {
my int $i = 0;
while nqp::islt_i($i, $count) {
my $task := nqp::atpos($build_plan, $i);
+ my int $code = nqp::atpos_i($task, 0);
$i = nqp::add_i($i, 1);
- if nqp::iseq_i(nqp::atpos_i($task, 0), 0) {
+ if nqp::iseq_i($code, 0) {
# Custom BUILD call.
nqp::atpos($task, 1)(self, |%attrinit);
}
- elsif nqp::iseq_i(nqp::atpos_i($task, 0), 1) {
+ elsif nqp::iseq_i($code, 1) {
# See if we have a value to initialize this attr
# with.
my $key_name := nqp::p6box_s(nqp::atpos_s($task, 2));
@@ -126,7 +150,29 @@ my class Mu {
nqp::atpos_s($task, 3)) = nqp::p6decont(%attrinit{$key_name});
}
}
- elsif nqp::iseq_i(nqp::atpos_i($task, 0), 4) {
+ elsif nqp::iseq_i($code, 2) {
+ my $key_name := nqp::p6box_s(nqp::atpos_s($task, 2));
+ if %attrinit.exists($key_name) {
+ nqp::getattr(self, nqp::atpos($task, 1),
+ nqp::atpos_s($task, 3)) = nqp::p6decont(%attrinit{$key_name});
+ }
+ else {
+ nqp::bindattr(self, nqp::atpos($task, 1),
+ nqp::atpos_s($task, 3), nqp::list())
+ }
+ }
+ elsif nqp::iseq_i($code, 3) {
+ my $key_name := nqp::p6box_s(nqp::atpos_s($task, 2));
+ if %attrinit.exists($key_name) {
+ nqp::getattr(self, nqp::atpos($task, 1),
+ nqp::atpos_s($task, 3)) = nqp::p6decont(%attrinit{$key_name});
+ }
+ else {
+ nqp::bindattr(self, nqp::atpos($task, 1),
+ nqp::atpos_s($task, 3), nqp::hash())
+ }
+ }
+ elsif nqp::iseq_i($code, 4) {
unless nqp::attrinited(self, nqp::atpos($task, 1), nqp::atpos_s($task, 2)) {
my $attr := nqp::getattr(self, nqp::atpos($task, 1), nqp::atpos_s($task, 2));
$attr = nqp::atpos($task, 3)(self, $attr);
Please sign in to comment.
Something went wrong with that request. Please try again.