Context 3: References to single objects and arrays - draft

In Context language it is difficult to create function that work with any multi-dimensional array. Reference to wrapper structure may be used to pass fixed-size multi-dimensional array as parameter. In principle correctly initialized reference to reference (to reference...) may be used to work with any multi-dimensional array, but initialization are bit complex and tends to errors. For example, three-dimension array must be supplied with two-dimension array of references and one-dimension array of references to references.

In Context 3 references to single objects and to arrays of objects differs. Like Context 1&2 references to single objects are automatically dereferenced. To deny derefernce, i.e. to get/set address, postfix operator ^ must be used. Reference to single object can't be indexed.

References to arrays (one- or multi-dimensional) must be supplied with indexes or array address operators []. Reference to array consist of array address and set of dimension sizes. To determine dimension size operator [?] may be used. This is similar to open arrays from Oberon programming language, but reference to array may be declared in any place where variable or field may be, not only in function header.

String constants are references to one-dimension array of char.

No explicit limitation of references to reference. Possibly, references to object and array of object are sufficient, but if need reference to reference (to reference ...) may be used.

No ambiguity. Reference to reference to array and reference to array of references are differ by address operators ^ and [] order.

Like Context 1&2 no differences between assignment and parameter passing.

Old-style references to objects @ are supported. References to references are not supported. It differs from new-style references ^ only by ability of dereference with index. Old-style references are deprecated and need unlil it being replaced in compiler itself.

Code samples:

C Context 1&2 Postfix (Context-like language with postfix address operator) Context 3 Context 3-alt Remark
char *strcpy(char *dst, char *src); char @strcpy(char @dst, char @src); char strcpy(char dst^, char src^)^; char strcpy(char dst[], char src[])[]; Like Context 3 String function. Parameters and result consists of pointer and one size
1) 1) 1) void doSome(int matrix[][]); Like Context 3 Matrix function. matrix parameter consist of pointer and two sizes
char C; char C; char C; char C; Like Context 3 Simple variable
char *RC = &C; char @RC := @C; char RC^ := C^; char RC^ := @C; char RC^ := C^; Reference to variable and it's initialization
char *RC2 = RC; char @RC2 := @RC; char RC2^ := RC^; char RC2^ := RC^; Like Context 3 Reference to variable and it's initialization
RC = &C; @RC := @C; RC^ := C^; RC^ := @C; RC^ := C^; Assignment to reference
char C2 = *RC; char C2 := RC; char C2 := RC; char C2 := RC; Like Context 3 Access by reference
char C3 = RC[3]; char C3 := RC[3]; char C3 := RC[3]; - - Access by reference as array (out of range)
char S[3]; char S[3]; char S[3]; char S[3]; Like Context 3 Array
char *RS = S; char @RS := @S; char RS^ := @S; char RS[] := S[]; Like Context 3 Reference to array and it's initialization
int A[5][7]; int A[5][7]; int A[5][7]; int A[5][7]; Like Context 3 Matrix
1) 1) 1) int RA[][] := A[][]; Like Context 3 Reference to matrix and it's initialization
int (*RA25X80)[25][80]; - - int RA25X80^[25][80]; // Error Like Context 3 References to fixed-size arrays are not allowed, references to arrays or wrapper structures may be used instead
1) 1) 1) int RRA^[][] := @RA[][]; int RRA^[][] := RA^[][]; Reference to reference to matrix and it's initialization
1) 1) 1) int E35 := RRA[3][5]; Like Context 3 Access by reference
- - - int D0 := RRA[?][ ];
int D1 := RRA[ ][?];
Like Context 3 Dimension size
1) 1) 1) doSome(A[][]);
Like Context 3 Parameter passing
char *AR[10]; char @AR[10]; char AR[10]^; char AR[10]^; Like Context 3 Array of references
int **RAR = AR; int @@RAR := @@AR; int RAR^^ := AR^^; int RAR[]^ := AR[]^; Like Context 3 Reference to array of references and it's initialization
- - - void RV^ := GetMem(19*19*4)^;
int RM[][] := int(RV^)[\19][\19];
Like Context 3 Conversion to reference to matrix
char *St = "String"; char @St := "String"; char St^ := "String"; char St[] := "String"; Like Context 3 String constant

1)Two-dimension array must be supplied with one-dimension array of references, each it element must point to corresponding row in two-dimension array.

Сайт создан в системе uCoz