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

Fixes #156. Fix callstack management and display. #163

Merged
merged 2 commits into from
Feb 18, 2018

Conversation

faultyserver
Copy link
Member

This PR overhauls how the callstack is managed throughout the interpreter, hopefully fixing #156 and preventing unwanted leaks from raise, return, etc.

To accomplish this, this commit also adds a few other changes:

  • Add missing location information to flow control nodes while parsing.
  • Add a name property to TFunctor objects, used for display in backtraces.
  • Improve colorization of callstack output.
  • Add add_breakpoint for for executing arbitrary Crystal code during execution of a Myst program in Specs.

…e execution.

`add_breakpoint` adds a method with the given name to the given Interpreter to allow specs to make arbitrary assertions and track arbitrary state _while_ a program is running.

This is particularly helpful when testing things like callstacks or `self` stack values, where the values don't exist/aren't relevant after execution has finished. With this approach, the "breakpoint" method can be called at any point in the Myst code being tested, and the spec will have access to the program's state at that point in the execution.

Example:

require "../support/breakpoints.cr"

it "Testing" do
  itr = Interpreter.new
  add_breakpoint(itr, "breakpoint") do |this, args, block|
    __args[0].should be_a(TInteger)
  end

  parse_and_interpret! %q(
    [1, 2, 3].each do |e|
      breakpoint(e)
    end
  ), interpreter: itr
end
This commit overhauls how the callstack is managed throughout the interpreter, hopefully fixing myst-lang#156 and preventing unwanted leaks from `raise`, `return`, etc.

To accomplish this, this commit also adds a few other changes:
- Add missing location information to flow control nodes while parsing.
- Add a `name` property to `TFunctor` objects, used for display in backtraces.
- Improve colorization of callstack output.
@faultyserver faultyserver added this to the Next milestone Feb 18, 2018
@faultyserver faultyserver merged commit a773676 into myst-lang:master Feb 18, 2018
@faultyserver faultyserver deleted the fix/callstack branch February 18, 2018 22:47
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