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
5fd8fd2c
Commit
5fd8fd2c
authored
Jan 06, 2014
by
ian-v
Browse files
Revert MP_BOOL, etc. and use <stdbool.h> instead
parent
7a16fadb
Changes
61
Expand all
Hide whitespace changes
Inline
Side-by-side
py/asmthumb.c
View file @
5fd8fd2c
...
...
@@ -45,7 +45,7 @@ asm_thumb_t *asm_thumb_new(uint max_num_labels) {
return
as
;
}
void
asm_thumb_free
(
asm_thumb_t
*
as
,
MP_BOOL
free_code
)
{
void
asm_thumb_free
(
asm_thumb_t
*
as
,
bool
free_code
)
{
if
(
free_code
)
{
m_del
(
byte
,
as
->
code_base
,
as
->
code_size
);
}
...
...
@@ -56,9 +56,9 @@ void asm_thumb_free(asm_thumb_t *as, MP_BOOL free_code) {
{
Label *lab = &g_array_index(as->label, Label, i);
if (lab->unresolved != NULL)
g_array_free(lab->unresolved,
MP_TRUE
);
g_array_free(lab->unresolved,
true
);
}
g_array_free(as->label,
MP_TRUE
);
g_array_free(as->label,
true
);
}
*/
m_del_obj
(
asm_thumb_t
,
as
);
...
...
@@ -87,7 +87,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) {
int i;
for (i = 0; i < as->label->len; ++i)
if (g_array_index(as->label, Label, i).unresolved != NULL)
return
MP_FALSE
;
return
false
;
}
*/
}
...
...
py/asmthumb.h
View file @
5fd8fd2c
...
...
@@ -44,7 +44,7 @@
typedef
struct
_asm_thumb_t
asm_thumb_t
;
asm_thumb_t
*
asm_thumb_new
(
uint
max_num_labels
);
void
asm_thumb_free
(
asm_thumb_t
*
as
,
MP_BOOL
free_code
);
void
asm_thumb_free
(
asm_thumb_t
*
as
,
bool
free_code
);
void
asm_thumb_start_pass
(
asm_thumb_t
*
as
,
int
pass
);
void
asm_thumb_end_pass
(
asm_thumb_t
*
as
);
uint
asm_thumb_get_code_size
(
asm_thumb_t
*
as
);
...
...
py/asmx64.c
View file @
5fd8fd2c
...
...
@@ -94,7 +94,7 @@ struct _asm_x64_t {
};
// for allocating memory, see src/v8/src/platform-linux.cc
void
*
alloc_mem
(
uint
req_size
,
uint
*
alloc_size
,
MP_BOOL
is_exec
)
{
void
*
alloc_mem
(
uint
req_size
,
uint
*
alloc_size
,
bool
is_exec
)
{
req_size
=
(
req_size
+
0xfff
)
&
(
~
0xfff
);
int
prot
=
PROT_READ
|
PROT_WRITE
|
(
is_exec
?
PROT_EXEC
:
0
);
void
*
ptr
=
mmap
(
NULL
,
req_size
,
prot
,
MAP_PRIVATE
|
MAP_ANONYMOUS
,
-
1
,
0
);
...
...
@@ -119,7 +119,7 @@ asm_x64_t* asm_x64_new(uint max_num_labels) {
return
as
;
}
void
asm_x64_free
(
asm_x64_t
*
as
,
MP_BOOL
free_code
)
{
void
asm_x64_free
(
asm_x64_t
*
as
,
bool
free_code
)
{
if
(
free_code
)
{
// need to un-mmap
//m_free(as->code_base);
...
...
@@ -131,9 +131,9 @@ void asm_x64_free(asm_x64_t* as, MP_BOOL free_code) {
{
Label* lab = &g_array_index(as->label, Label, i);
if (lab->unresolved != NULL)
g_array_free(lab->unresolved,
MP_TRUE
);
g_array_free(lab->unresolved,
true
);
}
g_array_free(as->label,
MP_TRUE
);
g_array_free(as->label,
true
);
}
*/
m_del_obj
(
asm_x64_t
,
as
);
...
...
@@ -154,7 +154,7 @@ void asm_x64_end_pass(asm_x64_t *as) {
as
->
code_size
=
as
->
code_offset
;
//as->code_base = m_new(byte, as->code_size); need to allocale executable memory
uint
actual_alloc
;
as
->
code_base
=
alloc_mem
(
as
->
code_size
,
&
actual_alloc
,
MP_TRUE
);
as
->
code_base
=
alloc_mem
(
as
->
code_size
,
&
actual_alloc
,
true
);
printf
(
"code_size: %u
\n
"
,
as
->
code_size
);
}
...
...
@@ -165,7 +165,7 @@ void asm_x64_end_pass(asm_x64_t *as) {
int i;
for (i = 0; i < as->label->len; ++i)
if (g_array_index(as->label, Label, i).unresolved != NULL)
return
MP_FALSE
;
return
false
;
}
*/
}
...
...
py/asmx64.h
View file @
5fd8fd2c
...
...
@@ -27,7 +27,7 @@
typedef
struct
_asm_x64_t
asm_x64_t
;
asm_x64_t
*
asm_x64_new
(
uint
max_num_labels
);
void
asm_x64_free
(
asm_x64_t
*
as
,
MP_BOOL
free_code
);
void
asm_x64_free
(
asm_x64_t
*
as
,
bool
free_code
);
void
asm_x64_start_pass
(
asm_x64_t
*
as
,
int
pass
);
void
asm_x64_end_pass
(
asm_x64_t
*
as
);
uint
asm_x64_get_code_size
(
asm_x64_t
*
as
);
...
...
py/bc.h
View file @
5fd8fd2c
mp_obj_t
mp_execute_byte_code
(
const
byte
*
code
,
const
mp_obj_t
*
args
,
uint
n_args
,
uint
n_state
);
MP_BOOL
mp_execute_byte_code_2
(
const
byte
**
ip_in_out
,
mp_obj_t
*
fastn
,
mp_obj_t
**
sp_in_out
);
bool
mp_execute_byte_code_2
(
const
byte
**
ip_in_out
,
mp_obj_t
*
fastn
,
mp_obj_t
**
sp_in_out
);
py/builtinimport.c
View file @
5fd8fd2c
...
...
@@ -58,7 +58,7 @@ mp_obj_t mp_builtin___import__(int n, mp_obj_t *args) {
return
mp_const_none
;
}
mp_obj_t
module_fun
=
mp_compile
(
pn
,
MP_FALSE
);
mp_obj_t
module_fun
=
mp_compile
(
pn
,
false
);
if
(
module_fun
==
mp_const_none
)
{
// TODO handle compile error correctly
...
...
py/compile.c
View file @
5fd8fd2c
This diff is collapsed.
Click to expand it.
py/compile.h
View file @
5fd8fd2c
mp_obj_t
mp_compile
(
mp_parse_node_t
pn
,
MP_BOOL
is_repl
);
mp_obj_t
mp_compile
(
mp_parse_node_t
pn
,
bool
is_repl
);
py/emit.h
View file @
5fd8fd2c
...
...
@@ -17,10 +17,10 @@ typedef enum {
typedef
struct
_emit_t
emit_t
;
typedef
struct
_emit_method_table_t
{
void
(
*
set_native_types
)(
emit_t
*
emit
,
MP_BOOL
do_native_types
);
void
(
*
set_native_types
)(
emit_t
*
emit
,
bool
do_native_types
);
void
(
*
start_pass
)(
emit_t
*
emit
,
pass_kind_t
pass
,
scope_t
*
scope
);
void
(
*
end_pass
)(
emit_t
*
emit
);
MP_BOOL
(
*
last_emit_was_return_value
)(
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
);
...
...
@@ -37,7 +37,7 @@ typedef struct _emit_method_table_t {
void
(
*
load_const_int
)(
emit_t
*
emit
,
qstr
qstr
);
void
(
*
load_const_dec
)(
emit_t
*
emit
,
qstr
qstr
);
void
(
*
load_const_id
)(
emit_t
*
emit
,
qstr
qstr
);
void
(
*
load_const_str
)(
emit_t
*
emit
,
qstr
qstr
,
MP_BOOL
bytes
);
void
(
*
load_const_str
)(
emit_t
*
emit
,
qstr
qstr
,
bool
bytes
);
void
(
*
load_const_verbatim_str
)(
emit_t
*
emit
,
const
char
*
str
);
// only needed for emitcpy
void
(
*
load_fast
)(
emit_t
*
emit
,
qstr
qstr
,
int
local_num
);
void
(
*
load_deref
)(
emit_t
*
emit
,
qstr
qstr
,
int
local_num
);
...
...
@@ -99,8 +99,8 @@ typedef struct _emit_method_table_t {
void
(
*
unpack_ex
)(
emit_t
*
emit
,
int
n_left
,
int
n_right
);
void
(
*
make_function
)(
emit_t
*
emit
,
scope_t
*
scope
,
int
n_dict_params
,
int
n_default_params
);
void
(
*
make_closure
)(
emit_t
*
emit
,
scope_t
*
scope
,
int
n_dict_params
,
int
n_default_params
);
void
(
*
call_function
)(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
MP_BOOL
have_star_arg
,
MP_BOOL
have_dbl_star_arg
);
void
(
*
call_method
)(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
MP_BOOL
have_star_arg
,
MP_BOOL
have_dbl_star_arg
);
void
(
*
call_function
)(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
bool
have_star_arg
,
bool
have_dbl_star_arg
);
void
(
*
call_method
)(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
bool
have_star_arg
,
bool
have_dbl_star_arg
);
void
(
*
return_value
)(
emit_t
*
emit
);
void
(
*
raise_varargs
)(
emit_t
*
emit
,
int
n_args
);
void
(
*
yield_value
)(
emit_t
*
emit
);
...
...
py/emitbc.c
View file @
5fd8fd2c
...
...
@@ -17,7 +17,7 @@
struct
_emit_t
{
pass_kind_t
pass
;
int
stack_size
;
MP_BOOL
last_emit_was_return_value
;
bool
last_emit_was_return_value
;
scope_t
*
scope
;
...
...
@@ -135,13 +135,13 @@ static void emit_write_byte_1_signed_label(emit_t* emit, byte b1, int label) {
c
[
2
]
=
code_offset
>>
8
;
}
static
void
emit_bc_set_native_types
(
emit_t
*
emit
,
MP_BOOL
do_native_types
)
{
static
void
emit_bc_set_native_types
(
emit_t
*
emit
,
bool
do_native_types
)
{
}
static
void
emit_bc_start_pass
(
emit_t
*
emit
,
pass_kind_t
pass
,
scope_t
*
scope
)
{
emit
->
pass
=
pass
;
emit
->
stack_size
=
0
;
emit
->
last_emit_was_return_value
=
MP_FALSE
;
emit
->
last_emit_was_return_value
=
false
;
emit
->
scope
=
scope
;
if
(
pass
==
PASS_2
)
{
memset
(
emit
->
label_offsets
,
-
1
,
emit
->
max_num_labels
*
sizeof
(
uint
));
...
...
@@ -182,7 +182,7 @@ static void emit_bc_end_pass(emit_t *emit) {
}
}
MP_BOOL
emit_bc_last_emit_was_return_value
(
emit_t
*
emit
)
{
bool
emit_bc_last_emit_was_return_value
(
emit_t
*
emit
)
{
return
emit
->
last_emit_was_return_value
;
}
...
...
@@ -211,7 +211,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta) {
if
(
emit
->
stack_size
>
emit
->
scope
->
stack_size
)
{
emit
->
scope
->
stack_size
=
emit
->
stack_size
;
}
emit
->
last_emit_was_return_value
=
MP_FALSE
;
emit
->
last_emit_was_return_value
=
false
;
}
static
void
emit_bc_label_assign
(
emit_t
*
emit
,
int
l
)
{
...
...
@@ -274,7 +274,7 @@ static void emit_bc_load_const_id(emit_t *emit, qstr qstr) {
emit_write_byte_1_qstr
(
emit
,
MP_BC_LOAD_CONST_ID
,
qstr
);
}
static
void
emit_bc_load_const_str
(
emit_t
*
emit
,
qstr
qstr
,
MP_BOOL
bytes
)
{
static
void
emit_bc_load_const_str
(
emit_t
*
emit
,
qstr
qstr
,
bool
bytes
)
{
emit_pre
(
emit
,
1
);
if
(
bytes
)
{
emit_write_byte_1_qstr
(
emit
,
MP_BC_LOAD_CONST_BYTES
,
qstr
);
...
...
@@ -613,7 +613,7 @@ static void emit_bc_make_closure(emit_t *emit, scope_t *scope, int n_dict_params
emit_write_byte_1_uint
(
emit
,
MP_BC_MAKE_CLOSURE
,
scope
->
unique_code_id
);
}
static
void
emit_bc_call_function
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
MP_BOOL
have_star_arg
,
MP_BOOL
have_dbl_star_arg
)
{
static
void
emit_bc_call_function
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
bool
have_star_arg
,
bool
have_dbl_star_arg
)
{
int
s
=
0
;
if
(
have_star_arg
)
{
s
+=
1
;
...
...
@@ -639,7 +639,7 @@ static void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword,
emit_write_byte_1_uint
(
emit
,
op
,
(
n_keyword
<<
8
)
|
n_positional
);
// TODO make it 2 separate uints
}
static
void
emit_bc_call_method
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
MP_BOOL
have_star_arg
,
MP_BOOL
have_dbl_star_arg
)
{
static
void
emit_bc_call_method
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
bool
have_star_arg
,
bool
have_dbl_star_arg
)
{
int
s
=
0
;
if
(
have_star_arg
)
{
s
+=
1
;
...
...
@@ -667,7 +667,7 @@ static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, M
static
void
emit_bc_return_value
(
emit_t
*
emit
)
{
emit_pre
(
emit
,
-
1
);
emit
->
last_emit_was_return_value
=
MP_TRUE
;
emit
->
last_emit_was_return_value
=
true
;
emit_write_byte_1
(
emit
,
MP_BC_RETURN_VALUE
);
}
...
...
py/emitcpy.c
View file @
5fd8fd2c
...
...
@@ -20,7 +20,7 @@ struct _emit_t {
int
pass
;
int
byte_code_offset
;
int
stack_size
;
MP_BOOL
last_emit_was_return_value
;
bool
last_emit_was_return_value
;
scope_t
*
scope
;
...
...
@@ -35,14 +35,14 @@ emit_t *emit_cpython_new(uint max_num_labels) {
return
emit
;
}
static
void
emit_cpy_set_native_types
(
emit_t
*
emit
,
MP_BOOL
do_native_types
)
{
static
void
emit_cpy_set_native_types
(
emit_t
*
emit
,
bool
do_native_types
)
{
}
static
void
emit_cpy_start_pass
(
emit_t
*
emit
,
pass_kind_t
pass
,
scope_t
*
scope
)
{
emit
->
pass
=
pass
;
emit
->
byte_code_offset
=
0
;
emit
->
stack_size
=
0
;
emit
->
last_emit_was_return_value
=
MP_FALSE
;
emit
->
last_emit_was_return_value
=
false
;
emit
->
scope
=
scope
;
if
(
pass
==
PASS_2
)
{
memset
(
emit
->
label_offsets
,
-
1
,
emit
->
max_num_labels
*
sizeof
(
int
));
...
...
@@ -56,7 +56,7 @@ static void emit_cpy_end_pass(emit_t *emit) {
}
}
static
MP_BOOL
emit_cpy_last_emit_was_return_value
(
emit_t
*
emit
)
{
static
bool
emit_cpy_last_emit_was_return_value
(
emit_t
*
emit
)
{
return
emit
->
last_emit_was_return_value
;
}
...
...
@@ -85,7 +85,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta, int byte_code_size) {
if
(
emit
->
stack_size
>
emit
->
scope
->
stack_size
)
{
emit
->
scope
->
stack_size
=
emit
->
stack_size
;
}
emit
->
last_emit_was_return_value
=
MP_FALSE
;
emit
->
last_emit_was_return_value
=
false
;
if
(
emit
->
pass
==
PASS_3
&&
byte_code_size
>
0
)
{
if
(
emit
->
byte_code_offset
>=
1000
)
{
printf
(
"%d "
,
emit
->
byte_code_offset
);
...
...
@@ -173,26 +173,26 @@ static void emit_cpy_load_const_id(emit_t *emit, qstr qstr) {
}
}
static
void
print_quoted_str
(
qstr
qstr
,
MP_BOOL
bytes
)
{
static
void
print_quoted_str
(
qstr
qstr
,
bool
bytes
)
{
const
char
*
str
=
qstr_str
(
qstr
);
int
len
=
strlen
(
str
);
MP_BOOL
has_single_quote
=
MP_FALSE
;
MP_BOOL
has_double_quote
=
MP_FALSE
;
bool
has_single_quote
=
false
;
bool
has_double_quote
=
false
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
if
(
str
[
i
]
==
'\''
)
{
has_single_quote
=
MP_TRUE
;
has_single_quote
=
true
;
}
else
if
(
str
[
i
]
==
'"'
)
{
has_double_quote
=
MP_TRUE
;
has_double_quote
=
true
;
}
}
if
(
bytes
)
{
printf
(
"b"
);
}
MP_BOOL
quote_single
=
MP_FALSE
;
bool
quote_single
=
false
;
if
(
has_single_quote
&&
!
has_double_quote
)
{
printf
(
"
\"
"
);
}
else
{
quote_single
=
MP_TRUE
;
quote_single
=
true
;
printf
(
"'"
);
}
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
...
...
@@ -213,7 +213,7 @@ static void print_quoted_str(qstr qstr, MP_BOOL bytes) {
}
}
static
void
emit_cpy_load_const_str
(
emit_t
*
emit
,
qstr
qstr
,
MP_BOOL
bytes
)
{
static
void
emit_cpy_load_const_str
(
emit_t
*
emit
,
qstr
qstr
,
bool
bytes
)
{
emit_pre
(
emit
,
1
,
3
);
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"LOAD_CONST "
);
...
...
@@ -681,7 +681,7 @@ static void emit_cpy_unpack_ex(emit_t *emit, int n_left, int n_right) {
}
}
static
void
emit_cpy_call_function
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
MP_BOOL
have_star_arg
,
MP_BOOL
have_dbl_star_arg
)
{
static
void
emit_cpy_call_function
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
bool
have_star_arg
,
bool
have_dbl_star_arg
)
{
int
s
=
0
;
if
(
have_star_arg
)
{
s
+=
1
;
...
...
@@ -708,13 +708,13 @@ static void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword
}
}
static
void
emit_cpy_call_method
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
MP_BOOL
have_star_arg
,
MP_BOOL
have_dbl_star_arg
)
{
static
void
emit_cpy_call_method
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
bool
have_star_arg
,
bool
have_dbl_star_arg
)
{
emit_cpy_call_function
(
emit
,
n_positional
,
n_keyword
,
have_star_arg
,
have_dbl_star_arg
);
}
static
void
emit_cpy_return_value
(
emit_t
*
emit
)
{
emit_pre
(
emit
,
-
1
,
1
);
emit
->
last_emit_was_return_value
=
MP_TRUE
;
emit
->
last_emit_was_return_value
=
true
;
if
(
emit
->
pass
==
PASS_3
)
{
printf
(
"RETURN_VALUE
\n
"
);
}
...
...
py/emitinlinethumb.c
View file @
5fd8fd2c
...
...
@@ -75,12 +75,12 @@ static void emit_inline_thumb_label(emit_inline_asm_t *emit, int label_num, qstr
asm_thumb_label_assign
(
emit
->
as
,
label_num
);
}
static
MP_BOOL
check_n_arg
(
qstr
op
,
int
n_args
,
int
wanted_n_args
)
{
static
bool
check_n_arg
(
qstr
op
,
int
n_args
,
int
wanted_n_args
)
{
if
(
wanted_n_args
==
n_args
)
{
return
MP_TRUE
;
return
true
;
}
else
{
printf
(
"SyntaxError: '%s' expects %d arguments'
\n
"
,
qstr_str
(
op
),
wanted_n_args
);
return
MP_FALSE
;
return
false
;
}
}
...
...
py/emitnative.c
View file @
5fd8fd2c
...
...
@@ -52,7 +52,7 @@
#define REG_TEMP2 (REG_RSI)
#define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_x64_mov_r64_to_local(emit->as, (reg), (local_num))
#define ASM_MOV_IMM_TO_REG(imm, reg) asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg))
#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg_temp)); asm_x64_mov_r64_to_local(emit->as, (reg_temp), (local_num)); } while (
MP_FALSE
)
#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg_temp)); asm_x64_mov_r64_to_local(emit->as, (reg_temp), (local_num)); } while (
false
)
#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_x64_mov_local_to_r64(emit->as, (local_num), (reg))
#define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_x64_mov_r64_to_r64(emit->as, (reg_src), (reg_dest))
#define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_x64_mov_local_addr_to_r64(emit->as, (local_num), (reg))
...
...
@@ -75,7 +75,7 @@
#define REG_TEMP2 (REG_R2)
#define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_thumb_mov_local_reg(emit->as, (local_num), (reg))
#define ASM_MOV_IMM_TO_REG(imm, reg) asm_thumb_mov_reg_i32_optimised(emit->as, (reg), (imm))
#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_thumb_mov_reg_i32_optimised(emit->as, (reg_temp), (imm)); asm_thumb_mov_local_reg(emit->as, (local_num), (reg_temp)); } while (
MP_FALSE
)
#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_thumb_mov_reg_i32_optimised(emit->as, (reg_temp), (imm)); asm_thumb_mov_local_reg(emit->as, (local_num), (reg_temp)); } while (
false
)
#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_thumb_mov_reg_local(emit->as, (reg), (local_num))
#define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_thumb_mov_reg_reg(emit->as, (reg_dest), (reg_src))
#define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_thumb_mov_reg_local_addr(emit->as, (reg), (local_num))
...
...
@@ -110,7 +110,7 @@ typedef struct _stack_info_t {
struct
_emit_t
{
int
pass
;
MP_BOOL
do_viper_types
;
bool
do_viper_types
;
int
local_vtype_alloc
;
vtype_kind_t
*
local_vtype
;
...
...
@@ -121,7 +121,7 @@ struct _emit_t {
int
stack_start
;
int
stack_size
;
MP_BOOL
last_emit_was_return_value
;
bool
last_emit_was_return_value
;
scope_t
*
scope
;
...
...
@@ -134,7 +134,7 @@ struct _emit_t {
emit_t
*
EXPORT_FUN
(
new
)(
uint
max_num_labels
)
{
emit_t
*
emit
=
m_new
(
emit_t
,
1
);
emit
->
do_viper_types
=
MP_FALSE
;
emit
->
do_viper_types
=
false
;
emit
->
local_vtype
=
NULL
;
emit
->
stack_info
=
NULL
;
#if N_X64
...
...
@@ -145,7 +145,7 @@ emit_t *EXPORT_FUN(new)(uint max_num_labels) {
return
emit
;
}
static
void
emit_native_set_viper_types
(
emit_t
*
emit
,
MP_BOOL
do_viper_types
)
{
static
void
emit_native_set_viper_types
(
emit_t
*
emit
,
bool
do_viper_types
)
{
emit
->
do_viper_types
=
do_viper_types
;
}
...
...
@@ -153,7 +153,7 @@ static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
emit
->
pass
=
pass
;
emit
->
stack_start
=
0
;
emit
->
stack_size
=
0
;
emit
->
last_emit_was_return_value
=
MP_FALSE
;
emit
->
last_emit_was_return_value
=
false
;
emit
->
scope
=
scope
;
if
(
emit
->
local_vtype
==
NULL
)
{
...
...
@@ -269,7 +269,7 @@ static void emit_native_end_pass(emit_t *emit) {
}
}
static
MP_BOOL
emit_native_last_emit_was_return_value
(
emit_t
*
emit
)
{
static
bool
emit_native_last_emit_was_return_value
(
emit_t
*
emit
)
{
return
emit
->
last_emit_was_return_value
;
}
...
...
@@ -292,13 +292,13 @@ static void adjust_stack(emit_t *emit, int stack_size_delta) {
/*
static void emit_pre_raw(emit_t *emit, int stack_size_delta) {
adjust_stack(emit, stack_size_delta);
emit->last_emit_was_return_value =
MP_FALSE
;
emit->last_emit_was_return_value =
false
;
}
*/
// this must be called at start of emit functions
static
void
emit_pre
(
emit_t
*
emit
)
{
emit
->
last_emit_was_return_value
=
MP_FALSE
;
emit
->
last_emit_was_return_value
=
false
;
// settle the stack
/*
if (regs_needed != 0) {
...
...
@@ -391,7 +391,7 @@ static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int re
}
static
void
emit_pre_pop_reg
(
emit_t
*
emit
,
vtype_kind_t
*
vtype
,
int
reg_dest
)
{
emit
->
last_emit_was_return_value
=
MP_FALSE
;
emit
->
last_emit_was_return_value
=
false
;
emit_access_stack
(
emit
,
1
,
vtype
,
reg_dest
);
adjust_stack
(
emit
,
-
1
);
}
...
...
@@ -618,7 +618,7 @@ static void emit_native_load_const_id(emit_t *emit, qstr qstr) {
}
}
static
void
emit_native_load_const_str
(
emit_t
*
emit
,
qstr
qstr
,
MP_BOOL
bytes
)
{
static
void
emit_native_load_const_str
(
emit_t
*
emit
,
qstr
qstr
,
bool
bytes
)
{
emit_pre
(
emit
);
if
(
emit
->
do_viper_types
)
{
// not implemented properly
...
...
@@ -1134,7 +1134,7 @@ static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_pa
assert
(
0
);
}
static
void
emit_native_call_function
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
MP_BOOL
have_star_arg
,
MP_BOOL
have_dbl_star_arg
)
{
static
void
emit_native_call_function
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
bool
have_star_arg
,
bool
have_dbl_star_arg
)
{
// call special viper runtime routine with type info for args, and wanted type info for return
assert
(
n_keyword
==
0
&&
!
have_star_arg
&&
!
have_dbl_star_arg
);
/*
...
...
@@ -1170,7 +1170,7 @@ static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyw
emit_post_push_reg
(
emit
,
VTYPE_PYOBJ
,
REG_RET
);
}
static
void
emit_native_call_method
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
MP_BOOL
have_star_arg
,
MP_BOOL
have_dbl_star_arg
)
{
static
void
emit_native_call_method
(
emit_t
*
emit
,
int
n_positional
,
int
n_keyword
,
bool
have_star_arg
,
bool
have_dbl_star_arg
)
{
assert
(
n_keyword
==
0
&&
!
have_star_arg
&&
!
have_dbl_star_arg
);
/*
if (n_positional == 0) {
...
...
@@ -1205,7 +1205,7 @@ static void emit_native_return_value(emit_t *emit) {
}
else
{
assert
(
vtype
==
VTYPE_PYOBJ
);
}
emit
->
last_emit_was_return_value
=
MP_TRUE
;
emit
->
last_emit_was_return_value
=
true
;
#if N_X64
//asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb
asm_x64_exit
(
emit
->
as
);
...
...
py/emitpass1.c
View file @
5fd8fd2c
...
...
@@ -42,7 +42,7 @@ static void emit_pass1_end_pass(emit_t *emit) {
static
void
emit_pass1_load_id
(
emit_t
*
emit
,
qstr
qstr
)
{
// name adding/lookup
MP_BOOL
added
;
bool
added
;
id_info_t
*
id
=
scope_find_or_add_id
(
emit
->
scope
,
qstr
,
&
added
);
if
(
added
)
{
if
(
qstr
==
MP_QSTR_AssertionError
)
{
...
...
@@ -73,7 +73,7 @@ static void emit_pass1_load_id(emit_t *emit, qstr qstr) {
static
id_info_t
*
get_id_for_modification
(
scope_t
*
scope
,
qstr
qstr
)
{
// name adding/lookup
MP_BOOL
added
;
bool
added
;
id_info_t
*
id
=
scope_find_or_add_id
(
scope
,
qstr
,
&
added
);
if
(
added
)
{
if
(
scope
->
kind
==
SCOPE_MODULE
||
scope
->
kind
==
SCOPE_CLASS
)
{
...
...
py/lexer.c
View file @
5fd8fd2c
...
...
@@ -35,7 +35,7 @@ struct _mp_lexer_t {
mp_token_t
tok_cur
;
};
MP_BOOL
str_strn_equal
(
const
char
*
str
,
const
char
*
strn
,
int
len
)
{
bool
str_strn_equal
(
const
char
*
str
,
const
char
*
strn
,
int
len
)
{
uint
i
=
0
;
while
(
i
<
len
&&
*
str
==
*
strn
)
{
...
...
@@ -70,74 +70,74 @@ void mp_token_show_error_prefix(const mp_token_t *tok) {
printf
(
"(%s:%d:%d) "
,
tok
->
src_name
,
tok
->
src_line
,
tok
->
src_column
);
}
MP_BOOL
mp_token_show_error
(
const
mp_token_t
*
tok
,
const
char
*
msg
)
{
bool
mp_token_show_error
(
const
mp_token_t
*
tok
,
const
char
*
msg
)
{
printf
(
"(%s:%d:%d) %s
\n
"
,
tok
->
src_name
,
tok
->
src_line
,
tok
->
src_column
,
msg
);
return
MP_FALSE
;
return
false
;
}
#define CUR_CHAR(lex) ((lex)->chr0)
static
MP_BOOL
is_end
(
mp_lexer_t
*
lex
)
{
static
bool
is_end
(
mp_lexer_t
*
lex
)
{
return
lex
->
chr0
==
MP_LEXER_CHAR_EOF
;
}
static
MP_BOOL
is_physical_newline
(
mp_lexer_t
*
lex
)
{
static
bool
is_physical_newline
(
mp_lexer_t
*
lex
)
{
return
lex
->
chr0
==
'\n'
||
lex
->
chr0
==
'\r'
;
}
static
MP_BOOL
is_char
(
mp_lexer_t
*
lex
,
char
c
)
{
static
bool
is_char
(
mp_lexer_t
*
lex
,
char
c
)
{
return
lex
->
chr0
==
c
;
}
static
MP_BOOL
is_char_or
(
mp_lexer_t
*
lex
,
char
c1
,
char
c2
)
{
static
bool
is_char_or
(
mp_lexer_t
*
lex
,
char
c1
,
char
c2
)
{
return
lex
->
chr0
==
c1
||
lex
->
chr0
==
c2
;
}
static
MP_BOOL
is_char_or3
(
mp_lexer_t
*
lex
,
char
c1
,
char
c2
,
char
c3
)
{
static
bool
is_char_or3
(
mp_lexer_t
*
lex
,
char
c1
,
char
c2
,
char
c3
)
{
return
lex
->
chr0
==
c1
||
lex
->
chr0
==
c2
||
lex
->
chr0
==
c3
;
}
/*
static
MP_BOOL
is_char_following(mp_lexer_t *lex, char c) {
static
bool
is_char_following(mp_lexer_t *lex, char c) {
return lex->chr1 == c;
}
*/
static
MP_BOOL
is_char_following_or
(
mp_lexer_t
*
lex
,
char
c1
,
char
c2
)
{
static
bool
is_char_following_or
(
mp_lexer_t
*
lex
,
char
c1
,
char
c2
)
{
return
lex
->
chr1
==
c1
||
lex
->
chr1
==
c2
;
}
static
MP_BOOL
is_char_following_following_or
(
mp_lexer_t
*
lex
,
char
c1
,
char
c2
)
{
static
bool
is_char_following_following_or
(
mp_lexer_t
*
lex
,
char
c1
,
char
c2
)
{
return
lex
->
chr2
==
c1
||
lex
->
chr2
==
c2
;
}
static
MP_BOOL
is_char_and
(
mp_lexer_t
*
lex
,
char
c1
,
char
c2
)
{
static
bool
is_char_and
(
mp_lexer_t
*
lex
,
char
c1
,
char
c2
)
{
return
lex
->
chr0
==
c1
&&
lex
->
chr1
==
c2
;
}
static
MP_BOOL
is_whitespace
(
mp_lexer_t
*
lex
)
{
static
bool
is_whitespace
(
mp_lexer_t
*
lex
)
{
return
unichar_isspace
(
lex
->
chr0
);
}
static
MP_BOOL
is_letter
(
mp_lexer_t
*
lex
)
{
static
bool
is_letter
(
mp_lexer_t
*
lex
)
{
return
unichar_isalpha
(
lex
->
chr0
);
}
static
MP_BOOL
is_digit
(
mp_lexer_t
*
lex
)
{
static
bool
is_digit
(
mp_lexer_t
*
lex
)
{
return
unichar_isdigit
(
lex
->
chr0
);
}
static
MP_BOOL
is_following_digit
(
mp_lexer_t
*
lex
)
{
static
bool
is_following_digit
(
mp_lexer_t
*
lex
)
{
return
unichar_isdigit
(
lex
->
chr1
);
}
// TODO UNICODE include unicode characters in definition of identifiers
static
MP_BOOL
is_head_of_identifier
(
mp_lexer_t
*
lex
)
{
static
bool
is_head_of_identifier
(
mp_lexer_t
*
lex
)
{
return
is_letter
(
lex
)
||
lex
->
chr0
==
'_'
;
}
// TODO UNICODE include unicode characters in definition of identifiers
static
MP_BOOL
is_tail_of_identifier
(
mp_lexer_t
*
lex
)
{
static
bool
is_tail_of_identifier
(
mp_lexer_t
*
lex
)
{
return
is_head_of_identifier
(
lex
)
||
is_digit
(
lex
);
}
...
...
@@ -280,12 +280,12 @@ static const char *tok_kw[] = {
NULL
,
};
static
void
mp_lexer_next_token_into
(
mp_lexer_t
*
lex
,
mp_token_t
*
tok
,
MP_BOOL
first_token
)
{
static
void
mp_lexer_next_token_into
(
mp_lexer_t
*
lex
,
mp_token_t
*
tok
,
bool
first_token
)
{
// skip white space and comments
MP_BOOL
had_physical_newline
=
MP_FALSE
;
bool
had_physical_newline
=
false
;
while
(
!
is_end
(
lex
))
{
if
(
is_physical_newline
(
lex
))
{
had_physical_newline
=
MP_TRUE
;
had_physical_newline
=
true
;
next_char
(
lex
);
}
else
if
(
is_whitespace
(
lex
))
{
next_char
(
lex
);
...
...
@@ -369,22 +369,22 @@ static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, MP_BOOL f
// a string or bytes literal
// parse type codes
MP_BOOL
is_raw
=
MP_FALSE
;
MP_BOOL
is_bytes
=
MP_FALSE
;
bool