Page 1 of 1

how to merge two mp_raw_code_t

Posted: Mon Dec 11, 2017 3:56 pm
by jickster
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.