bdfhjk / VICER

4 stars 3 forks source link

Pointers + Arrays + stdlib + VarArgs #36

Closed chaser92 closed 9 years ago

nutka7 commented 9 years ago

There is only partial support for arrays. You only support string literals, but you don't support array templates. I mean char *a; a = "123456789"; works, but int tab[100]; doesn't.

Moreover if you meet an array name to resolve, then you simply put the array location on the stack. But later you don't have any instruction that could handle it, because you make an assumption that you can only access array via pointers. One solution is that push method of the expression stack, could always check for array location, and in case it is one, it should push pointer to the first element of the array instead. It follows the rule that array can't be a lvalue.

Another solution is to have a cast instruction that converts array location to a pointer to its first element.

It's very good, you cared for each location, to remember which array it belongs to. This way you can fully control pointers correctness, a big +. I wondered if memory should be aware of arrays, but for this reason I can't really find a better solution.