Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make $x<does><not><exist> not explode.
  • Loading branch information
jnthn committed Apr 14, 2013
1 parent b7c3945 commit 9ceb63a
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions lib/QAST/JASTCompiler.nqp
Expand Up @@ -3008,11 +3008,15 @@ class QAST::CompilerJAST {
}

multi method as_jast(QAST::VarWithFallback $node, :$want) {
my $var_res := self.compile_var($node);
if $*BINDVAL || $var_res.type != $RT_OBJ {
$var_res
if $*BINDVAL {
self.compile_var($node)
}
else {
elsif $node.scope ne 'positional' && $node.scope ne 'associative' {
my $var_res := self.compile_var($node);
if ($var_res.type != $RT_OBJ) {
return $var_res;
}

my $il := JAST::InstructionList.new();
$il.append($var_res.jast);
$*STACK.obtain($il, $var_res);
Expand All @@ -3029,6 +3033,30 @@ class QAST::CompilerJAST {

result($il, $RT_OBJ);
}
else {
my $fb_temp := $node.unique('fb_tmp');
self.as_jast(QAST::Op.new(
:op('ifnull'),
QAST::Op.new(
:op('if'),
QAST::Op.new(
:op('isconcrete'),
QAST::Op.new(
:op('bind'),
QAST::Var.new( :name($fb_temp), :scope('local'), :decl('var') ),
$node[0]
)
),
QAST::Var.new(
:scope($node.scope),
QAST::Var.new( :name($fb_temp), :scope('local') ),
$node[1]
),
QAST::Op.new( :op('null') )
),
$node.fallback
))
}
}

method compile_var($node) {
Expand Down

0 comments on commit 9ceb63a

Please sign in to comment.