Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typed exceptions #150

Merged
merged 10 commits into from
Sep 27, 2024
Merged

Add typed exceptions #150

merged 10 commits into from
Sep 27, 2024

Conversation

jonnyboyC
Copy link
Collaborator

@jonnyboyC jonnyboyC commented Sep 27, 2024

Problem

So far we've only had a small subset of the functionality for exceptions. Currently we supports the syntax but not the behavior of typed and multiple arm exception handlers.

Solution

Built out the remaining functionality in order to implement exceptions. This includes

  • New methods on the base Fiber class to handle the generation of an appropriate backTrace
  • New instructions to implement the exceptions systems
  • Update the compiler to emit instructions for each catch arms.

Below is an example.

try {
  try {
    raise Error("test");
  // check if raised error matches Runtime Error
  } catch e: RuntimeError {
    assert(false);
  // check if raised error matches Syntax Error
  } catch e: SyntaxError {
    assert(false);
  }
// check if raised error matches Error
} catch e: Error {
  assert(true)
}

Overall some of the goals with the design are to basically make both exception paths and non exception paths as fast as possible.

None Exception

  • We take a small performance hit for having the fiber be larger
  • We now typically have larger jumps as we have more instructions in place when handlers as present

Overall these both are still relatively cheap

  • When we raise and don't catch we should exit basically immediately and print the trace
  • For caught exceptions we do have to allocate a list of IPs which we use later to generate the backtrace

Overall we should be able to optimize this slightly as we have to do some double allocation at the moment.

@jonnyboyC jonnyboyC self-assigned this Sep 27, 2024
@jonnyboyC jonnyboyC marked this pull request as ready for review September 27, 2024 00:56
@jonnyboyC jonnyboyC merged commit 3426c55 into main Sep 27, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant