Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code generator #37

Merged
merged 5 commits into from
Feb 20, 2024
Merged

Refactor code generator #37

merged 5 commits into from
Feb 20, 2024

Conversation

deleterium
Copy link
Owner

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.

@deleterium
Copy link
Owner Author

Almost all code changed was renaming variables and/or moving code to another file. New code added for two minor issues and to create a new property in register to control their life and releasing time: endurance: 'Standard' | 'Scope' | 'Sentence'

@deleterium deleterium merged commit bc2c7dc into main Feb 20, 2024
2 checks passed
@deleterium deleterium deleted the refactorCodeGenerator branch February 20, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant