next up previous
Next: Initialization and Execution Up: A Generated Solution Previous: Left-to-right evaluation

   
Implementing the Memory

In Section 3.2.2, two operations were used to access memory:

Operations exported by the memory abstract data type[41] :

extern void Store(CharPtr, int);
extern int Fetch(CharPtr);
This macro is invoked in definition 53.

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:

Include appropriate library modules[42] :

SPMdollar;/Scan/idn.specs
SPMdollar;/Name/envmod.specs
This macro is invoked in definition 55.

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:

Declare the ``Value'' property with integer values[43] :

Value: int;
This macro is invoked in definition 51.

Given these facilities, the C implementation of the abstract data type is quite simple:

Implementation of the memory module[44] :

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);
}
This macro is invoked in definition 52.

The variable env must be initialized before the Store and Fetch operations can be used:

Initialize the memory module[45] :

env = NewEnv();
This macro is invoked in definition 48.


next up previous
Next: Initialization and Execution Up: A Generated Solution Previous: Left-to-right evaluation
William Waite
1998-08-30