Sunday, October 13, 2013

Program – Single Code Vector

The program model was modified to contain a single code vector of program words so that during execution, no handling of individual lines is needed.  Program execution will simply flow from one line to the next as if it was a single block of code.  This will allow for fast execution. The temporary line code vector that was added to the line info list was replaced with an offset into the single code vector and the code size of the line.

The code vector was previously just a QVector of the program words.  However, the QVector class does not have an existing function for inserting another vector into a vector.  Therefore, a new ProgramCode class was created based on the QVector class.  This was similar to the ProgramLine that was previously implemented and then removed.  This time, a new insert line routine was implemented to insert a vector (code for a line) into another vector (the single code for the program).

The new insert line routine does nothing if the line to insert is empty.  Otherwise the program is first resized to allow for the new line.  A hole is made for the new line if the insert point is not at the end of the program.  Finally, the code of the line is copied into the program code.

The update line routine was modified (insert operation only) to insert the code for a line that does not have an error.  The offset for the new line is determined.  If the new line will be at the end of the program, the offset is set to the current size of the program, otherwise the offset is set to the offset of the line being inserted before.  The size is set to the size of the line code, and the line is inserted into the program.

The update error routine was modified to return if the line being inserted has an error.  This is used to determine if the code for the line is to be inserted into the program.  If the line has an translator error, the line was not encoded, so there is no code to insert into the program, though information for the line is still inserted into the line info list.

The debug text routine previously just retrieved the code vector inserted into the line info list for a specified line.  Since this code vector was removed, this routine was modified to calculate the address of the line by adding the offset for the line to the base address of the program code vector.  The size is obtained from the new size added to the line info list.

[commit dd94ed0ef9]

Program Model Update – Encoding

The program model needs to encode lines when an update signal is received once each line has been successfully translated.  The program model update slot routine receives this signal from the edit box, which includes the line number, number of lines deleted, number of lines inserted, and a list of strings of the lines.  The type of operations needed on the program is then determined (change, insert or remove lines) and calls the update line routine to perform the operation for each line affected.

The update line routine was modified to encode the line after a successful translate.  A temporary program word vector was added to the line info list to the code for the line.  The line info list currently holds a pointer to the translated RPN list (temporary), and an index to the error list if the line has an error.  The program model will contain a single program word vector for the entire program unit with the line info list containing offsets and sizes of the lines within this vector.  This will allow execution through the program without using time dealing with lines.  Only the insert operation was modified to store the line code vector at this time.

The tester class encode input routine was modified to let the program model translate and encode the line, by calling the update slot routine directly to insert a single line to the end of the program.  An access function to the RPN list pointer was added to the program model to get the RPN list for a line to determine if there was a translation error and to get the information about the error (column, length and message).  The debug text routine was modified to take a line index argument instead of a program word pointer and a word count, which uses the line index to get the program line code and work count.  Because the program model still possesses the RPN list, the encode input routine can no longer delete it.

As a result, a token memory leak occurred (which could previously be seen when running the GUI and then exiting) because the program model was not deleting the RPN lists contained in the line info list when the application exited.  This was corrected by deleting all of the RPN lists in the program model destructor.  The tester class run routine was modified not to report token errors after each line, which will be reported when the application terminates.

[commit 49b3231acb]