index(...) Module Interface Specification

(0) CHARACTERISTICS

-type specified: index

-features: deterministic, parameterized

-foreign types: status

-parameters: xmax: int

(1) SYNTAX

ACCESS-PROGRAMS

Program Name
Arg#1Arg#2Arg#3Arg#4Result Type
CATENATEstatus:Oindex:VOindex:VO   
COPYstatus:Oindex:Vindex:VO   
DELETEstatus:Oindex:VOint:V   
DESTROYstatus:Oindex:O     
GET_INTstatus:Oindex:Vint:V  int
INITstatus:Oindex:VO     
IS_EQUALstatus:Oindex:Vindex:V  bool
NB_ELEMSstatus:Oindex:V    int
PUT_INTstatus:Oindex:VOint:Vint:V 

(2) CANONICAL TRACES

canonical(T) T = _ m:<int>; a[1]..a[m]:<int> [T = INIT(*1, *).[PUT_INT(*1, *, j, a[j])]j=1..m (0 m m xmax)]

AUXILIARY FUNCTIONS

canGet: <index> × <int> <bool>

canGet(x, n) = x _ 1 n n nbElems(x)

canPut: <index> × <int> <bool>

canPut(x, n) = x _ 1 n n nbElems(x) + 1

getInt: <index> × <int> <int>

getInt(x, n) (canGet(x, n)) = i where T1,T2:<index>; i:<int> [x = T1.PUT_INT(*1, *, n, i).T2 ]

nbElems: <index> <int>

nbElems(x) = count(x, "PUT_INT")

putInt: <index> × <int> × <int> <index>

putInt(x, n, i) (canPut(x, n)) =

ConditionValue
n < nbElems(x) + 1T1.PUT_INT(*1, *, n, i).T2 where T1,T2:<index>; j:<int> [x = T1.PUT_INT(*1, *, n, j).T2 ]
n = nbElems(x) + 1 x.PUT_INT(*1, *, n, i)

(3) SEMANTICS

ACCESS-PROGRAMS

Legality(CATENATE(s, (x, T), (y, U))) =

ConditionValue
T = _ U = _ %no_init%
T _ U _ nbElems(T) + nbElems(U) > xmax%out_of_space%
T _ U _ nbElems(T) + nbElems(U) xmax%legal%

CATENATE(s , (x, T), (y, U)) =

ConditionValue
T = _ U = _ status::_
T _ U _ nbElems(T) + nbElems(U) > xmaxstatus::OUT_OF_SPACE(*)
T _ U _ nbElems(T) + nbElems(U) xmaxstatus::LEGAL(*)

CATENATE(s, (x, T) , (y, U)) = T.[PUT_INT(*1, *, j + nbElems(T), a[j])]j=1..m where m:<int>; a[1]..a[m]:<int> [U = INIT(*1, *).[PUT_INT(*1, *, j, a[j])]j=1..m ]

CATENATE(s, (x, T), (y, U) ) =

ConditionValue
x yU
x = y T.[PUT_INT(*1, *, j + nbElems(T), a[j])]j=1..m where m:<int>; a[1]..a[m]:<int> [U = INIT(*1, *).[PUT_INT(*1, *, j, a[j])]j=1..m ]

Legality(COPY(s, U, (x, T))) =

ConditionValue
T = _ U = _ %no_init%
T _ U _%legal%

COPY(s , U, (x, T)) =

ConditionValue
T = _ U = _ status::_
T _ U _status::LEGAL(*)

COPY(s, U, (x, T) ) = U

Legality(DELETE(s, (x, T), n)) =

ConditionValue
T = _ %no_init%
T _ ¬canGet(T, n)%bad_access%
T _ canGet(T, n)%legal%

DELETE(s , (x, T), n) =

ConditionValue
T = _ status::INIT()
T _ ¬canGet(T, n)status::ACCESS(*)
T _ canGet(T, n)status::LEGAL(*)

DELETE(s, (x, T) , n) = T1.[PUT_INT(*1, *, j - 1, a[j])]j=n + 1..m where m:<int>; T1:<index>; a[1]..a[m]:<int> [T = T1.[PUT_INT(*1, *, j, a[j])]j=n..m ]

Legality(DESTROY(s, x)) = %legal%

DESTROY(s , x) = status::LEGAL(*)

DESTROY(s, x ) = _

Legality(GET_INT(s, T, n)) =

ConditionValue
T = _ %no_init%
T _ ¬canGet(T, n)%bad_access%
T _ canGet(T, n)%legal%

GET_INT(s , T, n) =

ConditionValue
T = _ status::_
T _ ¬canGet(T, n)status::ACCESS(*)
T _ canGet(T, n)status::LEGAL(*)

GET_INT(s, T, n) = getInt(T, n)

Legality(INIT(s, (x, T))) =

ConditionValue
T _%nonempty_trace%
T = _ %legal%

INIT(s , (x, T)) =

ConditionValue
T _status::NONEMPTY(*)
T = _ status::LEGAL(*)

INIT(s, (x, T) ) = INIT(*1, *)

Legality(IS_EQUAL(s, T1, T2)) = %legal%

IS_EQUAL(s , T1, T2) = status::LEGAL(*)

IS_EQUAL(s, T1, T2) = T1 = T2

Legality(NB_ELEMS(s, T)) =

ConditionValue
T = _ %no_init%
T _%legal%

NB_ELEMS(s , T) =

ConditionValue
T = _ status::_
T _status::LEGAL(*)

NB_ELEMS(s, T) = nbElems(T)

Legality(PUT_INT(s, (x, T), n, i)) =

ConditionValue
T = _ %no_init%
T _ ¬canPut(T, n)%bad_access%
T _ canPut(T, n) n > xmax%out_of_space%
T _ canPut(T, n) n xmax%legal%

PUT_INT(s , (x, T), n, i) =

ConditionValue
T = _ status::_
T _ ¬canPut(T, n)status::ACCESS(*)
T _ canPut(T, n) n > xmaxstatus::OUT_OF_SPACE(*)
T _ canPut(T, n) n xmaxstatus::LEGAL(*)

PUT_INT(s, (x, T) , n, i) = putInt(T, n, i)