[cexpr] Add support for casting plitems

This allows using references in expressions, eg:

    $frames.size * size_t($properties.limits.maxSamplers)

As references remain property list items until actually evaluated.
This commit is contained in:
Bill Currie 2021-12-05 18:24:59 +09:00
parent e7b067d6a9
commit 062f616548

View file

@ -118,6 +118,14 @@ CAST_TO (float)
CAST_TO (double)
#undef CAST_TO
static void
cast_plitem (const exprval_t **params, exprval_t *result, exprctx_t *context)
{
// first argument is ignored because cexpr_cast_plitem is meant to used
// in an operator list
cexpr_cast_plitem (0, params[0], result, context);
}
FUNC2 (min, int, int, min)
FUNC2 (min, uint, uint, min)
FUNC2 (min, size_t, size_t, min)
@ -171,6 +179,12 @@ static exprtype_t *double_params[] = {
&cexpr_double,
};
static exprtype_t *plitem_params[] = {
&cexpr_plitem,
&cexpr_plitem,
&cexpr_plitem,
};
#define FUNC(name, rtype, n, ptype) \
{ &cexpr_##rtype, n, ptype##_params, FNAME(name, rtype, ptype) }
@ -228,6 +242,7 @@ static exprfunc_t rtype##_func[] = { \
FUNC (cast, rtype, 1, size_t), \
FUNC (cast, rtype, 1, float), \
FUNC (cast, rtype, 1, double), \
{ &cexpr_##rtype, 1, plitem_params, cast_plitem }, \
{} \
};