blob: 27c206ce398218703d5af91fd899f7be845cd3f6 [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2013, 2014 Damien P. George
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
Dave Hylandsf14b92b2014-03-12 18:06:26 -070027#include <stdlib.h>
Dave Hylandsf14b92b2014-03-12 18:06:26 -070028#include <stdio.h>
Dave Hylands4f1b7fe2014-06-15 22:33:14 -070029#include <stdint.h>
Dave Hylandsf14b92b2014-03-12 18:06:26 -070030
Damien George2cf6dfa2015-01-01 21:06:20 +000031#include "py/nlr.h"
Damien George2cf6dfa2015-01-01 21:06:20 +000032#include "py/compile.h"
33#include "py/runtime.h"
34#include "py/repl.h"
35#include "py/gc.h"
36#include "py/pfenv.h"
Paul Sokolovskybf195862014-12-20 20:45:01 +020037#ifdef MICROPY_HAL_H
Damien George7a37f642014-07-02 13:42:37 +010038#include MICROPY_HAL_H
Paul Sokolovskybf195862014-12-20 20:45:01 +020039#endif
Damien Georgec9fd6642014-03-29 14:20:05 +000040#include "readline.h"
Dave Hylandsf14b92b2014-03-12 18:06:26 -070041#include "pyexec.h"
Damien Georged553be52014-04-17 18:03:27 +010042#include "genhdr/py-version.h"
Dave Hylandsf14b92b2014-03-12 18:06:26 -070043
Damien Georgef704e7f2014-03-24 12:23:37 +000044pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
45STATIC bool repl_display_debugging_info = 0;
Dave Hylandsf14b92b2014-03-12 18:06:26 -070046
Damien Georgebc1488a2014-10-26 15:39:22 +000047#define EXEC_FLAG_PRINT_EOF (1)
48#define EXEC_FLAG_ALLOW_DEBUGGING (2)
49#define EXEC_FLAG_IS_REPL (4)
50
Dave Hylandsf14b92b2014-03-12 18:06:26 -070051// parses, compiles and executes the code in the lexer
52// frees the lexer before returning
Damien Georgebc1488a2014-10-26 15:39:22 +000053// EXEC_FLAG_PRINT_EOF prints 2 EOF chars: 1 after normal output, 1 after exception output
54// EXEC_FLAG_ALLOW_DEBUGGING allows debugging info to be printed after executing the code
55// EXEC_FLAG_IS_REPL is used for REPL inputs (flag passed on to mp_compile)
56STATIC int parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, int exec_flags) {
57 int ret = 0;
Damien George0bfc7632015-02-07 18:33:58 +000058 uint32_t start = 0;
Damien Georgebc1488a2014-10-26 15:39:22 +000059
Dave Hylandsf14b92b2014-03-12 18:06:26 -070060 nlr_buf_t nlr;
Dave Hylandsf14b92b2014-03-12 18:06:26 -070061 if (nlr_push(&nlr) == 0) {
Damien George0bfc7632015-02-07 18:33:58 +000062 // parse and compile the script
63 qstr source_name = lex->source_name;
64 mp_parse_node_t pn = mp_parse(lex, input_kind);
65 mp_obj_t module_fun = mp_compile(pn, source_name, MP_EMIT_OPT_NONE, exec_flags & EXEC_FLAG_IS_REPL);
66
67 // execute code
Damien George5cbc9e02014-11-27 16:58:31 +000068 mp_hal_set_interrupt_char(CHAR_CTRL_C); // allow ctrl-C to interrupt us
Damien George0bfc7632015-02-07 18:33:58 +000069 start = HAL_GetTick();
Damien Georged17926d2014-03-30 13:35:08 +010070 mp_call_function_0(module_fun);
Damien George5cbc9e02014-11-27 16:58:31 +000071 mp_hal_set_interrupt_char(-1); // disable interrupt
Dave Hylandsf14b92b2014-03-12 18:06:26 -070072 nlr_pop();
Dave Hylands8d62bbd2014-10-21 23:04:38 -070073 ret = 1;
Damien Georgebc1488a2014-10-26 15:39:22 +000074 if (exec_flags & EXEC_FLAG_PRINT_EOF) {
Damien George0b32e502015-02-13 15:04:53 +000075 mp_hal_stdout_tx_strn("\x04", 1);
Damien Georgebc1488a2014-10-26 15:39:22 +000076 }
Dave Hylandsf14b92b2014-03-12 18:06:26 -070077 } else {
78 // uncaught exception
79 // FIXME it could be that an interrupt happens just before we disable it here
Damien George5cbc9e02014-11-27 16:58:31 +000080 mp_hal_set_interrupt_char(-1); // disable interrupt
Damien Georgebc1488a2014-10-26 15:39:22 +000081 // print EOF after normal output
82 if (exec_flags & EXEC_FLAG_PRINT_EOF) {
Damien George0b32e502015-02-13 15:04:53 +000083 mp_hal_stdout_tx_strn("\x04", 1);
Damien Georgebc1488a2014-10-26 15:39:22 +000084 }
Dave Hylands8d62bbd2014-10-21 23:04:38 -070085 // check for SystemExit
Damien George3be69842014-10-22 19:13:28 +010086 if (mp_obj_is_subclass_fast(mp_obj_get_type((mp_obj_t)nlr.ret_val), &mp_type_SystemExit)) {
87 // at the moment, the value of SystemExit is unused
88 ret = PYEXEC_FORCED_EXIT;
89 } else {
Paul Sokolovsky46c3ab22014-12-06 14:29:09 +020090 mp_obj_print_exception(printf_wrapper, NULL, (mp_obj_t)nlr.ret_val);
Damien George3be69842014-10-22 19:13:28 +010091 ret = 0;
Dave Hylands8d62bbd2014-10-21 23:04:38 -070092 }
Dave Hylandsf14b92b2014-03-12 18:06:26 -070093 }
94
95 // display debugging info if wanted
Damien Georgebc1488a2014-10-26 15:39:22 +000096 if ((exec_flags & EXEC_FLAG_ALLOW_DEBUGGING) && repl_display_debugging_info) {
Damien George5cbc9e02014-11-27 16:58:31 +000097 mp_uint_t ticks = HAL_GetTick() - start; // TODO implement a function that does this properly
98 printf("took " UINT_FMT " ms\n", ticks);
Dave Hylandsf14b92b2014-03-12 18:06:26 -070099 gc_collect();
100 // qstr info
101 {
Damien Georged03c6812014-10-05 21:51:54 +0100102 mp_uint_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700103 qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
Damien Georged03c6812014-10-05 21:51:54 +0100104 printf("qstr:\n n_pool=" UINT_FMT "\n n_qstr=" UINT_FMT "\n n_str_data_bytes=" UINT_FMT "\n n_total_bytes=" UINT_FMT "\n", n_pool, n_qstr, n_str_data_bytes, n_total_bytes);
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700105 }
106
107 // GC info
Paul Sokolovsky6aaccc42014-12-21 00:24:58 +0200108 gc_dump_info();
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700109 }
110
Damien Georgebc1488a2014-10-26 15:39:22 +0000111 if (exec_flags & EXEC_FLAG_PRINT_EOF) {
Damien George0b32e502015-02-13 15:04:53 +0000112 mp_hal_stdout_tx_strn("\x04", 1);
Damien Georgebc1488a2014-10-26 15:39:22 +0000113 }
114
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700115 return ret;
116}
117
Damien Georgef704e7f2014-03-24 12:23:37 +0000118int pyexec_raw_repl(void) {
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700119 vstr_t line;
120 vstr_init(&line, 32);
121
122raw_repl_reset:
Damien George0b32e502015-02-13 15:04:53 +0000123 mp_hal_stdout_tx_str("raw REPL; CTRL-B to exit\r\n");
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700124
125 for (;;) {
126 vstr_reset(&line);
Damien George0b32e502015-02-13 15:04:53 +0000127 mp_hal_stdout_tx_str(">");
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700128 for (;;) {
Damien George0b32e502015-02-13 15:04:53 +0000129 int c = mp_hal_stdin_rx_chr();
Damien George5cbc9e02014-11-27 16:58:31 +0000130 if (c == CHAR_CTRL_A) {
Damien Georgef704e7f2014-03-24 12:23:37 +0000131 // reset raw REPL
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700132 goto raw_repl_reset;
Damien George5cbc9e02014-11-27 16:58:31 +0000133 } else if (c == CHAR_CTRL_B) {
Damien Georgef704e7f2014-03-24 12:23:37 +0000134 // change to friendly REPL
Damien George0b32e502015-02-13 15:04:53 +0000135 mp_hal_stdout_tx_str("\r\n");
Damien Georgef704e7f2014-03-24 12:23:37 +0000136 vstr_clear(&line);
137 pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
138 return 0;
Damien George5cbc9e02014-11-27 16:58:31 +0000139 } else if (c == CHAR_CTRL_C) {
Damien Georgef704e7f2014-03-24 12:23:37 +0000140 // clear line
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700141 vstr_reset(&line);
Damien George5cbc9e02014-11-27 16:58:31 +0000142 } else if (c == CHAR_CTRL_D) {
Damien Georgef704e7f2014-03-24 12:23:37 +0000143 // input finished
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700144 break;
Damien Georged8b47d32014-04-03 22:11:43 +0100145 } else if (c <= 127) {
146 // let through any other ASCII character
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700147 vstr_add_char(&line, c);
148 }
149 }
150
Damien Georgef704e7f2014-03-24 12:23:37 +0000151 // indicate reception of command
Damien George0b32e502015-02-13 15:04:53 +0000152 mp_hal_stdout_tx_str("OK");
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700153
Damien Georgef704e7f2014-03-24 12:23:37 +0000154 if (line.len == 0) {
155 // exit for a soft reset
Damien George0b32e502015-02-13 15:04:53 +0000156 mp_hal_stdout_tx_str("\r\n");
Damien Georgef704e7f2014-03-24 12:23:37 +0000157 vstr_clear(&line);
Dave Hylands8d62bbd2014-10-21 23:04:38 -0700158 return PYEXEC_FORCED_EXIT;
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700159 }
160
Damien Georgef704e7f2014-03-24 12:23:37 +0000161 mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, line.buf, line.len, 0);
Damien Georgeb0edec62014-05-10 17:48:46 +0100162 if (lex == NULL) {
Damien Georgebc1488a2014-10-26 15:39:22 +0000163 printf("\x04MemoryError\n\x04");
Damien Georgeb0edec62014-05-10 17:48:46 +0100164 } else {
Damien Georgebc1488a2014-10-26 15:39:22 +0000165 int ret = parse_compile_execute(lex, MP_PARSE_FILE_INPUT, EXEC_FLAG_PRINT_EOF);
Dave Hylands8d62bbd2014-10-21 23:04:38 -0700166 if (ret & PYEXEC_FORCED_EXIT) {
167 return ret;
168 }
Damien Georgeb0edec62014-05-10 17:48:46 +0100169 }
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700170 }
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700171}
172
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200173#if MICROPY_REPL_EVENT_DRIVEN
174
175typedef struct _friendly_repl_t {
176 vstr_t line;
177 bool cont_line;
178} friendly_repl_t;
179
180friendly_repl_t repl;
181
182void pyexec_friendly_repl_init(void) {
183 vstr_init(&repl.line, 32);
184 repl.cont_line = false;
185 readline_init(&repl.line);
Damien George0b32e502015-02-13 15:04:53 +0000186 mp_hal_stdout_tx_str(">>> ");
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200187}
188
189void pyexec_friendly_repl_reset() {
190 repl.cont_line = false;
191 vstr_reset(&repl.line);
192 readline_init(&repl.line);
193}
194
195int pyexec_friendly_repl_process_char(int c) {
196 int ret = readline_process_char(c);
197
198 if (!repl.cont_line) {
199
200 if (ret == CHAR_CTRL_A) {
201 // change to raw REPL
202 pyexec_mode_kind = PYEXEC_MODE_RAW_REPL;
Damien George0b32e502015-02-13 15:04:53 +0000203 mp_hal_stdout_tx_str("\r\n");
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200204 vstr_clear(&repl.line);
205 return PYEXEC_SWITCH_MODE;
206 } else if (ret == CHAR_CTRL_B) {
207 // reset friendly REPL
Damien George0b32e502015-02-13 15:04:53 +0000208 mp_hal_stdout_tx_str("\r\n");
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200209 goto friendly_repl_reset;
210 } else if (ret == CHAR_CTRL_C) {
211 // break
Damien George0b32e502015-02-13 15:04:53 +0000212 mp_hal_stdout_tx_str("\r\n");
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200213 goto input_restart;
214 } else if (ret == CHAR_CTRL_D) {
215 // exit for a soft reset
Damien George0b32e502015-02-13 15:04:53 +0000216 mp_hal_stdout_tx_str("\r\n");
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200217 vstr_clear(&repl.line);
218 return PYEXEC_FORCED_EXIT;
219 } else if (vstr_len(&repl.line) == 0) {
220 //goto input_restart;
221 }
222
223 if (ret < 0) {
224 return 0;
225 }
226
Damien George827b0f72015-01-29 13:57:23 +0000227 if (!mp_repl_continue_with_input(vstr_null_terminated_str(&repl.line))) {
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200228 goto exec;
229 }
230
Damien George0d3cb672015-01-28 23:43:01 +0000231 vstr_add_byte(&repl.line, '\n');
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200232 repl.cont_line = true;
Damien George0b32e502015-02-13 15:04:53 +0000233 mp_hal_stdout_tx_str("... ");
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200234 readline_note_newline();
235 return 0;
236
237 } else {
238
239 if (ret == CHAR_CTRL_C) {
240 // cancel everything
Damien George0b32e502015-02-13 15:04:53 +0000241 mp_hal_stdout_tx_str("\r\n");
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200242 repl.cont_line = false;
243 goto input_restart;
244 } else if (ret == CHAR_CTRL_D) {
245 // stop entering compound statement
246 goto exec;
247 }
248
249 if (ret < 0) {
250 return 0;
251 }
252
Damien George827b0f72015-01-29 13:57:23 +0000253 if (mp_repl_continue_with_input(vstr_null_terminated_str(&repl.line))) {
Damien George0d3cb672015-01-28 23:43:01 +0000254 vstr_add_byte(&repl.line, '\n');
Damien George0b32e502015-02-13 15:04:53 +0000255 mp_hal_stdout_tx_str("... ");
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200256 readline_note_newline();
257 return 0;
258 }
259
260exec: ;
261 mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, vstr_str(&repl.line), vstr_len(&repl.line), 0);
262 if (lex == NULL) {
263 printf("MemoryError\n");
264 } else {
265 int ret = parse_compile_execute(lex, MP_PARSE_SINGLE_INPUT, EXEC_FLAG_ALLOW_DEBUGGING | EXEC_FLAG_IS_REPL);
266 if (ret & PYEXEC_FORCED_EXIT) {
267 return ret;
268 }
269 }
270
271friendly_repl_reset: // TODO
272input_restart:
273 pyexec_friendly_repl_reset();
Damien George0b32e502015-02-13 15:04:53 +0000274 mp_hal_stdout_tx_str(">>> ");
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200275 return 0;
276 }
277}
278
279#else //MICROPY_REPL_EVENT_DRIVEN
280
Damien Georgef704e7f2014-03-24 12:23:37 +0000281int pyexec_friendly_repl(void) {
282 vstr_t line;
283 vstr_init(&line, 32);
284
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700285#if defined(USE_HOST_MODE) && MICROPY_HW_HAS_LCD
286 // in host mode, we enable the LCD for the repl
Damien Georged17926d2014-03-30 13:35:08 +0100287 mp_obj_t lcd_o = mp_call_function_0(mp_load_name(qstr_from_str("LCD")));
288 mp_call_function_1(mp_load_attr(lcd_o, qstr_from_str("light")), mp_const_true);
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700289#endif
290
Damien Georgef704e7f2014-03-24 12:23:37 +0000291friendly_repl_reset:
Damien George0b32e502015-02-13 15:04:53 +0000292 mp_hal_stdout_tx_str("Micro Python " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE "; " MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME "\r\n");
293 mp_hal_stdout_tx_str("Type \"help()\" for more information.\r\n");
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700294
295 // to test ctrl-C
296 /*
297 {
298 uint32_t x[4] = {0x424242, 0xdeaddead, 0x242424, 0xdeadbeef};
299 for (;;) {
300 nlr_buf_t nlr;
301 printf("pyexec_repl: %p\n", x);
Damien George5cbc9e02014-11-27 16:58:31 +0000302 mp_hal_set_interrupt_char(CHAR_CTRL_C);
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700303 if (nlr_push(&nlr) == 0) {
304 for (;;) {
305 }
306 } else {
307 printf("break\n");
308 }
309 }
310 }
311 */
312
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700313 for (;;) {
Damien Georgebc1488a2014-10-26 15:39:22 +0000314 input_restart:
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700315 vstr_reset(&line);
316 int ret = readline(&line, ">>> ");
317
Damien George5cbc9e02014-11-27 16:58:31 +0000318 if (ret == CHAR_CTRL_A) {
Damien Georgef704e7f2014-03-24 12:23:37 +0000319 // change to raw REPL
Damien George0b32e502015-02-13 15:04:53 +0000320 mp_hal_stdout_tx_str("\r\n");
Damien Georgef704e7f2014-03-24 12:23:37 +0000321 vstr_clear(&line);
322 pyexec_mode_kind = PYEXEC_MODE_RAW_REPL;
323 return 0;
Damien George5cbc9e02014-11-27 16:58:31 +0000324 } else if (ret == CHAR_CTRL_B) {
Damien Georgef704e7f2014-03-24 12:23:37 +0000325 // reset friendly REPL
Damien George0b32e502015-02-13 15:04:53 +0000326 mp_hal_stdout_tx_str("\r\n");
Damien Georgef704e7f2014-03-24 12:23:37 +0000327 goto friendly_repl_reset;
Damien George5cbc9e02014-11-27 16:58:31 +0000328 } else if (ret == CHAR_CTRL_C) {
Damien Georgef704e7f2014-03-24 12:23:37 +0000329 // break
Damien George0b32e502015-02-13 15:04:53 +0000330 mp_hal_stdout_tx_str("\r\n");
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700331 continue;
Damien George5cbc9e02014-11-27 16:58:31 +0000332 } else if (ret == CHAR_CTRL_D) {
Damien Georgef704e7f2014-03-24 12:23:37 +0000333 // exit for a soft reset
Damien George0b32e502015-02-13 15:04:53 +0000334 mp_hal_stdout_tx_str("\r\n");
Damien Georgef704e7f2014-03-24 12:23:37 +0000335 vstr_clear(&line);
Dave Hylands8d62bbd2014-10-21 23:04:38 -0700336 return PYEXEC_FORCED_EXIT;
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700337 } else if (vstr_len(&line) == 0) {
338 continue;
339 }
340
Damien George827b0f72015-01-29 13:57:23 +0000341 while (mp_repl_continue_with_input(vstr_null_terminated_str(&line))) {
Damien George0d3cb672015-01-28 23:43:01 +0000342 vstr_add_byte(&line, '\n');
Damien George50912e72015-01-20 11:55:10 +0000343 ret = readline(&line, "... ");
Damien George5cbc9e02014-11-27 16:58:31 +0000344 if (ret == CHAR_CTRL_C) {
Damien Georgebc1488a2014-10-26 15:39:22 +0000345 // cancel everything
Damien George0b32e502015-02-13 15:04:53 +0000346 mp_hal_stdout_tx_str("\r\n");
Damien Georgebc1488a2014-10-26 15:39:22 +0000347 goto input_restart;
Damien George5cbc9e02014-11-27 16:58:31 +0000348 } else if (ret == CHAR_CTRL_D) {
Damien George97790452014-04-08 11:04:29 +0000349 // stop entering compound statement
350 break;
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700351 }
352 }
353
354 mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, vstr_str(&line), vstr_len(&line), 0);
Damien Georgeb0edec62014-05-10 17:48:46 +0100355 if (lex == NULL) {
356 printf("MemoryError\n");
357 } else {
Damien George50912e72015-01-20 11:55:10 +0000358 ret = parse_compile_execute(lex, MP_PARSE_SINGLE_INPUT, EXEC_FLAG_ALLOW_DEBUGGING | EXEC_FLAG_IS_REPL);
Dave Hylands8d62bbd2014-10-21 23:04:38 -0700359 if (ret & PYEXEC_FORCED_EXIT) {
360 return ret;
361 }
Damien Georgeb0edec62014-05-10 17:48:46 +0100362 }
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700363 }
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700364}
365
Paul Sokolovsky87bc8e22015-01-15 10:46:27 +0200366#endif //MICROPY_REPL_EVENT_DRIVEN
367
Damien George3be69842014-10-22 19:13:28 +0100368int pyexec_file(const char *filename) {
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700369 mp_lexer_t *lex = mp_lexer_new_from_file(filename);
370
371 if (lex == NULL) {
372 printf("could not open file '%s' for reading\n", filename);
373 return false;
374 }
375
Damien Georgebc1488a2014-10-26 15:39:22 +0000376 return parse_compile_execute(lex, MP_PARSE_FILE_INPUT, 0);
Dave Hylandsf14b92b2014-03-12 18:06:26 -0700377}
378
379mp_obj_t pyb_set_repl_info(mp_obj_t o_value) {
380 repl_display_debugging_info = mp_obj_get_int(o_value);
381 return mp_const_none;
382}
383
384MP_DEFINE_CONST_FUN_OBJ_1(pyb_set_repl_info_obj, pyb_set_repl_info);