Skip to content

Instantly share code, notes, and snippets.

@masak

masak/1-test.p6 Secret

Last active October 2, 2015 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/56e03f67ab6f030791e7 to your computer and use it in GitHub Desktop.
Save masak/56e03f67ab6f030791e7 to your computer and use it in GitHub Desktop.
Debug statements near a bug I'm investigating
{
my $ast = q:to/./;
(statements
(sub (ident "f") (parameters) (statements
(my (ident "b") (assign (ident "b") (block (parameters) (statements
(return (int 5))))))
(sub (ident "g") (parameters) (statements
(stexpr (call (ident "b") (arguments)))))
(stexpr (call (ident "g") (arguments)))
(stexpr (call (ident "say") (arguments (str "Dead code. Should have returned from f."))))))
(stexpr (call (ident "f") (arguments))))
.
is-result $ast, "", "return statements bind lexically to their surrounding subroutine";
}
RUNTIME RUN
INVOKING Q::Identifier.new(name => "f")
GET-VAR f
FIND LOOKING IN Frame|197586992 (elems, charat, int, lc, trim, sorted, prefix:<->, min, join, index, grep, map, f, abs, chr, ord, uc, reversed, substr, type, max, chars, Q::Literal::Str, Q::Arguments, str, split, Q::Identifier, say, Q::Postfix::Call, infix:<+>)
THE THING WE GOT WAS A Val::Sub
DECLARE-VAR g
PUT-VAR g
FIND LOOKING IN Frame|197587088 (g)
THE THING WE PUT WAS A Val::Sub
DECLARE-VAR b
PUT-VAR b
FIND LOOKING IN Frame|197587088 (g, b)
THE THING WE PUT WAS A Val::None
DECLARE-VAR --RETURN-TO--
PUT-VAR --RETURN-TO--
FIND LOOKING IN Frame|197587088 (g, b, --RETURN-TO--)
THE THING WE PUT WAS A Frame
ASSIGNING b
(value): Val::Block
PUT-VAR b
FIND LOOKING IN Frame|197587088 (g, b, --RETURN-TO--)
THE THING WE PUT WAS A Val::Block
GET-VAR b
FIND LOOKING IN Frame|197587088 (g, b, --RETURN-TO--)
THE THING WE GOT WAS A Val::Block <--- look, so we even see that we stored it correctly
HM: Val::Block
INVOKING Q::Identifier.new(name => "g")
GET-VAR g
FIND LOOKING IN Frame|197587088 (g, b, --RETURN-TO--)
THE THING WE GOT WAS A Val::Sub
DECLARE-VAR --RETURN-TO--
PUT-VAR --RETURN-TO--
FIND LOOKING IN Frame|197587136 (--RETURN-TO--)
THE THING WE PUT WAS A Frame
INVOKING Q::Identifier.new(name => "b")
GET-VAR b
FIND LOOKING IN Frame|197587136 (--RETURN-TO--)
FIND LOOKING IN Frame|197586944 (g, b)
THE THING WE GOT WAS A Val::None <--- and now when we look again from inside sub g, the block is gone
Trying to invoke a None
in method eval at /home/masak/ours/007/lib/_007/Q.pm:228
in method run at /home/masak/ours/007/lib/_007/Q.pm:275
in method run at /home/masak/ours/007/lib/_007/Q.pm:451
in method call at /home/masak/ours/007/lib/_007/Runtime.pm:184
in method eval at /home/masak/ours/007/lib/_007/Q.pm:231
in method run at /home/masak/ours/007/lib/_007/Q.pm:275
in method run at /home/masak/ours/007/lib/_007/Q.pm:451
in method call at /home/masak/ours/007/lib/_007/Runtime.pm:184
in method eval at /home/masak/ours/007/lib/_007/Q.pm:231
in method run at /home/masak/ours/007/lib/_007/Q.pm:275
in method run at /home/masak/ours/007/lib/_007/Q.pm:451
in method run at /home/masak/ours/007/lib/_007/Runtime.pm:31
in sub is-result at /home/masak/ours/007/lib/_007/Test.pm:186
in block <unit> at t/semantics/return.t:18
@masak
Copy link
Author

masak commented Oct 2, 2015

Ok, spotted it.

Lines 25 and 38 should be the same frame/pad, but they're different. Likely one of them is the static frame/pad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment