Commit b829b5ca authored by Damien George's avatar Damien George
Browse files

Implement mp_parse_node_free; print properly repr(string).

parent e0722ee9
...@@ -24,13 +24,13 @@ static mp_obj_t mp_builtin_eval(mp_obj_t o_in) { ...@@ -24,13 +24,13 @@ static mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
const byte *str = mp_obj_str_get_data(o_in, &str_len); const byte *str = mp_obj_str_get_data(o_in, &str_len);
// create the lexer // create the lexer
mp_lexer_t *lex = mp_lexer_new_from_str_len("<string>", (const char*)str, str_len, 0); mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_string_gt_, (const char*)str, str_len, 0);
qstr source_name = mp_lexer_source_name(lex);
// parse the string // parse the string
qstr parse_exc_id; qstr parse_exc_id;
const char *parse_exc_msg; const char *parse_exc_msg;
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_EVAL_INPUT, &parse_exc_id, &parse_exc_msg); mp_parse_node_t pn = mp_parse(lex, MP_PARSE_EVAL_INPUT, &parse_exc_id, &parse_exc_msg);
qstr source_name = mp_lexer_source_name(lex);
mp_lexer_free(lex); mp_lexer_free(lex);
if (pn == MP_PARSE_NODE_NULL) { if (pn == MP_PARSE_NODE_NULL) {
...@@ -40,6 +40,7 @@ static mp_obj_t mp_builtin_eval(mp_obj_t o_in) { ...@@ -40,6 +40,7 @@ static mp_obj_t mp_builtin_eval(mp_obj_t o_in) {
// compile the string // compile the string
mp_obj_t module_fun = mp_compile(pn, source_name, false); mp_obj_t module_fun = mp_compile(pn, source_name, false);
mp_parse_node_free(pn);
if (module_fun == mp_const_none) { if (module_fun == mp_const_none) {
// TODO handle compile error correctly // TODO handle compile error correctly
......
...@@ -29,9 +29,7 @@ mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) { ...@@ -29,9 +29,7 @@ mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) {
} }
*/ */
uint mod_name_l; qstr mod_name = mp_obj_str_get_qstr(args[0]);
const byte *mod_name_s = mp_obj_str_get_data(args[0], &mod_name_l);
qstr mod_name = qstr_from_strn((const char*)mod_name_s, mod_name_l);
mp_obj_t loaded = mp_obj_module_get(mod_name); mp_obj_t loaded = mp_obj_module_get(mod_name);
if (loaded != MP_OBJ_NULL) { if (loaded != MP_OBJ_NULL) {
...@@ -44,6 +42,7 @@ mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) { ...@@ -44,6 +42,7 @@ mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) {
// TODO handle lexer error correctly // TODO handle lexer error correctly
return mp_const_none; return mp_const_none;
} }
qstr source_name = mp_lexer_source_name(lex);
// create a new module object // create a new module object
mp_obj_t module_obj = mp_obj_new_module(mod_name); mp_obj_t module_obj = mp_obj_new_module(mod_name);
...@@ -60,7 +59,6 @@ mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) { ...@@ -60,7 +59,6 @@ mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) {
qstr parse_exc_id; qstr parse_exc_id;
const char *parse_exc_msg; const char *parse_exc_msg;
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT, &parse_exc_id, &parse_exc_msg); mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT, &parse_exc_id, &parse_exc_msg);
qstr source_name = mp_lexer_source_name(lex);
mp_lexer_free(lex); mp_lexer_free(lex);
if (pn == MP_PARSE_NODE_NULL) { if (pn == MP_PARSE_NODE_NULL) {
...@@ -72,6 +70,7 @@ mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) { ...@@ -72,6 +70,7 @@ mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) {
// compile the imported script // compile the imported script
mp_obj_t module_fun = mp_compile(pn, source_name, false); mp_obj_t module_fun = mp_compile(pn, source_name, false);
mp_parse_node_free(pn);
if (module_fun == mp_const_none) { if (module_fun == mp_const_none) {
// TODO handle compile error correctly // TODO handle compile error correctly
......
...@@ -192,29 +192,26 @@ static void print_quoted_str(qstr qstr, bool bytes) { ...@@ -192,29 +192,26 @@ static void print_quoted_str(qstr qstr, bool bytes) {
if (bytes) { if (bytes) {
printf("b"); printf("b");
} }
bool quote_single = false; int quote_char = '\'';
if (has_single_quote && !has_double_quote) { if (has_single_quote && !has_double_quote) {
printf("\""); quote_char = '"';
} else {
quote_single = true;
printf("'");
} }
for (int i = 0; i < len; i++) { printf("%c", quote_char);
if (str[i] == '\n') { for (const char *s = str, *top = str + len; s < top; s++) {
printf("\\n"); if (*s == quote_char) {
} else if (str[i] == '\\') { printf("\\%c", quote_char);
} else if (*s == '\\') {
printf("\\\\"); printf("\\\\");
} else if (str[i] == '\'' && quote_single) { } else if (32 <= *s && *s <= 126) {
printf("\\'"); printf("%c", *s);
} else if (*s == '\n') {
printf("\\n");
// TODO add more escape codes here
} else { } else {
printf("%c", str[i]); printf("\\x%02x", (*s) & 0xff);
} }
} }
if (has_single_quote && !has_double_quote) { printf("%c", quote_char);
printf("\"");
} else {
printf("'");
}
} }
static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) { static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) {
......
...@@ -493,8 +493,8 @@ static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs ...@@ -493,8 +493,8 @@ static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
} }
c = num; c = num;
} else { } else {
// TODO error message // unrecognised escape character; CPython lets this through verbatim as '\' and then the character
assert(0); vstr_add_char(&lex->vstr, '\\');
} }
break; break;
} }
...@@ -644,10 +644,10 @@ static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs ...@@ -644,10 +644,10 @@ static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
} }
} }
mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_stream_next_char_t stream_next_char, mp_lexer_stream_close_t stream_close) { mp_lexer_t *mp_lexer_new(qstr src_name, void *stream_data, mp_lexer_stream_next_char_t stream_next_char, mp_lexer_stream_close_t stream_close) {
mp_lexer_t *lex = m_new(mp_lexer_t, 1); mp_lexer_t *lex = m_new(mp_lexer_t, 1);
lex->source_name = qstr_from_str(src_name); lex->source_name = src_name;
lex->stream_data = stream_data; lex->stream_data = stream_data;
lex->stream_next_char = stream_next_char; lex->stream_next_char = stream_next_char;
lex->stream_close = stream_close; lex->stream_close = stream_close;
......
...@@ -124,8 +124,8 @@ typedef struct _mp_lexer_t mp_lexer_t; ...@@ -124,8 +124,8 @@ typedef struct _mp_lexer_t mp_lexer_t;
void mp_token_show(const mp_token_t *tok); void mp_token_show(const mp_token_t *tok);
mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_stream_next_char_t stream_next_char, mp_lexer_stream_close_t stream_close); mp_lexer_t *mp_lexer_new(qstr src_name, void *stream_data, mp_lexer_stream_next_char_t stream_next_char, mp_lexer_stream_close_t stream_close);
mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, uint free_len); mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, uint len, uint free_len);
void mp_lexer_free(mp_lexer_t *lex); void mp_lexer_free(mp_lexer_t *lex);
qstr mp_lexer_source_name(mp_lexer_t *lex); qstr mp_lexer_source_name(mp_lexer_t *lex);
......
...@@ -28,7 +28,7 @@ static void str_buf_free(mp_lexer_str_buf_t *sb) { ...@@ -28,7 +28,7 @@ static void str_buf_free(mp_lexer_str_buf_t *sb) {
m_del_obj(mp_lexer_str_buf_t, sb); m_del_obj(mp_lexer_str_buf_t, sb);
} }
mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, uint free_len) { mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, uint len, uint free_len) {
mp_lexer_str_buf_t *sb = m_new_obj(mp_lexer_str_buf_t); mp_lexer_str_buf_t *sb = m_new_obj(mp_lexer_str_buf_t);
sb->free_len = free_len; sb->free_len = free_len;
sb->src_beg = str; sb->src_beg = str;
......
...@@ -28,7 +28,7 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) { ...@@ -28,7 +28,7 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
return NULL; return NULL;
} }
return mp_lexer_new_from_str_len(filename, data, size, size); return mp_lexer_new_from_str_len(qstr_from_str(filename), data, size, size);
} }
/******************************************************************************/ /******************************************************************************/
......
...@@ -287,6 +287,7 @@ mp_obj_t mp_obj_str_builder_end(mp_obj_t o_in); ...@@ -287,6 +287,7 @@ mp_obj_t mp_obj_str_builder_end(mp_obj_t o_in);
bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2); bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2);
uint mp_obj_str_get_hash(mp_obj_t self_in); uint mp_obj_str_get_hash(mp_obj_t self_in);
uint mp_obj_str_get_len(mp_obj_t self_in); uint mp_obj_str_get_len(mp_obj_t self_in);
qstr mp_obj_str_get_qstr(mp_obj_t self_in); // use this if you will anyway convert the string to a qstr
const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need the string to be null terminated const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need the string to be null terminated
const byte *mp_obj_str_get_data(mp_obj_t self_in, uint *len); const byte *mp_obj_str_get_data(mp_obj_t self_in, uint *len);
......
...@@ -40,11 +40,39 @@ void str_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj ...@@ -40,11 +40,39 @@ void str_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj
if (kind == PRINT_STR && !is_bytes) { if (kind == PRINT_STR && !is_bytes) {
print(env, "%.*s", str_len, str_data); print(env, "%.*s", str_len, str_data);
} else { } else {
// this escapes characters, but it will be very slow to print (calling print many times)
bool has_single_quote = false;
bool has_double_quote = false;
for (const byte *s = str_data, *top = str_data + str_len; (!has_single_quote || !has_double_quote) && s < top; s++) {
if (*s == '\'') {
has_single_quote = true;
} else if (*s == '"') {
has_double_quote = true;
}
}
if (is_bytes) { if (is_bytes) {
print(env, "b"); print(env, "b");
} }
// TODO need to escape chars etc int quote_char = '\'';
print(env, "'%.*s'", str_len, str_data); if (has_single_quote && !has_double_quote) {
quote_char = '"';
}
print(env, "%c", quote_char);
for (const byte *s = str_data, *top = str_data + str_len; s < top; s++) {
if (*s == quote_char) {
print(env, "\\%c", quote_char);
} else if (*s == '\\') {
print(env, "\\\\");
} else if (32 <= *s && *s <= 126) {
print(env, "%c", *s);
} else if (*s == '\n') {
print(env, "\\n");
// TODO add more escape codes here if we want to match CPython
} else {
print(env, "\\x%02x", *s);
}
}
print(env, "%c", quote_char);
} }
} }
...@@ -474,13 +502,17 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) { ...@@ -474,13 +502,17 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) {
} }
} }
void bad_implicit_conversion(mp_obj_t self_in) __attribute__((noreturn));
void bad_implicit_conversion(mp_obj_t self_in) {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "Can't convert '%s' object to str implicitly", mp_obj_get_type_str(self_in)));
}
uint mp_obj_str_get_hash(mp_obj_t self_in) { uint mp_obj_str_get_hash(mp_obj_t self_in) {
if (MP_OBJ_IS_STR(self_in)) { if (MP_OBJ_IS_STR(self_in)) {
GET_STR_HASH(self_in, h); GET_STR_HASH(self_in, h);
return h; return h;
} else { } else {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "Can't convert '%s' object to str implicitly", bad_implicit_conversion(self_in);
mp_obj_get_type_str(self_in)));
} }
} }
...@@ -489,8 +521,20 @@ uint mp_obj_str_get_len(mp_obj_t self_in) { ...@@ -489,8 +521,20 @@ uint mp_obj_str_get_len(mp_obj_t self_in) {
GET_STR_LEN(self_in, l); GET_STR_LEN(self_in, l);
return l; return l;
} else { } else {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "Can't convert '%s' object to str implicitly", bad_implicit_conversion(self_in);
mp_obj_get_type_str(self_in))); }
}
// use this if you will anyway convert the string to a qstr
// will be more efficient for the case where it's already a qstr
qstr mp_obj_str_get_qstr(mp_obj_t self_in) {
if (MP_OBJ_IS_QSTR(self_in)) {
return MP_OBJ_QSTR_VALUE(self_in);
} else if (MP_OBJ_IS_TYPE(self_in, &str_type)) {
mp_obj_str_t *self = self_in;
return qstr_from_strn((char*)self->data, self->len);
} else {
bad_implicit_conversion(self_in);
} }
} }
...@@ -502,8 +546,7 @@ const char *mp_obj_str_get_str(mp_obj_t self_in) { ...@@ -502,8 +546,7 @@ const char *mp_obj_str_get_str(mp_obj_t self_in) {
(void)l; // len unused (void)l; // len unused
return (const char*)s; return (const char*)s;
} else { } else {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "Can't convert '%s' object to str implicitly", bad_implicit_conversion(self_in);
mp_obj_get_type_str(self_in)));
} }
} }
...@@ -513,8 +556,7 @@ const byte *mp_obj_str_get_data(mp_obj_t self_in, uint *len) { ...@@ -513,8 +556,7 @@ const byte *mp_obj_str_get_data(mp_obj_t self_in, uint *len) {
*len = l; *len = l;
return s; return s;
} else { } else {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "Can't convert '%s' object to str implicitly", bad_implicit_conversion(self_in);
mp_obj_get_type_str(self_in)));
} }
} }
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#define RULE_ARG_OPT_TOK (0x3000) #define RULE_ARG_OPT_TOK (0x3000)
#define RULE_ARG_OPT_RULE (0x4000) #define RULE_ARG_OPT_RULE (0x4000)
#define ADD_BLANK_NODE(rule_id) ((rule_id) == RULE_funcdef || (rule_id) == RULE_classdef || (rule_id) == RULE_comp_for || (rule_id) == RULE_lambdef || (rule_id) == RULE_lambdef_nocond)
// (un)comment to use rule names; for debugging // (un)comment to use rule names; for debugging
//#define USE_RULE_NAME (1) //#define USE_RULE_NAME (1)
...@@ -135,15 +137,23 @@ mp_parse_node_struct_t *parse_node_new_struct(int src_line, int rule_id, int num ...@@ -135,15 +137,23 @@ mp_parse_node_struct_t *parse_node_new_struct(int src_line, int rule_id, int num
return pn; return pn;
} }
int parse_node_free_struct(mp_parse_node_t pn_in) { uint mp_parse_node_free(mp_parse_node_t pn) {
int cnt = 0; uint cnt = 0;
if (MP_PARSE_NODE_IS_STRUCT(pn_in)) { if (MP_PARSE_NODE_IS_STRUCT(pn)) {
mp_parse_node_struct_t *pn = (mp_parse_node_struct_t *)pn_in; mp_parse_node_struct_t *pns = (mp_parse_node_struct_t *)pn;
int n = pn->kind_num_nodes >> 8; uint n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
for (int i = 0; i < n; i++) { uint rule_id = MP_PARSE_NODE_STRUCT_KIND(pns);
cnt += parse_node_free_struct(pn->nodes[i]); bool adjust = ADD_BLANK_NODE(rule_id);
if (adjust) {
n--;
}
for (uint i = 0; i < n; i++) {
cnt += mp_parse_node_free(pns->nodes[i]);
}
if (adjust) {
n++;
} }
m_del_var(mp_parse_node_struct_t, mp_parse_node_t, n, pn); m_del_var(mp_parse_node_struct_t, mp_parse_node_t, n, pns);
cnt++; cnt++;
} }
return cnt; return cnt;
...@@ -174,15 +184,15 @@ void mp_parse_node_print(mp_parse_node_t pn, int indent) { ...@@ -174,15 +184,15 @@ void mp_parse_node_print(mp_parse_node_t pn, int indent) {
default: assert(0); default: assert(0);
} }
} else { } else {
mp_parse_node_struct_t *pns2 = (mp_parse_node_struct_t*)pn; mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
int n = pns2->kind_num_nodes >> 8; uint n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
#ifdef USE_RULE_NAME #ifdef USE_RULE_NAME
printf("%s(%d) (n=%d)\n", rules[MP_PARSE_NODE_STRUCT_KIND(pns2)]->rule_name, MP_PARSE_NODE_STRUCT_KIND(pns2), n); printf("%s(%d) (n=%d)\n", rules[MP_PARSE_NODE_STRUCT_KIND(pns)]->rule_name, MP_PARSE_NODE_STRUCT_KIND(pns), n);
#else #else
printf("rule(%u) (n=%d)\n", (uint)MP_PARSE_NODE_STRUCT_KIND(pns2), n); printf("rule(%u) (n=%d)\n", (uint)MP_PARSE_NODE_STRUCT_KIND(pns), n);
#endif #endif
for (int i = 0; i < n; i++) { for (uint i = 0; i < n; i++) {
mp_parse_node_print(pns2->nodes[i], indent + 2); mp_parse_node_print(pns->nodes[i], indent + 2);
} }
} }
} }
...@@ -472,7 +482,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, qstr ...@@ -472,7 +482,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, qstr
} }
// always emit these rules, and add an extra blank node at the end (to be used by the compiler to store data) // always emit these rules, and add an extra blank node at the end (to be used by the compiler to store data)
if (rule->rule_id == RULE_funcdef || rule->rule_id == RULE_classdef || rule->rule_id == RULE_comp_for || rule->rule_id == RULE_lambdef || rule->rule_id == RULE_lambdef_nocond) { if (ADD_BLANK_NODE(rule->rule_id)) {
emit_rule = true; emit_rule = true;
push_result_node(parser, MP_PARSE_NODE_NULL); push_result_node(parser, MP_PARSE_NODE_NULL);
i += 1; i += 1;
......
...@@ -53,7 +53,7 @@ typedef struct _mp_parse_node_struct_t { ...@@ -53,7 +53,7 @@ typedef struct _mp_parse_node_struct_t {
#define MP_PARSE_NODE_STRUCT_NUM_NODES(pns) ((pns)->kind_num_nodes >> 8) #define MP_PARSE_NODE_STRUCT_NUM_NODES(pns) ((pns)->kind_num_nodes >> 8)
mp_parse_node_t mp_parse_node_new_leaf(machine_int_t kind, machine_int_t arg); mp_parse_node_t mp_parse_node_new_leaf(machine_int_t kind, machine_int_t arg);
int parse_node_free_struct(mp_parse_node_t pn_in); uint mp_parse_node_free(mp_parse_node_t pn);
void mp_parse_node_print(mp_parse_node_t pn, int indent); void mp_parse_node_print(mp_parse_node_t pn, int indent);
......
...@@ -91,4 +91,5 @@ Q(<listcomp>) ...@@ -91,4 +91,5 @@ Q(<listcomp>)
Q(<dictcomp>) Q(<dictcomp>)
Q(<setcomp>) Q(<setcomp>)
Q(<genexpr>) Q(<genexpr>)
Q(<string>)
Q(<stdin>) Q(<stdin>)
...@@ -49,7 +49,7 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) { ...@@ -49,7 +49,7 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
f_read(&fb->fp, fb->buf, sizeof(fb->buf), &n); f_read(&fb->fp, fb->buf, sizeof(fb->buf), &n);
fb->len = n; fb->len = n;
fb->pos = 0; fb->pos = 0;
return mp_lexer_new(filename, fb, (mp_lexer_stream_next_char_t)file_buf_next_char, (mp_lexer_stream_close_t)file_buf_close); return mp_lexer_new(qstr_from_str(filename), fb, (mp_lexer_stream_next_char_t)file_buf_next_char, (mp_lexer_stream_close_t)file_buf_close);
} }
/******************************************************************************/ /******************************************************************************/
......
...@@ -378,7 +378,7 @@ void do_repl(void) { ...@@ -378,7 +378,7 @@ void do_repl(void) {
} }
} }
mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", vstr_str(&line), vstr_len(&line), 0); mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, vstr_str(&line), vstr_len(&line), 0);
qstr parse_exc_id; qstr parse_exc_id;
const char *parse_exc_msg; const char *parse_exc_msg;
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT, &parse_exc_id, &parse_exc_msg); mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT, &parse_exc_id, &parse_exc_msg);
...@@ -393,6 +393,7 @@ void do_repl(void) { ...@@ -393,6 +393,7 @@ void do_repl(void) {
// parse okay // parse okay
mp_lexer_free(lex); mp_lexer_free(lex);
mp_obj_t module_fun = mp_compile(pn, source_name, true); mp_obj_t module_fun = mp_compile(pn, source_name, true);
mp_parse_node_free(pn);
if (module_fun != mp_const_none) { if (module_fun != mp_const_none) {
nlr_buf_t nlr; nlr_buf_t nlr;
uint32_t start = sys_tick_counter; uint32_t start = sys_tick_counter;
...@@ -439,6 +440,8 @@ bool do_file(const char *filename) { ...@@ -439,6 +440,8 @@ bool do_file(const char *filename) {
mp_lexer_free(lex); mp_lexer_free(lex);
mp_obj_t module_fun = mp_compile(pn, source_name, false); mp_obj_t module_fun = mp_compile(pn, source_name, false);
mp_parse_node_free(pn);
if (module_fun == mp_const_none) { if (module_fun == mp_const_none) {
return false; return false;
} }
......
...@@ -62,7 +62,6 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind ...@@ -62,7 +62,6 @@ static void execute_from_lexer(mp_lexer_t *lex, mp_parse_input_kind_t input_kind
*/ */
mp_obj_t module_fun = mp_compile(pn, source_name, is_repl); mp_obj_t module_fun = mp_compile(pn, source_name, is_repl);
parse_node_free_struct(pn);
if (module_fun == mp_const_none) { if (module_fun == mp_const_none) {
// compile error // compile error
...@@ -139,7 +138,7 @@ static void do_repl(void) { ...@@ -139,7 +138,7 @@ static void do_repl(void) {
} }
} }
mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", line, strlen(line), false); mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, line, strlen(line), false);
execute_from_lexer(lex, MP_PARSE_SINGLE_INPUT, true); execute_from_lexer(lex, MP_PARSE_SINGLE_INPUT, true);
free(line); free(line);
} }
...@@ -163,7 +162,7 @@ static void do_file(const char *file) { ...@@ -163,7 +162,7 @@ static void do_file(const char *file) {
} }
static void do_str(const char *str) { static void do_str(const char *str) {
mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", str, strlen(str), false); mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, str, strlen(str), false);
execute_from_lexer(lex, MP_PARSE_SINGLE_INPUT, false); execute_from_lexer(lex, MP_PARSE_SINGLE_INPUT, false);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment