Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dotnet] Compile DNST::Throw and DNST::TryCatch.
  • Loading branch information
jnthn committed Oct 21, 2010
1 parent e47a5fb commit c6bbf47
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dotnet/compiler/DNST2CSharp.pm
Expand Up @@ -95,6 +95,22 @@ our multi sub cs_for(DNST::TryFinally $tf) {
return $code;
}

our multi sub cs_for(DNST::TryCatch $tc) {
unless +@($tc) == 2 { pir::die('DNST::TryCatch nodes must have 2 children') }
my $try_result := get_unique_id('try_result');
my $code := " RakudoObject $try_result;\n" ~
" try \{\n" ~
cs_for((@($tc))[0]);
$code := $code ~
" $try_result = $*LAST_TEMP;\n" ~
" } catch(" ~ $tc.exception_type ~ " " ~ $tc.exception_var ~ ")\{\n" ~
cs_for((@($tc))[1]) ~
" $try_result = $*LAST_TEMP;\n" ~
" }\n";
$*LAST_TEMP := $try_result;
return $code;
}

our multi sub cs_for(DNST::MethodCall $mc) {
# Code generate all the arguments.
my @arg_names;
Expand Down Expand Up @@ -220,6 +236,11 @@ our multi sub cs_for(DNST::Literal $lit) {
return '';
}

our multi sub cs_for(DNST::Throw $throw) {
$*LAST_TEMP := 'null';
return ' throw;';
}

our multi sub cs_for(String $s) {
$*LAST_TEMP := $s;
return '';
Expand Down

0 comments on commit c6bbf47

Please sign in to comment.