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

Remove use of globals #15

Open
alexpogostin opened this issue Dec 29, 2023 · 3 comments
Open

Remove use of globals #15

alexpogostin opened this issue Dec 29, 2023 · 3 comments

Comments

@alexpogostin
Copy link
Owner

Wow - just don't feel comfortable with all these global variables. Some of it has to do with no malloc functions?? Maybe - not a good excuse, but certainly would have been one way to solve this would have been some form of memory management, malloc type thing.

@alexpogostin
Copy link
Owner Author

alexpogostin commented Jan 7, 2024

As an example, tokenTreeIndex, which is has an extern in tasks.c and is defined in lexer.c. In tasks.c its used twice in task_3. All thats occuring is that its being set to 0. In one case its being set to zero just prior to taskControl(...) enabling task_4. Could I add an argument to taskControl(...) - a value to pass to a task? The complication becomes the issue of the corporative multitasking nature of the code? How about a setter and getter? An area of data which is basically global, but has a more managed atomic reads and writes of these shared values. The values would be assigned as static in this memory manager.

@alexpogostin
Copy link
Owner Author

With recent commit into master (a7ff768), the first steps in removing globals has begun. Started out small, that is - two integer variables used to track the integer and string numbers used in the interpreter (intNum and strNum). A new source has been added, varman (variable manager) which can now set, get and increment each of these values. The globals for both intNum and strNum have been removed.

@alexpogostin
Copy link
Owner Author

Removed two additional int globals, intVarsIndex and strVarsIndex. The next global int to remove would be tokenTreeIndex, but this one is referenced over 100 times in the code, so much more care and time needs to be taken.

@alexpogostin alexpogostin changed the title Too many globals Remove use of globals Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant