#### Stores
Type
locations ~> atoms
Alias
locs = locations
*/
Type
stores ~> maps(locations, values?)
*/
Entity
< _ , store(_:stores) > ---> < _ , store(_:stores) >
*/
Funcon
store-clear : =>null-type
Rule
< store-clear , store(_) > ---> < null-value , store(map( )) >
*/
Funcon initialise-storing(X:=>T) : =>T
~> sequential(store-clear,
initialise-giving(initialise-generating(X)))
Alias
init-storing = initialise-storing
*/
#### Simple variables
*/
Datatype
variables ::= variable(_:locations, _:value-types)
Alias
vars = variables
Alias
var = variable
*/
Funcon
allocate-variable(T:types) : =>variables
Alias
alloc = allocate-variable
*/
Rule
< use-atom-not-in(dom(Sigma)) , store(Sigma) > ---> < L , store(Sigma′) >
map-override({L |-> ( )}, Sigma′) ~> Sigma′′
-------------------------------------------------------------------------
< allocate-variable(T:types) , store(Sigma) >
---> < variable(L, T) , store(Sigma′′) >
Funcon
recycle-variables(_:variables+) : =>null-type
Alias
recycle = recycle-variables
*/
Rule
is-in-set(L, dom(Sigma)) == true
---------------------------------------------------------------------
< recycle-variables(variable(L:locations, T:types)) , store(Sigma) >
---> < null-value , store(map-delete(Sigma, {L})) >
Rule
is-in-set(L, dom(Sigma)) == false
---------------------------------------------------------------------
< recycle-variables(variable(L:locations, T:types)) , store(Sigma) >
---> < fail , store(Sigma) >
Rule
recycle-variables(Var:variables, Var+:variables+)
~> sequential(recycle-variables(Var), recycle-variables(Var+))
Funcon
initialise-variable(_:variables, _:values) : =>null-type
Alias
init = initialise-variable
*/
Rule
and(is-in-set(L, dom(Sigma)),
not is-value(map-lookup(Sigma, L)),
is-in-type(Val, T))
== true
----------------------------------------------------------------------------
< initialise-variable(variable(L:locations, T:types), Val:values) ,
store(Sigma) > ---> < null-value , store(map-override({L|->Val}, Sigma)) >
Rule
and(is-in-set(L, dom(Sigma)),
not is-value(map-lookup(Sigma, L)),
is-in-type(Val, T))
== false
----------------------------------------------------------------------------
< initialise-variable(variable(L:locations, T:types), Val:values) ,
store(Sigma) > ---> < fail , store(Sigma) >
Funcon allocate-initialised-variable(T, Val:T) : =>variables
~> give(allocate-variable(T),
sequential(initialise-variable(given, Val), given))
Alias
alloc-init = allocate-initialised-variable
*/
Funcon
assign(_:variables, _:values) : =>null-type
*/
Rule
and(is-in-set(L, dom(Sigma)), is-in-type(Val, T)) == true
-----------------------------------------------------------------------
< assign(variable(L:locations, T:types), Val:values) ,
store(Sigma) > ---> < null-value , store(map-override({L|->Val}, Sigma)) >
Rule
and(is-in-set(L, dom(Sigma)), is-in-type(Val, T)) == false
--------------------------------------------------------------------------
< assign(variable(L:locations,T:types), Val:values) ,
store(Sigma) > ---> < fail , store(Sigma) >
Funcon
assigned(_:variables) : =>values
*/
Rule
map-lookup(Sigma, L) ~> (Val:values)
------------------------------------------------------------------
< assigned(variable(L:locations, T:types)) , store(Sigma) >
---> < Val , store(Sigma) >
Rule
map-lookup(Sigma, L) == ( )
------------------------------------------------------------------
< assigned(variable(L:locations, T:types)) , store(Sigma) >
---> < fail , store(Sigma) >
Funcon
current-value(_:values) : =>values
*/
Rule
current-value(Var:variables) ~> assigned(Var)
Rule
current-value(U:~variables) ~> U
Funcon
un-assign(_:variables) : =>null-type
*/
Rule
is-in-set(L, dom(Sigma)) == true
--------------------------------------------------------------------------
< un-assign(variable(L:locations, T:types)) , store(Sigma) >
---> < null-value , store(map-override({L |-> ( )}, Sigma)) >
Rule
is-in-set(L, dom(Sigma)) == false
--------------------------------------------------------------------------
< un-assign(variable(L:locations, T:types)) , store(Sigma) >
---> < fail , store(Sigma) >
#### Structured variables
*/
Funcon
structural-assign(_:values, _:values) : =>null-type
*/
Rule
structural-assign(V1:variables, V2:values)
~> assign(V1, V2)
Rule
V1 : ~variables
V1 ~> datatype-value(I1:identifiers, V1*:values*)
V2 ~> datatype-value(I2:identifiers, V2*:values*)
-----------------------------------------------------------------------
structural-assign(V1:datatype-values, V2:datatype-values)
~> sequential(
check-true(is-equal(I1, I2)),
effect(tuple(interleave-map(
structural-assign(tuple-elements(given)),
tuple-zip(tuple(V1*), tuple(V2*))))),
null-value)
*/
Rule
dom(M1) == {}
------------------------------------------------------
structural-assign(M1:maps(_,_), M2:maps(_,_))
~> check-true(is-equal(dom(M2), { }))
Rule
some-element(dom(M1)) ~> K
----------------------------------------------------------------------------
structural-assign(M1:maps(_, _), M2:maps(_, _))
~> sequential(check-true(is-in-set(K, dom(M2))),
structural-assign(map-lookup(M1, K), map-lookup(M2, K)),
structural-assign(map-delete(M1, {K}), map-delete(M2, {K})))
Rule
V1 : ~(datatype-values|maps(_, _))
---------------------------------------------------------------
structural-assign(V1:values,V2:values)
~> check-true(is-equal(V1, V2))
Funcon
structural-assigned(_:values) : =>values
*/
Rule
structural-assigned(Var:variables) ~> assigned(Var)
Rule
V : ~variables
V ~> datatype-value(I:identifiers, V*:values*)
----------------------------------------------------------------------------
structural-assigned(V:datatype-values)
~> datatype-value(I, interleave-map(structural-assigned(given), V*))
*/
Rule
structural-assigned(M:maps(_, _))
~> map(interleave-map(structural-assigned(given), map-elements(M)))
Rule
U : ~(datatype-values|maps(_, _))
------------------------------------------
structural-assigned(U:values) ~> U
/*
A storage location is represented by an atom.