py: Simplify stack get/set to become stack adjust in emitters.

Can do this now that the stack size calculation is improved.
This commit is contained in:
Damien George 2014-04-10 17:28:54 +00:00
parent 069a35e3a5
commit d66ae18640
6 changed files with 18 additions and 39 deletions

View File

@ -1595,7 +1595,7 @@ void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var,
EMIT_ARG(label_assign, top_label);
// at this point we actually have 1 less element on the stack
EMIT_ARG(set_stack_size, EMIT(get_stack_size) - 1);
EMIT_ARG(adjust_stack_size, -1);
// store next value to var
c_assign(comp, pn_var, ASSIGN_STORE);
@ -1728,7 +1728,7 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
EMIT_ARG(jump, success_label); // jump over exception handler
EMIT_ARG(label_assign, l1); // start of exception handler
EMIT_ARG(set_stack_size, EMIT(get_stack_size) + 6); // stack adjust for the 3 exception items, +3 for possible UNWIND_JUMP state
EMIT_ARG(adjust_stack_size, 6); // stack adjust for the 3 exception items, +3 for possible UNWIND_JUMP state
uint l2 = comp_next_label(comp);
@ -1795,12 +1795,12 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
}
EMIT_ARG(jump, l2);
EMIT_ARG(label_assign, end_finally_label);
EMIT_ARG(set_stack_size, EMIT(get_stack_size) + 3); // stack adjust for the 3 exception items
EMIT_ARG(adjust_stack_size, 3); // stack adjust for the 3 exception items
}
compile_decrease_except_level(comp);
EMIT(end_finally);
EMIT_ARG(set_stack_size, EMIT(get_stack_size) - 5); // stack adjust
EMIT_ARG(adjust_stack_size, -5); // stack adjust
EMIT_ARG(label_assign, success_label);
compile_node(comp, pn_else); // else block, can be null
@ -1815,9 +1815,9 @@ void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n_except
if (n_except == 0) {
assert(MP_PARSE_NODE_IS_NULL(pn_else));
EMIT_ARG(set_stack_size, EMIT(get_stack_size) + 3); // stack adjust for possible UNWIND_JUMP state
EMIT_ARG(adjust_stack_size, 3); // stack adjust for possible UNWIND_JUMP state
compile_node(comp, pn_body);
EMIT_ARG(set_stack_size, EMIT(get_stack_size) - 3);
EMIT_ARG(adjust_stack_size, -3);
} else {
compile_try_except(comp, pn_body, n_except, pn_except, pn_else);
}
@ -2027,7 +2027,7 @@ void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[0]); // success value
EMIT_ARG(jump, l_end);
EMIT_ARG(label_assign, l_fail);
EMIT_ARG(set_stack_size, EMIT(get_stack_size) - 1); // adjust stack size
EMIT_ARG(adjust_stack_size, -1); // adjust stack size
compile_node(comp, pns_test_if_else->nodes[1]); // failure value
EMIT_ARG(label_assign, l_end);
}
@ -2134,7 +2134,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
uint l_end = comp_next_label(comp);
EMIT_ARG(jump, l_end);
EMIT_ARG(label_assign, l_fail);
EMIT_ARG(set_stack_size, EMIT(get_stack_size) + 1);
EMIT_ARG(adjust_stack_size, 1);
EMIT(rot_two);
EMIT(pop_top);
EMIT_ARG(label_assign, l_end);

View File

@ -24,8 +24,7 @@ typedef struct _emit_method_table_t {
void (*start_pass)(emit_t *emit, pass_kind_t pass, scope_t *scope);
void (*end_pass)(emit_t *emit);
bool (*last_emit_was_return_value)(emit_t *emit);
int (*get_stack_size)(emit_t *emit);
void (*set_stack_size)(emit_t *emit, int size);
void (*adjust_stack_size)(emit_t *emit, int delta);
void (*set_line_number)(emit_t *emit, int line);
void (*load_id)(emit_t *emit, qstr qstr);

View File

@ -292,12 +292,8 @@ STATIC bool emit_bc_last_emit_was_return_value(emit_t *emit) {
return emit->last_emit_was_return_value;
}
STATIC int emit_bc_get_stack_size(emit_t *emit) {
return emit->stack_size;
}
STATIC void emit_bc_set_stack_size(emit_t *emit, int size) {
emit->stack_size = size;
STATIC void emit_bc_adjust_stack_size(emit_t *emit, int delta) {
emit->stack_size += delta;
}
STATIC void emit_bc_set_source_line(emit_t *emit, int source_line) {
@ -836,8 +832,7 @@ const emit_method_table_t emit_bc_method_table = {
emit_bc_start_pass,
emit_bc_end_pass,
emit_bc_last_emit_was_return_value,
emit_bc_get_stack_size,
emit_bc_set_stack_size,
emit_bc_adjust_stack_size,
emit_bc_set_source_line,
emit_bc_load_id,

View File

@ -60,12 +60,8 @@ STATIC bool emit_cpy_last_emit_was_return_value(emit_t *emit) {
return emit->last_emit_was_return_value;
}
STATIC int emit_cpy_get_stack_size(emit_t *emit) {
return emit->stack_size;
}
STATIC void emit_cpy_set_stack_size(emit_t *emit, int size) {
emit->stack_size = size;
STATIC void emit_cpy_adjust_stack_size(emit_t *emit, int delta) {
emit->stack_size += delta;
}
STATIC void emit_cpy_set_source_line(emit_t *emit, int source_line) {
@ -793,8 +789,7 @@ const emit_method_table_t emit_cpython_method_table = {
emit_cpy_start_pass,
emit_cpy_end_pass,
emit_cpy_last_emit_was_return_value,
emit_cpy_get_stack_size,
emit_cpy_set_stack_size,
emit_cpy_adjust_stack_size,
emit_cpy_set_source_line,
emit_cpy_load_id,

View File

@ -295,12 +295,8 @@ STATIC bool emit_native_last_emit_was_return_value(emit_t *emit) {
return emit->last_emit_was_return_value;
}
STATIC int emit_native_get_stack_size(emit_t *emit) {
return emit->stack_size;
}
STATIC void emit_native_set_stack_size(emit_t *emit, int size) {
emit->stack_size = size;
STATIC void emit_native_adjust_stack_size(emit_t *emit, int delta) {
emit->stack_size += delta;
}
STATIC void emit_native_set_source_line(emit_t *emit, int source_line) {
@ -1304,8 +1300,7 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
emit_native_start_pass,
emit_native_end_pass,
emit_native_last_emit_was_return_value,
emit_native_get_stack_size,
emit_native_set_stack_size,
emit_native_adjust_stack_size,
emit_native_set_source_line,
emit_native_load_id,

View File

@ -39,10 +39,6 @@ STATIC bool emit_pass1_last_emit_was_return_value(emit_t *emit) {
return false;
}
STATIC int emit_pass1_get_stack_size(emit_t *emit) {
return 0;
}
STATIC void emit_pass1_load_id(emit_t *emit, qstr qstr) {
// name adding/lookup
bool added;
@ -108,7 +104,6 @@ const emit_method_table_t emit_pass1_method_table = {
emit_pass1_start_pass,
emit_pass1_end_pass,
emit_pass1_last_emit_was_return_value,
emit_pass1_get_stack_size,
(void*)emit_pass1_dummy,
(void*)emit_pass1_dummy,