@@ -29,15 +29,15 @@ struct ReturnInstruction{T} <: AbstractInstruction
2929 arg:: TypedVar{T}
3030end
3131
32- mutable struct TapedFunction{F}
32+ mutable struct TapedFunction{F, T }
3333 func:: F # maybe a function, a constructor, or a callable object
3434 arity:: Int
3535 ir:: Core.CodeInfo
3636 tape:: RawTape
3737 unified_tape:: Vector{FunctionWrapper{Nothing, Tuple{TapedFunction}}}
3838 counter:: Int
3939 bindings:: Dict{Symbol, Any}
40- retval:: TypedVar
40+ retval:: TypedVar{T}
4141
4242 function TapedFunction (f:: F , args... ; cache= false ) where {F}
4343 args_type = _accurate_typeof .(args)
@@ -55,15 +55,17 @@ mutable struct TapedFunction{F}
5555 utape = Vector {FunctionWrapper{Nothing, Tuple{TapedFunction}}} ()
5656 bindings = translate! (tape, ir)
5757
58- tf = new {F} (f, length (args), ir, tape, utape, 1 , bindings, TypedVar {Any} (:none ))
58+ T = isa (ir. rettype, Core. Const) ? ir. rettype. val : ir. rettype
59+ tf = new {F, T} (f, length (args), ir, tape, utape, 1 ,
60+ bindings, TypedVar {T} (:none ))
5961 TRCache[cache_key] = tf # set cache
6062 # unify!(tf)
6163 return tf
6264 end
6365
64- function TapedFunction (tf:: TapedFunction{F} ) where {F}
65- new {F} (tf. func, tf. arity, tf. ir, tf. tape, tf. unified_tape,
66- tf. counter, tf. bindings, TypedVar {Any} ( :none ) )
66+ function TapedFunction (tf:: TapedFunction{F, T } ) where {F, T }
67+ new {F, T } (tf. func, tf. arity, tf. ir, tf. tape, tf. unified_tape,
68+ tf. counter, tf. bindings, tf . retval )
6769 end
6870end
6971
@@ -122,6 +124,19 @@ function Base.show(io::IO, tf::TapedFunction)
122124 print (io, String (take! (buf)))
123125end
124126
127+ function Base. show (io:: IO , rtape:: RawTape )
128+ buf = IOBuffer ()
129+ print (buf, length (rtape), " -element RawTape" )
130+ isempty (rtape) || println (buf, " :" )
131+ i = 1
132+ for instr in rtape
133+ print (buf, " \t " , i, " => " )
134+ show (buf, instr)
135+ i += 1
136+ end
137+ print (io, String (take! (buf)))
138+ end
139+
125140# # methods for Instruction
126141Base. show (io:: IO , instr:: AbstractInstruction ) = println (io, " A " , typeof (instr))
127142
0 commit comments