Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
6f355fd3
Commit
6f355fd3
authored
Apr 10, 2014
by
Damien George
Browse files
py: Make labels unsigned ints (converted from int).
Labels should never be negative, and this modified type signature reflects that.
parent
bf8ae4d9
Changes
8
Hide whitespace changes
Inline
Side-by-side
py/asmthumb.c
View file @
6f355fd3
...
...
@@ -22,7 +22,7 @@ struct _asm_thumb_t {
byte
*
code_base
;
byte
dummy_data
[
8
];
int
max_num_labels
;
u
int
max_num_labels
;
int
*
label_offsets
;
int
num_locals
;
uint
push_reglist
;
...
...
@@ -212,7 +212,7 @@ void asm_thumb_exit(asm_thumb_t *as) {
asm_thumb_write_op16
(
as
,
OP_POP_RLIST_PC
(
as
->
push_reglist
));
}
void
asm_thumb_label_assign
(
asm_thumb_t
*
as
,
int
label
)
{
void
asm_thumb_label_assign
(
asm_thumb_t
*
as
,
u
int
label
)
{
assert
(
label
<
as
->
max_num_labels
);
if
(
as
->
pass
==
ASM_THUMB_PASS_2
)
{
// assign label offset
...
...
@@ -225,7 +225,7 @@ void asm_thumb_label_assign(asm_thumb_t *as, int label) {
}
}
STATIC
int
get_label_dest
(
asm_thumb_t
*
as
,
int
label
)
{
STATIC
int
get_label_dest
(
asm_thumb_t
*
as
,
u
int
label
)
{
assert
(
label
<
as
->
max_num_labels
);
return
as
->
label_offsets
[
label
];
}
...
...
@@ -308,7 +308,7 @@ void asm_thumb_ite_ge(asm_thumb_t *as) {
#define OP_B_N(byte_offset) (0xe000 | (((byte_offset) >> 1) & 0x07ff))
void
asm_thumb_b_n
(
asm_thumb_t
*
as
,
int
label
)
{
void
asm_thumb_b_n
(
asm_thumb_t
*
as
,
u
int
label
)
{
int
dest
=
get_label_dest
(
as
,
label
);
int
rel
=
dest
-
as
->
code_offset
;
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
...
...
@@ -321,7 +321,7 @@ void asm_thumb_b_n(asm_thumb_t *as, int label) {
#define OP_BCC_N(cond, byte_offset) (0xd000 | ((cond) << 8) | (((byte_offset) >> 1) & 0x00ff))
void
asm_thumb_bcc_n
(
asm_thumb_t
*
as
,
int
cond
,
int
label
)
{
void
asm_thumb_bcc_n
(
asm_thumb_t
*
as
,
int
cond
,
u
int
label
)
{
int
dest
=
get_label_dest
(
as
,
label
);
int
rel
=
dest
-
as
->
code_offset
;
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
...
...
@@ -380,7 +380,7 @@ void asm_thumb_mov_reg_local_addr(asm_thumb_t *as, uint rlo_dest, int local_num)
#define OP_BW_HI(byte_offset) (0xf000 | (((byte_offset) >> 12) & 0x07ff))
#define OP_BW_LO(byte_offset) (0xb800 | (((byte_offset) >> 1) & 0x07ff))
void
asm_thumb_b_label
(
asm_thumb_t
*
as
,
int
label
)
{
void
asm_thumb_b_label
(
asm_thumb_t
*
as
,
u
int
label
)
{
int
dest
=
get_label_dest
(
as
,
label
);
int
rel
=
dest
-
as
->
code_offset
;
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
...
...
@@ -403,7 +403,7 @@ void asm_thumb_b_label(asm_thumb_t *as, int label) {
#define OP_BCC_W_HI(cond, byte_offset) (0xf000 | ((cond) << 6) | (((byte_offset) >> 10) & 0x0400) | (((byte_offset) >> 14) & 0x003f))
#define OP_BCC_W_LO(byte_offset) (0x8000 | ((byte_offset) & 0x2000) | (((byte_offset) >> 1) & 0x0fff))
void
asm_thumb_bcc_label
(
asm_thumb_t
*
as
,
int
cond
,
int
label
)
{
void
asm_thumb_bcc_label
(
asm_thumb_t
*
as
,
int
cond
,
u
int
label
)
{
int
dest
=
get_label_dest
(
as
,
label
);
int
rel
=
dest
-
as
->
code_offset
;
rel
-=
4
;
// account for instruction prefetch, PC is 4 bytes ahead of this instruction
...
...
py/asmthumb.h
View file @
6f355fd3
...
...
@@ -53,7 +53,7 @@ void *asm_thumb_get_code(asm_thumb_t *as);
void
asm_thumb_entry
(
asm_thumb_t
*
as
,
int
num_locals
);
void
asm_thumb_exit
(
asm_thumb_t
*
as
);
void
asm_thumb_label_assign
(
asm_thumb_t
*
as
,
int
label
);
void
asm_thumb_label_assign
(
asm_thumb_t
*
as
,
u
int
label
);
// argument order follows ARM, in general dest is first
// note there is a difference between movw and mov.w, and many others!
...
...
@@ -67,8 +67,8 @@ void asm_thumb_subs_rlo_rlo_i3(asm_thumb_t *as, uint rlo_dest, uint rlo_src, int
void
asm_thumb_cmp_reg_reg
(
asm_thumb_t
*
as
,
uint
rlo_a
,
uint
rlo_b
);
void
asm_thumb_cmp_rlo_i8
(
asm_thumb_t
*
as
,
uint
rlo
,
int
i8
);
void
asm_thumb_ite_ge
(
asm_thumb_t
*
as
);
void
asm_thumb_b_n
(
asm_thumb_t
*
as
,
int
label
);
void
asm_thumb_bcc_n
(
asm_thumb_t
*
as
,
int
cond
,
int
label
);
void
asm_thumb_b_n
(
asm_thumb_t
*
as
,
u
int
label
);
void
asm_thumb_bcc_n
(
asm_thumb_t
*
as
,
int
cond
,
u
int
label
);
void
asm_thumb_mov_reg_i32
(
asm_thumb_t
*
as
,
uint
reg_dest
,
machine_uint_t
i32_src
);
// convenience
void
asm_thumb_mov_reg_i32_optimised
(
asm_thumb_t
*
as
,
uint
reg_dest
,
int
i32_src
);
// convenience
...
...
@@ -76,7 +76,7 @@ void asm_thumb_mov_local_reg(asm_thumb_t *as, int local_num_dest, uint rlo_src);
void
asm_thumb_mov_reg_local
(
asm_thumb_t
*
as
,
uint
rlo_dest
,
int
local_num
);
// convenience
void
asm_thumb_mov_reg_local_addr
(
asm_thumb_t
*
as
,
uint
rlo_dest
,
int
local_num
);
// convenience
void
asm_thumb_b_label
(
asm_thumb_t
*
as
,
int
label
);
// convenience ?
void
asm_thumb_bcc_label
(
asm_thumb_t
*
as
,
int
cc
,
int
label
);
// convenience: picks narrow or wide branch
void
asm_thumb_b_label
(
asm_thumb_t
*
as
,
u
int
label
);
// convenience ?
void
asm_thumb_bcc_label
(
asm_thumb_t
*
as
,
int
cc
,
u
int
label
);
// convenience: picks narrow or wide branch
void
asm_thumb_bl_ind
(
asm_thumb_t
*
as
,
void
*
fun_ptr
,
uint
fun_id
,
uint
reg_temp
);
// convenience ?
py/compile.c
View file @
6f355fd3
...
...
@@ -43,10 +43,10 @@ typedef struct _compiler_t {
uint8_t
had_error
;
// try to keep compiler clean from nlr
uint8_t
func_arg_is_super
;
// used to compile special case of super() function call
int
next_label
;
u
int
next_label
;
int
break_label
;
int
continue_label
;
u
int
break_label
;
u
int
continue_label
;
int
break_continue_except_level
;
uint16_t
cur_except_level
;
// increased for SETUP_EXCEPT, SETUP_FINALLY; decreased for POP_BLOCK, POP_EXCEPT
...
...
@@ -196,7 +196,7 @@ mp_parse_node_t fold_constants(mp_parse_node_t pn) {
STATIC
void
compile_trailer_paren_helper
(
compiler_t
*
comp
,
mp_parse_node_t
pn_arglist
,
bool
is_method_call
,
int
n_positional_extra
);
STATIC
void
compile_node
(
compiler_t
*
comp
,
mp_parse_node_t
pn
);
STATIC
int
comp_next_label
(
compiler_t
*
comp
)
{
STATIC
u
int
comp_next_label
(
compiler_t
*
comp
)
{
return
comp
->
next_label
++
;
}
...
...
@@ -467,7 +467,7 @@ STATIC void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if
int
n
=
MP_PARSE_NODE_STRUCT_NUM_NODES
(
pns
);
if
(
MP_PARSE_NODE_STRUCT_KIND
(
pns
)
==
PN_or_test
)
{
if
(
jump_if
==
false
)
{
int
label2
=
comp_next_label
(
comp
);
u
int
label2
=
comp_next_label
(
comp
);
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++
)
{
cpython_c_if_cond
(
comp
,
pns
->
nodes
[
i
],
true
,
label2
,
true
);
}
...
...
@@ -485,7 +485,7 @@ STATIC void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if
cpython_c_if_cond
(
comp
,
pns
->
nodes
[
i
],
false
,
label
,
true
);
}
}
else
{
int
label2
=
comp_next_label
(
comp
);
u
int
label2
=
comp_next_label
(
comp
);
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++
)
{
cpython_c_if_cond
(
comp
,
pns
->
nodes
[
i
],
false
,
label2
,
true
);
}
...
...
@@ -528,7 +528,7 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la
int
n
=
MP_PARSE_NODE_STRUCT_NUM_NODES
(
pns
);
if
(
MP_PARSE_NODE_STRUCT_KIND
(
pns
)
==
PN_or_test
)
{
if
(
jump_if
==
false
)
{
int
label2
=
comp_next_label
(
comp
);
u
int
label2
=
comp_next_label
(
comp
);
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++
)
{
c_if_cond
(
comp
,
pns
->
nodes
[
i
],
true
,
label2
);
}
...
...
@@ -546,7 +546,7 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la
c_if_cond
(
comp
,
pns
->
nodes
[
i
],
false
,
label
);
}
}
else
{
int
label2
=
comp_next_label
(
comp
);
u
int
label2
=
comp_next_label
(
comp
);
for
(
int
i
=
0
;
i
<
n
-
1
;
i
++
)
{
c_if_cond
(
comp
,
pns
->
nodes
[
i
],
false
,
label2
);
}
...
...
@@ -1202,7 +1202,7 @@ void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
mp_parse_node_struct_t
*
pns_test_if_expr
=
(
mp_parse_node_struct_t
*
)
pns
->
nodes
[
0
];
mp_parse_node_struct_t
*
pns_test_if_else
=
(
mp_parse_node_struct_t
*
)
pns_test_if_expr
->
nodes
[
1
];
int
l_fail
=
comp_next_label
(
comp
);
u
int
l_fail
=
comp_next_label
(
comp
);
c_if_cond
(
comp
,
pns_test_if_else
->
nodes
[
0
],
false
,
l_fail
);
// condition
compile_node
(
comp
,
pns_test_if_expr
->
nodes
[
0
]);
// success value
EMIT
(
return_value
);
...
...
@@ -1451,7 +1451,7 @@ void compile_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
void
compile_assert_stmt
(
compiler_t
*
comp
,
mp_parse_node_struct_t
*
pns
)
{
int
l_end
=
comp_next_label
(
comp
);
u
int
l_end
=
comp_next_label
(
comp
);
c_if_cond
(
comp
,
pns
->
nodes
[
0
],
true
,
l_end
);
EMIT_ARG
(
load_global
,
MP_QSTR_AssertionError
);
// we load_global instead of load_id, to be consistent with CPython
if
(
!
MP_PARSE_NODE_IS_NULL
(
pns
->
nodes
[
1
]))
{
...
...
@@ -1466,9 +1466,9 @@ void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
void
compile_if_stmt
(
compiler_t
*
comp
,
mp_parse_node_struct_t
*
pns
)
{
// TODO proper and/or short circuiting
int
l_end
=
comp_next_label
(
comp
);
u
int
l_end
=
comp_next_label
(
comp
);
int
l_fail
=
comp_next_label
(
comp
);
u
int
l_fail
=
comp_next_label
(
comp
);
c_if_cond
(
comp
,
pns
->
nodes
[
0
],
false
,
l_fail
);
// if condition
compile_node
(
comp
,
pns
->
nodes
[
1
]);
// if block
...
...
@@ -1529,10 +1529,10 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
#define START_BREAK_CONTINUE_BLOCK \
int old_break_label = comp->break_label; \
int old_continue_label = comp->continue_label; \
int break_label = comp_next_label(comp); \
int continue_label = comp_next_label(comp); \
u
int old_break_label = comp->break_label; \
u
int old_continue_label = comp->continue_label; \
u
int break_label = comp_next_label(comp); \
u
int continue_label = comp_next_label(comp); \
comp->break_label = break_label; \
comp->continue_label = continue_label; \
comp->break_continue_except_level = comp->cur_except_level;
...
...
@@ -1547,7 +1547,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// compared to CPython, we have an optimised version of while loops
#if MICROPY_EMIT_CPYTHON
int
done_label
=
comp_next_label
(
comp
);
u
int
done_label
=
comp_next_label
(
comp
);
EMIT_ARG
(
setup_loop
,
break_label
);
EMIT_ARG
(
label_assign
,
continue_label
);
c_if_cond
(
comp
,
pns
->
nodes
[
0
],
false
,
done_label
);
// condition
...
...
@@ -1562,7 +1562,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT
(
pop_block
);
}
#else
int
top_label
=
comp_next_label
(
comp
);
u
int
top_label
=
comp_next_label
(
comp
);
EMIT_ARG
(
jump
,
continue_label
);
EMIT_ARG
(
label_assign
,
top_label
);
compile_node
(
comp
,
pns
->
nodes
[
1
]);
// body
...
...
@@ -1584,8 +1584,8 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
void
compile_for_stmt_optimised_range
(
compiler_t
*
comp
,
mp_parse_node_t
pn_var
,
mp_parse_node_t
pn_start
,
mp_parse_node_t
pn_end
,
mp_parse_node_t
pn_step
,
mp_parse_node_t
pn_body
,
mp_parse_node_t
pn_else
)
{
START_BREAK_CONTINUE_BLOCK
int
top_label
=
comp_next_label
(
comp
);
int
entry_label
=
comp_next_label
(
comp
);
u
int
top_label
=
comp_next_label
(
comp
);
u
int
entry_label
=
comp_next_label
(
comp
);
// compile: start, duplicated on stack
compile_node
(
comp
,
pn_start
);
...
...
@@ -1682,8 +1682,8 @@ void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
START_BREAK_CONTINUE_BLOCK
int
pop_label
=
comp_next_label
(
comp
);
int
end_label
=
comp_next_label
(
comp
);
u
int
pop_label
=
comp_next_label
(
comp
);
u
int
end_label
=
comp_next_label
(
comp
);
// I don't think our implementation needs SETUP_LOOP/POP_BLOCK for for-statements
#if MICROPY_EMIT_CPYTHON
...
...
@@ -1721,8 +1721,8 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
// setup code
int
stack_size
=
EMIT
(
get_stack_size
);
int
l1
=
comp_next_label
(
comp
);
int
success_label
=
comp_next_label
(
comp
);
u
int
l1
=
comp_next_label
(
comp
);
u
int
success_label
=
comp_next_label
(
comp
);
EMIT_ARG
(
setup_except
,
l1
);
compile_increase_except_level
(
comp
);
...
...
@@ -1731,14 +1731,14 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
EMIT
(
pop_block
);
EMIT_ARG
(
jump
,
success_label
);
EMIT_ARG
(
label_assign
,
l1
);
int
l2
=
comp_next_label
(
comp
);
u
int
l2
=
comp_next_label
(
comp
);
for
(
int
i
=
0
;
i
<
n_except
;
i
++
)
{
assert
(
MP_PARSE_NODE_IS_STRUCT_KIND
(
pn_excepts
[
i
],
PN_try_stmt_except
));
// should be
mp_parse_node_struct_t
*
pns_except
=
(
mp_parse_node_struct_t
*
)
pn_excepts
[
i
];
qstr
qstr_exception_local
=
0
;
int
end_finally_label
=
comp_next_label
(
comp
);
u
int
end_finally_label
=
comp_next_label
(
comp
);
if
(
MP_PARSE_NODE_IS_NULL
(
pns_except
->
nodes
[
0
]))
{
// this is a catch all exception handler
...
...
@@ -1773,7 +1773,7 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
EMIT
(
pop_top
);
int
l3
=
0
;
u
int
l3
=
0
;
if
(
qstr_exception_local
!=
0
)
{
l3
=
comp_next_label
(
comp
);
EMIT_ARG
(
setup_finally
,
l3
);
...
...
@@ -1810,7 +1810,7 @@ void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except,
void
compile_try_finally
(
compiler_t
*
comp
,
mp_parse_node_t
pn_body
,
int
n_except
,
mp_parse_node_t
*
pn_except
,
mp_parse_node_t
pn_else
,
mp_parse_node_t
pn_finally
)
{
// don't understand how the stack works with exceptions, so we force it to return to the correct value
int
stack_size
=
EMIT
(
get_stack_size
);
int
l_finally_block
=
comp_next_label
(
comp
);
u
int
l_finally_block
=
comp_next_label
(
comp
);
EMIT_ARG
(
setup_finally
,
l_finally_block
);
compile_increase_except_level
(
comp
);
...
...
@@ -1866,7 +1866,7 @@ void compile_with_stmt_helper(compiler_t *comp, int n, mp_parse_node_t *nodes, m
// no more pre-bits, compile the body of the with
compile_node
(
comp
,
body
);
}
else
{
int
l_end
=
comp_next_label
(
comp
);
u
int
l_end
=
comp_next_label
(
comp
);
if
(
MP_PARSE_NODE_IS_STRUCT_KIND
(
nodes
[
0
],
PN_with_item
))
{
// this pre-bit is of the form "a as b"
mp_parse_node_struct_t
*
pns
=
(
mp_parse_node_struct_t
*
)
nodes
[
0
];
...
...
@@ -2024,8 +2024,8 @@ void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
mp_parse_node_struct_t
*
pns_test_if_else
=
(
mp_parse_node_struct_t
*
)
pns
->
nodes
[
1
];
int
stack_size
=
EMIT
(
get_stack_size
);
int
l_fail
=
comp_next_label
(
comp
);
int
l_end
=
comp_next_label
(
comp
);
u
int
l_fail
=
comp_next_label
(
comp
);
u
int
l_end
=
comp_next_label
(
comp
);
c_if_cond
(
comp
,
pns_test_if_else
->
nodes
[
0
],
false
,
l_fail
);
// condition
compile_node
(
comp
,
pns
->
nodes
[
0
]);
// success value
EMIT_ARG
(
jump
,
l_end
);
...
...
@@ -2055,7 +2055,7 @@ void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
void
compile_or_test
(
compiler_t
*
comp
,
mp_parse_node_struct_t
*
pns
)
{
int
l_end
=
comp_next_label
(
comp
);
u
int
l_end
=
comp_next_label
(
comp
);
int
n
=
MP_PARSE_NODE_STRUCT_NUM_NODES
(
pns
);
for
(
int
i
=
0
;
i
<
n
;
i
+=
1
)
{
compile_node
(
comp
,
pns
->
nodes
[
i
]);
...
...
@@ -2067,7 +2067,7 @@ void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
void
compile_and_test
(
compiler_t
*
comp
,
mp_parse_node_struct_t
*
pns
)
{
int
l_end
=
comp_next_label
(
comp
);
u
int
l_end
=
comp_next_label
(
comp
);
int
n
=
MP_PARSE_NODE_STRUCT_NUM_NODES
(
pns
);
for
(
int
i
=
0
;
i
<
n
;
i
+=
1
)
{
compile_node
(
comp
,
pns
->
nodes
[
i
]);
...
...
@@ -2088,7 +2088,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
int
num_nodes
=
MP_PARSE_NODE_STRUCT_NUM_NODES
(
pns
);
compile_node
(
comp
,
pns
->
nodes
[
0
]);
bool
multi
=
(
num_nodes
>
3
);
int
l_fail
=
0
;
u
int
l_fail
=
0
;
if
(
multi
)
{
l_fail
=
comp_next_label
(
comp
);
}
...
...
@@ -2135,7 +2135,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
}
if
(
multi
)
{
int
l_end
=
comp_next_label
(
comp
);
u
int
l_end
=
comp_next_label
(
comp
);
EMIT_ARG
(
jump
,
l_end
);
EMIT_ARG
(
label_assign
,
l_fail
);
EMIT
(
rot_two
);
...
...
@@ -2835,8 +2835,8 @@ void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, mp_parse
// for loop
mp_parse_node_struct_t
*
pns_comp_for2
=
(
mp_parse_node_struct_t
*
)
pn_iter
;
compile_node
(
comp
,
pns_comp_for2
->
nodes
[
1
]);
int
l_end2
=
comp_next_label
(
comp
);
int
l_top2
=
comp_next_label
(
comp
);
u
int
l_end2
=
comp_next_label
(
comp
);
u
int
l_top2
=
comp_next_label
(
comp
);
EMIT
(
get_iter
);
EMIT_ARG
(
label_assign
,
l_top2
);
EMIT_ARG
(
for_iter
,
l_end2
);
...
...
@@ -2982,8 +2982,8 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
EMIT_ARG
(
build_set
,
0
);
}
int
l_end
=
comp_next_label
(
comp
);
int
l_top
=
comp_next_label
(
comp
);
u
int
l_end
=
comp_next_label
(
comp
);
u
int
l_top
=
comp_next_label
(
comp
);
EMIT_ARG
(
load_id
,
qstr_arg
);
EMIT_ARG
(
label_assign
,
l_top
);
EMIT_ARG
(
for_iter
,
l_end
);
...
...
@@ -3102,7 +3102,7 @@ void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind_t pass
compile_syntax_error
(
comp
,
nodes
[
i
],
"inline assembler 'label' requires 1 argument"
);
return
;
}
int
lab
=
comp_next_label
(
comp
);
u
int
lab
=
comp_next_label
(
comp
);
if
(
pass
>
PASS_1
)
{
EMIT_INLINE_ASM_ARG
(
label
,
lab
,
MP_PARSE_NODE_LEAF_ARG
(
pn_arg
[
0
]));
}
...
...
py/emit.h
View file @
6f355fd3
...
...
@@ -32,7 +32,7 @@ typedef struct _emit_method_table_t {
void
(
*
store_id
)(
emit_t
*
emit
,
qstr
qstr
);
void
(
*
delete_id
)(
emit_t
*
emit
,
qstr
qstr
);
void
(
*
label_assign
)(
emit_t
*
emit
,
int
l
);
void
(
*
label_assign
)(
emit_t
*
emit
,
u
int
l
);
void
(
*
import_name
)(
emit_t
*
emit
,
qstr
qstr
);
void
(
*
import_from
)(
emit_t
*
emit
,
qstr
qstr
);
void
(
*
import_star
)(
emit_t
*
emit
);
...
...
@@ -68,21 +68,21 @@ typedef struct _emit_method_table_t {
void
(
*
pop_top
)(
emit_t
*
emit
);
void
(
*
rot_two
)(
emit_t
*
emit
);
void
(
*
rot_three
)(
emit_t
*
emit
);
void
(
*
jump
)(
emit_t
*
emit
,
int
label
);
void
(
*
pop_jump_if_true
)(
emit_t
*
emit
,
int
label
);
void
(
*
pop_jump_if_false
)(
emit_t
*
emit
,
int
label
);
void
(
*
jump_if_true_or_pop
)(
emit_t
*
emit
,
int
label
);
void
(
*
jump_if_false_or_pop
)(
emit_t
*
emit
,
int
label
);
void
(
*
setup_loop
)(
emit_t
*
emit
,
int
label
);
void
(
*
break_loop
)(
emit_t
*
emit
,
int
label
,
int
except_depth
);
void
(
*
continue_loop
)(
emit_t
*
emit
,
int
label
,
int
except_depth
);
void
(
*
setup_with
)(
emit_t
*
emit
,
int
label
);
void
(
*
jump
)(
emit_t
*
emit
,
u
int
label
);
void
(
*
pop_jump_if_true
)(
emit_t
*
emit
,
u
int
label
);
void
(
*
pop_jump_if_false
)(
emit_t
*
emit
,
u
int
label
);
void
(
*
jump_if_true_or_pop
)(
emit_t
*
emit
,
u
int
label
);
void
(
*
jump_if_false_or_pop
)(
emit_t
*
emit
,
u
int
label
);
void
(
*
setup_loop
)(
emit_t
*
emit
,
u
int
label
);
void
(
*
break_loop
)(
emit_t
*
emit
,
u
int
label
,
int
except_depth
);
void
(
*
continue_loop
)(
emit_t
*
emit
,
u
int
label
,
int
except_depth
);
void
(
*
setup_with
)(
emit_t
*
emit
,
u
int
label
);
void
(
*
with_cleanup
)(
emit_t
*
emit
);
void
(
*
setup_except
)(
emit_t
*
emit
,
int
label
);
void
(
*
setup_finally
)(
emit_t
*
emit
,
int
label
);
void
(
*
setup_except
)(
emit_t
*
emit
,
u
int
label
);
void
(
*
setup_finally
)(
emit_t
*
emit
,
u
int
label
);
void
(
*
end_finally
)(
emit_t
*
emit
);
void
(
*
get_iter
)(
emit_t
*
emit
);
void
(
*
for_iter
)(
emit_t
*
emit
,
int
label
);
void
(
*
for_iter
)(
emit_t
*
emit
,
u
int
label
);
void
(
*
for_iter_end
)(
emit_t
*
emit
);
void
(
*
pop_block
)(
emit_t
*
emit
);
void
(
*
pop_except
)(
emit_t
*
emit
);
...
...
@@ -136,7 +136,7 @@ typedef struct _emit_inline_asm_method_table_t {
void
(
*
start_pass
)(
emit_inline_asm_t
*
emit
,
pass_kind_t
pass
,
scope_t
*
scope
);
void
(
*
end_pass
)(
emit_inline_asm_t
*
emit
);
int
(
*
count_params
)(
emit_inline_asm_t
*
emit
,
int
n_params
,
mp_parse_node_t
*
pn_params
);
void
(
*
label
)(
emit_inline_asm_t
*
emit
,
int
label_num
,
qstr
label_id
);
void
(
*
label
)(
emit_inline_asm_t
*
emit
,
u
int
label_num
,
qstr
label_id
);
void
(
*
op
)(
emit_inline_asm_t
*
emit
,
qstr
op
,
int
n_args
,
mp_parse_node_t
*
pn_args
);
}
emit_inline_asm_method_table_t
;
...
...
py/emitbc.c
View file @
6f355fd3
...
...
@@ -171,7 +171,7 @@ STATIC void emit_write_byte_code_byte_qstr(emit_t* emit, byte b, qstr qstr) {
}
// unsigned labels are relative to ip following this instruction, stored as 16 bits
STATIC
void
emit_write_byte_code_byte_unsigned_label
(
emit_t
*
emit
,
byte
b1
,
int
label
)
{
STATIC
void
emit_write_byte_code_byte_unsigned_label
(
emit_t
*
emit
,
byte
b1
,
u
int
label
)
{
uint
byte_code_offset
;
if
(
emit
->
pass
<
PASS_3
)
{
byte_code_offset
=
0
;
...
...
@@ -185,7 +185,7 @@ STATIC void emit_write_byte_code_byte_unsigned_label(emit_t* emit, byte b1, int
}
// signed labels are relative to ip following this instruction, stored as 16 bits, in excess
STATIC
void
emit_write_byte_code_byte_signed_label
(
emit_t
*
emit
,
byte
b1
,
int
label
)
{
STATIC
void
emit_write_byte_code_byte_signed_label
(
emit_t
*
emit
,
byte
b1
,
u
int
label
)
{
int
byte_code_offset
;
if
(
emit
->
pass
<
PASS_3
)
{
byte_code_offset
=
0
;
...
...
@@ -329,7 +329,7 @@ STATIC void emit_bc_pre(emit_t *emit, int stack_size_delta) {
emit
->
last_emit_was_return_value
=
false
;
}
STATIC
void
emit_bc_label_assign
(
emit_t
*
emit
,
int
l
)
{
STATIC
void
emit_bc_label_assign
(
emit_t
*
emit
,
u
int
l
)
{
emit_bc_pre
(
emit
,
0
);
assert
(
l
<
emit
->
max_num_labels
);
if
(
emit
->
pass
==
PASS_2
)
{
...
...
@@ -551,37 +551,37 @@ STATIC void emit_bc_rot_three(emit_t *emit) {
emit_write_byte_code_byte
(
emit
,
MP_BC_ROT_THREE
);
}
STATIC
void
emit_bc_jump
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_bc_jump
(
emit_t
*
emit
,
u
int
label
)
{
emit_bc_pre
(
emit
,
0
);
emit_write_byte_code_byte_signed_label
(
emit
,
MP_BC_JUMP
,
label
);
}
STATIC
void
emit_bc_pop_jump_if_true
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_bc_pop_jump_if_true
(
emit_t
*
emit
,
u
int
label
)
{
emit_bc_pre
(
emit
,
-
1
);
emit_write_byte_code_byte_signed_label
(
emit
,
MP_BC_POP_JUMP_IF_TRUE
,
label
);
}
STATIC
void
emit_bc_pop_jump_if_false
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_bc_pop_jump_if_false
(
emit_t
*
emit
,
u
int
label
)
{
emit_bc_pre
(
emit
,
-
1
);
emit_write_byte_code_byte_signed_label
(
emit
,
MP_BC_POP_JUMP_IF_FALSE
,
label
);
}
STATIC
void
emit_bc_jump_if_true_or_pop
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_bc_jump_if_true_or_pop
(
emit_t
*
emit
,
u
int
label
)
{
emit_bc_pre
(
emit
,
-
1
);
emit_write_byte_code_byte_signed_label
(
emit
,
MP_BC_JUMP_IF_TRUE_OR_POP
,
label
);
}
STATIC
void
emit_bc_jump_if_false_or_pop
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_bc_jump_if_false_or_pop
(
emit_t
*
emit
,
u
int
label
)
{
emit_bc_pre
(
emit
,
-
1
);
emit_write_byte_code_byte_signed_label
(
emit
,
MP_BC_JUMP_IF_FALSE_OR_POP
,
label
);
}
STATIC
void
emit_bc_setup_loop
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_bc_setup_loop
(
emit_t
*
emit
,
u
int
label
)
{
emit_bc_pre
(
emit
,
0
);
emit_write_byte_code_byte_unsigned_label
(
emit
,
MP_BC_SETUP_LOOP
,
label
);
}
STATIC
void
emit_bc_unwind_jump
(
emit_t
*
emit
,
int
label
,
int
except_depth
)
{
STATIC
void
emit_bc_unwind_jump
(
emit_t
*
emit
,
u
int
label
,
int
except_depth
)
{
if
(
except_depth
==
0
)
{
emit_bc_jump
(
emit
,
label
);
}
else
{
...
...
@@ -591,7 +591,7 @@ STATIC void emit_bc_unwind_jump(emit_t *emit, int label, int except_depth) {
}
}
STATIC
void
emit_bc_setup_with
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_bc_setup_with
(
emit_t
*
emit
,
u
int
label
)
{
emit_bc_pre
(
emit
,
7
);
emit_write_byte_code_byte_unsigned_label
(
emit
,
MP_BC_SETUP_WITH
,
label
);
}
...
...
@@ -601,12 +601,12 @@ STATIC void emit_bc_with_cleanup(emit_t *emit) {
emit_write_byte_code_byte
(
emit
,
MP_BC_WITH_CLEANUP
);
}
STATIC
void
emit_bc_setup_except
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_bc_setup_except
(
emit_t
*
emit
,
u
int
label
)
{
emit_bc_pre
(
emit
,
6
);
emit_write_byte_code_byte_unsigned_label
(
emit
,
MP_BC_SETUP_EXCEPT
,
label
);
}
STATIC
void
emit_bc_setup_finally
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_bc_setup_finally
(
emit_t
*
emit
,
u
int
label
)
{
emit_bc_pre
(
emit
,
6
);
emit_write_byte_code_byte_unsigned_label
(
emit
,
MP_BC_SETUP_FINALLY
,
label
);
}
...
...
@@ -621,7 +621,7 @@ STATIC void emit_bc_get_iter(emit_t *emit) {
emit_write_byte_code_byte
(
emit
,
MP_BC_GET_ITER
);
}
STATIC
void
emit_bc_for_iter
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_bc_for_iter
(
emit_t
*
emit
,
u
int
label
)
{
emit_bc_pre
(
emit
,
1
);
emit_write_byte_code_byte_unsigned_label
(
emit
,
MP_BC_FOR_ITER
,
label
);
}
...
...
py/emitcpy.c
View file @
6f355fd3
...
...
@@ -100,7 +100,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta, int byte_code_size) {
emit
->
byte_code_offset
+=
byte_code_size
;
}
STATIC
void
emit_cpy_label_assign
(
emit_t
*
emit
,
int
l
)
{
STATIC
void
emit_cpy_label_assign
(
emit_t
*
emit
,
u
int
l
)
{
emit_pre
(
emit
,
0
,
0
);
assert
(
l
<
emit
->
max_num_labels
);
if
(
emit
->
pass
==
PASS_2
)
{
...
...
@@ -402,7 +402,7 @@ STATIC void emit_cpy_rot_three(emit_t *emit) {
}
}
STATIC
void
emit_cpy_jump
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_cpy_jump
(
emit_t
*
emit
,
u
int
label
)
{
emit_pre
(
emit
,
0
,
3
);
if
(
emit
->
pass
==
PASS_3
)
{
int
dest
=
emit
->
label_offsets
[
label
];
...
...
@@ -414,49 +414,49 @@ STATIC void emit_cpy_jump(emit_t *emit, int label) {
}
}
STATIC
void
emit_cpy_pop_jump_if_true
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_cpy_pop_jump_if_true
(
emit_t
*
emit
,
u
int
label
)
{
emit_pre
(
emit
,
-
1
,
3
);
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"POP_JUMP_IF_TRUE %d
\n
"
,
emit
->
label_offsets
[
label
]);
}
}
STATIC
void
emit_cpy_pop_jump_if_false
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_cpy_pop_jump_if_false
(
emit_t
*
emit
,
u
int
label
)
{
emit_pre
(
emit
,
-
1
,
3
);
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"POP_JUMP_IF_FALSE %d
\n
"
,
emit
->
label_offsets
[
label
]);
}
}
STATIC
void
emit_cpy_jump_if_true_or_pop
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_cpy_jump_if_true_or_pop
(
emit_t
*
emit
,
u
int
label
)
{
emit_pre
(
emit
,
-
1
,
3
);
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"JUMP_IF_TRUE_OR_POP %d
\n
"
,
emit
->
label_offsets
[
label
]);
}
}
STATIC
void
emit_cpy_jump_if_false_or_pop
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_cpy_jump_if_false_or_pop
(
emit_t
*
emit
,
u
int
label
)
{
emit_pre
(
emit
,
-
1
,
3
);
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"JUMP_IF_FALSE_OR_POP %d
\n
"
,
emit
->
label_offsets
[
label
]);
}
}
STATIC
void
emit_cpy_setup_loop
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_cpy_setup_loop
(
emit_t
*
emit
,
u
int
label
)
{
emit_pre
(
emit
,
0
,
3
);
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"SETUP_LOOP %d
\n
"
,
emit
->
label_offsets
[
label
]);
}
}
STATIC
void
emit_cpy_break_loop
(
emit_t
*
emit
,
int
label
,
int
except_depth
)
{
STATIC
void
emit_cpy_break_loop
(
emit_t
*
emit
,
u
int
label
,
int
except_depth
)
{
emit_pre
(
emit
,
0
,
1
);
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"BREAK_LOOP
\n
"
);
}
}
STATIC
void
emit_cpy_continue_loop
(
emit_t
*
emit
,
int
label
,
int
except_depth
)
{
STATIC
void
emit_cpy_continue_loop
(
emit_t
*
emit
,
u
int
label
,
int
except_depth
)
{
if
(
except_depth
==
0
)
{
emit_cpy_jump
(
emit
,
label
);
}
else
{
...
...
@@ -467,7 +467,7 @@ STATIC void emit_cpy_continue_loop(emit_t *emit, int label, int except_depth) {
}
}
STATIC
void
emit_cpy_setup_with
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_cpy_setup_with
(
emit_t
*
emit
,
u
int
label
)
{
emit_pre
(
emit
,
7
,
3
);
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"SETUP_WITH %d
\n
"
,
emit
->
label_offsets
[
label
]);
...
...
@@ -481,14 +481,14 @@ STATIC void emit_cpy_with_cleanup(emit_t *emit) {
}
}
STATIC
void
emit_cpy_setup_except
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_cpy_setup_except
(
emit_t
*
emit
,
u
int
label
)
{
emit_pre
(
emit
,
6
,
3
);
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"SETUP_EXCEPT %d
\n
"
,
emit
->
label_offsets
[
label
]);
}
}
STATIC
void
emit_cpy_setup_finally
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_cpy_setup_finally
(
emit_t
*
emit
,
u
int
label
)
{
emit_pre
(
emit
,
6
,
3
);
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"SETUP_FINALLY %d
\n
"
,
emit
->
label_offsets
[
label
]);
...
...
@@ -509,7 +509,7 @@ STATIC void emit_cpy_get_iter(emit_t *emit) {
}
}
STATIC
void
emit_cpy_for_iter
(
emit_t
*
emit
,
int
label
)
{
STATIC
void
emit_cpy_for_iter
(
emit_t
*
emit
,
u
int
label
)
{
emit_pre
(
emit
,
1
,
3
);
<