how to merge two mp_raw_code_t

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

how to merge two mp_raw_code_t

Post by jickster » Mon Dec 11, 2017 3:56 pm

If you have a `.py`, you can compile the whole file and execute it as one entity . . . but using example in pyexec_friendly_repl(), you can also compile and execute it one "block" at a time using MP_PARSE_SINGLE_INPUT.


Code: Select all

        // got a line with non-zero length, see if it needs continuing
            while (mp_repl_continue_with_input(vstr_null_terminated_str(&line))) {
                vstr_add_byte(&line, '\n');
                ret = readline(&line, "... ");
                if (ret == CHAR_CTRL_C) {
                    // cancel everything
                    mp_hal_stdout_tx_str("\r\n");
                    goto input_restart;
                } else if (ret == CHAR_CTRL_D) {
                    // stop entering compound statement
                    break;
                }
            }


Compiling a block (or a file) returns an mp_raw_code_t. If you compile first block then execute it, you'll be executing a mp_raw_code_t and same will be true for the next block and the next . . . until you reach the end of the file.

Question is: how do you combine two mp_raw_code_t into one? It should definitely be possible since each block is independent of the next with respect to compilation.

Post Reply