pc2550/numnum

implement dims and shape attributes of matrix

Opened this issue · 1 comments

implement dims and shape attributes of matrix

Hey guys, I was working on this, and I couldn't figure out how to go about certain things:

Currently, an expression cannot be of "matrix" type. Instead matrices are implemented using "MatrixAccess" and "MatrixAssign" assignments, which correspond to:

int[2][2] b; 
b[0][0] = 3 /* assign */
print(b[0][0]); /* access */

But the way it is right now, we don't support the following for example.

int [2][2] b;
b[0][0] = 4;

int [2][2] c;
c = b; /* copy an array, doesn't work because there's no expression type "matrix"

Which is just fine with me. But if we want to store the shape of an array in a variable, I don't know how we can do that. Because we can't do shape_of_arr = shape(arr), because the only way we can assign to a matrix type is element-wise. We can't do shape(arr)[3] either because the type of the expression shape(arr) cannot be a matrix.

Two solutions I can think of:

(1) Restrict shape()'s usage only to assignment statements only, then hack our codegen for assignment to handle it.
(2) Reimplement matrices as referenced arrays and let an expression have the type matrix.

Option 2 requires a lot of reworking the parser and codegen. I vote for option 1. What do you all think?