mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-07 01:42:04 +00:00
[qfcc] Add an @construct type function
I decided to not mess with actual casts. In retrospect, this is probably for the best as it avoids any bit-cast conflicts, but should allow for block initializers with a few tweaks. `@construct (type, args...)` in Ruamoko follows the same path as `type(args...)` in glsl.
This commit is contained in:
parent
6840a208b9
commit
36c0b45bab
6 changed files with 19 additions and 14 deletions
|
@ -416,7 +416,7 @@ build_function_call (const expr_t *fexpr, const type_t *ftype,
|
|||
const expr_t *
|
||||
function_expr (const expr_t *fexpr, const expr_t *args)
|
||||
{
|
||||
if (fexpr->type == ex_symbol && fexpr->symbol->sy_type == sy_type) {
|
||||
if (fexpr->type == ex_type) {
|
||||
return constructor_expr (fexpr, args);
|
||||
}
|
||||
|
||||
|
|
|
@ -287,7 +287,7 @@ math_constructor (const type_t *type, const expr_t *params, const expr_t *e)
|
|||
const expr_t *
|
||||
constructor_expr (const expr_t *e, const expr_t *params)
|
||||
{
|
||||
auto type = e->symbol->type;
|
||||
auto type = e->typ.type;
|
||||
if (is_algebra (type)) {
|
||||
return error (e, "algebra not implemented");
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ proc_symbol (const expr_t *expr, rua_ctx_t *ctx)
|
|||
}
|
||||
sym = symtab_lookup (current_symtab, sym->name);
|
||||
if (sym) {
|
||||
if (sym->sy_type == sy_expr) {
|
||||
if (sym->sy_type == sy_expr || sym->sy_type == sy_type_param) {
|
||||
return sym->expr;
|
||||
}
|
||||
if (sym->sy_type == sy_convert) {
|
||||
|
|
|
@ -438,10 +438,10 @@ SRC_LINE
|
|||
"genUType clamp(genUType x, uint minVal, uint maxVal);" "\n"
|
||||
"genFType mix(genFType x, genFType y, genFType a) = " GLSL(46) ";" "\n"
|
||||
"genFType mix(genFType x, genFType y, float a)" "\n"
|
||||
"{ return mix (x, y, (genFType) a); }" "\n"
|
||||
"{ return mix (x, y, @construct (genFType, a)); }" "\n"
|
||||
"genDType mix(genDType x, genDType y, genDType a) = " GLSL(46) ";" "\n"
|
||||
"genDType mix(genDType x, genDType y, double a)" "\n"
|
||||
"{ return mix (x, y, (genDType) a); }" "\n"
|
||||
"{ return mix (x, y, @construct (genDType, a)); }" "\n"
|
||||
"genFType mix(genFType x, genFType y, genBType a) = " SPV(169) ";" "\n"
|
||||
"genDType mix(genDType x, genDType y, genBType a) = " SPV(169) ";" "\n"
|
||||
"genIType mix(genIType x, genIType y, genBType a) = " SPV(169) ";" "\n"
|
||||
|
|
|
@ -436,14 +436,7 @@ function_call_header
|
|||
;
|
||||
|
||||
function_identifier
|
||||
: type_specifier
|
||||
{
|
||||
auto type = $1.type;
|
||||
auto sym = new_symbol (type->name);
|
||||
sym->sy_type = sy_type;
|
||||
sym->type = type;
|
||||
$$ = new_symbol_expr (sym);
|
||||
}
|
||||
: type_specifier { $$ = new_type_expr ($1.type); }
|
||||
| postfix_expression
|
||||
;
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ int yylex (YYSTYPE *yylval, YYLTYPE *yylloc);
|
|||
%token CLASS DEFS ENCODE END IMPLEMENTATION INTERFACE PRIVATE
|
||||
%token PROTECTED PROTOCOL PUBLIC SELECTOR REFERENCE SELF THIS
|
||||
|
||||
%token GENERIC
|
||||
%token GENERIC CONSTRUCT
|
||||
%token AT_FUNCTION AT_FIELD AT_POINTER AT_ARRAY
|
||||
%token AT_BASE AT_WIDTH AT_VECTOR AT_ROWS AT_COLS AT_MATRIX
|
||||
%token AT_INT AT_UINT AT_BOOL AT_FLOAT
|
||||
|
@ -2153,6 +2153,17 @@ cast_expr
|
|||
}
|
||||
$$ = new_binary_expr ('C', type_expr, $4);
|
||||
}
|
||||
| CONSTRUCT '(' typename ',' expr_list[args] ')' //FIXME arg_expr instead?
|
||||
{
|
||||
auto spec = $3;
|
||||
auto args = $args;
|
||||
auto type_expr = spec.type_expr;
|
||||
if (!type_expr) {
|
||||
spec = default_type ($typename, nullptr);
|
||||
type_expr = new_type_expr (spec.type);
|
||||
}
|
||||
$$ = new_call_expr (type_expr, args, nullptr);
|
||||
}
|
||||
| unary_expr %prec LOW
|
||||
;
|
||||
|
||||
|
@ -3024,6 +3035,7 @@ static keyword_t qf_keywords[] = {
|
|||
{"@dual", QC_DUAL, },
|
||||
{"@undual", QC_UNDUAL, },
|
||||
|
||||
{"@construct", QC_CONSTRUCT, },
|
||||
{"@generic", QC_GENERIC, },
|
||||
{"@function", QC_AT_FUNCTION, },
|
||||
{"@field", QC_AT_FIELD, },
|
||||
|
|
Loading…
Reference in a new issue