Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dotnet] Add storage of exception handlers per block, sketch out a co…
…uple of ops for searching for exception handlers lexically and dynamically and a few other bits of stubbing in.
- Loading branch information
Showing
6 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Rakudo.Metamodel; | ||
|
||
namespace Rakudo.Runtime.Exceptions | ||
{ | ||
/// <summary> | ||
/// Various bits of logic relating to exception dispatch. | ||
/// </summary> | ||
public static class ExceptionDispatcher | ||
{ | ||
/// <summary> | ||
/// Invokes the specified exception handler with the given exception | ||
/// object. | ||
/// </summary> | ||
/// <param name="Handler"></param> | ||
/// <param name="ExceptionObject"></param> | ||
/// <returns></returns> | ||
public static RakudoObject CallHandler(ThreadContext TC, RakudoObject Handler, RakudoObject ExceptionObject) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
/// <summary> | ||
/// Dies from an unhandled exception. | ||
/// </summary> | ||
/// <param name="Exception"></param> | ||
public static void DieFromUnhandledException(ThreadContext TC, RakudoObject Exception) | ||
{ | ||
// Try to stringify the exception object. | ||
try | ||
{ | ||
var StrMeth = Exception.STable.FindMethod(TC, Exception, "Str", Hints.NO_HINT); | ||
var Stringified = StrMeth.STable.Invoke(TC, StrMeth, CaptureHelper.FormWith(new RakudoObject[] { Exception })); | ||
Console.WriteLine(Ops.unbox_str(TC, Stringified)); | ||
} | ||
catch | ||
{ | ||
Console.Error.WriteLine("Died from an exception, and died trying to stringify it too."); | ||
} | ||
|
||
// We'll also write a stack trace. It's a .Net one for now. | ||
Console.Error.Write(new Exception().StackTrace); | ||
|
||
// Exit with an error code. | ||
Environment.Exit(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Rakudo.Runtime.Exceptions | ||
{ | ||
/// <summary> | ||
/// Various types of exceptions that can occur. (The constant values | ||
/// match those used in Parrot for the control exceptions. Maybe that'll | ||
/// be OK, maybe we should encapsulate things a bit more. We'll see.) | ||
/// </summary> | ||
public static class ExceptionType | ||
{ | ||
public const int NORMAL = 0; | ||
public const int CONTROL_RETURN = 57; | ||
public const int CONTROL_OK = 58; | ||
public const int CONTROL_BREAK = 59; | ||
public const int CONTROL_CONTINUE = 60; | ||
public const int CONTROL_ERROR = 61; | ||
public const int CONTROL_TAKE = 62; | ||
public const int CONTROL_LEAVE = 63; | ||
public const int CONTROL_EXIT = 64; | ||
public const int CONTROL_LOOP_NEXT = 65; | ||
public const int CONTROL_LOOP_LAST = 66; | ||
public const int CONTROL_LOOP_REDO = 67; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using Rakudo.Metamodel; | ||
|
||
namespace Rakudo.Runtime.Exceptions | ||
{ | ||
/// <summary> | ||
/// Represents an exception handler. | ||
/// </summary> | ||
public struct Handler | ||
{ | ||
/// <summary> | ||
/// The type of exception that the handler accepts. | ||
/// </summary> | ||
public int Type; | ||
|
||
/// <summary> | ||
/// Something invokable that will handle the exception. | ||
/// </summary> | ||
public RakudoObject HandleBlock; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters