*.mpy-files seem not be executed by µP

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Thomas Bartzick
Posts: 3
Joined: Tue Mar 01, 2022 12:29 pm
Location: Germany

*.mpy-files seem not be executed by µP

Post by Thomas Bartzick » Tue Mar 01, 2022 12:49 pm

My dear fellow 'pythoniers',

I am using µP v1.13 in a RTOS-embedded system.

I would like to use pre-compiled bytecode or native code executing my µP-script under RTOS-environment in order to get higher execution performance.

So, as long I know, that my *.py does already work fine, I do the following steps:

(1) mpy-cross -march x85 -X emit=native MyScript.py (=> MyScript.mpy)
(2) Calling "ret = do_file(pathfilename.mpy);" in C-code on my embedded platform (as like with the *.py-script before).

This will invoke the following chain of process:
(3) do_file(...) => execute_from_lexer(...) => mp_lexer_new_from_file(...) => mp_reader_new_file(...) => {file-opening...} => mp_reader_new_file_from_fd(...) => parse_tree = mp_parse(...) => module_fun = mp_compile(...) => mp_call_function_0(...)

All these functions except to file-operation are part of the µP-C-code, included in my project and seem to work fine for *.py-files.
But as it comes to byte- or native-code, parsing the code leads to a µP-exception.

There is either a problem with the *.mpy-code or with the way I do processing it. :?

So, please, can anybody give me a hint, what's wrong?

Most regards,
Thomas

PS: Following the call-stack shows, that the parser gets a syntax-error:
> ImageAtBase0xb7c30000!mp_parse(_mp_lexer_t * lex, mp_parse_input_kind_t input_kind) Line 962 C
ImageAtBase0xb7c30000!execute_from_lexer(int source_kind, const void * source, mp_parse_input_kind_t input_kind, bool is_repl) Line 147 C
ImageAtBase0xb7c30000!do_file(const char * file) Line 432 C
ImageAtBase0xb7c30000!mpymain_(const unsigned char nSelPYC, const unsigned char * const cpcFFID) Line 635 C
ImageAtBase0xb7c30000!mpymain(const unsigned char nSelPYC, const unsigned char * const cpcFFID) Line 455 C
[External Code]

Code-snippit including the line mentioned above:
mp_token_kind_t tok_kind = rule_arg & RULE_ARG_ARG_MASK;
if (lex->tok_kind == tok_kind) {
// matched token
if (tok_kind == MP_TOKEN_NAME) {
push_result_token(&parser, rule_id);
}
mp_lexer_to_next(lex);
} else {
// failed to match token
if (i > 0) {
// already eaten tokens so can't backtrack
goto syntax_error;
} else {
// this rule failed, so backtrack
backtrack = true;
goto next_rule;
}
}

Post Reply