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

Interpreter: allow inspecting block vars without affecting program #12520

Merged
merged 5 commits into from Sep 27, 2022

Conversation

asterite
Copy link
Member

Fixes #12518

This would would also be good for 1.6

@asterite
Copy link
Member Author

I also fixed another bug that I noticed that happened when you introduced new vars while debugging inside a block.

So now the only thing remaining is being able to define new vars inside a block and later change their type (similar to what you can do at the top level,) but I'll leave that for another PR.

@asterite
Copy link
Member Author

Here's an example session showing how it works now:

✗ bin/crystal i foo.cr
Using compiled compiler at .build/crystal
From: foo.cr:6:44 InsertionSort.class#sort:

     1: class InsertionSort
     2:   def self.sort(arr)
     3:     (1..arr.size - 1).each do |i|
     4:       (0..i - 1).each do |j|
     5:         debugger
 =>  6:         arr[j], arr[i] = arr[i], arr[j] if arr[i] < arr[j]
     7:       end
     8:     end
     9:   end
    10: end
    11:

pry(InsertionSort.sort)> i
=> 1
pry(InsertionSort.sort)> j
=> 0
pry(InsertionSort.sort)> arr
=> [4, 8, 7, 2, 6, 5, 3, 0, 9, 1]
pry(InsertionSort.sort)> b = [1, 2, 3]
=> [1, 2, 3]
pry(InsertionSort.sort)> b
=> [1, 2, 3]
pry(InsertionSort.sort)> b.reverse
=> [3, 2, 1]
pry(InsertionSort.sort)> continue
From: foo.cr:6:44 InsertionSort.class#sort:

     1: class InsertionSort
     2:   def self.sort(arr)
     3:     (1..arr.size - 1).each do |i|
     4:       (0..i - 1).each do |j|
     5:         debugger
 =>  6:         arr[j], arr[i] = arr[i], arr[j] if arr[i] < arr[j]
     7:       end
     8:     end
     9:   end
    10: end
    11:

pry(InsertionSort.sort)> i
=> 2
pry(InsertionSort.sort)> j
=> 0
pry(InsertionSort.sort)> continue
From: foo.cr:6:44 InsertionSort.class#sort:

     1: class InsertionSort
     2:   def self.sort(arr)
     3:     (1..arr.size - 1).each do |i|
     4:       (0..i - 1).each do |j|
     5:         debugger
 =>  6:         arr[j], arr[i] = arr[i], arr[j] if arr[i] < arr[j]
     7:       end
     8:     end
     9:   end
    10: end
    11:

pry(InsertionSort.sort)> ^C

@zw963
Copy link
Contributor

zw963 commented Sep 24, 2022

Add to milestone 1.6 ?

@straight-shoota straight-shoota modified the milestones: 1.7.0, 1.6.0 Sep 26, 2022
@asterite asterite merged commit 543acb0 into master Sep 27, 2022
@asterite asterite deleted the interpreter/pry-block-var branch September 27, 2022 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Interpreter mode] Integer overflow when do each loop.
3 participants