Saturday, October 5, 2013

Variable Dictionaries

When the program is run, the values for the variables need to be initialized (numbers to zero, and strings to empty).  If all three data types of variables are stored in the same dictionary, the initialization routine would need to check the data type for each variable before initializing its value.  This is not necessary if a variable dictionary contains a single data type, in which case it just has to loop through and initialize a single value type.  The variable dictionaries will not hold the actual variable values.  The run-time module will allocate and own the arrays with the values.

For now, no other information is needed in the variable dictionaries.  The variable name is stored as the dictionary key, and the data type is implied by which dictionary contains the variable.  Therefore at this moment, the base dictionary class is sufficient for the variable dictionaries.  However, eventually addition information will need to be stored with the variable.

To complete the implementation of the variable dictionaries, three dictionaries, one for each data type, were added to the program unit class with the associated allocation and access functions.  Encode and operand text routines were implemented for each of the three data types.  These routines call the add (for encode) or string (for operand text) routines of the variable dictionary for the associated data type.  These functions were placed in a the new basic.cpp source file, which will also contain the run-time routines for the variable and variable reference codes along with other miscellaneous functions (the two rem functions were also moved into this file).

Finally, pointers to these functions were placed in the six table entries for these codes (variable and variable reference times the three data types).  Several new statements were added to encoder test #1 so that there are more than one variable of each data type.  The expected results file for this test was updated for the variable names that are now in the output along with the output of the new statements.

[commit 2843b44761]

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)