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

[Bug] REPL auto-import does not work. #741

Closed
laurensvalk opened this issue Oct 20, 2022 · 9 comments
Closed

[Bug] REPL auto-import does not work. #741

laurensvalk opened this issue Oct 20, 2022 · 9 comments
Assignees
Labels
bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime)

Comments

@laurensvalk
Copy link
Member

When starting the REPL, everything in the pybricks package is supposed to be pre-imported.

This no longer works because:

    for (size_t i = 0; i < MP_ARRAY_SIZE(pybricks_globals_table); i++) {
        mp_rom_obj_t module = pybricks_globals_table[i].value;
        if (mp_obj_is_type(module, &mp_type_module)) {
            // Import everything from the module.
            mp_import_all((mp_obj_t)module);
        }
    }

and the modules are no longer included in pybricks_globals_table.

@laurensvalk laurensvalk added bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) labels Oct 20, 2022
@laurensvalk laurensvalk self-assigned this Oct 20, 2022
@laurensvalk
Copy link
Member Author

While we are doing this, we could consider importing everything, including those from MicroPython modules. I'll have a look at the RAM cost.

@laurensvalk
Copy link
Member Author

laurensvalk commented Oct 20, 2022

While we are doing this, we could consider importing everything, including those from MicroPython modules. I'll have a look at the RAM cost

On Prime Hub, when importing everything:

stack: 604 out of 36976
GC: total: 259008, used: 2272, free: 256736
 No. of 1-blocks: 14, 2-blocks: 3, max blk sz: 112, max free sz: 15915

When importing only pybricks modules (+36 bytes build size for the check):

stack: 604 out of 36976
GC: total: 259008, used: 1008, free: 258000
 No. of 1-blocks: 20, 2-blocks: 4, max blk sz: 19, max free sz: 16116

So, about 1.2K extra heap used for importing everything from the (currently included) MicroPython modules.

Now check on Move Hub. Oh wait, no REPL. 😆

So I think we can just import everything. If anyone ever needs the REPL and use RAM to the limits, they can just run an empty script that raises the KeyboardInterrupt.

@dlech
Copy link
Member

dlech commented Oct 20, 2022

Are we sure that there are and never will be name conflicts for importing * from *? It seems like it would be safer to import * from pybricks modules but import module for everything else.

@laurensvalk
Copy link
Member Author

OK, I'll restore importing Pybricks modules only.

@laurensvalk laurensvalk reopened this Oct 20, 2022
@dlech
Copy link
Member

dlech commented Oct 20, 2022

I like the idea of importing the other modules too. Maybe we could import * if module starts with pybricks else import module?

@laurensvalk
Copy link
Member Author

Sure. Will do that tomorrow.

@laurensvalk
Copy link
Member Author

mp_import_name and several other related calls just fetch the module but don't register it as loaded. Simply doing it like pybricks/pybricks-micropython@7b57a7a works though.

@dlech
Copy link
Member

dlech commented Oct 21, 2022

can this be closed now?

@laurensvalk
Copy link
Member Author

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime)
Projects
None yet
Development

No branches or pull requests

2 participants