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

Failure to create return vars #168

Closed
timholy opened this issue Mar 17, 2019 · 1 comment
Closed

Failure to create return vars #168

timholy opened this issue Mar 17, 2019 · 1 comment

Comments

@timholy
Copy link
Member

timholy commented Mar 17, 2019

While working on updating the docs, I came across something really weird:

julia> using JuliaInterpreter

julia> @breakpoint sum([1, 2]) any(x->x>4, a)
breakpoint(sum(a::AbstractArray) in Base at reducedim.jl:648, line 648)

julia> val = @interpret sum([1,2,3])
6

julia> val
6

julia> frame, bp = @interpret sum([1,2,5])
(Frame for sum(a::AbstractArray) in Base at reducedim.jl:648
c 1 648  1nothing
  2 648%2 = (Base.#sum#550)(Colon(), #self#, a)
  3 648  └──      return %2
a = [1, 2, 5], breakpoint(sum(a::AbstractArray) in Base at reducedim.jl:648, line 648))

julia> frame
ERROR: UndefVarError: frame not defined

julia> bp
ERROR: UndefVarError: bp not defined

julia> x, y = begin
           (1, 2)
       end
(1, 2)

julia> x
1

julia> y
2

julia> macroexpand(Main, :(frame, bp = @interpret sum([1, 2])))
:((frame, bp = begin
              #= /home/tim/.julia/dev/JuliaInterpreter/src/construct.jl:633 =#
              #11#theargs = (sum, a)
              #= /home/tim/.julia/dev/JuliaInterpreter/src/construct.jl:634 =#
              #12#frame = (JuliaInterpreter.JuliaInterpreter).enter_call_expr((JuliaInterpreter.Expr)(:call, #11#theargs...))
              #= /home/tim/.julia/dev/JuliaInterpreter/src/construct.jl:635 =#
              if #12#frame === JuliaInterpreter.nothing
                  #= /home/tim/.julia/dev/JuliaInterpreter/src/construct.jl:636 =#
                  return (JuliaInterpreter.eval)((JuliaInterpreter.Expr)(:call, (JuliaInterpreter.map)(JuliaInterpreter.QuoteNode, #11#theargs)...))
              end
              #= /home/tim/.julia/dev/JuliaInterpreter/src/construct.jl:638 =#
              if (JuliaInterpreter.shouldbreak)(#12#frame, 1)
                  #= /home/tim/.julia/dev/JuliaInterpreter/src/construct.jl:639 =#
                  return (#12#frame, (JuliaInterpreter.BreakpointRef)((#12#frame).framecode, 1))
              end
              #= /home/tim/.julia/dev/JuliaInterpreter/src/construct.jl:641 =#
              #13#ret = (JuliaInterpreter.finish_and_return!)(#12#frame)
              #= /home/tim/.julia/dev/JuliaInterpreter/src/construct.jl:642 =#
              if #13#ret isa JuliaInterpreter.BreakpointRef
                  (#12#frame, #13#ret)
              else
                  #13#ret
              end
          end))

julia> 

If you access ans then you can get both frame and bp, but collecting them by ordinary means seems not to work. Do you understand this at all?

@KristofferC
Copy link
Member

KristofferC commented Mar 17, 2019

Yes, it is the return statement in the macro

julia> a, b = return 1, 2
(1, 2)

julia> a
ERROR: UndefVarError: a not defined

julia> b
ERROR: UndefVarError: b not defined

julia> ans
(1, 2)

timholy added a commit that referenced this issue Mar 17, 2019
Fix the return value of atsign-interpret (fixes #168)
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

No branches or pull requests

2 participants