Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The object 'gencode AuxVars' in code generator was traversing the entire AST, and the 'setupGenCode auxVars' was used only in file codeGenerator.ts. Also in some points the object
Program
was not accessible. This caused some variables needed to be updated in two places, like the "jumpId".To make things simpler, both auxVars objects (from setupGenCode and genCode) were merged and renamed to Program.Context, making more sense. So the object Program was enough to store all variables and methods needed. The variables needed by each sentence were grouped in an object at Program.Context.SentenceContext.
Also all code related to the Context was moved to a new file
Context.ts
, making easier to check/maintain the code.In this way, the registersInfo was not needed to be created every sentence. They are build at start of compilation and can better handle the scoped registers. Found then two bugs were registers were not released after used.
A side effect is that the Program.Context object needs to reference other properties in Program (like Program.memory[]), so it cannot be initialized in just one step. So the Program object is initialized on SmartC class without the Context (that's why we ignore an error there) and the Context is initialized on constructor, passing the Program to the Context creator.