}
+/**
+ * Test if an operation is a scalar or boolean.
+ */
+static GLboolean
+_slang_is_scalar_or_boolean(slang_assemble_ctx *A, slang_operation *oper)
+{
+ slang_typeinfo type;
+ GLint size;
+
+ slang_typeinfo_construct(&type);
+ _slang_typeof_operation(A, oper, &type);
+ size = _slang_sizeof_type_specifier(&type.spec);
+ slang_typeinfo_destruct(&type);
+ return size == 1;
+}
+
/**
* Generate loop code using high-level IR_LOOP instruction
slang_ir_node *prevLoop, *loop, *cond, *breakIf, *body;
GLboolean isConst, constTrue;
+ /* type-check expression */
+ if (!_slang_is_scalar_or_boolean(A, &oper->children[0])) {
+ slang_info_log_error(A->log, "scalar/boolean expression expected for 'while'");
+ return NULL;
+ }
+
/* Check if loop condition is a constant */
isConst = _slang_is_constant_cond(&oper->children[0], &constTrue);
slang_ir_node *prevLoop, *loop, *cond;
GLboolean isConst, constTrue;
+ /* type-check expression */
+ if (!_slang_is_scalar_or_boolean(A, &oper->children[1])) {
+ slang_info_log_error(A->log, "scalar/boolean expression expected for 'do/while'");
+ return NULL;
+ }
+
loop = new_loop(NULL);
/* save old, push new loop */
slang_ir_node *ifNode, *cond, *ifBody, *elseBody;
GLboolean isConst, constTrue;
+ /* type-check expression */
+ if (!_slang_is_scalar_or_boolean(A, &oper->children[0])) {
+ slang_info_log_error(A->log, "scalar/boolean expression expected for 'if'");
+ return NULL;
+ }
+
isConst = _slang_is_constant_cond(&oper->children[0], &constTrue);
if (isConst) {
if (constTrue) {