Add basic execution function
This commit is contained in:
@@ -9,7 +9,10 @@ function gen_code(graph::DAG)
|
||||
|
||||
for node in get_entry_nodes(graph)
|
||||
enqueue!(nodeQueue, node => 1)
|
||||
push!(inputSyms, Symbol("data_$(replace(string(node.id), "-"=>"_"))_in"))
|
||||
push!(
|
||||
inputSyms,
|
||||
Symbol("data_$(replace(string(node.id), "-"=>"_"))_in"),
|
||||
)
|
||||
end
|
||||
|
||||
node = nothing
|
||||
@@ -27,6 +30,33 @@ function gen_code(graph::DAG)
|
||||
|
||||
# node is now the last node we looked at -> the output node
|
||||
outSym = Symbol("data_$(replace(string(node.id), "-"=>"_"))")
|
||||
|
||||
return (code = Expr(:block, code...), inputSymbols = inputSyms, outputSymbol = outSym)
|
||||
|
||||
return (
|
||||
code = Expr(:block, code...),
|
||||
inputSymbols = inputSyms,
|
||||
outputSymbol = outSym,
|
||||
)
|
||||
end
|
||||
|
||||
function execute(graph::DAG, input::Vector{Particle})
|
||||
(code, inputSymbols, outputSymbol) = gen_code(graph)
|
||||
|
||||
@assert length(input) == length(inputSymbols)
|
||||
|
||||
assignInputs = Vector{Expr}()
|
||||
for i in 1:length(input)
|
||||
push!(
|
||||
assignInputs,
|
||||
Meta.parse(
|
||||
"$(inputSymbols[i]) = ParticleValue(Particle($(input[i]).P0, $(input[i]).P1, $(input[i]).P2, $(input[i]).P3, $(input[i]).m), 1.0)",
|
||||
),
|
||||
)
|
||||
end
|
||||
|
||||
assignInputs = Expr(:block, assignInputs...)
|
||||
eval(assignInputs)
|
||||
eval(code)
|
||||
|
||||
eval(Meta.parse("result = $outputSymbol"))
|
||||
return result
|
||||
end
|
||||
|
Reference in New Issue
Block a user