summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-04-07 00:08:17 +0100
committerDamien George <damien.p.george@gmail.com>2015-04-07 00:08:17 +0100
commitc9aa1883ed87da61d5745036dc55c382c3f4d6ca (patch)
treed4967e844be00547c329f38606f4ac3fc7fc4728 /py
parent78772ada0ddc9222c0338f94a42e33e10bb24b55 (diff)
downloadmicropython-c9aa1883ed87da61d5745036dc55c382c3f4d6ca.tar.gz
micropython-c9aa1883ed87da61d5745036dc55c382c3f4d6ca.zip
py: Simplify bytecode prelude when encoding closed over variables.
Diffstat (limited to 'py')
-rw-r--r--py/bc.c7
-rw-r--r--py/emitbc.c11
-rw-r--r--py/showbc.c6
3 files changed, 8 insertions, 16 deletions
diff --git a/py/bc.c b/py/bc.c
index af855e9474..865065ab19 100644
--- a/py/bc.c
+++ b/py/bc.c
@@ -228,9 +228,10 @@ continue2:;
// bytecode prelude: initialise closed over variables
const byte *ip = code_state->ip;
- for (mp_uint_t n_local = *ip++; n_local > 0; n_local--) {
- mp_uint_t local_num = *ip++;
- code_state->state[n_state - 1 - local_num] = mp_obj_new_cell(code_state->state[n_state - 1 - local_num]);
+ mp_uint_t local_num;
+ while ((local_num = *ip++) != 255) {
+ code_state->state[n_state - 1 - local_num] =
+ mp_obj_new_cell(code_state->state[n_state - 1 - local_num]);
}
// now that we skipped over the prelude, set the ip for the VM
diff --git a/py/emitbc.c b/py/emitbc.c
index 70267bd7cc..f55fa964be 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -322,21 +322,14 @@ void mp_emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
}
// bytecode prelude: initialise closed over variables
- int num_cell = 0;
- for (int i = 0; i < scope->id_info_len; i++) {
- id_info_t *id = &scope->id_info[i];
- if (id->kind == ID_INFO_KIND_CELL) {
- num_cell += 1;
- }
- }
- assert(num_cell <= 255);
- emit_write_bytecode_byte(emit, num_cell); // write number of locals that are cells
for (int i = 0; i < scope->id_info_len; i++) {
id_info_t *id = &scope->id_info[i];
if (id->kind == ID_INFO_KIND_CELL) {
+ assert(id->local_num < 255);
emit_write_bytecode_byte(emit, id->local_num); // write the local which should be converted to a cell
}
}
+ emit_write_bytecode_byte(emit, 255); // end of list sentinel
}
void mp_emit_bc_end_pass(emit_t *emit) {
diff --git a/py/showbc.c b/py/showbc.c
index 3a468326db..c9eeaff9fa 100644
--- a/py/showbc.c
+++ b/py/showbc.c
@@ -95,10 +95,8 @@ void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *ip
// bytecode prelude: initialise closed over variables
{
- uint n_local = *ip++;
- printf("(NUM_LOCAL %u)\n", n_local);
- for (; n_local > 0; n_local--) {
- uint local_num = *ip++;
+ uint local_num;
+ while ((local_num = *ip++) != 255) {
printf("(INIT_CELL %u)\n", local_num);
}
len -= ip - mp_showbc_code_start;