-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: clear finished hooks after intepreting #12174
Conversation
Well, in the end I added the ability to execute finished hooks in interpreted mode. So you can try this: # foo.cr
macro finished
puts "Bye!"
end
puts "Hello!" If you execute that with
Now it's:
You can also try this: # foo.cr
macro finished
puts "Bye!"
end
puts "Hello!"
debugger
puts "Hello again!" Then with
Which makes sense, because That said, I don't think executing code is common in finished hooks. It's usually used to define code. But I think it still makes sense to execute it, just like in non-interpreted mode. |
Oh, and you can also try this:
That is, you can actually define finished hooks in interactive mode, and they get executed. |
@cyangle If you want/can, you can check if the interpreter works fine in your particular case with this PR |
@asterite Thanks a lot! Now I can use the interpreter to debug my Lucky toy app: $ cr i src/toy.cr
Using compiled compiler at /home/chao/git/personal/crystal/.build/crystal
Listening on http://0.0.0.0:8080
2022-06-30 22:50:29 +00:00
From: expanded macro: setup_call_method:15:3 Api::V1::Users::Show#call:
10: begin
11: logger.info do
12: "user_id: #{id}"
13: end
14: debugger
=> 15: json(UserTwin.new(current_user!))
16: end
17: end
18:
19: __temp_139 = run_after_pipes
20:
pry> id
"774107312037625857"
pry> current_user
GET /api/v1/users/774107312037625857 (7fbb6ac9-6096-4da8-b1a1-33ff01e43c7c)
▸ user_id: 774107312037625857
#<User:0x7f4b24983840 id: 774107312037625857, name: "Erick Schmidt", email: "[email protected]", lock_version: 0, age: 18, created_at: 2022-06-27 05:53:23.634084000 UTC, updated_at: 2022-06-27 05:53:23.634085000 UTC, deleted_at: nil>
pry> current_user!
#<User:0x7f4b24983840 id: 774107312037625857, name: "Erick Schmidt", email: "[email protected]", lock_version: 0, age: 18, created_at: 2022-06-27 05:53:23.634084000 UTC, updated_at: 2022-06-27 05:53:23.634085000 UTC, deleted_at: nil>
pry> current_user!.id
774107312037625857
pry> current_user!.name
"Erick Schmidt"
pry> UserTwin.new(current_user!)
#<UserTwin:0x7f4b309a1460 @age=18, @id=774107312037625857, @name="Erick Schmidt", @email="[email protected]", @lock_version=0, @created_at=2022-06-27 05:53:23.634084000 UTC, @updated_at=2022-06-27 05:53:23.634085000 UTC, @deleted_at=nil> I also tried it with the Lucky website, it worked. @jwoertink This is awesome! |
Awesome! @asterite would it be hard to add specs? Do you want me to do that? Also, for when this is merged, is this a reasonable change in the description? Thx! Fixes #12172 Some explanation:
|
Hi @beta-ziliani! There are no specs for pry yet and doing that is a huge task, and for now I won't have time to do that. |
Another thing is the interpreter is mostly experimental. If it doesn't work well, it's not a big deal because compiled programs are the ones shipped. But I promise I'll introduce tests for pry later on, otherwise it will be hard to make it evolve in a safe way. But I'd like to leave it for later. |
Fixes #12172
Some explanation:
macro finished
was able to declare vars, etc.puts "Hi"
inside a finished hook, you won't see it in interpreted mode (I'm leaving that for a later PR)