In Section 3.2.2, two operations were used to access memory:
This macro is invoked in definition 53.
extern void Store(CharPtr, int);
extern int Fetch(CharPtr);
This section defines an abstract data type that implements those operations by using library facilities and a bit of C code.
The Eli library provides facilities to recognize identical identifiers, map identifiers to entities, and associate properties with entities. A memory for the interpreter can be easily implemented using such facilities, although they offer considerably more power than this simple application requires. The first step is to make the identifier recognition and mapping operations part of the specification:
This macro is invoked in definition 55.
SPMdollar;/Scan/idn.specs
SPMdollar;/Name/envmod.specs
Since any arbitrary set of properties can be associated with an entity, those desired for this application must be specified. A special property definition language is used for this purpose:
This macro is invoked in definition 51.
Value: int;
Given these facilities, the C implementation of the abstract data type is quite simple:
This macro is invoked in definition 52.
Environment env;
void
Store(char* id, int val)
{ int sym, class = 1;
mkidn(id, strlen(id), &sym, &class);
ResetValue(DefineIdn(env, sym), val);
}
int
Fetch(char* id)
{ int sym, class = 1;
mkidn(id, strlen(id), &sym, &class);
return GetValue(DefineIdn(env, sym),0);
}
The variable env must be initialized before the Store and Fetch operations can be used: