Now the generated code looks like this:

AST(:($(Expr(:lambda, Any[:x,:y], 
Any[Any[Any[:x,:Any,1],Any[:y,:Any,1],Any[:v1,:Any,7],Any[:v2,:Any,7]],Any[],0,Any[]],
 
:(begin  # none, line 2:
        NewvarNode(:v1)
        NewvarNode(:v2)
        v1 = 2.1 
        v2 = 2.2 
        (v1,v2) = 
((top(getfield))((top(getfield))(Transmission,:Download),:download_task))(Val{symbol("##7731")},x,y,v1,v2)
 
        return v1 + v2
    end)))))

however, when i call test(1.1,2.2), it gives me the following error:

signal (11): Segmentation fault
var_binding_pointer at  codegen.cpp:2858
emit_assignment at  codegen.cpp:3052
emit_function at  codegen.cpp:4697
jl_eh_restore_state at  julia.h:1410
jl_compile at  codegen.cpp:812
jl_trampoline_compile_function at  builtins.c:1025
jl_apply at  gf.c:1709
do_call at  interpreter.c:66
eval at  interpreter.c:213
jl_toplevel_eval_flex at  toplevel.c:544
jl_eh_restore_state at  julia.h:1410
eval_user_input at ./REPL.jl:62
unknown function (ip: 0x7f52402a9497)
jl_apply at  gf.c:1711
anonymous at ./REPL.jl:85
start_task at  task.c:246
unknown function (ip: (nil))
Segmentation fault





On Thursday, March 10, 2016 at 10:07:05 PM UTC-8, Julia Tylors wrote:
>
> I fixed it, It should have been like this:
>
>  (:v1,:v2) = 
> ((top(getfield))((top(getfield))(Staged,:Runtime),:kernel_call))(Val{symbol("##7731")},x,y,v1,v2)
>
> On Thursday, March 10, 2016 at 3:48:49 PM UTC-8, Yichao Yu wrote:
>>
>> On Thu, Mar 10, 2016 at 6:04 PM, Julia Tylors <julia...@gmail.com> 
>> wrote: 
>> > 
>> > 
>> > Hi fellows, I have a problem which i can't solve. 
>> > 
>> > I have a function test(x,y) which has the ast as follows: 
>> > (test.env.defs.func.code) 
>> > 
>> > 
>> > :($(Expr(:method, :test, 
>> > :((top(svec))((top(apply_type))(Tuple,Any,Any),(top(svec))())), 
>> > AST(:($(Expr(:lambda, Any[:x,:y], 
>> > 
>> Any[Any[Any[:x,:Any,1],Any[:y,:Any,1],Any[:v1,:Any,7],Any[:v2,:Any,7]],Any[],0,Any[]],
>>  
>>
>> > :(begin  # none, line 2: 
>> >         NewvarNode(:v1) 
>> >         NewvarNode(:v2) 
>> >         v1 = 2.1 
>> >         v2 = 2.2 
>> >         $(Expr(:(=), :v1, :v2, 
>> > 
>> :(((top(getfield))((top(getfield))(Transmission,:Download),:download_task))(Val{symbol("##7775")},x,y,v1,v2))))
>>  
>>
>> >         return v1 + v2 
>> >     end))))), false))) 
>> > 
>> > 
>>
>> Can you show how you generated `test`? 
>>
>> > 
>> > when i call test(1.1,2.2), it returns 4.4 but it should have returned 
>> > v1 = 1.1*2.2 = 2.42 
>> > v2 = 2.2*2.1 = 4.62 
>> > 
>> > so the result should be v1+v2 , 7.04 
>> > 
>> > Here is the download_task function. 
>> > @generated function download_task{id}(::Type{Val{id}}, args...) 
>> > println("Download Task $id for argument types $args") 
>> > :((args[1] * args[2]), (args[2] * args[3])) 
>> > end 
>> > 
>> > I am suspicious about the part in bold 
>> > 
>> > $(Expr(:(=), :v1, :v2, 
>> > 
>> :(((top(getfield))((top(getfield))(Transmission,:Download),:download_task))(Val{symbol("##7775")},x,y,v1,v2))))
>>  
>>
>> > 
>> > this part doesn't get executed! Or somewhat expanded wrong. I am not 
>> totally 
>> > sure. 
>> > Anyone with a better understanding , please help me out.! 
>> > 
>> > Thanks 
>>
>

Reply via email to