File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77#include "py/runtime.h"
88#include "py/repl.h"
99
10- void do_str (const char * src ) {
10+ void do_str (const char * src , mp_parse_input_kind_t input_kind ) {
1111 mp_lexer_t * lex = mp_lexer_new_from_str_len (MP_QSTR__lt_stdin_gt_ , src , strlen (src ), 0 );
1212 if (lex == NULL ) {
1313 return ;
@@ -16,7 +16,7 @@ void do_str(const char *src) {
1616 nlr_buf_t nlr ;
1717 if (nlr_push (& nlr ) == 0 ) {
1818 qstr source_name = lex -> source_name ;
19- mp_parse_node_t pn = mp_parse (lex , MP_PARSE_SINGLE_INPUT );
19+ mp_parse_node_t pn = mp_parse (lex , input_kind );
2020 mp_obj_t module_fun = mp_compile (pn , source_name , MP_EMIT_OPT_NONE , true);
2121 mp_call_function_0 (module_fun );
2222 nlr_pop ();
@@ -28,7 +28,8 @@ void do_str(const char *src) {
2828
2929int main (int argc , char * * argv ) {
3030 mp_init ();
31- do_str ("print('hello world!', list(x+1 for x in range(10)), end='eol\n')" );
31+ do_str ("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')" , MP_PARSE_SINGLE_INPUT );
32+ do_str ("for i in range(10):\n print(i)" , MP_PARSE_FILE_INPUT );
3233 mp_deinit ();
3334 return 0 ;
3435}
Original file line number Diff line number Diff line change 99#include "py/gc.h"
1010#include "pyexec.h"
1111
12- void do_str (const char * src ) {
12+ void do_str (const char * src , mp_parse_input_kind_t input_kind ) {
1313 mp_lexer_t * lex = mp_lexer_new_from_str_len (MP_QSTR__lt_stdin_gt_ , src , strlen (src ), 0 );
1414 if (lex == NULL ) {
1515 printf ("MemoryError: lexer could not allocate memory\n" );
@@ -19,7 +19,7 @@ void do_str(const char *src) {
1919 nlr_buf_t nlr ;
2020 if (nlr_push (& nlr ) == 0 ) {
2121 qstr source_name = lex -> source_name ;
22- mp_parse_node_t pn = mp_parse (lex , MP_PARSE_SINGLE_INPUT );
22+ mp_parse_node_t pn = mp_parse (lex , input_kind );
2323 mp_obj_t module_fun = mp_compile (pn , source_name , MP_EMIT_OPT_NONE , true);
2424 mp_call_function_0 (module_fun );
2525 nlr_pop ();
@@ -51,7 +51,8 @@ int main(int argc, char **argv) {
5151 #else
5252 pyexec_friendly_repl ();
5353 #endif
54- //do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')");
54+ //do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT);
55+ //do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT);
5556 mp_deinit ();
5657 return 0 ;
5758}
Original file line number Diff line number Diff line change 1212#include "py/gc.h"
1313#include "py/repl.h"
1414
15- void do_str (const char * src ) {
15+ void do_str (const char * src , mp_parse_input_kind_t input_kind ) {
1616 mp_lexer_t * lex = mp_lexer_new_from_str_len (MP_QSTR__lt_stdin_gt_ , src , strlen (src ), 0 );
1717 if (lex == NULL ) {
1818 return ;
@@ -21,7 +21,7 @@ void do_str(const char *src) {
2121 nlr_buf_t nlr ;
2222 if (nlr_push (& nlr ) == 0 ) {
2323 qstr source_name = lex -> source_name ;
24- mp_parse_node_t pn = mp_parse (lex , MP_PARSE_SINGLE_INPUT );
24+ mp_parse_node_t pn = mp_parse (lex , input_kind );
2525 mp_obj_t module_fun = mp_compile (pn , source_name , MP_EMIT_OPT_NONE , true);
2626 mp_call_function_0 (module_fun );
2727 nlr_pop ();
@@ -36,7 +36,7 @@ int main(int argc, char **argv) {
3636 void * heap = malloc (16 * 1024 );
3737 gc_init (heap , (char * )heap + 16 * 1024 );
3838 mp_init ();
39- do_str ("print('hello world!')" );
39+ do_str ("print('hello world!')" , MP_PARSE_SINGLE_INPUT );
4040 mp_deinit ();
4141 return 0 ;
4242}
You can’t perform that action at this time.
0 commit comments