OEP

153

Title

Dynamically-sized arrays

Summary

Allow the size of regular arrays to be determined at runtime.

Owner

Peter Welch

Status

Proposed

Date-Proposed

2006-04-12

Keywords

language arrays mobiles

In occam-pi as it stands, the size of non-mobile arrays must be constant (so they can be determined at compile time). This makes code such as the following -- where a temporary array is sized according to a parameter -- illegal:

PROC foo (VAL INT n)
  [n]INT tmp:
  ...  do something with tmp
:

The code can be rewritten to use a mobile array instead, but that changes the communication and assignment semantics of the array. Ideally we would permit the above code, and simply allocate tmp in mobilespace at runtime.

KRoC provides a FIXED type decorator which can be used to change the semantics of variables declared as mobiles, but it cannot currently be used with arrays or INITIAL declarations, and it is not proposed as a permanent language extension. Nevertheless, we can imagine using it to show how the compiler would rewrite the above code once n was found not to be constant:

PROC foo (VAL INT n)
  INITIAL FIXED MOBILE []INT tmp IS MOBILE [n]INT:
  ...  do something with tmp
:

OEP/153 (last edited 2007-09-27 01:28:42 by ats1)