Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement compiling handlers besides CATCH and CONTROL.
  • Loading branch information
jnthn committed Jul 14, 2012
1 parent 30ab35b commit cee5640
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/QAST/Operations.nqp
Expand Up @@ -802,10 +802,31 @@ QAST::Operations.add_core_op('handle', -> $qastcomp, $op {
simple_handler($control_label, %handlers<CONTROL>);
}
if @other {
my $type_reg := $*REGALLOC.fresh_i();
$ops.push($other_label);
$ops.push_pirop(".get_results ($reg)");
# XXX Need to emit type-selection ladder...
nqp::die("Only CATCH and CONTROL handlers implemented so far");

# Create labels for each type and emit type selection ladder.
my %type_labels;
$ops.push_pirop('set', $type_reg, $reg ~ '["type"]');
for @other {
my $lbl := $qastcomp.post_new('Label',
:name($qastcomp.unique('handle_type_')));
$ops.push_pirop('eq', $type_reg, %handler_names{$_}, $lbl);
%type_labels{$_} := $lbl;
}

# Emit handler for each type.
for @other {
my $handler_post := $qastcomp.coerce($qastcomp.as_post(%handlers{$_}), 'P');
$ops.push(%type_labels{$_});
$ops.push($handler_post);
$ops.push_pirop('finalize', $reg);
$ops.push_pirop('pop_upto_eh', $reg);
$ops.push_pirop('pop_eh');
$ops.push_pirop('set', $procpost.result, $handler_post.result);
$ops.push_pirop('goto', $skip_handler_label);
}
}

# Postlude.
Expand Down

0 comments on commit cee5640

Please sign in to comment.