@@ -173,6 +173,49 @@ namespace phylanx { namespace execution_tree { namespace compiler
173173 return extract_copy_value (arg_, name_);
174174 }
175175
176+ // evaluate object itself and use the returned value to
177+ // asynchronously evaluate the arguments
178+ hpx::shared_future<result_type> async (
179+ arguments_type const & args, eval_context ctx) const
180+ {
181+ if (is_primitive_operand (arg_))
182+ {
183+ arguments_type params;
184+ params.reserve (args.size ());
185+ for (auto const & arg : args)
186+ {
187+ params.emplace_back (extract_ref_value (arg, name_));
188+ }
189+
190+ return value_operand (arg_, std::move (params), name_).share ();
191+ }
192+ return hpx::make_ready_future (extract_copy_value (arg_, name_))
193+ .share ();
194+ }
195+
196+ hpx::shared_future<result_type> async (
197+ arguments_type&& args, eval_context ctx) const
198+ {
199+ if (is_primitive_operand (arg_))
200+ {
201+ arguments_type keep_alive (std::move (args));
202+
203+ // construct argument-pack to use for actual call
204+ arguments_type params;
205+ params.reserve (keep_alive.size ());
206+ for (auto const & arg : keep_alive)
207+ {
208+ params.emplace_back (extract_ref_value (arg, name_));
209+ }
210+
211+ return value_operand (
212+ arg_, std::move (params), name_, " <unknown>" , std::move (ctx))
213+ .share ();
214+ }
215+ return hpx::make_ready_future (extract_copy_value (arg_, name_))
216+ .share ();
217+ }
218+
176219 using kwarguments_type = std::map<std::string, primitive_argument_type>;
177220
178221 result_type operator ()(arguments_type&& args, kwarguments_type&& kwargs,
@@ -222,6 +265,53 @@ namespace phylanx { namespace execution_tree { namespace compiler
222265 return extract_copy_value (arg_, name_);
223266 }
224267
268+ hpx::shared_future<result_type> async (arguments_type&& args,
269+ kwarguments_type&& kwargs, eval_context ctx) const
270+ {
271+ if (is_primitive_operand (arg_))
272+ {
273+ arguments_type keep_alive (std::move (args));
274+ kwarguments_type kw_keep_alive (std::move (kwargs));
275+
276+ // construct argument-pack to use for actual call
277+ arguments_type params;
278+ params.reserve (keep_alive.size () + num_named_args_);
279+ for (auto const & arg : keep_alive)
280+ {
281+ params.emplace_back (extract_ref_value (arg, name_));
282+ }
283+
284+ // fill in the given named arguments at their correct positions
285+ for (auto const & kwarg : kw_keep_alive)
286+ {
287+ auto it = std::find (named_args_.get (),
288+ named_args_.get () + num_named_args_, kwarg.first );
289+ if (it == named_args_.get () + num_named_args_)
290+ {
291+ HPX_THROW_EXCEPTION (hpx::bad_parameter,
292+ " function::operator()" ,
293+ hpx::util::format (" cannot locate requested "
294+ " named argument '{}'" , kwarg.first ));
295+ }
296+
297+ std::ptrdiff_t kwarg_pos =
298+ std::distance (named_args_.get (), it);
299+ if (kwarg_pos >= std::ptrdiff_t (params.size ()))
300+ {
301+ params.resize (kwarg_pos + 1 );
302+ }
303+
304+ params[kwarg_pos] = extract_ref_value (kwarg.second , name_);
305+ }
306+
307+ return value_operand (
308+ arg_, std::move (params), name_, " <unknown>" , std::move (ctx))
309+ .share ();
310+ }
311+ return hpx::make_ready_future (extract_copy_value (arg_, name_))
312+ .share ();
313+ }
314+
225315 template <typename T1, typename ... Ts>
226316 typename std::enable_if<
227317 !std::is_same<eval_context, typename std::decay<T1>::type>::value,
0 commit comments