Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dotnet] Start to stub in the bits we'll need to implement .leave.
  • Loading branch information
jnthn committed Oct 21, 2010
1 parent c6bbf47 commit 670415d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
18 changes: 16 additions & 2 deletions dotnet/compiler/PAST2DNSTCompiler.pm
Expand Up @@ -140,9 +140,10 @@ method compile(PAST::Node $node) {
return DNST::CompilationUnit.new(
DNST::Using.new( :namespace('System') ),
DNST::Using.new( :namespace('System.Collections.Generic') ),
DNST::Using.new( :namespace('Rakudo.Runtime') ),
DNST::Using.new( :namespace('Rakudo.Metamodel') ),
DNST::Using.new( :namespace('Rakudo.Metamodel.Representations') ),
DNST::Using.new( :namespace('Rakudo.Runtime') ),
DNST::Using.new( :namespace('Rakudo.Runtime.Exceptions') ),
$class
);
}
Expand Down Expand Up @@ -357,7 +358,20 @@ our multi sub dnst_for(PAST::Block $block) {
));
$result.push(DNST::Bind.new( 'TC.CurrentContext', 'C' ));
$result.push(DNST::TryFinally.new(
$stmts,
DNST::TryCatch.new(
:exception_type('LeaveStackUnwinderException'),
:exception_var('exc'),
$stmts,
DNST::Stmts.new(
DNST::If.new(
DNST::Literal.new(
:value("(exc.TargetBlock == StaticBlockInfo[$our_sbi] ? 1 : 0)")
),
DNST::Throw.new()
),
"exc.PayLoad"
)
),
DNST::Bind.new( 'TC.CurrentContext', 'C.Caller' )
));

Expand Down
3 changes: 3 additions & 0 deletions dotnet/runtime/Rakudo.Net.csproj
Expand Up @@ -45,6 +45,8 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Init.cs" />
Expand All @@ -57,6 +59,7 @@
<Compile Include="Metamodel\Representations\RakudoCodeRef.cs" />
<Compile Include="Metamodel\REPRRegistry.cs" />
<Compile Include="Runtime\Context.cs" />
<Compile Include="Runtime\Exceptions\LeaveStackUnwinderException.cs" />
<Compile Include="Runtime\ExecutionDomain.cs" />
<Compile Include="Metamodel\KnowHOW\KnowHOWBootstrapper.cs" />
<Compile Include="Metamodel\KnowHOW\KnowHOWREPR.cs" />
Expand Down
36 changes: 36 additions & 0 deletions dotnet/runtime/Runtime/Exceptions/LeaveStackUnwinderException.cs
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rakudo.Metamodel;
using Rakudo.Metamodel.Representations;

namespace Rakudo.Runtime.Exceptions
{
/// <summary>
/// This exception is thrown to actually unwind the (dotnet) stack after
/// we run an exception handler.
/// </summary>
public class LeaveStackUnwinderException : Exception
{
/// <summary>
/// The block we're looking for.
/// </summary>
public RakudoCodeRef.Instance TargetBlock;

/// <summary>
/// The value to exit with.
/// </summary>
public RakudoObject PayLoad;

/// <summary>
/// Creates a LeaveStackUnwinderException to
/// </summary>
/// <param name="TargetBlock"></param>
public LeaveStackUnwinderException(RakudoCodeRef.Instance TargetBlock, RakudoObject PayLoad)
{
this.TargetBlock = TargetBlock;
this.PayLoad = PayLoad;
}
}
}

0 comments on commit 670415d

Please sign in to comment.