Skip to content

Commit

Permalink
libexpr: use std::function rather than C function pointers for primops
Browse files Browse the repository at this point in the history
In preparation for the C bindings, which use this.

Change-Id: Ic1c58998951e69e66a794976585a381754dfbbeb
  • Loading branch information
puckipedia committed Mar 17, 2024
1 parent 7acdcf5 commit 883d2ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 883d2ad

Please sign in to comment.