Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 3739f27

Browse files
committed
Geometry Compiler: array[i,j,k]: bug #48
1 parent ea1d946 commit 3739f27

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

libcurv/gl_compiler.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,25 @@ GL_Value gl_eval_index2_expr(
611611
throw Exception(acx, "2 indexes (a[i,j]) not supported for this array");
612612
}
613613

614+
// compile array[i,j,k] expression
615+
GL_Value gl_eval_index3_expr(
616+
GL_Value array, Operation& op_ix1, Operation& op_ix2, Operation& op_ix3,
617+
GL_Frame& f, const Context& acx)
618+
{
619+
if (array.type.rank_ == 2 && array.type.base_info().rank == 1) {
620+
// 2D array of vector.
621+
auto ix1 = gl_eval_expr(f, op_ix1, GL_Type::Num());
622+
auto ix2 = gl_eval_expr(f, op_ix2, GL_Type::Num());
623+
auto ix3 = gl_eval_expr(f, op_ix3, GL_Type::Num());
624+
GL_Value result = f.gl.newvalue(GL_Type::Num());
625+
f.gl.out << " " << result.type << " " << result << " = " << array
626+
<< "[int(" << ix1 << ")*" << array.type.dim1_
627+
<< "+" << "int(" << ix2 << ")][int(" << ix3 << ")];\n";
628+
return result;
629+
}
630+
throw Exception(acx, "3 indexes (a[i,j,k]) not supported for this array");
631+
}
632+
614633
GL_Value Call_Expr::gl_eval(GL_Frame& f) const
615634
{
616635
GL_Value glval;
@@ -627,6 +646,10 @@ GL_Value Call_Expr::gl_eval(GL_Frame& f) const
627646
if (list->size() == 2)
628647
return gl_eval_index2_expr(glval, *list->at(0), *list->at(1), f,
629648
At_GL_Phrase(arg_->syntax_, f));
649+
if (list->size() == 3)
650+
return gl_eval_index3_expr(glval,
651+
*list->at(0), *list->at(1), *list->at(2),
652+
f, At_GL_Phrase(arg_->syntax_, f));
630653
}
631654
Value val = gl_constify(*fun_, f);
632655
Value v = val;

0 commit comments

Comments
 (0)