Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
return typecheck now passes both Nil and Failure
Failure now considers itself to be derived from Nil, and the return
typecheck bypass now is based on Nil.  The upshot is that Nil is now
regarded as the simplest form of failure, and people will be less
tempted to use type objects to indicate failure.
  • Loading branch information
TimToady committed Nov 10, 2015
1 parent 2ad739e commit 8517d87
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/core/Failure.pm
@@ -1,4 +1,4 @@
my class Failure {
my class Failure is Nil {
has $.exception;
has $.backtrace;
#?if moar
Expand Down Expand Up @@ -67,6 +67,9 @@ my class Failure {
method Numeric(Failure:D:) { $!handled ?? NaN !! self!throw(); }
multi method Str(Failure:D:) { $!handled ?? $.mess !! self!throw(); }
multi method gist(Failure:D:) { $!handled ?? $.mess !! self!throw(); }
multi method gist(Failure:U:) { '(' ~ self.^name ~ ')' }
multi method perl(Failure:D:) { self.Mu::perl() }
multi method perl(Failure:U:) { self.^name }
method mess (Failure:D:) {
"(HANDLED) " x $!handled ~ self.exception.message ~ "\n" ~ self.backtrace;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/List.pm
Expand Up @@ -568,7 +568,7 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP

self
}
multi method STORE(List:D: \item) {
multi method STORE(List:D: Mu \item) {
self.STORE((item,));
}

Expand Down
22 changes: 11 additions & 11 deletions src/core/Nil.pm
@@ -1,23 +1,23 @@
my class Nil is Cool { # declared in BOOTSTRAP
method new(*@) { Nil }
multi method gist(Nil:) { 'Nil' }
method Numeric() { warn "Use of Nil in numeric context"; 0 }
method Str() { warn "Use of Nil in string context"; '' }
method Numeric() { warn "Use of {self.gist} in numeric context"; 0 }
method Str() { warn "Use of {self.gist} in string context"; '' }
method sink(*@) { Nil } # required by RESTRICTED setting

method AT-POS(*@) { Nil }
method AT-KEY(*@) { Nil }
# method ACCEPTS(*@) { Nil } # XXX spec says Nil, but makes spectest hang

method BIND-POS(*@) { die "Attempted to BIND-POS to Nil." }
method BIND-KEY(*@) { fail X::Bind.new(target => 'Nil') }
method ASSIGN-POS(*@) { die "Attempted to ASSIGN-POS to Nil." }
method ASSIGN-KEY(*@) { die "Attempted to ASSIGN-KEY to Nil." }
method STORE(*@) { die "Attempted to STORE to Nil." }
method push(*@) is nodal { die "Attempted to push to Nil." }
method append(*@) is nodal { die "Attempted to append to Nil." }
method unshift(*@) is nodal { die "Attempted to unshift to Nil." }
method prepend(*@) is nodal { die "Attempted to prepend to Nil." }
method BIND-POS(*@) { die "Attempted to BIND-POS to {self.gist}." }
method BIND-KEY(*@) { fail X::Bind.new(target => '{self.gist}') }
method ASSIGN-POS(*@) { die "Attempted to ASSIGN-POS to {self.gist}." }
method ASSIGN-KEY(*@) { die "Attempted to ASSIGN-KEY to {self.gist}." }
method STORE(*@) { die "Attempted to STORE to {self.gist}." }
method push(*@) is nodal { die "Attempted to push to {self.gist}." }
method append(*@) is nodal { die "Attempted to append to {self.gist}." }
method unshift(*@) is nodal { die "Attempted to unshift to {self.gist}." }
method prepend(*@) is nodal { die "Attempted to prepend to {self.gist}." }
method FALLBACK(*@) { Nil }
}

Expand Down
2 changes: 1 addition & 1 deletion src/vm/moar/Perl6/Ops.nqp
Expand Up @@ -594,7 +594,7 @@ $ops.add_hll_op('perl6', 'p6typecheckrv', -> $qastcomp, $op {
nqp::push(@ops, MAST::Op.new( :op('decont'), $decont, $value_res.result_reg ));
nqp::push(@ops, MAST::Op.new( :op('istype'), $istype, $decont, $type_res.result_reg ));
nqp::push(@ops, MAST::Op.new( :op('if_i'), $istype, $lbl_done ));
nqp::push(@ops, MAST::Op.new( :op('const_s'), $str_failure, MAST::SVal.new( :value('Failure') ) ));
nqp::push(@ops, MAST::Op.new( :op('const_s'), $str_failure, MAST::SVal.new( :value('Nil') ) ));
nqp::push(@ops, MAST::Op.new( :op('getlexstatic_o'), $failure_o, $str_failure));
nqp::push(@ops, MAST::Op.new( :op('istype'), $isfailure, $decont, $failure_o) );
nqp::push(@ops, MAST::Op.new( :op('if_i'), $isfailure, $lbl_done ));
Expand Down

0 comments on commit 8517d87

Please sign in to comment.