Commit 7a16fadb authored by ian-v's avatar ian-v
Browse files

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

parent e03c0533
......@@ -45,7 +45,7 @@ asm_thumb_t *asm_thumb_new(uint max_num_labels) {
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) {
m_del(byte, as->code_base, as->code_size);
}
......@@ -56,9 +56,9 @@ void asm_thumb_free(asm_thumb_t *as, bool free_code) {
{
Label *lab = &g_array_index(as->label, Label, i);
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);
......@@ -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 false;
return MP_FALSE;
}
*/
}
......
......@@ -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, 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_end_pass(asm_thumb_t *as);
uint asm_thumb_get_code_size(asm_thumb_t *as);
......
......@@ -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, bool is_exec) {
void *alloc_mem(uint req_size, uint *alloc_size, MP_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, bool free_code) {
void asm_x64_free(asm_x64_t* as, MP_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, bool free_code) {
{
Label* lab = &g_array_index(as->label, Label, i);
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);
......@@ -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, true);
as->code_base = alloc_mem(as->code_size, &actual_alloc, MP_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 false;
return MP_FALSE;
}
*/
}
......
......@@ -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, 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_end_pass(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);
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) {
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) {
// 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 {
typedef struct _emit_t emit_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 (*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);
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, 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_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, 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 (*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 (*return_value)(emit_t *emit);
void (*raise_varargs)(emit_t *emit, int n_args);
void (*yield_value)(emit_t *emit);
......
......@@ -17,7 +17,7 @@
struct _emit_t {
pass_kind_t pass;
int stack_size;
bool last_emit_was_return_value;
MP_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, 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) {
emit->pass = pass;
emit->stack_size = 0;
emit->last_emit_was_return_value = false;
emit->last_emit_was_return_value = MP_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) {
}
}
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;
}
......@@ -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 = false;
emit->last_emit_was_return_value = MP_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, bool bytes) {
static void emit_bc_load_const_str(emit_t *emit, qstr qstr, MP_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, 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;
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, 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;
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, b
static void emit_bc_return_value(emit_t *emit) {
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);
}
......
......@@ -20,7 +20,7 @@ struct _emit_t {
int pass;
int byte_code_offset;
int stack_size;
bool last_emit_was_return_value;
MP_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, 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) {
emit->pass = pass;
emit->byte_code_offset = 0;
emit->stack_size = 0;
emit->last_emit_was_return_value = false;
emit->last_emit_was_return_value = MP_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 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;
}
......@@ -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 = false;
emit->last_emit_was_return_value = MP_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, bool bytes) {
static void print_quoted_str(qstr qstr, MP_BOOL bytes) {
const char *str = qstr_str(qstr);
int len = strlen(str);
bool has_single_quote = false;
bool has_double_quote = false;
MP_BOOL has_single_quote = MP_FALSE;
MP_BOOL has_double_quote = MP_FALSE;
for (int i = 0; i < len; i++) {
if (str[i] == '\'') {
has_single_quote = true;
has_single_quote = MP_TRUE;
} else if (str[i] == '"') {
has_double_quote = true;
has_double_quote = MP_TRUE;
}
}
if (bytes) {
printf("b");
}
bool quote_single = false;
MP_BOOL quote_single = MP_FALSE;
if (has_single_quote && !has_double_quote) {
printf("\"");
} else {
quote_single = true;
quote_single = MP_TRUE;
printf("'");
}
for (int i = 0; i < len; i++) {
......@@ -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);
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, 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;
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, 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);
}
static void emit_cpy_return_value(emit_t *emit) {
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) {
printf("RETURN_VALUE\n");
}
......
......@@ -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 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) {
return true;
return MP_TRUE;
} else {
printf("SyntaxError: '%s' expects %d arguments'\n", qstr_str(op), wanted_n_args);
return false;
return MP_FALSE;
}
}
......
......@@ -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 (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_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 (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_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;
bool do_viper_types;
MP_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;
bool last_emit_was_return_value;
MP_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 = false;
emit->do_viper_types = MP_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, 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;
}
......@@ -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 = false;
emit->last_emit_was_return_value = MP_FALSE;
emit->scope = scope;
if (emit->local_vtype == NULL) {
......@@ -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;
}
......@@ -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 = false;
emit->last_emit_was_return_value = MP_FALSE;
}
*/
// this must be called at start of emit functions
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
/*
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 = false;
emit->last_emit_was_return_value = MP_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, bool bytes) {
static void emit_native_load_const_str(emit_t *emit, qstr qstr, MP_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, 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
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, 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);
/*
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 = true;
emit->last_emit_was_return_value = MP_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);
......
......@@ -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
bool added;
MP_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
bool added;
MP_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) {
......
......@@ -35,7 +35,7 @@ struct _mp_lexer_t {
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;
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);
}
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);
return false;
return MP_FALSE;
}
#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;
}
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';
}
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;
}
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;
}
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;
}
/*
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;
}
*/
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;
}
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;
}
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;
}
static bool is_whitespace(mp_lexer_t *lex) {
static MP_BOOL is_whitespace(mp_lexer_t *lex) {
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);
}
static bool is_digit(mp_lexer_t *lex) {
static MP_BOOL is_digit(mp_lexer_t *lex) {
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);
}
// 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 == '_';
}
// 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);
}
......@@ -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, 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
bool had_physical_newline = false;
MP_BOOL had_physical_newline = MP_FALSE;
while (!is_end(lex)) {
if (is_physical_newline(lex)) {
had_physical_newline = true;
had_physical_newline = MP_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, bool firs
// a string or bytes literal
// parse type codes
bool is_raw = false;
bool is_bytes = false;
MP_BOOL is_raw = MP_FALSE;
MP_BOOL is_bytes = MP_FALSE;
if (is_char(lex, 'u')) {