Hello,
Sorry, this is a LONG post! To answer such a short question.
The first part of the post is a high level description of the existing system that I am trying to integrate µPython in. This (relatively large) system is pre-existing and non-negotiable. I was given the task to make µPython work in the system and do not have the freedom to change the system to make it work with µPython. This part is, in some way, a justification of my needs for the various
The second part describes the various technical issues that comes from the fact that I need to integrate the systems together. You can jump straight to the second part if you want to, but you will miss some of the context/justification for the asks.
--------------------- Part 1: The system that I am integrating µPython in
This is an embedded OS (single thread) with a call back driven GUI for interaction with the user.
The user facing GUI has 2 important concepts:
1) The "screen" concept
- This is a full screen GUI.
- There is always one and only one Screen active view at a time.
- The user can seamlessly switch from one screen to another. The Screen state needs to be preserved when entering/exiting a screen (so that you return to the same state when returning to the same screen).
- They are 2 types of Screens. System Screens (not context dependent) and "app" Screens which depend on the active app.
2) The "App" concept
- There is always ONE single active app
- “App” group functionality, “Screens” and user data
- An “App” is at the same time comparable to a class and an object instance. With the functionally and “screens” part of the class and the user data being an object instance. The user can have as many copies (object instances) of the app as he wants.
- The user can switch app whenever he wants. The app states must be preserved.
- Python will be an “App” of the system.
---------------------------------- Part 2: The issues that I am trying to fix/work around
The Python "app" in my system will present the user with an interactive "screen" (REPL loop).
-----
This interactive screen has to work through a call back system. So I need to break the current REPL into 3 parts: repl_init, repl_step(user entered text) and repl_end.
I have actually succeeded in doing so (at least I think so). The only issue that I am still facing is on the use of the “mp_stack_ctrl_init” calls.
Doing the init only at the top of the repl_init function does not work because the stack size/pos when executing repl_init does not match the stack size/pos when executing repl_step. I have therefore placed a call to mp_stack_ctrl_init at the top of each of the 3 repl functions.
How much trouble will that cause?
-----
When the user exits the interactive python area, I need to save the state and restore it when he returns for the user to feel that there is continuity of operation.
One issue is that I am memory limited so, if I allocate 1MB for the heap, but that only 5KB are used, I will waste a LOT of ram that I do not have the luxury to waste.
- Is there anyway to "compress" the RAM through the garbage?
- Could the garbage "clear" unused area (set them to 0) so that a zip could be applied to it to avoid needless use of memory?
----
Python is not the only thing running on the system, and my users can switch from one screen to another.
The "fixed size" heap allocation is therefore problematic; It would be great if the load/save state and GC system allowed memory compress (regroup?) and resize as this would allow a much nicer interaction with the rest of the system.
----
Question on re-entrance.
The system already has a native programming language (well 2 of them to be precise). And is highly extensible through user programs.
I am planning to add some python to native system hooks to allow python to call on existing system functionally to allow python and the native system to interact and to allow python programmers to use existing stuff (native, or user enhanced).
One issue is. If the user has created a native user program that in turn calls a Python sub-program. What will happen if said user was to create a python program calling the native user program? Ie: Python calls native that calls python again. Will it work? Does µPython store data in global variables that will cause things to break?
----
And debugging in all that?
It would be nice if µPython had a way to debug code
I think that this is it for the moment. Thanks for taking the time to try to help me. I am in the early stages of the integration process, so I am having a hard time, but hopefully, it will get better!
Cyrille