-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py: Move all global state (variables) to a common place. #1017
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
Conversation
This is allows to keep track of where all the global variables are.
This is apparently good change, especially if it leads to code savings. Would need to review in more detail regarding what's included and what's not. Some things to think about alongside this change:
|
Glad you agree this is a good path to follow. The PR is messy, but the idea is there.
Yes, we can have a (sub)struct for heap/gc variables.
Yes, definitely. It was on my agenda to have different structs for data, bss, and bss-containing-root-pointers. Just didn't know the cleanest way to do it yet. |
That might become a messy git log afterwards which becomes harder to investigate due to mixing (sort of) seperate issues. If the plan is to move away from Plan 9 anyway, consider doing that in one single commit and then build upon that? For the rest: there should be only benefits to reducing the amount of global state so this is definitely a good thing |
Yeah, ok. I'll do a separate PR for that. |
Note that, to support proper globals/locals context switching when calling functions, we should have an "outer" global state object which is small, easy to fit on the stack, and easy to change globals/locals. Something like: struct mpy_ctx_t {
mp_obj_dict_t *globals, *locals;
mp_heap_state_t *heap_state;
mp_interp_state_t *interp_state;
}; Possibly don't need to separate heap_state and interp_state here. |
This PR is now waiting on #1022. |
Superseded by #1032. |
This is allows to keep track of where all the global variables are, and will help if we ever want to have a global state object to pass to each function. Although code size was not a reason for doing this, the change actually gives some savings of code size: about 60 bytes on x64, and 200 bytes (!) on stmhal.
This is for review only, and is still a bit messy. It also includes a partial move away from Plan 9 style header includes.
Comments welcome!