const type: ARRAY_IDX_RANGE is new struct
var integer: minIdx is 1;
var integer: maxIdx is 0;
end struct;
const func ARRAY_IDX_RANGE: [ (in integer: minIdx) .. (in integer: maxIdx) ] is func
result
var ARRAY_IDX_RANGE: indexRange is ARRAY_IDX_RANGE.value;
begin
indexRange.minIdx := minIdx;
indexRange.maxIdx := maxIdx;
end func;
const func ARRAY_IDX_RANGE: [ (in integer: minIdx) len (in integer: length) ] is func
result
var ARRAY_IDX_RANGE: indexRange is ARRAY_IDX_RANGE.value;
begin
indexRange.minIdx := minIdx;
indexRange.maxIdx := pred(minIdx + length);
end func;
const func type: array (in type: baseType) is func
result
var type: arrayType is void;
local
var type: tupleType is void;
begin
arrayType := get_type(getfunc(array (attr baseType)));
if arrayType = void then
global
arrayType := newtype;
IN_PARAM_IS_REFERENCE(arrayType);
tupleType := tuple(baseType);
const boolean: isArrayType (attr arrayType) is TRUE;
const type: array (attr baseType) is arrayType;
const type: base_type (attr arrayType) is baseType;
const proc: (ref arrayType: dest) ::= (in arrayType: source) is action "ARR_CREATE";
const proc: destroy (ref arrayType: aValue) is action "ARR_DESTR";
const proc: (inout arrayType: dest) := (in arrayType: source) is action "ARR_CPY";
const proc: (inout arrayType: arr) &:= (in arrayType: extension) is action "ARR_APPEND";
const proc: (inout arrayType: arr) &:= (in baseType: element) is action "ARR_PUSH";
const func arrayType: [] (in tupleType: aTuple) is action "ARR_ARRLIT";
const func arrayType: [] (in baseType: anElement) is action "ARR_BASELIT";
const func arrayType: [ (in integer: start) ] (in tupleType: aTuple) is action "ARR_ARRLIT2";
const func arrayType: [ (in integer: start) ] (in baseType: anElement) is action "ARR_BASELIT2";
const func arrayType: (in arrayType: arr1) & (in arrayType: arr2) is action "ARR_CAT";
const func baseType: (in arrayType: arr) [ (in integer: index) ] is action "ARR_IDX";
const varfunc baseType: (inout arrayType: arr) [ (in integer: index) ] is action "ARR_IDX";
const func arrayType: (in arrayType: arr) [ (in integer: start) .. ] is action "ARR_TAIL";
const func arrayType: (in arrayType: arr) [ .. (in integer: stop) ] is action "ARR_HEAD";
const func arrayType: (in arrayType: arr) [ (in integer: start) ..
(in integer: stop) ] is action "ARR_RANGE";
const func arrayType: (in arrayType: arr) [ (in integer: start) len
(in integer: length) ] is action "ARR_SUBARR";
const proc: insert (inout arrayType: arr, in integer: index,
in baseType: element) is action "ARR_INSERT";
const proc: insert (inout arrayType: arr, in integer: index,
in arrayType: elements) is action "ARR_INSERT_ARRAY";
const func baseType: remove (inout arrayType: arr, in integer: index) is action "ARR_REMOVE";
const func arrayType: remove (inout arrayType: arr, in integer: index,
in integer: length) is action "ARR_REMOVE_ARRAY";
const func integer: length (in arrayType: arr) is action "ARR_LNG";
const func integer: minIdx (in arrayType: arr) is action "ARR_MINIDX";
const func integer: maxIdx (in arrayType: arr) is action "ARR_MAXIDX";
const func arrayType: (in integer: factor) times (in baseType: element) is action "ARR_TIMES";
const func arrayType: (attr arrayType) . _GENERATE_EMPTY_ARRAY is action "ARR_EMPTY";
const arrayType: (attr arrayType) . value is arrayType._GENERATE_EMPTY_ARRAY;
const func tupleType: (attr tupleType) conv (in arrayType: arr) is action "ARR_CONV";
const func arrayType: (in ARRAY_IDX_RANGE: indexRange) times
(in baseType: element) is
return [indexRange.minIdx] (tupleType conv
(succ(indexRange.maxIdx - indexRange.minIdx) times element));
const proc: for (inout baseType: forVar) range (in arrayType: arr) do
(in proc: statements)
end for is func
local
var integer: number is 0;
begin
for number range minIdx(arr) to maxIdx(arr) do
forVar := arr[number];
statements;
end for;
end func;
const proc: for key (inout integer: keyVar) range (in arrayType: arr) do
(in proc: statements)
end for is func
begin
for keyVar range minIdx(arr) to maxIdx(arr) do
statements;
end for;
end func;
const proc: for (inout baseType: forVar) key (inout integer: keyVar) range (in arrayType: arr) do
(in proc: statements)
end for is func
begin
for keyVar range minIdx(arr) to maxIdx(arr) do
forVar := arr[keyVar];
statements;
end for;
end func;
const proc: for (inout baseType: forVar)
range (in arrayType: arr)
until (ref func boolean: condition) do
(in proc: statements)
end for is func
local
var integer: index is 0;
var integer: maxIdx is 0;
begin
index := minIdx(arr);
maxIdx := maxIdx(arr);
if index <= maxIdx then
forVar := arr[index];
while index <= maxIdx and not condition do
statements;
incr(index);
if index <= maxIdx then
forVar := arr[index];
end if;
end while;
end if;
end func;
const proc: for (inout baseType: forVar)
range (in arrayType: arr)
until (ref boolean: condition) do
(in proc: statements)
end for is func
local
var integer: index is 0;
var integer: maxIdx is 0;
begin
index := minIdx(arr);
maxIdx := maxIdx(arr);
if index <= maxIdx then
forVar := arr[index];
while index <= maxIdx and not condition do
statements;
incr(index);
if index <= maxIdx then
forVar := arr[index];
end if;
end while;
end if;
end func;
const proc: for key (inout integer: keyVar)
range (in arrayType: arr)
until (ref func boolean: condition) do
(in proc: statements)
end for is func
begin
for keyVar range minIdx(arr) to maxIdx(arr) until condition do
statements;
end for;
end func;
const proc: for key (inout integer: keyVar)
range (in arrayType: arr)
until (ref boolean: condition) do
(in proc: statements)
end for is func
begin
for keyVar range minIdx(arr) to maxIdx(arr) until condition do
statements;
end for;
end func;
const proc: for (inout baseType: forVar)
key (inout integer: keyVar)
range (in arrayType: arr)
until (ref func boolean: condition) do
(in proc: statements)
end for is func
local
var integer: maxIdx is 0;
begin
keyVar := minIdx(arr);
maxIdx := maxIdx(arr);
if keyVar <= maxIdx then
forVar := arr[keyVar];
while keyVar <= maxIdx and not condition do
statements;
incr(keyVar);
if keyVar <= maxIdx then
forVar := arr[keyVar];
end if;
end while;
end if;
end func;
const proc: for (inout baseType: forVar)
key (inout integer: keyVar)
range (in arrayType: arr)
until (ref boolean: condition) do
(in proc: statements)
end for is func
local
var integer: maxIdx is 0;
begin
keyVar := minIdx(arr);
maxIdx := maxIdx(arr);
if keyVar <= maxIdx then
forVar := arr[keyVar];
while keyVar <= maxIdx and not condition do
statements;
incr(keyVar);
if keyVar <= maxIdx then
forVar := arr[keyVar];
end if;
end while;
end if;
end func;
const func baseType: rand (in arrayType: arr) is
return arr[rand(minIdx(arr), maxIdx(arr))];
if getobj((in baseType: element1) = (in baseType: element2)) <> NIL and
getobj((in baseType: element1) <> (in baseType: element2)) <> NIL then
const func boolean: (in arrayType: arr1) = (in arrayType: arr2) is func
result
var boolean: isEqual is FALSE;
local
var integer: number is 1;
begin
if minIdx(arr1) = minIdx(arr2) and maxIdx(arr1) = maxIdx(arr2) then
isEqual := TRUE;
number := minIdx(arr1);
while number <= maxIdx(arr1) and isEqual do
isEqual := arr1[number] = arr2[number];
incr(number);
end while;
end if;
end func;
const func boolean: (in arrayType: arr1) <> (in arrayType: arr2) is func
result
var boolean: isNotEqual is TRUE;
local
var integer: number is 1;
begin
if minIdx(arr1) = minIdx(arr2) and maxIdx(arr1) = maxIdx(arr2) then
isNotEqual := FALSE;
number := minIdx(arr1);
while number <= maxIdx(arr1) and not isNotEqual do
isNotEqual := arr1[number] <> arr2[number];
incr(number);
end while;
end if;
end func;
end if;
if getobj((in baseType: element1) < (in baseType: element2)) <> NIL and
getobj((in baseType: element1) > (in baseType: element2)) <> NIL then
const proc: insert (inout arrayType: arr, in baseType: element) is func
local
var integer: number is 1;
begin
number := minIdx(arr);
while number <= maxIdx(arr) and arr[number] < element do
incr(number);
end while;
if number > maxIdx(arr) then
arr := arr & [] (element);
elsif arr[number] > element then
arr := arr[.. pred(number)] & [] (element) & arr[number ..];
end if;
end func;
end if;
if getobj(compare(in baseType: element1, in baseType: element2)) <> NIL then
const func integer: compare (in arrayType: arr1, in arrayType: arr2) is func
result
var integer: signumValue is 0;
local
var integer: idx1 is 0;
var integer: idx2 is 0;
begin
idx1 := minIdx(arr1);
idx2 := minIdx(arr2);
while idx1 <= maxIdx(arr1) and idx2 <= maxIdx(arr2) and compare(arr1[idx1], arr2[idx2]) = 0 do
incr(idx1);
incr(idx2);
end while;
if idx1 <= maxIdx(arr1) and idx2 <= maxIdx(arr2) then
signumValue := compare(arr1[idx1], arr2[idx2]);
else
signumValue := compare(length(arr1), length(arr2));
end if;
end func;
const func boolean: (in arrayType: arr1) < (in arrayType: arr2) is
return compare(arr1, arr2) < 0;
const func boolean: (in arrayType: arr1) > (in arrayType: arr2) is
return compare(arr1, arr2) > 0;
const func boolean: (in arrayType: arr1) <= (in arrayType: arr2) is
return compare(arr1, arr2) <= 0;
const func boolean: (in arrayType: arr1) >= (in arrayType: arr2) is
return compare(arr1, arr2) >= 0;
const reference: (attr arrayType) . dataCompare is getobj(compare(in baseType: element1, in baseType: element2));
const func arrayType: SORT (in arrayType: arr, in reference: dataCompare) is action "ARR_SORT";
const func arrayType: SORT_REVERSE (in arrayType: arr, in reference: dataCompare) is action "ARR_SORT_REVERSE";
const func arrayType: sort (in arrayType: arr_obj) is
return SORT(arr_obj, arrayType.dataCompare);
const func arrayType: sort (in func arrayType: arr_obj) is
return SORT(arr_obj, arrayType.dataCompare);
const func arrayType: sort (in arrayType: arr_obj, REVERSE) is
return SORT_REVERSE(arr_obj, arrayType.dataCompare);
const func arrayType: sort (in func arrayType: arr_obj, REVERSE) is
return SORT_REVERSE(arr_obj, arrayType.dataCompare);
end if;
end global;
end if;
end func;
const type: TEST_1 is array integer;
const type: TEST_2 is array integer;
const type: TEST_3 is array string;
const proc: ENABLE_SORT (in type: arrayType) is func
begin
const reference: (attr arrayType) . dataCompare is getobj(compare(in base_type(arrayType): element1, in base_type(arrayType): element2));
const func arrayType: SORT (in arrayType: arr, in reference: dataCompare) is action "ARR_SORT";
const func arrayType: sort (in arrayType: arr_obj) is
return SORT(arr_obj, arrayType.dataCompare);
end func;