From 9041cd4b10ec6105d9041d103fe0a78022c3472c Mon Sep 17 00:00:00 2001 From: Pelle Johnsen Date: Mon, 16 Nov 2020 08:08:35 +0000 Subject: [PATCH] [glsl-in] Handle simple casts --- src/front/glsl/parser.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/front/glsl/parser.rs b/src/front/glsl/parser.rs index 1171b4d0a8..f16da82bac 100644 --- a/src/front/glsl/parser.rs +++ b/src/front/glsl/parser.rs @@ -244,10 +244,25 @@ pomelo! { function_call ::= function_call_or_method(fc) { match fc.kind { FunctionCallKind::TypeConstructor(ty) => { - let h = extra.context.expressions.append(Expression::Compose { - ty, - components: fc.args.iter().map(|a| a.expression).collect(), - }); + let h = if fc.args.len() == 1 { + let kind = match extra.module.types[ty].inner { + TypeInner::Scalar{kind, ..} => kind, + TypeInner::Vector{kind, ..} => kind, + _ => { + return Err(ErrorKind::SemanticError("Can only cast to scalar or vector")); + } + }; + extra.context.expressions.append(Expression::As { + kind, + expr: fc.args[0].expression, + convert: true, + }) + } else { + extra.context.expressions.append(Expression::Compose { + ty, + components: fc.args.iter().map(|a| a.expression).collect(), + }) + }; ExpressionRule { expression: h, statements: fc.args.into_iter().map(|a| a.statements).flatten().collect(),