Skip to content
Snippets Groups Projects
Commit 7a16fadb authored by ian-v's avatar ian-v
Browse files

Co-exist with C++ (issue #85)

parent e03c0533
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ asm_thumb_t *asm_thumb_new(uint max_num_labels) { ...@@ -45,7 +45,7 @@ asm_thumb_t *asm_thumb_new(uint max_num_labels) {
return as; return as;
} }
void asm_thumb_free(asm_thumb_t *as, bool free_code) { void asm_thumb_free(asm_thumb_t *as, MP_BOOL free_code) {
if (free_code) { if (free_code) {
m_del(byte, as->code_base, as->code_size); m_del(byte, as->code_base, as->code_size);
} }
...@@ -56,9 +56,9 @@ void asm_thumb_free(asm_thumb_t *as, bool free_code) { ...@@ -56,9 +56,9 @@ void asm_thumb_free(asm_thumb_t *as, bool free_code) {
{ {
Label *lab = &g_array_index(as->label, Label, i); Label *lab = &g_array_index(as->label, Label, i);
if (lab->unresolved != NULL) if (lab->unresolved != NULL)
g_array_free(lab->unresolved, true); g_array_free(lab->unresolved, MP_TRUE);
} }
g_array_free(as->label, true); g_array_free(as->label, MP_TRUE);
} }
*/ */
m_del_obj(asm_thumb_t, as); m_del_obj(asm_thumb_t, as);
...@@ -87,7 +87,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) { ...@@ -87,7 +87,7 @@ void asm_thumb_end_pass(asm_thumb_t *as) {
int i; int i;
for (i = 0; i < as->label->len; ++i) for (i = 0; i < as->label->len; ++i)
if (g_array_index(as->label, Label, i).unresolved != NULL) if (g_array_index(as->label, Label, i).unresolved != NULL)
return false; return MP_FALSE;
} }
*/ */
} }
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
typedef struct _asm_thumb_t asm_thumb_t; typedef struct _asm_thumb_t asm_thumb_t;
asm_thumb_t *asm_thumb_new(uint max_num_labels); asm_thumb_t *asm_thumb_new(uint max_num_labels);
void asm_thumb_free(asm_thumb_t *as, bool free_code); void asm_thumb_free(asm_thumb_t *as, MP_BOOL free_code);
void asm_thumb_start_pass(asm_thumb_t *as, int pass); void asm_thumb_start_pass(asm_thumb_t *as, int pass);
void asm_thumb_end_pass(asm_thumb_t *as); void asm_thumb_end_pass(asm_thumb_t *as);
uint asm_thumb_get_code_size(asm_thumb_t *as); uint asm_thumb_get_code_size(asm_thumb_t *as);
......
...@@ -94,7 +94,7 @@ struct _asm_x64_t { ...@@ -94,7 +94,7 @@ struct _asm_x64_t {
}; };
// for allocating memory, see src/v8/src/platform-linux.cc // for allocating memory, see src/v8/src/platform-linux.cc
void *alloc_mem(uint req_size, uint *alloc_size, bool is_exec) { void *alloc_mem(uint req_size, uint *alloc_size, MP_BOOL is_exec) {
req_size = (req_size + 0xfff) & (~0xfff); req_size = (req_size + 0xfff) & (~0xfff);
int prot = PROT_READ | PROT_WRITE | (is_exec ? PROT_EXEC : 0); int prot = PROT_READ | PROT_WRITE | (is_exec ? PROT_EXEC : 0);
void *ptr = mmap(NULL, req_size, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 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) { ...@@ -119,7 +119,7 @@ asm_x64_t* asm_x64_new(uint max_num_labels) {
return as; return as;
} }
void asm_x64_free(asm_x64_t* as, bool free_code) { void asm_x64_free(asm_x64_t* as, MP_BOOL free_code) {
if (free_code) { if (free_code) {
// need to un-mmap // need to un-mmap
//m_free(as->code_base); //m_free(as->code_base);
...@@ -131,9 +131,9 @@ void asm_x64_free(asm_x64_t* as, bool free_code) { ...@@ -131,9 +131,9 @@ void asm_x64_free(asm_x64_t* as, bool free_code) {
{ {
Label* lab = &g_array_index(as->label, Label, i); Label* lab = &g_array_index(as->label, Label, i);
if (lab->unresolved != NULL) if (lab->unresolved != NULL)
g_array_free(lab->unresolved, true); g_array_free(lab->unresolved, MP_TRUE);
} }
g_array_free(as->label, true); g_array_free(as->label, MP_TRUE);
} }
*/ */
m_del_obj(asm_x64_t, as); m_del_obj(asm_x64_t, as);
...@@ -154,7 +154,7 @@ void asm_x64_end_pass(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_size = as->code_offset;
//as->code_base = m_new(byte, as->code_size); need to allocale executable memory //as->code_base = m_new(byte, as->code_size); need to allocale executable memory
uint actual_alloc; uint actual_alloc;
as->code_base = alloc_mem(as->code_size, &actual_alloc, true); as->code_base = alloc_mem(as->code_size, &actual_alloc, MP_TRUE);
printf("code_size: %u\n", as->code_size); printf("code_size: %u\n", as->code_size);
} }
...@@ -165,7 +165,7 @@ void asm_x64_end_pass(asm_x64_t *as) { ...@@ -165,7 +165,7 @@ void asm_x64_end_pass(asm_x64_t *as) {
int i; int i;
for (i = 0; i < as->label->len; ++i) for (i = 0; i < as->label->len; ++i)
if (g_array_index(as->label, Label, i).unresolved != NULL) if (g_array_index(as->label, Label, i).unresolved != NULL)
return false; return MP_FALSE;
} }
*/ */
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
typedef struct _asm_x64_t asm_x64_t; typedef struct _asm_x64_t asm_x64_t;
asm_x64_t* asm_x64_new(uint max_num_labels); asm_x64_t* asm_x64_new(uint max_num_labels);
void asm_x64_free(asm_x64_t* as, bool free_code); void asm_x64_free(asm_x64_t* as, MP_BOOL free_code);
void asm_x64_start_pass(asm_x64_t *as, int pass); void asm_x64_start_pass(asm_x64_t *as, int pass);
void asm_x64_end_pass(asm_x64_t *as); void asm_x64_end_pass(asm_x64_t *as);
uint asm_x64_get_code_size(asm_x64_t* as); uint asm_x64_get_code_size(asm_x64_t* as);
......
mp_obj_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, uint n_state); mp_obj_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, uint n_state);
bool mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out); MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out);
...@@ -58,7 +58,7 @@ mp_obj_t mp_builtin___import__(int n, mp_obj_t *args) { ...@@ -58,7 +58,7 @@ mp_obj_t mp_builtin___import__(int n, mp_obj_t *args) {
return mp_const_none; return mp_const_none;
} }
mp_obj_t module_fun = mp_compile(pn, false); mp_obj_t module_fun = mp_compile(pn, MP_FALSE);
if (module_fun == mp_const_none) { if (module_fun == mp_const_none) {
// TODO handle compile error correctly // TODO handle compile error correctly
......
This diff is collapsed.
mp_obj_t mp_compile(mp_parse_node_t pn, bool is_repl); mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl);
...@@ -17,10 +17,10 @@ typedef enum { ...@@ -17,10 +17,10 @@ typedef enum {
typedef struct _emit_t emit_t; typedef struct _emit_t emit_t;
typedef struct _emit_method_table_t { typedef struct _emit_method_table_t {
void (*set_native_types)(emit_t *emit, bool do_native_types); void (*set_native_types)(emit_t *emit, MP_BOOL do_native_types);
void (*start_pass)(emit_t *emit, pass_kind_t pass, scope_t *scope); void (*start_pass)(emit_t *emit, pass_kind_t pass, scope_t *scope);
void (*end_pass)(emit_t *emit); void (*end_pass)(emit_t *emit);
bool (*last_emit_was_return_value)(emit_t *emit); MP_BOOL (*last_emit_was_return_value)(emit_t *emit);
int (*get_stack_size)(emit_t *emit); int (*get_stack_size)(emit_t *emit);
void (*set_stack_size)(emit_t *emit, int size); void (*set_stack_size)(emit_t *emit, int size);
...@@ -37,7 +37,7 @@ typedef struct _emit_method_table_t { ...@@ -37,7 +37,7 @@ typedef struct _emit_method_table_t {
void (*load_const_int)(emit_t *emit, qstr qstr); void (*load_const_int)(emit_t *emit, qstr qstr);
void (*load_const_dec)(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_id)(emit_t *emit, qstr qstr);
void (*load_const_str)(emit_t *emit, qstr qstr, bool bytes); void (*load_const_str)(emit_t *emit, qstr qstr, MP_BOOL bytes);
void (*load_const_verbatim_str)(emit_t *emit, const char *str); // only needed for emitcpy 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_fast)(emit_t *emit, qstr qstr, int local_num);
void (*load_deref)(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 { ...@@ -99,8 +99,8 @@ typedef struct _emit_method_table_t {
void (*unpack_ex)(emit_t *emit, int n_left, int n_right); 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_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 (*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, bool have_star_arg, bool have_dbl_star_arg); 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, bool have_star_arg, 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 (*return_value)(emit_t *emit); void (*return_value)(emit_t *emit);
void (*raise_varargs)(emit_t *emit, int n_args); void (*raise_varargs)(emit_t *emit, int n_args);
void (*yield_value)(emit_t *emit); void (*yield_value)(emit_t *emit);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
struct _emit_t { struct _emit_t {
pass_kind_t pass; pass_kind_t pass;
int stack_size; int stack_size;
bool last_emit_was_return_value; MP_BOOL last_emit_was_return_value;
scope_t *scope; scope_t *scope;
...@@ -135,13 +135,13 @@ static void emit_write_byte_1_signed_label(emit_t* emit, byte b1, int label) { ...@@ -135,13 +135,13 @@ static void emit_write_byte_1_signed_label(emit_t* emit, byte b1, int label) {
c[2] = code_offset >> 8; c[2] = code_offset >> 8;
} }
static void emit_bc_set_native_types(emit_t *emit, bool do_native_types) { static void emit_bc_set_native_types(emit_t *emit, MP_BOOL do_native_types) {
} }
static void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { static void emit_bc_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
emit->pass = pass; emit->pass = pass;
emit->stack_size = 0; emit->stack_size = 0;
emit->last_emit_was_return_value = false; emit->last_emit_was_return_value = MP_FALSE;
emit->scope = scope; emit->scope = scope;
if (pass == PASS_2) { if (pass == PASS_2) {
memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(uint)); memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(uint));
...@@ -182,7 +182,7 @@ static void emit_bc_end_pass(emit_t *emit) { ...@@ -182,7 +182,7 @@ static void emit_bc_end_pass(emit_t *emit) {
} }
} }
bool emit_bc_last_emit_was_return_value(emit_t *emit) { MP_BOOL emit_bc_last_emit_was_return_value(emit_t *emit) {
return emit->last_emit_was_return_value; return emit->last_emit_was_return_value;
} }
...@@ -211,7 +211,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta) { ...@@ -211,7 +211,7 @@ static void emit_pre(emit_t *emit, int stack_size_delta) {
if (emit->stack_size > emit->scope->stack_size) { if (emit->stack_size > emit->scope->stack_size) {
emit->scope->stack_size = emit->stack_size; emit->scope->stack_size = emit->stack_size;
} }
emit->last_emit_was_return_value = false; emit->last_emit_was_return_value = MP_FALSE;
} }
static void emit_bc_label_assign(emit_t *emit, int l) { 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) { ...@@ -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); emit_write_byte_1_qstr(emit, MP_BC_LOAD_CONST_ID, qstr);
} }
static void emit_bc_load_const_str(emit_t *emit, qstr qstr, bool bytes) { static void emit_bc_load_const_str(emit_t *emit, qstr qstr, MP_BOOL bytes) {
emit_pre(emit, 1); emit_pre(emit, 1);
if (bytes) { if (bytes) {
emit_write_byte_1_qstr(emit, MP_BC_LOAD_CONST_BYTES, qstr); 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 ...@@ -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); 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, bool have_star_arg, bool have_dbl_star_arg) { 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) {
int s = 0; int s = 0;
if (have_star_arg) { if (have_star_arg) {
s += 1; s += 1;
...@@ -639,7 +639,7 @@ static void emit_bc_call_function(emit_t *emit, int n_positional, int n_keyword, ...@@ -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 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, bool have_star_arg, bool have_dbl_star_arg) { 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) {
int s = 0; int s = 0;
if (have_star_arg) { if (have_star_arg) {
s += 1; s += 1;
...@@ -667,7 +667,7 @@ static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, b ...@@ -667,7 +667,7 @@ static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, b
static void emit_bc_return_value(emit_t *emit) { static void emit_bc_return_value(emit_t *emit) {
emit_pre(emit, -1); emit_pre(emit, -1);
emit->last_emit_was_return_value = true; emit->last_emit_was_return_value = MP_TRUE;
emit_write_byte_1(emit, MP_BC_RETURN_VALUE); emit_write_byte_1(emit, MP_BC_RETURN_VALUE);
} }
......
...@@ -20,7 +20,7 @@ struct _emit_t { ...@@ -20,7 +20,7 @@ struct _emit_t {
int pass; int pass;
int byte_code_offset; int byte_code_offset;
int stack_size; int stack_size;
bool last_emit_was_return_value; MP_BOOL last_emit_was_return_value;
scope_t *scope; scope_t *scope;
...@@ -35,14 +35,14 @@ emit_t *emit_cpython_new(uint max_num_labels) { ...@@ -35,14 +35,14 @@ emit_t *emit_cpython_new(uint max_num_labels) {
return emit; return emit;
} }
static void emit_cpy_set_native_types(emit_t *emit, bool do_native_types) { static void emit_cpy_set_native_types(emit_t *emit, MP_BOOL do_native_types) {
} }
static void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { static void emit_cpy_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) {
emit->pass = pass; emit->pass = pass;
emit->byte_code_offset = 0; emit->byte_code_offset = 0;
emit->stack_size = 0; emit->stack_size = 0;
emit->last_emit_was_return_value = false; emit->last_emit_was_return_value = MP_FALSE;
emit->scope = scope; emit->scope = scope;
if (pass == PASS_2) { if (pass == PASS_2) {
memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(int)); memset(emit->label_offsets, -1, emit->max_num_labels * sizeof(int));
...@@ -56,7 +56,7 @@ static void emit_cpy_end_pass(emit_t *emit) { ...@@ -56,7 +56,7 @@ static void emit_cpy_end_pass(emit_t *emit) {
} }
} }
static bool emit_cpy_last_emit_was_return_value(emit_t *emit) { static MP_BOOL emit_cpy_last_emit_was_return_value(emit_t *emit) {
return emit->last_emit_was_return_value; 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) { ...@@ -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) { if (emit->stack_size > emit->scope->stack_size) {
emit->scope->stack_size = emit->stack_size; emit->scope->stack_size = emit->stack_size;
} }
emit->last_emit_was_return_value = false; emit->last_emit_was_return_value = MP_FALSE;
if (emit->pass == PASS_3 && byte_code_size > 0) { if (emit->pass == PASS_3 && byte_code_size > 0) {
if (emit->byte_code_offset >= 1000) { if (emit->byte_code_offset >= 1000) {
printf("%d ", emit->byte_code_offset); printf("%d ", emit->byte_code_offset);
...@@ -173,26 +173,26 @@ static void emit_cpy_load_const_id(emit_t *emit, qstr qstr) { ...@@ -173,26 +173,26 @@ static void emit_cpy_load_const_id(emit_t *emit, qstr qstr) {
} }
} }
static void print_quoted_str(qstr qstr, bool bytes) { static void print_quoted_str(qstr qstr, MP_BOOL bytes) {
const char *str = qstr_str(qstr); const char *str = qstr_str(qstr);
int len = strlen(str); int len = strlen(str);
bool has_single_quote = false; MP_BOOL has_single_quote = MP_FALSE;
bool has_double_quote = false; MP_BOOL has_double_quote = MP_FALSE;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
if (str[i] == '\'') { if (str[i] == '\'') {
has_single_quote = true; has_single_quote = MP_TRUE;
} else if (str[i] == '"') { } else if (str[i] == '"') {
has_double_quote = true; has_double_quote = MP_TRUE;
} }
} }
if (bytes) { if (bytes) {
printf("b"); printf("b");
} }
bool quote_single = false; MP_BOOL quote_single = MP_FALSE;
if (has_single_quote && !has_double_quote) { if (has_single_quote && !has_double_quote) {
printf("\""); printf("\"");
} else { } else {
quote_single = true; quote_single = MP_TRUE;
printf("'"); printf("'");
} }
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
...@@ -213,7 +213,7 @@ static void print_quoted_str(qstr qstr, bool bytes) { ...@@ -213,7 +213,7 @@ static void print_quoted_str(qstr qstr, bool bytes) {
} }
} }
static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, bool bytes) { static void emit_cpy_load_const_str(emit_t *emit, qstr qstr, MP_BOOL bytes) {
emit_pre(emit, 1, 3); emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) { if (emit->pass == PASS_3) {
printf("LOAD_CONST "); printf("LOAD_CONST ");
...@@ -681,7 +681,7 @@ static void emit_cpy_unpack_ex(emit_t *emit, int n_left, int n_right) { ...@@ -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, bool have_star_arg, bool have_dbl_star_arg) { 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) {
int s = 0; int s = 0;
if (have_star_arg) { if (have_star_arg) {
s += 1; s += 1;
...@@ -708,13 +708,13 @@ static void emit_cpy_call_function(emit_t *emit, int n_positional, int n_keyword ...@@ -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, bool have_star_arg, bool have_dbl_star_arg) { 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) {
emit_cpy_call_function(emit, n_positional, n_keyword, have_star_arg, 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) { static void emit_cpy_return_value(emit_t *emit) {
emit_pre(emit, -1, 1); emit_pre(emit, -1, 1);
emit->last_emit_was_return_value = true; emit->last_emit_was_return_value = MP_TRUE;
if (emit->pass == PASS_3) { if (emit->pass == PASS_3) {
printf("RETURN_VALUE\n"); printf("RETURN_VALUE\n");
} }
......
...@@ -75,12 +75,12 @@ static void emit_inline_thumb_label(emit_inline_asm_t *emit, int label_num, qstr ...@@ -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); asm_thumb_label_assign(emit->as, label_num);
} }
static bool check_n_arg(qstr op, int n_args, int wanted_n_args) { static MP_BOOL check_n_arg(qstr op, int n_args, int wanted_n_args) {
if (wanted_n_args == n_args) { if (wanted_n_args == n_args) {
return true; return MP_TRUE;
} else { } else {
printf("SyntaxError: '%s' expects %d arguments'\n", qstr_str(op), wanted_n_args); printf("SyntaxError: '%s' expects %d arguments'\n", qstr_str(op), wanted_n_args);
return false; return MP_FALSE;
} }
} }
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
#define REG_TEMP2 (REG_RSI) #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_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_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 (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 (MP_FALSE)
#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_x64_mov_local_to_r64(emit->as, (local_num), (reg)) #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_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)) #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 @@ ...@@ -75,7 +75,7 @@
#define REG_TEMP2 (REG_R2) #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_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_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 (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 (MP_FALSE)
#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_thumb_mov_reg_local(emit->as, (reg), (local_num)) #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_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)) #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 { ...@@ -110,7 +110,7 @@ typedef struct _stack_info_t {
struct _emit_t { struct _emit_t {
int pass; int pass;
bool do_viper_types; MP_BOOL do_viper_types;
int local_vtype_alloc; int local_vtype_alloc;
vtype_kind_t *local_vtype; vtype_kind_t *local_vtype;
...@@ -121,7 +121,7 @@ struct _emit_t { ...@@ -121,7 +121,7 @@ struct _emit_t {
int stack_start; int stack_start;
int stack_size; int stack_size;
bool last_emit_was_return_value; MP_BOOL last_emit_was_return_value;
scope_t *scope; scope_t *scope;
...@@ -134,7 +134,7 @@ struct _emit_t { ...@@ -134,7 +134,7 @@ struct _emit_t {
emit_t *EXPORT_FUN(new)(uint max_num_labels) { emit_t *EXPORT_FUN(new)(uint max_num_labels) {
emit_t *emit = m_new(emit_t, 1); emit_t *emit = m_new(emit_t, 1);
emit->do_viper_types = false; emit->do_viper_types = MP_FALSE;
emit->local_vtype = NULL; emit->local_vtype = NULL;
emit->stack_info = NULL; emit->stack_info = NULL;
#if N_X64 #if N_X64
...@@ -145,7 +145,7 @@ emit_t *EXPORT_FUN(new)(uint max_num_labels) { ...@@ -145,7 +145,7 @@ emit_t *EXPORT_FUN(new)(uint max_num_labels) {
return emit; return emit;
} }
static void emit_native_set_viper_types(emit_t *emit, bool do_viper_types) { static void emit_native_set_viper_types(emit_t *emit, MP_BOOL do_viper_types) {
emit->do_viper_types = 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 ...@@ -153,7 +153,7 @@ static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
emit->pass = pass; emit->pass = pass;
emit->stack_start = 0; emit->stack_start = 0;
emit->stack_size = 0; emit->stack_size = 0;
emit->last_emit_was_return_value = false; emit->last_emit_was_return_value = MP_FALSE;
emit->scope = scope; emit->scope = scope;
if (emit->local_vtype == NULL) { if (emit->local_vtype == NULL) {
...@@ -269,7 +269,7 @@ static void emit_native_end_pass(emit_t *emit) { ...@@ -269,7 +269,7 @@ static void emit_native_end_pass(emit_t *emit) {
} }
} }
static bool emit_native_last_emit_was_return_value(emit_t *emit) { static MP_BOOL emit_native_last_emit_was_return_value(emit_t *emit) {
return emit->last_emit_was_return_value; return emit->last_emit_was_return_value;
} }
...@@ -292,13 +292,13 @@ static void adjust_stack(emit_t *emit, int stack_size_delta) { ...@@ -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) { static void emit_pre_raw(emit_t *emit, int stack_size_delta) {
adjust_stack(emit, stack_size_delta); adjust_stack(emit, stack_size_delta);
emit->last_emit_was_return_value = false; emit->last_emit_was_return_value = MP_FALSE;
} }
*/ */
// this must be called at start of emit functions // this must be called at start of emit functions
static void emit_pre(emit_t *emit) { static void emit_pre(emit_t *emit) {
emit->last_emit_was_return_value = false; emit->last_emit_was_return_value = MP_FALSE;
// settle the stack // settle the stack
/* /*
if (regs_needed != 0) { if (regs_needed != 0) {
...@@ -391,7 +391,7 @@ static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int re ...@@ -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) { static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) {
emit->last_emit_was_return_value = false; emit->last_emit_was_return_value = MP_FALSE;
emit_access_stack(emit, 1, vtype, reg_dest); emit_access_stack(emit, 1, vtype, reg_dest);
adjust_stack(emit, -1); adjust_stack(emit, -1);
} }
...@@ -618,7 +618,7 @@ static void emit_native_load_const_id(emit_t *emit, qstr qstr) { ...@@ -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, bool bytes) { static void emit_native_load_const_str(emit_t *emit, qstr qstr, MP_BOOL bytes) {
emit_pre(emit); emit_pre(emit);
if (emit->do_viper_types) { if (emit->do_viper_types) {
// not implemented properly // not implemented properly
...@@ -1134,7 +1134,7 @@ static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_pa ...@@ -1134,7 +1134,7 @@ static void emit_native_make_closure(emit_t *emit, scope_t *scope, int n_dict_pa
assert(0); assert(0);
} }
static void emit_native_call_function(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { 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) {
// call special viper runtime routine with type info for args, and wanted type info for return // 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); 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 ...@@ -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); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
} }
static void emit_native_call_method(emit_t *emit, int n_positional, int n_keyword, bool have_star_arg, bool have_dbl_star_arg) { 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) {
assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg); assert(n_keyword == 0 && !have_star_arg && !have_dbl_star_arg);
/* /*
if (n_positional == 0) { if (n_positional == 0) {
...@@ -1205,7 +1205,7 @@ static void emit_native_return_value(emit_t *emit) { ...@@ -1205,7 +1205,7 @@ static void emit_native_return_value(emit_t *emit) {
} else { } else {
assert(vtype == VTYPE_PYOBJ); assert(vtype == VTYPE_PYOBJ);
} }
emit->last_emit_was_return_value = true; emit->last_emit_was_return_value = MP_TRUE;
#if N_X64 #if N_X64
//asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb //asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb
asm_x64_exit(emit->as); asm_x64_exit(emit->as);
......
...@@ -42,7 +42,7 @@ static void emit_pass1_end_pass(emit_t *emit) { ...@@ -42,7 +42,7 @@ static void emit_pass1_end_pass(emit_t *emit) {
static void emit_pass1_load_id(emit_t *emit, qstr qstr) { static void emit_pass1_load_id(emit_t *emit, qstr qstr) {
// name adding/lookup // name adding/lookup
bool added; MP_BOOL added;
id_info_t *id = scope_find_or_add_id(emit->scope, qstr, &added); id_info_t *id = scope_find_or_add_id(emit->scope, qstr, &added);
if (added) { if (added) {
if (qstr == MP_QSTR_AssertionError) { if (qstr == MP_QSTR_AssertionError) {
...@@ -73,7 +73,7 @@ static void emit_pass1_load_id(emit_t *emit, qstr qstr) { ...@@ -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) { static id_info_t *get_id_for_modification(scope_t *scope, qstr qstr) {
// name adding/lookup // name adding/lookup
bool added; MP_BOOL added;
id_info_t *id = scope_find_or_add_id(scope, qstr, &added); id_info_t *id = scope_find_or_add_id(scope, qstr, &added);
if (added) { if (added) {
if (scope->kind == SCOPE_MODULE || scope->kind == SCOPE_CLASS) { if (scope->kind == SCOPE_MODULE || scope->kind == SCOPE_CLASS) {
......
...@@ -35,7 +35,7 @@ struct _mp_lexer_t { ...@@ -35,7 +35,7 @@ struct _mp_lexer_t {
mp_token_t tok_cur; mp_token_t tok_cur;
}; };
bool str_strn_equal(const char *str, const char *strn, int len) { MP_BOOL str_strn_equal(const char *str, const char *strn, int len) {
uint i = 0; uint i = 0;
while (i < len && *str == *strn) { while (i < len && *str == *strn) {
...@@ -70,74 +70,74 @@ void mp_token_show_error_prefix(const mp_token_t *tok) { ...@@ -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); printf("(%s:%d:%d) ", tok->src_name, tok->src_line, tok->src_column);
} }
bool mp_token_show_error(const mp_token_t *tok, const char *msg) { MP_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); printf("(%s:%d:%d) %s\n", tok->src_name, tok->src_line, tok->src_column, msg);
return false; return MP_FALSE;
} }
#define CUR_CHAR(lex) ((lex)->chr0) #define CUR_CHAR(lex) ((lex)->chr0)
static bool is_end(mp_lexer_t *lex) { static MP_BOOL is_end(mp_lexer_t *lex) {
return lex->chr0 == MP_LEXER_CHAR_EOF; return lex->chr0 == MP_LEXER_CHAR_EOF;
} }
static bool is_physical_newline(mp_lexer_t *lex) { static MP_BOOL is_physical_newline(mp_lexer_t *lex) {
return lex->chr0 == '\n' || lex->chr0 == '\r'; return lex->chr0 == '\n' || lex->chr0 == '\r';
} }
static bool is_char(mp_lexer_t *lex, char c) { static MP_BOOL is_char(mp_lexer_t *lex, char c) {
return lex->chr0 == c; return lex->chr0 == c;
} }
static bool is_char_or(mp_lexer_t *lex, char c1, char c2) { static MP_BOOL is_char_or(mp_lexer_t *lex, char c1, char c2) {
return lex->chr0 == c1 || lex->chr0 == c2; return lex->chr0 == c1 || lex->chr0 == c2;
} }
static bool is_char_or3(mp_lexer_t *lex, char c1, char c2, char c3) { static MP_BOOL is_char_or3(mp_lexer_t *lex, char c1, char c2, char c3) {
return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3; return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3;
} }
/* /*
static bool is_char_following(mp_lexer_t *lex, char c) { static MP_BOOL is_char_following(mp_lexer_t *lex, char c) {
return lex->chr1 == c; return lex->chr1 == c;
} }
*/ */
static bool is_char_following_or(mp_lexer_t *lex, char c1, char c2) { static MP_BOOL is_char_following_or(mp_lexer_t *lex, char c1, char c2) {
return lex->chr1 == c1 || lex->chr1 == c2; return lex->chr1 == c1 || lex->chr1 == c2;
} }
static bool is_char_following_following_or(mp_lexer_t *lex, char c1, char c2) { static MP_BOOL is_char_following_following_or(mp_lexer_t *lex, char c1, char c2) {
return lex->chr2 == c1 || lex->chr2 == c2; return lex->chr2 == c1 || lex->chr2 == c2;
} }
static bool is_char_and(mp_lexer_t *lex, char c1, char c2) { static MP_BOOL is_char_and(mp_lexer_t *lex, char c1, char c2) {
return lex->chr0 == c1 && lex->chr1 == c2; return lex->chr0 == c1 && lex->chr1 == c2;
} }
static bool is_whitespace(mp_lexer_t *lex) { static MP_BOOL is_whitespace(mp_lexer_t *lex) {
return unichar_isspace(lex->chr0); return unichar_isspace(lex->chr0);
} }
static bool is_letter(mp_lexer_t *lex) { static MP_BOOL is_letter(mp_lexer_t *lex) {
return unichar_isalpha(lex->chr0); return unichar_isalpha(lex->chr0);
} }
static bool is_digit(mp_lexer_t *lex) { static MP_BOOL is_digit(mp_lexer_t *lex) {
return unichar_isdigit(lex->chr0); return unichar_isdigit(lex->chr0);
} }
static bool is_following_digit(mp_lexer_t *lex) { static MP_BOOL is_following_digit(mp_lexer_t *lex) {
return unichar_isdigit(lex->chr1); return unichar_isdigit(lex->chr1);
} }
// TODO UNICODE include unicode characters in definition of identifiers // TODO UNICODE include unicode characters in definition of identifiers
static bool is_head_of_identifier(mp_lexer_t *lex) { static MP_BOOL is_head_of_identifier(mp_lexer_t *lex) {
return is_letter(lex) || lex->chr0 == '_'; return is_letter(lex) || lex->chr0 == '_';
} }
// TODO UNICODE include unicode characters in definition of identifiers // TODO UNICODE include unicode characters in definition of identifiers
static bool is_tail_of_identifier(mp_lexer_t *lex) { static MP_BOOL is_tail_of_identifier(mp_lexer_t *lex) {
return is_head_of_identifier(lex) || is_digit(lex); return is_head_of_identifier(lex) || is_digit(lex);
} }
...@@ -280,12 +280,12 @@ static const char *tok_kw[] = { ...@@ -280,12 +280,12 @@ static const char *tok_kw[] = {
NULL, NULL,
}; };
static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool first_token) { static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, MP_BOOL first_token) {
// skip white space and comments // skip white space and comments
bool had_physical_newline = false; MP_BOOL had_physical_newline = MP_FALSE;
while (!is_end(lex)) { while (!is_end(lex)) {
if (is_physical_newline(lex)) { if (is_physical_newline(lex)) {
had_physical_newline = true; had_physical_newline = MP_TRUE;
next_char(lex); next_char(lex);
} else if (is_whitespace(lex)) { } else if (is_whitespace(lex)) {
next_char(lex); next_char(lex);
...@@ -369,22 +369,22 @@ static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs ...@@ -369,22 +369,22 @@ static void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
// a string or bytes literal // a string or bytes literal
// parse type codes // parse type codes
bool is_raw = false; MP_BOOL is_raw = MP_FALSE;
bool is_bytes = false; MP_BOOL is_bytes = MP_FALSE;
if (is_char(lex, 'u')) { if (is_char(lex, 'u')) {
next_char(lex); next_char(lex);
} else if (is_char(lex, 'b')) { } else if (is_char(lex, 'b')) {
is_bytes = true; is_bytes = MP_TRUE;
next_char(lex); next_char(lex);
if (is_char(lex, 'r')) { if (is_char(lex, 'r')) {
is_raw = true; is_raw = MP_TRUE;
next_char(lex); next_char(lex);
} }
} else if (is_char(lex, 'r')) { } else if (is_char(lex, 'r')) {
is_raw = true; is_raw = MP_TRUE;
next_char(lex); next_char(lex);
if (is_char(lex, 'b')) { if (is_char(lex, 'b')) {
is_bytes = true; is_bytes = MP_TRUE;
next_char(lex); next_char(lex);
} }
} }
...@@ -628,7 +628,7 @@ mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_strea ...@@ -628,7 +628,7 @@ mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_strea
} }
// preload first token // preload first token
mp_lexer_next_token_into(lex, &lex->tok_cur, true); mp_lexer_next_token_into(lex, &lex->tok_cur, MP_TRUE);
return lex; return lex;
} }
...@@ -644,44 +644,44 @@ void mp_lexer_free(mp_lexer_t *lex) { ...@@ -644,44 +644,44 @@ void mp_lexer_free(mp_lexer_t *lex) {
} }
void mp_lexer_to_next(mp_lexer_t *lex) { void mp_lexer_to_next(mp_lexer_t *lex) {
mp_lexer_next_token_into(lex, &lex->tok_cur, false); mp_lexer_next_token_into(lex, &lex->tok_cur, MP_FALSE);
} }
const mp_token_t *mp_lexer_cur(const mp_lexer_t *lex) { const mp_token_t *mp_lexer_cur(const mp_lexer_t *lex) {
return &lex->tok_cur; return &lex->tok_cur;
} }
bool mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind) { MP_BOOL mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind) {
return lex->tok_cur.kind == kind; return lex->tok_cur.kind == kind;
} }
/* /*
bool mp_lexer_is_str(mp_lexer_t *lex, const char *str) { MP_BOOL mp_lexer_is_str(mp_lexer_t *lex, const char *str) {
return mp_token_is_str(&lex->tok_cur, str); return mp_token_is_str(&lex->tok_cur, str);
} }
bool mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind) { MP_BOOL mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind) {
if (mp_lexer_is_kind(lex, kind)) { if (mp_lexer_is_kind(lex, kind)) {
mp_lexer_to_next(lex); mp_lexer_to_next(lex);
return true; return MP_TRUE;
} }
return false; return MP_FALSE;
} }
bool mp_lexer_opt_str(mp_lexer_t *lex, const char *str) { MP_BOOL mp_lexer_opt_str(mp_lexer_t *lex, const char *str) {
if (mp_lexer_is_str(lex, str)) { if (mp_lexer_is_str(lex, str)) {
mp_lexer_to_next(lex); mp_lexer_to_next(lex);
return true; return MP_TRUE;
} }
return false; return MP_FALSE;
} }
*/ */
bool mp_lexer_show_error(mp_lexer_t *lex, const char *msg) { MP_BOOL mp_lexer_show_error(mp_lexer_t *lex, const char *msg) {
return mp_token_show_error(&lex->tok_cur, msg); return mp_token_show_error(&lex->tok_cur, msg);
} }
bool mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg) { MP_BOOL mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg) {
printf(" File \"%s\", line %d column %d\n%s\n", lex->tok_cur.src_name, lex->tok_cur.src_line, lex->tok_cur.src_column, msg); printf(" File \"%s\", line %d column %d\n%s\n", lex->tok_cur.src_name, lex->tok_cur.src_line, lex->tok_cur.src_column, msg);
return false; return MP_FALSE;
} }
...@@ -124,20 +124,20 @@ typedef struct _mp_lexer_t mp_lexer_t; ...@@ -124,20 +124,20 @@ typedef struct _mp_lexer_t mp_lexer_t;
void mp_token_show(const mp_token_t *tok); void mp_token_show(const mp_token_t *tok);
void mp_token_show_error_prefix(const mp_token_t *tok); void mp_token_show_error_prefix(const mp_token_t *tok);
bool mp_token_show_error(const mp_token_t *tok, const char *msg); MP_BOOL mp_token_show_error(const mp_token_t *tok, const char *msg);
mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_stream_next_char_t stream_next_char, mp_lexer_stream_close_t stream_close); mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_stream_next_char_t stream_next_char, mp_lexer_stream_close_t stream_close);
void mp_lexer_free(mp_lexer_t *lex); void mp_lexer_free(mp_lexer_t *lex);
void mp_lexer_to_next(mp_lexer_t *lex); void mp_lexer_to_next(mp_lexer_t *lex);
const mp_token_t *mp_lexer_cur(const mp_lexer_t *lex); const mp_token_t *mp_lexer_cur(const mp_lexer_t *lex);
bool mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind); MP_BOOL mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind);
/* unused /* unused
bool mp_lexer_is_str(mp_lexer_t *lex, const char *str); MP_BOOL mp_lexer_is_str(mp_lexer_t *lex, const char *str);
bool mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind); MP_BOOL mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind);
bool mp_lexer_opt_str(mp_lexer_t *lex, const char *str); MP_BOOL mp_lexer_opt_str(mp_lexer_t *lex, const char *str);
*/ */
bool mp_lexer_show_error(mp_lexer_t *lex, const char *msg); MP_BOOL mp_lexer_show_error(mp_lexer_t *lex, const char *msg);
bool mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg); MP_BOOL mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg);
// used to import a module; must be implemented for a specific port // used to import a module; must be implemented for a specific port
mp_lexer_t *mp_import_open_file(qstr mod_name); mp_lexer_t *mp_import_open_file(qstr mod_name);
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "lexer.h" #include "lexer.h"
typedef struct _str_buf_t { typedef struct _str_buf_t {
bool free; // free src_beg when done MP_BOOL free; // free src_beg when done
const char *src_beg; // beginning of source const char *src_beg; // beginning of source
const char *src_cur; // current location in source const char *src_cur; // current location in source
const char *src_end; // end (exclusive) of source const char *src_end; // end (exclusive) of source
...@@ -30,7 +30,7 @@ void str_buf_free(str_buf_t *sb) { ...@@ -30,7 +30,7 @@ void str_buf_free(str_buf_t *sb) {
} }
} }
mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str) { mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str) {
str_buf_t *sb = m_new(str_buf_t, 1); str_buf_t *sb = m_new(str_buf_t, 1);
sb->free = free_str; sb->free = free_str;
sb->src_beg = str; sb->src_beg = str;
...@@ -56,7 +56,7 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) { ...@@ -56,7 +56,7 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
return NULL; return NULL;
} }
return mp_lexer_new_from_str_len(filename, data, size, true); return mp_lexer_new_from_str_len(filename, data, size, MP_TRUE);
} }
/******************************************************************************/ /******************************************************************************/
......
mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str); mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str);
mp_lexer_t *mp_lexer_new_from_file(const char *filename); mp_lexer_t *mp_lexer_new_from_file(const char *filename);
void mp_import_set_directory(const char *dir); void mp_import_set_directory(const char *dir);
...@@ -38,8 +38,8 @@ mp_map_t *mp_map_new(mp_map_kind_t kind, int n) { ...@@ -38,8 +38,8 @@ mp_map_t *mp_map_new(mp_map_kind_t kind, int n) {
return map; return map;
} }
mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_not_found) { mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, MP_BOOL add_if_not_found) {
bool is_map_mp_obj = (map->kind == MP_MAP_OBJ); MP_BOOL is_map_mp_obj = (map->kind == MP_MAP_OBJ);
machine_uint_t hash; machine_uint_t hash;
if (is_map_mp_obj) { if (is_map_mp_obj) {
hash = mp_obj_hash(index); hash = mp_obj_hash(index);
...@@ -61,7 +61,7 @@ mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_n ...@@ -61,7 +61,7 @@ mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_n
map->table = m_new0(mp_map_elem_t, map->alloc); map->table = m_new0(mp_map_elem_t, map->alloc);
for (int i = 0; i < old_alloc; i++) { for (int i = 0; i < old_alloc; i++) {
if (old_table[i].key != NULL) { if (old_table[i].key != NULL) {
mp_map_lookup_helper(map, old_table[i].key, true)->value = old_table[i].value; mp_map_lookup_helper(map, old_table[i].key, MP_TRUE)->value = old_table[i].value;
} }
} }
m_del(mp_map_elem_t, old_table, old_alloc); m_del(mp_map_elem_t, old_table, old_alloc);
...@@ -90,7 +90,7 @@ mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_n ...@@ -90,7 +90,7 @@ mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_n
} }
} }
mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, bool add_if_not_found) { mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, MP_BOOL add_if_not_found) {
mp_obj_t o = (mp_obj_t)(machine_uint_t)index; mp_obj_t o = (mp_obj_t)(machine_uint_t)index;
return mp_map_lookup_helper(map, o, add_if_not_found); return mp_map_lookup_helper(map, o, add_if_not_found);
} }
...@@ -104,7 +104,7 @@ void mp_set_init(mp_set_t *set, int n) { ...@@ -104,7 +104,7 @@ void mp_set_init(mp_set_t *set, int n) {
set->table = m_new0(mp_obj_t, set->alloc); set->table = m_new0(mp_obj_t, set->alloc);
} }
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found) { mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, MP_BOOL add_if_not_found) {
int hash = mp_obj_hash(index); int hash = mp_obj_hash(index);
int pos = hash % set->alloc; int pos = hash % set->alloc;
for (;;) { for (;;) {
...@@ -121,7 +121,7 @@ mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found) { ...@@ -121,7 +121,7 @@ mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found) {
set->table = m_new(mp_obj_t, set->alloc); set->table = m_new(mp_obj_t, set->alloc);
for (int i = 0; i < old_alloc; i++) { for (int i = 0; i < old_alloc; i++) {
if (old_table[i] != NULL) { if (old_table[i] != NULL) {
mp_set_lookup(set, old_table[i], true); mp_set_lookup(set, old_table[i], MP_TRUE);
} }
} }
m_del(mp_obj_t, old_table, old_alloc); m_del(mp_obj_t, old_table, old_alloc);
......
...@@ -26,8 +26,8 @@ typedef struct _mp_set_t { ...@@ -26,8 +26,8 @@ typedef struct _mp_set_t {
int get_doubling_prime_greater_or_equal_to(int x); int get_doubling_prime_greater_or_equal_to(int x);
void mp_map_init(mp_map_t *map, mp_map_kind_t kind, int n); void mp_map_init(mp_map_t *map, mp_map_kind_t kind, int n);
mp_map_t *mp_map_new(mp_map_kind_t kind, int n); mp_map_t *mp_map_new(mp_map_kind_t kind, int n);
mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_not_found); mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, MP_BOOL add_if_not_found);
mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, bool add_if_not_found); mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr index, MP_BOOL add_if_not_found);
void mp_set_init(mp_set_t *set, int n); void mp_set_init(mp_set_t *set, int n);
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found); mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, MP_BOOL add_if_not_found);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment