Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
d66ae186
Commit
d66ae186
authored
Apr 10, 2014
by
Damien George
Browse files
py: Simplify stack get/set to become stack adjust in emitters.
Can do this now that the stack size calculation is improved.
parent
069a35e3
Changes
6
Hide whitespace changes
Inline
Side-by-side
py/compile.c
View file @
d66ae186
...
...
@@ -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
(
s
e
t_stack_size
,
EMIT
(
get_stack_size
)
-
1
);
EMIT_ARG
(
adju
st_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
(
ge
t_stack_size
)
+
6
);
// stack adjust for the 3 exception items, +3 for possible UNWIND_JUMP state
EMIT_ARG
(
adjus
t_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
(
ge
t_stack_size
)
+
3
);
// stack adjust for the 3 exception items
EMIT_ARG
(
adjus
t_stack_size
,
3
);
// stack adjust for the 3 exception items
}
compile_decrease_except_level
(
comp
);
EMIT
(
end_finally
);
EMIT_ARG
(
s
e
t_stack_size
,
EMIT
(
get_stack_size
)
-
5
);
// stack adjust
EMIT_ARG
(
adju
st_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
(
ge
t_stack_size
)
+
3
);
// stack adjust for possible UNWIND_JUMP state
EMIT_ARG
(
adjus
t_stack_size
,
3
);
// stack adjust for possible UNWIND_JUMP state
compile_node
(
comp
,
pn_body
);
EMIT_ARG
(
s
e
t_stack_size
,
EMIT
(
get_stack_size
)
-
3
);
EMIT_ARG
(
adju
st_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
(
s
e
t_stack_size
,
EMIT
(
get_stack_size
)
-
1
);
// adjust stack size
EMIT_ARG
(
adju
st_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
(
ge
t_stack_size
)
+
1
);
EMIT_ARG
(
adjus
t_stack_size
,
1
);
EMIT
(
rot_two
);
EMIT
(
pop_top
);
EMIT_ARG
(
label_assign
,
l_end
);
...
...
py/emit.h
View file @
d66ae186
...
...
@@ -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
);
...
...
py/emitbc.c
View file @
d66ae186
...
...
@@ -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
,
...
...
py/emitcpy.c
View file @
d66ae186
...
...
@@ -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
,
...
...
py/emitnative.c
View file @
d66ae186
...
...
@@ -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
,
...
...
py/emitpass1.c
View file @
d66ae186
...
...
@@ -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
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment