summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-09-24 13:15:57 +0100
committerDamien George <damien.p.george@gmail.com>2015-09-24 13:15:57 +0100
commit9d5e5c08ab1ee417251420a13573a951d3bf1ce8 (patch)
treedcdff588c88e167ea34c3adcd62fa998b1fb4073
parent5572f735b65cb4704725966d5437564501ceb673 (diff)
downloadmicropython-9d5e5c08ab1ee417251420a13573a951d3bf1ce8.tar.gz
micropython-9d5e5c08ab1ee417251420a13573a951d3bf1ce8.zip
py/compile: Put compiler state on the C stack.
It's relatively small (between 44 and 56 bytes) and helps to reduce heap pressure and fragmentation during compilation.
-rw-r--r--py/compile.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/py/compile.c b/py/compile.c
index 82a27bb0b8..e00af60ad6 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
- * Copyright (c) 2013, 2014 Damien P. George
+ * Copyright (c) 2013-2015 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -3316,10 +3316,12 @@ STATIC void scope_compute_things(scope_t *scope) {
}
mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is_repl) {
- compiler_t *comp = m_new0(compiler_t, 1);
+ // put compiler state on the stack, it's relatively small
+ compiler_t comp_state = {0};
+ compiler_t *comp = &comp_state;
+
comp->source_file = source_file;
comp->is_repl = is_repl;
- comp->compile_error = MP_OBJ_NULL;
// create the module scope
scope_t *module_scope = scope_new_and_link(comp, SCOPE_MODULE, pn, emit_opt);
@@ -3339,10 +3341,6 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is
#if MICROPY_EMIT_NATIVE
comp->emit_method_table = &emit_bc_method_table;
#endif
- #if MICROPY_EMIT_INLINE_THUMB
- comp->emit_inline_asm = NULL;
- comp->emit_inline_asm_method_table = NULL;
- #endif
uint max_num_labels = 0;
for (scope_t *s = comp->scope_head; s != NULL && comp->compile_error == MP_OBJ_NULL; s = s->next) {
if (false) {
@@ -3495,12 +3493,8 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, uint emit_opt, bool is
s = next;
}
- // free the compiler
- mp_obj_t compile_error = comp->compile_error;
- m_del_obj(compiler_t, comp);
-
- if (compile_error != MP_OBJ_NULL) {
- nlr_raise(compile_error);
+ if (comp->compile_error != MP_OBJ_NULL) {
+ nlr_raise(comp->compile_error);
} else {
// return function that executes the outer module
return mp_make_function_from_raw_code(outer_raw_code, MP_OBJ_NULL, MP_OBJ_NULL);