Tuesday, September 24, 2013

Encoding Program Lines (Begin)

The initial version of the encode routine was implemented that takes the token list generated by the translator and converts it to a vector of program words, the contents of which will be inserted into the program.  The size for the program word vector is obtained from the token list, which was calculated at the end of a successful translation.  For now, the operand words are set to zero for instructions with an operand.  Dictionary look ups will be required to generate the indexes for the operands.

The ProgramWord class was implemented containing a single unsigned short (16-bit) word variable with instruction and operand access functions.  This class does not determine whether the word is an instruction or an operand, which is up to the user of this class.  There are access functions for getting the code from an instruction word, checking if an instruction word has a sub-code set, setting an instruction to a code and sub-code, getting the operand word, and setting the operand word.

The ProgramLine class was implemented to contain a vector of program words and is based on the QVector class of the ProgramWord class.  A class was implemented instead of just using a vector so that a text routine could be added to convert the program line into text for testing.  The instruction text and operand text routines were implemented in the ProgramWord class.  I single text could not be implemented since by itself, this class does not know whether the word is used as an instruction or an operand.

The test encode input routine was modified to call the encode routine upon a successful translation and output the encoded program line (a vector of program words) using the program line text routine.  Since the operand words are set to zero, encoder test #1 currently fails since the text for operands is do no match.  This will be handled as the dictionaries are implemented.

[commit 60add1604a]