@@ -18,20 +18,6 @@ mutable struct Instruction{F} <: AbstractInstruction
1818 tape:: Tape
1919end
2020
21-
22- """
23- NewInstruction
24-
25- A `NewInstruction` stands for a `new` operator, which only appears in
26- an inner constructor. Its represtation in IRCode is not a function call,
27- so we need a new intruction type to represent it on tapes.
28- """
29- mutable struct NewInstruction <: AbstractInstruction
30- input:: Tuple
31- output
32- tape:: Tape
33- end
34-
3521Tape () = Tape (Vector {AbstractInstruction} (), 1 , nothing )
3622Tape (owner) = Tape (Vector {AbstractInstruction} (), 1 , owner)
3723MacroTools. @forward Tape. tape Base. iterate, Base. length
@@ -92,7 +78,7 @@ function Base.show(io::IO, tp::Tape)
9278end
9379
9480function (instr:: Instruction{F} )() where F
95- # Catch run-time exceptions / errors.
81+ # catch run-time exceptions / errors.
9682 try
9783 output = instr. fun (map (val, instr. input)... )
9884 instr. output. val = output
@@ -102,9 +88,9 @@ function (instr::Instruction{F})() where F
10288 end
10389end
10490
105-
106- function (instr:: NewInstruction )()
107- # Catch run-time exceptions / errors.
91+ function _new end
92+ function (instr:: Instruction{typeof(_new)} )()
93+ # catch run-time exceptions / errors.
10894 try
10995 expr = Expr (:new , map (val, instr. input)... )
11096 output = eval (expr)
@@ -147,15 +133,15 @@ function run_and_record!(tape::Tape, f, args...)
147133 return output
148134end
149135
150- function run_and_record_new ! (tape:: Tape , args... )
136+ function run_and_record ! (tape:: Tape , :: typeof (_new) , args... )
151137 output = try
152138 expr = Expr (:new , map (val, args)... )
153139 box (eval (expr))
154140 catch e
155141 @warn e
156142 Box {Any} (nothing )
157143 end
158- ins = NewInstruction ( args, output, tape)
144+ ins = Instruction (_new, args, output, tape)
159145 push! (tape, ins)
160146 return output
161147end
@@ -233,7 +219,7 @@ function intercept(ir; recorder=:run_and_record!)
233219 ir[x] = IRTools. xcall (@__MODULE__ , recorder, tape, new_args... )
234220 elseif Meta. isexpr (st. expr, :new )
235221 args = st. expr. args
236- ir[x] = IRTools. xcall (@__MODULE__ , :run_and_record_new! , tape, args... )
222+ ir[x] = IRTools. xcall (@__MODULE__ , recorder , tape, _new , args... )
237223 else
238224 @warn " Unknown IR code: " st
239225 end
0 commit comments