libexpr: use std::function rather than C function pointers for primops

In preparation for the C bindings, which use this.

Change-Id: Ic1c58998951e69e66a794976585a381754dfbbeb
This commit is contained in:
puck 2024-03-17 16:04:36 +00:00
parent 7acdcf5511
commit 883d2ad4d2
2 changed files with 6 additions and 3 deletions

View file

@ -36,7 +36,7 @@ enum RepairFlag : bool;
/**
* Function that implements a primop.
*/
typedef void (* PrimOpFun) (EvalState & state, const PosIdx pos, Value * * args, Value & v);
typedef std::function<void (EvalState &, const PosIdx, Value **, Value &)> PrimOpFun;
/**
* Info about a primitive operation, and its implementation

View file

@ -3279,8 +3279,11 @@ static void prim_sort(EvalState & state, const PosIdx pos, Value * * args, Value
callFunction. */
/* TODO: (layus) this is absurd. An optimisation like this
should be outside the lambda creation */
if (args[0]->isPrimOp() && args[0]->primOp->fun == prim_lessThan)
return CompareValues(state, noPos, "while evaluating the ordering function passed to builtins.sort")(a, b);
if (args[0]->isPrimOp()) {
auto target = args[0]->primOp->fun.target<decltype(&prim_lessThan)>();
if (target && *target == prim_lessThan)
return CompareValues(state, noPos, "while evaluating the ordering function passed to builtins.sort")(a, b);
}
Value * vs[] = {a, b};
Value vBool;