diff --git a/src/Func.cc b/src/Func.cc index 7b6c028b2e..82744623bb 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -310,6 +310,30 @@ ScriptFunc::ScriptFunc(const IDPtr& arg_id, StmtPtr arg_body, } } +ScriptFunc::ScriptFunc(std::string _name, FuncTypePtr ft, + std::vector bs, std::vector priorities) + { + name = std::move(_name); + frame_size = ft->ParamList()->GetTypes().size(); + type = std::move(ft); + + auto n = bs.size(); + ASSERT(n == priorities.size()); + + for ( auto i = 0; i < n; ++i ) + { + Body b; + b.stmts = std::move(bs[i]); + b.priority = priorities[i]; + bodies.push_back(b); + } + + sort(bodies.begin(), bodies.end()); + + current_body = bodies[0].stmts; + current_priority = bodies[0].priority; + } + ScriptFunc::~ScriptFunc() { if ( ! weak_closure_ref ) diff --git a/src/Func.h b/src/Func.h index c6c496eebb..c1871270cb 100644 --- a/src/Func.h +++ b/src/Func.h @@ -151,6 +151,10 @@ public: const std::vector& inits, size_t frame_size, int priority); + // For compiled scripts. + ScriptFunc(std::string name, FuncTypePtr ft, + std::vector bodies, std::vector priorities); + ~ScriptFunc() override; bool IsPure() const override;