Revert MP_BOOL, etc. and use <stdbool.h> instead

This commit is contained in:
ian-v 2014-01-06 13:51:53 -08:00
parent 7a16fadbf8
commit 5fd8fd2c16
61 changed files with 517 additions and 529 deletions

View File

@ -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;
}
*/
}

View File

@ -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);

View File

@ -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;
}
*/
}

View File

@ -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);

View File

@ -1,2 +1,2 @@
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);

View File

@ -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

View File

@ -39,9 +39,9 @@ typedef enum {
#define EMIT_OPT_ASM_THUMB (4)
typedef struct _compiler_t {
MP_BOOL is_repl;
bool is_repl;
pass_kind_t pass;
MP_BOOL had_error; // try to keep compiler clean from nlr
bool had_error; // try to keep compiler clean from nlr
int next_label;
@ -50,9 +50,9 @@ typedef struct _compiler_t {
int except_nest_level;
int n_arg_keyword;
MP_BOOL have_star_arg;
MP_BOOL have_dbl_star_arg;
MP_BOOL have_bare_star;
bool have_star_arg;
bool have_dbl_star_arg;
bool have_bare_star;
int param_pass;
int param_pass_num_dict_params;
int param_pass_num_default_params;
@ -261,36 +261,36 @@ void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
#if MICROPY_EMIT_CPYTHON
static MP_BOOL cpython_c_tuple_is_const(mp_parse_node_t pn) {
static bool cpython_c_tuple_is_const(mp_parse_node_t pn) {
if (!MP_PARSE_NODE_IS_LEAF(pn)) {
return MP_FALSE;
return false;
}
if (MP_PARSE_NODE_IS_ID(pn)) {
return MP_FALSE;
return false;
}
return MP_TRUE;
return true;
}
static void cpython_c_print_quoted_str(vstr_t *vstr, qstr qstr, MP_BOOL bytes) {
static void cpython_c_print_quoted_str(vstr_t *vstr, 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) {
vstr_printf(vstr, "b");
}
MP_BOOL quote_single = MP_FALSE;
bool quote_single = false;
if (has_single_quote && !has_double_quote) {
vstr_printf(vstr, "\"");
} else {
quote_single = MP_TRUE;
quote_single = true;
vstr_printf(vstr, "'");
}
for (int i = 0; i < len; i++) {
@ -319,8 +319,8 @@ static void cpython_c_tuple_emit_const(compiler_t *comp, mp_parse_node_t pn, vst
case MP_PARSE_NODE_SMALL_INT: vstr_printf(vstr, "%d", arg); break;
case MP_PARSE_NODE_INTEGER: vstr_printf(vstr, "%s", qstr_str(arg)); break;
case MP_PARSE_NODE_DECIMAL: vstr_printf(vstr, "%s", qstr_str(arg)); break;
case MP_PARSE_NODE_STRING: cpython_c_print_quoted_str(vstr, arg, MP_FALSE); break;
case MP_PARSE_NODE_BYTES: cpython_c_print_quoted_str(vstr, arg, MP_TRUE); break;
case MP_PARSE_NODE_STRING: cpython_c_print_quoted_str(vstr, arg, false); break;
case MP_PARSE_NODE_BYTES: cpython_c_print_quoted_str(vstr, arg, true); break;
case MP_PARSE_NODE_TOKEN:
switch (arg) {
case MP_TOKEN_KW_FALSE: vstr_printf(vstr, "False"); break;
@ -339,33 +339,33 @@ static void cpython_c_tuple(compiler_t *comp, mp_parse_node_t pn, mp_parse_node_
n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns_list);
}
int total = n;
MP_BOOL is_const = MP_TRUE;
bool is_const = true;
if (!MP_PARSE_NODE_IS_NULL(pn)) {
total += 1;
if (!cpython_c_tuple_is_const(pn)) {
is_const = MP_FALSE;
is_const = false;
}
}
for (int i = 0; i < n; i++) {
if (!cpython_c_tuple_is_const(pns_list->nodes[i])) {
is_const = MP_FALSE;
is_const = false;
break;
}
}
if (total > 0 && is_const) {
MP_BOOL need_comma = MP_FALSE;
bool need_comma = false;
vstr_t *vstr = vstr_new();
vstr_printf(vstr, "(");
if (!MP_PARSE_NODE_IS_NULL(pn)) {
cpython_c_tuple_emit_const(comp, pn, vstr);
need_comma = MP_TRUE;
need_comma = true;
}
for (int i = 0; i < n; i++) {
if (need_comma) {
vstr_printf(vstr, ", ");
}
cpython_c_tuple_emit_const(comp, pns_list->nodes[i], vstr);
need_comma = MP_TRUE;
need_comma = true;
}
if (total == 1) {
vstr_printf(vstr, ",)");
@ -412,25 +412,25 @@ void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_tuple(comp, MP_PARSE_NODE_NULL, pns);
}
static MP_BOOL node_is_const_false(mp_parse_node_t pn) {
static bool node_is_const_false(mp_parse_node_t pn) {
return MP_PARSE_NODE_IS_TOKEN_KIND(pn, MP_TOKEN_KW_FALSE);
// untested: || (MP_PARSE_NODE_IS_SMALL_INT(pn) && MP_PARSE_NODE_LEAF_ARG(pn) == 1);
}
static MP_BOOL node_is_const_true(mp_parse_node_t pn) {
static bool node_is_const_true(mp_parse_node_t pn) {
return MP_PARSE_NODE_IS_TOKEN_KIND(pn, MP_TOKEN_KW_TRUE) || (MP_PARSE_NODE_IS_SMALL_INT(pn) && MP_PARSE_NODE_LEAF_ARG(pn) == 1);
}
#if MICROPY_EMIT_CPYTHON
// the is_nested variable is purely to match with CPython, which doesn't fully optimise not's
static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump_if, int label, MP_BOOL is_nested) {
static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label, bool is_nested) {
if (node_is_const_false(pn)) {
if (jump_if == MP_FALSE) {
if (jump_if == false) {
EMIT(jump, label);
}
return;
} else if (node_is_const_true(pn)) {
if (jump_if == MP_TRUE) {
if (jump_if == true) {
EMIT(jump, label);
}
return;
@ -438,42 +438,42 @@ static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) {
if (jump_if == MP_FALSE) {
if (jump_if == false) {
int label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) {
cpython_c_if_cond(comp, pns->nodes[i], MP_TRUE, label2, MP_TRUE);
cpython_c_if_cond(comp, pns->nodes[i], true, label2, true);
}
cpython_c_if_cond(comp, pns->nodes[n - 1], MP_FALSE, label, MP_TRUE);
cpython_c_if_cond(comp, pns->nodes[n - 1], false, label, true);
EMIT(label_assign, label2);
} else {
for (int i = 0; i < n; i++) {
cpython_c_if_cond(comp, pns->nodes[i], MP_TRUE, label, MP_TRUE);
cpython_c_if_cond(comp, pns->nodes[i], true, label, true);
}
}
return;
} else if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_and_test) {
if (jump_if == MP_FALSE) {
if (jump_if == false) {
for (int i = 0; i < n; i++) {
cpython_c_if_cond(comp, pns->nodes[i], MP_FALSE, label, MP_TRUE);
cpython_c_if_cond(comp, pns->nodes[i], false, label, true);
}
} else {
int label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) {
cpython_c_if_cond(comp, pns->nodes[i], MP_FALSE, label2, MP_TRUE);
cpython_c_if_cond(comp, pns->nodes[i], false, label2, true);
}
cpython_c_if_cond(comp, pns->nodes[n - 1], MP_TRUE, label, MP_TRUE);
cpython_c_if_cond(comp, pns->nodes[n - 1], true, label, true);
EMIT(label_assign, label2);
}
return;
} else if (!is_nested && MP_PARSE_NODE_STRUCT_KIND(pns) == PN_not_test_2) {
cpython_c_if_cond(comp, pns->nodes[0], !jump_if, label, MP_TRUE);
cpython_c_if_cond(comp, pns->nodes[0], !jump_if, label, true);
return;
}
}
// nothing special, fall back to default compiling for node and jump
compile_node(comp, pn);
if (jump_if == MP_FALSE) {
if (jump_if == false) {
EMIT(pop_jump_if_false, label);
} else {
EMIT(pop_jump_if_true, label);
@ -481,17 +481,17 @@ static void cpython_c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump
}
#endif
static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump_if, int label) {
static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label) {
#if MICROPY_EMIT_CPYTHON
cpython_c_if_cond(comp, pn, jump_if, label, MP_FALSE);
cpython_c_if_cond(comp, pn, jump_if, label, false);
#else
if (node_is_const_false(pn)) {
if (jump_if == MP_FALSE) {
if (jump_if == false) {
EMIT(jump, label);
}
return;
} else if (node_is_const_true(pn)) {
if (jump_if == MP_TRUE) {
if (jump_if == true) {
EMIT(jump, label);
}
return;
@ -499,30 +499,30 @@ static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump_if, int
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) {
if (jump_if == MP_FALSE) {
if (jump_if == false) {
int label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) {
c_if_cond(comp, pns->nodes[i], MP_TRUE, label2);
c_if_cond(comp, pns->nodes[i], true, label2);
}
c_if_cond(comp, pns->nodes[n - 1], MP_FALSE, label);
c_if_cond(comp, pns->nodes[n - 1], false, label);
EMIT(label_assign, label2);
} else {
for (int i = 0; i < n; i++) {
c_if_cond(comp, pns->nodes[i], MP_TRUE, label);
c_if_cond(comp, pns->nodes[i], true, label);
}
}
return;
} else if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_and_test) {
if (jump_if == MP_FALSE) {
if (jump_if == false) {
for (int i = 0; i < n; i++) {
c_if_cond(comp, pns->nodes[i], MP_FALSE, label);
c_if_cond(comp, pns->nodes[i], false, label);
}
} else {
int label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) {
c_if_cond(comp, pns->nodes[i], MP_FALSE, label2);
c_if_cond(comp, pns->nodes[i], false, label2);
}
c_if_cond(comp, pns->nodes[n - 1], MP_TRUE, label);
c_if_cond(comp, pns->nodes[n - 1], true, label);
EMIT(label_assign, label2);
}
return;
@ -534,7 +534,7 @@ static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, MP_BOOL jump_if, int
// nothing special, fall back to default compiling for node and jump
compile_node(comp, pn);
if (jump_if == MP_FALSE) {
if (jump_if == false) {
EMIT(pop_jump_if_false, label);
} else {
EMIT(pop_jump_if_true, label);
@ -803,7 +803,7 @@ void compile_funcdef_param(compiler_t *comp, mp_parse_node_t pn) {
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) {
// bare star
comp->have_bare_star = MP_TRUE;
comp->have_bare_star = true;
}
}
}
@ -819,18 +819,18 @@ qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint
}
// save variables (probably don't need to do this, since we can't have nested definitions..?)
MP_BOOL old_have_bare_star = comp->have_bare_star;
bool old_have_bare_star = comp->have_bare_star;
int old_param_pass = comp->param_pass;
int old_param_pass_num_dict_params = comp->param_pass_num_dict_params;
int old_param_pass_num_default_params = comp->param_pass_num_default_params;
// compile default parameters
comp->have_bare_star = MP_FALSE;
comp->have_bare_star = false;
comp->param_pass = 1; // pass 1 does any default parameters after bare star
comp->param_pass_num_dict_params = 0;
comp->param_pass_num_default_params = 0;
apply_to_single_or_list(comp, pns->nodes[1], PN_typedargslist, compile_funcdef_param);
comp->have_bare_star = MP_FALSE;
comp->have_bare_star = false;
comp->param_pass = 2; // pass 2 does any default parameters before bare star
comp->param_pass_num_dict_params = 0;
comp->param_pass_num_default_params = 0;
@ -876,12 +876,12 @@ qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint
// nodes[1] has parent classes, if any
if (MP_PARSE_NODE_IS_NULL(pns->nodes[1])) {
// no parent classes
EMIT(call_function, 2, 0, MP_FALSE, MP_FALSE);
EMIT(call_function, 2, 0, false, false);
} else {
// have a parent class or classes
// TODO what if we have, eg, *a or **a in the parent list?
compile_node(comp, pns->nodes[1]);
EMIT(call_function, 2 + list_len(pns->nodes[1], PN_arglist), 0, MP_FALSE, MP_FALSE);
EMIT(call_function, 2 + list_len(pns->nodes[1], PN_arglist), 0, false, false);
}
// return its name (the 'C' in class C(...):")
@ -889,14 +889,14 @@ qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint
}
// returns true if it was a built-in decorator (even if the built-in had an error)
static MP_BOOL compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_node_t *name_nodes, uint *emit_options) {
static bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_node_t *name_nodes, uint *emit_options) {
if (MP_PARSE_NODE_LEAF_ARG(name_nodes[0]) != MP_QSTR_micropython) {
return MP_FALSE;
return false;
}
if (name_len != 2) {
printf("SyntaxError: invalid micropython decorator\n");
return MP_TRUE;
return true;
}
qstr attr = MP_PARSE_NODE_LEAF_ARG(name_nodes[1]);
@ -916,7 +916,7 @@ static MP_BOOL compile_built_in_decorator(compiler_t *comp, int name_len, mp_par
printf("SyntaxError: invalid micropython decorator '%s'\n", qstr_str(attr));
}
return MP_TRUE;
return true;
}
void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) {
@ -974,7 +974,7 @@ void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) {
// call each decorator
for (int i = 0; i < n - num_built_in_decorators; i++) {
EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE);
EMIT(call_function, 1, 0, false, false);
}
// store func/class object into name
@ -1094,7 +1094,7 @@ void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (comp->scope_cur->kind != SCOPE_FUNCTION) {
printf("SyntaxError: 'return' outside function\n");
comp->had_error = MP_TRUE;
comp->had_error = true;
return;
}
if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) {
@ -1106,7 +1106,7 @@ void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t*)pns_test_if_expr->nodes[1];
int l_fail = comp_next_label(comp);
c_if_cond(comp, pns_test_if_else->nodes[0], MP_FALSE, l_fail); // condition
c_if_cond(comp, pns_test_if_else->nodes[0], false, l_fail); // condition
compile_node(comp, pns_test_if_expr->nodes[0]); // success value
EMIT(return_value);
EMIT(label_assign, l_fail);
@ -1143,13 +1143,13 @@ void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// eg a -> q1=q2=a
// a.b.c -> q1=a, q2=a.b.c
void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q1, qstr *q2) {
MP_BOOL is_as = MP_FALSE;
bool is_as = false;
if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dotted_as_name)) {
mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
// a name of the form x as y; unwrap it
*q1 = MP_PARSE_NODE_LEAF_ARG(pns->nodes[1]);
pn = pns->nodes[0];
is_as = MP_TRUE;
is_as = true;
}
if (MP_PARSE_NODE_IS_ID(pn)) {
// just a simple name
@ -1220,7 +1220,7 @@ void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) {
#if MICROPY_EMIT_CPYTHON
EMIT(load_const_verbatim_str, "('*',)");
#else
EMIT(load_const_str, qstr_from_str_static("*"), MP_FALSE);
EMIT(load_const_str, qstr_from_str_static("*"), false);
EMIT(build_tuple, 1);
#endif
@ -1262,7 +1262,7 @@ void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) {
assert(MP_PARSE_NODE_IS_STRUCT_KIND(pn_nodes[i], PN_import_as_name));
mp_parse_node_struct_t *pns3 = (mp_parse_node_struct_t*)pn_nodes[i];
qstr id2 = MP_PARSE_NODE_LEAF_ARG(pns3->nodes[0]); // should be id
EMIT(load_const_str, id2, MP_FALSE);
EMIT(load_const_str, id2, false);
}
EMIT(build_tuple, n);
#endif
@ -1315,12 +1315,12 @@ void compile_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
int l_end = comp_next_label(comp);
c_if_cond(comp, pns->nodes[0], MP_TRUE, l_end);
c_if_cond(comp, pns->nodes[0], true, l_end);
EMIT(load_id, MP_QSTR_AssertionError);
if (!MP_PARSE_NODE_IS_NULL(pns->nodes[1])) {
// assertion message
compile_node(comp, pns->nodes[1]);
EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE);
EMIT(call_function, 1, 0, false, false);
}
EMIT(raise_varargs, 1);
EMIT(label_assign, l_end);
@ -1332,7 +1332,7 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
int l_end = comp_next_label(comp);
int l_fail = comp_next_label(comp);
c_if_cond(comp, pns->nodes[0], MP_FALSE, l_fail); // if condition
c_if_cond(comp, pns->nodes[0], false, l_fail); // if condition
compile_node(comp, pns->nodes[1]); // if block
//if (!(MP_PARSE_NODE_IS_NULL(pns->nodes[2]) && MP_PARSE_NODE_IS_NULL(pns->nodes[3]))) { // optimisation; doesn't align with CPython
@ -1355,7 +1355,7 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
for (int i = 0; i < n; i++) {
mp_parse_node_struct_t *pns_elif2 = (mp_parse_node_struct_t*)pns_elif->nodes[i];
l_fail = comp_next_label(comp);
c_if_cond(comp, pns_elif2->nodes[0], MP_FALSE, l_fail); // elif condition
c_if_cond(comp, pns_elif2->nodes[0], false, l_fail); // elif condition
compile_node(comp, pns_elif2->nodes[1]); // elif block
if (!EMIT(last_emit_was_return_value)) { // simple optimisation to align with CPython
@ -1368,7 +1368,7 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// a single elif block
l_fail = comp_next_label(comp);
c_if_cond(comp, pns_elif->nodes[0], MP_FALSE, l_fail); // elif condition
c_if_cond(comp, pns_elif->nodes[0], false, l_fail); // elif condition
compile_node(comp, pns_elif->nodes[1]); // elif block
if (!EMIT(last_emit_was_return_value)) { // simple optimisation to align with CPython
@ -1399,7 +1399,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
int done_label = comp_next_label(comp);
EMIT(setup_loop, break_label);
EMIT(label_assign, continue_label);
c_if_cond(comp, pns->nodes[0], MP_FALSE, done_label); // condition
c_if_cond(comp, pns->nodes[0], false, done_label); // condition
compile_node(comp, pns->nodes[1]); // body
if (!EMIT(last_emit_was_return_value)) {
EMIT(jump, continue_label);
@ -1416,7 +1416,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT(label_assign, top_label);
compile_node(comp, pns->nodes[1]); // body
EMIT(label_assign, continue_label);
c_if_cond(comp, pns->nodes[0], MP_TRUE, top_label); // condition
c_if_cond(comp, pns->nodes[0], true, top_label); // condition
#endif
// break/continue apply to outer loop (if any) in the else block
@ -1732,7 +1732,7 @@ void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
// for REPL, evaluate then print the expression
EMIT(load_id, MP_QSTR___repl_print__);
compile_node(comp, pns->nodes[0]);
EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE);
EMIT(call_function, 1, 0, false, false);
EMIT(pop_top);
} else {
@ -1837,7 +1837,7 @@ void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) {
int stack_size = EMIT(get_stack_size);
int l_fail = comp_next_label(comp);
int l_end = comp_next_label(comp);
c_if_cond(comp, pns_test_if_else->nodes[0], MP_FALSE, l_fail); // condition
c_if_cond(comp, pns_test_if_else->nodes[0], false, l_fail); // condition
compile_node(comp, pns->nodes[0]); // success value
EMIT(jump, l_end);
EMIT(label_assign, l_fail);
@ -1898,7 +1898,7 @@ void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) {
int stack_size = EMIT(get_stack_size);
int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
compile_node(comp, pns->nodes[0]);
MP_BOOL multi = (num_nodes > 3);
bool multi = (num_nodes > 3);
int l_fail = 0;
if (multi) {
l_fail = comp_next_label(comp);
@ -2042,15 +2042,15 @@ void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
}
void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_struct_t *pns, MP_BOOL is_method_call) {
void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool is_method_call) {
// function to call is on top of stack
int old_n_arg_keyword = comp->n_arg_keyword;
MP_BOOL old_have_star_arg = comp->have_star_arg;
MP_BOOL old_have_dbl_star_arg = comp->have_dbl_star_arg;
bool old_have_star_arg = comp->have_star_arg;
bool old_have_dbl_star_arg = comp->have_dbl_star_arg;
comp->n_arg_keyword = 0;
comp->have_star_arg = MP_FALSE;
comp->have_dbl_star_arg = MP_FALSE;
comp->have_star_arg = false;
comp->have_dbl_star_arg = false;
compile_node(comp, pns->nodes[0]); // arguments to function call; can be null
@ -2082,7 +2082,7 @@ void compile_power_trailers(compiler_t *comp, mp_parse_node_struct_t *pns) {
mp_parse_node_struct_t *pns_period = (mp_parse_node_struct_t*)pns->nodes[i];
mp_parse_node_struct_t *pns_paren = (mp_parse_node_struct_t*)pns->nodes[i + 1];
EMIT(load_method, MP_PARSE_NODE_LEAF_ARG(pns_period->nodes[0])); // get the method
compile_trailer_paren_helper(comp, pns_paren, MP_TRUE);
compile_trailer_paren_helper(comp, pns_paren, true);
i += 1;
} else {
compile_node(comp, pns->nodes[i]);
@ -2153,7 +2153,7 @@ void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_
compile_node(comp, pns_comp_for->nodes[1]); // source of the iterator
EMIT(get_iter);
EMIT(call_function, 1, 0, MP_FALSE, MP_FALSE);
EMIT(call_function, 1, 0, false, false);
}
void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) {
@ -2252,23 +2252,23 @@ void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) {
int n = list_get(&pns1->nodes[0], PN_dictorsetmaker_list2, &nodes);
// first element sets whether it's a dict or set
MP_BOOL is_dict;
bool is_dict;
if (MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_dictorsetmaker_item)) {
// a dictionary
EMIT(build_map, 1 + n);
compile_node(comp, pns->nodes[0]);
EMIT(store_map);
is_dict = MP_TRUE;
is_dict = true;
} else {
// a set
compile_node(comp, pns->nodes[0]); // 1st value of set
is_dict = MP_FALSE;
is_dict = false;
}
// process rest of elements
for (int i = 0; i < n; i++) {
mp_parse_node_t pn = nodes[i];
MP_BOOL is_key_value = MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dictorsetmaker_item);
bool is_key_value = MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dictorsetmaker_item);
compile_node(comp, pn);
if (is_dict) {
if (!is_key_value) {
@ -2314,7 +2314,7 @@ void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) {
}
void compile_trailer_paren(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_trailer_paren_helper(comp, pns, MP_FALSE);
compile_trailer_paren_helper(comp, pns, false);
}
void compile_trailer_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) {
@ -2401,7 +2401,7 @@ void compile_arglist_star(compiler_t *comp, mp_parse_node_struct_t *pns) {
printf("SyntaxError?: can't have multiple *x\n");
return;
}
comp->have_star_arg = MP_TRUE;
comp->have_star_arg = true;
compile_node(comp, pns->nodes[0]);
}
@ -2410,7 +2410,7 @@ void compile_arglist_dbl_star(compiler_t *comp, mp_parse_node_struct_t *pns) {
printf("SyntaxError?: can't have multiple **x\n");
return;
}
comp->have_dbl_star_arg = MP_TRUE;
comp->have_dbl_star_arg = true;
compile_node(comp, pns->nodes[0]);
}
@ -2475,8 +2475,8 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) {
case MP_PARSE_NODE_SMALL_INT: EMIT(load_const_small_int, arg); break;
case MP_PARSE_NODE_INTEGER: EMIT(load_const_int, arg); break;
case MP_PARSE_NODE_DECIMAL: EMIT(load_const_dec, arg); break;
case MP_PARSE_NODE_STRING: EMIT(load_const_str, arg, MP_FALSE); break;
case MP_PARSE_NODE_BYTES: EMIT(load_const_str, arg, MP_TRUE); break;
case MP_PARSE_NODE_STRING: EMIT(load_const_str, arg, false); break;
case MP_PARSE_NODE_BYTES: EMIT(load_const_str, arg, true); break;
case MP_PARSE_NODE_TOKEN:
if (arg == MP_TOKEN_NEWLINE) {
// this can occur when file_input lets through a NEWLINE (eg if file starts with a newline)
@ -2501,7 +2501,7 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) {
}
}
void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star, MP_BOOL allow_annotations) {
void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star, bool allow_annotations) {
// TODO verify that *k and **k are last etc
qstr param_name = 0;
mp_parse_node_t pn_annotation = MP_PARSE_NODE_NULL;
@ -2544,7 +2544,7 @@ void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_ki
if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) {
// bare star
// TODO see http://www.python.org/dev/peps/pep-3102/
comp->have_bare_star = MP_TRUE;
comp->have_bare_star = true;
//assert(comp->scope_cur->num_dict_params == 0);
} else if (MP_PARSE_NODE_IS_ID(pns->nodes[0])) {
// named star
@ -2577,23 +2577,23 @@ void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_ki
if (!MP_PARSE_NODE_IS_NULL(pn_annotation)) {
// TODO this parameter has an annotation
}
MP_BOOL added;
bool added;
id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, param_name, &added);
if (!added) {
printf("SyntaxError?: same name used for parameter; %s\n", qstr_str(param_name));
return;
}
id_info->param = MP_TRUE;
id_info->param = true;
id_info->kind = ID_INFO_KIND_LOCAL;
}
}
void compile_scope_func_param(compiler_t *comp, mp_parse_node_t pn) {
compile_scope_func_lambda_param(comp, pn, PN_typedargslist_name, PN_typedargslist_star, PN_typedargslist_dbl_star, MP_TRUE);
compile_scope_func_lambda_param(comp, pn, PN_typedargslist_name, PN_typedargslist_star, PN_typedargslist_dbl_star, true);
}
void compile_scope_lambda_param(compiler_t *comp, mp_parse_node_t pn) {
compile_scope_func_lambda_param(comp, pn, PN_varargslist_name, PN_varargslist_star, PN_varargslist_dbl_star, MP_FALSE);
compile_scope_func_lambda_param(comp, pn, PN_varargslist_name, PN_varargslist_star, PN_varargslist_dbl_star, false);
}
void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, mp_parse_node_t pn_inner_expr, int l_top, int for_depth) {
@ -2614,7 +2614,7 @@ void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, mp_parse
} else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn_iter, PN_comp_if)) {
// if condition
mp_parse_node_struct_t *pns_comp_if = (mp_parse_node_struct_t*)pn_iter;
c_if_cond(comp, pns_comp_if->nodes[0], MP_FALSE, l_top);
c_if_cond(comp, pns_comp_if->nodes[0], false, l_top);
pn_iter = pns_comp_if->nodes[1];
goto tail_recursion;
} else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn_iter, PN_comp_for)) {
@ -2708,7 +2708,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
// work out number of parameters, keywords and default parameters, and add them to the id_info array
// must be done before compiling the body so that arguments are numbered first (for LOAD_FAST etc)
if (comp->pass == PASS_1) {
comp->have_bare_star = MP_FALSE;
comp->have_bare_star = false;
apply_to_single_or_list(comp, pns->nodes[1], PN_typedargslist, compile_scope_func_param);
}
@ -2728,7 +2728,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
// work out number of parameters, keywords and default parameters, and add them to the id_info array
// must be done before compiling the body so that arguments are numbered first (for LOAD_FAST etc)
if (comp->pass == PASS_1) {
comp->have_bare_star = MP_FALSE;
comp->have_bare_star = false;
apply_to_single_or_list(comp, pns->nodes[0], PN_varargslist, compile_scope_lambda_param);
}
@ -2745,7 +2745,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
qstr qstr_arg = qstr_from_str_static(".0");
if (comp->pass == PASS_1) {
MP_BOOL added;
bool added;
id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, qstr_arg, &added);
assert(added);
id_info->kind = ID_INFO_KIND_LOCAL;
@ -2782,14 +2782,14 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
assert(MP_PARSE_NODE_STRUCT_KIND(pns) == PN_classdef);
if (comp->pass == PASS_1) {
MP_BOOL added;
bool added;
id_info_t *id_info = scope_find_or_add_id(scope, MP_QSTR___class__, &added);
assert(added);
id_info->kind = ID_INFO_KIND_LOCAL;
id_info = scope_find_or_add_id(scope, MP_QSTR___locals__, &added);
assert(added);
id_info->kind = ID_INFO_KIND_LOCAL;
id_info->param = MP_TRUE;
id_info->param = true;
scope->num_params = 1; // __locals__ is the parameter
}
@ -3005,11 +3005,11 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
}
}
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) {
compiler_t *comp = m_new(compiler_t, 1);
comp->is_repl = is_repl;
comp->had_error = MP_FALSE;
comp->had_error = false;
comp->break_label = 0;
comp->continue_label = 0;
@ -3030,7 +3030,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl) {
comp->emit_inline_asm_method_table = NULL;
uint max_num_labels = 0;
for (scope_t *s = comp->scope_head; s != NULL && !comp->had_error; s = s->next) {
if (MP_FALSE) {
if (false) {
#if MICROPY_EMIT_INLINE_THUMB
} else if (s->emit_options == EMIT_OPT_ASM_THUMB) {
compile_scope_inline_asm(comp, s, PASS_1);
@ -3064,7 +3064,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl) {
#endif
#endif // !MICROPY_EMIT_CPYTHON
for (scope_t *s = comp->scope_head; s != NULL && !comp->had_error; s = s->next) {
if (MP_FALSE) {
if (false) {
// dummy
#if MICROPY_EMIT_INLINE_THUMB
@ -3126,7 +3126,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, MP_BOOL is_repl) {
}
}
MP_BOOL had_error = comp->had_error;
bool had_error = comp->had_error;
m_del_obj(compiler_t, comp);
if (had_error) {

View File

@ -1 +1 @@
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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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");
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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) {

View File

@ -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 is_raw = false;
bool is_bytes = false;
if (is_char(lex, 'u')) {
next_char(lex);
} else if (is_char(lex, 'b')) {
is_bytes = MP_TRUE;
is_bytes = true;
next_char(lex);
if (is_char(lex, 'r')) {
is_raw = MP_TRUE;
is_raw = true;
next_char(lex);
}
} else if (is_char(lex, 'r')) {
is_raw = MP_TRUE;
is_raw = true;
next_char(lex);
if (is_char(lex, 'b')) {
is_bytes = MP_TRUE;
is_bytes = true;
next_char(lex);
}
}
@ -628,7 +628,7 @@ mp_lexer_t *mp_lexer_new(const char *src_name, void *stream_data, mp_lexer_strea
}
// preload first token
mp_lexer_next_token_into(lex, &lex->tok_cur, MP_TRUE);
mp_lexer_next_token_into(lex, &lex->tok_cur, true);
return lex;
}
@ -644,44 +644,44 @@ void mp_lexer_free(mp_lexer_t *lex) {
}
void mp_lexer_to_next(mp_lexer_t *lex) {
mp_lexer_next_token_into(lex, &lex->tok_cur, MP_FALSE);
mp_lexer_next_token_into(lex, &lex->tok_cur, false);
}
const mp_token_t *mp_lexer_cur(const mp_lexer_t *lex) {
return &lex->tok_cur;
}
MP_BOOL mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind) {
bool mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind) {
return lex->tok_cur.kind == kind;
}
/*
MP_BOOL mp_lexer_is_str(mp_lexer_t *lex, const char *str) {
bool mp_lexer_is_str(mp_lexer_t *lex, const char *str) {
return mp_token_is_str(&lex->tok_cur, str);
}
MP_BOOL mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind) {
bool mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind) {
if (mp_lexer_is_kind(lex, kind)) {
mp_lexer_to_next(lex);
return MP_TRUE;
return true;
}
return MP_FALSE;
return false;
}
MP_BOOL mp_lexer_opt_str(mp_lexer_t *lex, const char *str) {
bool mp_lexer_opt_str(mp_lexer_t *lex, const char *str) {
if (mp_lexer_is_str(lex, str)) {
mp_lexer_to_next(lex);
return MP_TRUE;
return true;
}
return MP_FALSE;
return false;
}
*/
MP_BOOL mp_lexer_show_error(mp_lexer_t *lex, const char *msg) {
bool mp_lexer_show_error(mp_lexer_t *lex, const char *msg) {
return mp_token_show_error(&lex->tok_cur, msg);
}
MP_BOOL mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg) {
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);
return MP_FALSE;
return false;
}

View File

@ -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_error_prefix(const mp_token_t *tok);
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);
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_to_next(mp_lexer_t *lex);
const mp_token_t *mp_lexer_cur(const mp_lexer_t *lex);
MP_BOOL mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind);
bool mp_lexer_is_kind(mp_lexer_t *lex, mp_token_kind_t kind);
/* unused
MP_BOOL mp_lexer_is_str(mp_lexer_t *lex, const char *str);
MP_BOOL mp_lexer_opt_kind(mp_lexer_t *lex, mp_token_kind_t kind);
MP_BOOL mp_lexer_opt_str(mp_lexer_t *lex, const char *str);
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);
bool mp_lexer_opt_str(mp_lexer_t *lex, const char *str);
*/
MP_BOOL mp_lexer_show_error(mp_lexer_t *lex, const char *msg);
MP_BOOL mp_lexer_show_error_pythonic(mp_lexer_t *lex, const char *msg);
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);
// used to import a module; must be implemented for a specific port
mp_lexer_t *mp_import_open_file(qstr mod_name);

View File

@ -7,7 +7,7 @@
#include "lexer.h"
typedef struct _str_buf_t {
MP_BOOL free; // free src_beg when done
bool free; // free src_beg when done
const char *src_beg; // beginning of source
const char *src_cur; // current location in source
const char *src_end; // end (exclusive) of source
@ -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, MP_BOOL free_str) {
mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, bool free_str) {
str_buf_t *sb = m_new(str_buf_t, 1);
sb->free = free_str;
sb->src_beg = str;
@ -56,7 +56,7 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
return NULL;
}
return mp_lexer_new_from_str_len(filename, data, size, MP_TRUE);
return mp_lexer_new_from_str_len(filename, data, size, true);
}
/******************************************************************************/

View File

@ -1,4 +1,4 @@
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_str_len(const char *src_name, const char *str, uint len, bool free_str);
mp_lexer_t *mp_lexer_new_from_file(const char *filename);
void mp_import_set_directory(const char *dir);

View File

@ -38,8 +38,8 @@ mp_map_t *mp_map_new(mp_map_kind_t kind, int n) {
return map;
}
mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, MP_BOOL add_if_not_found) {
MP_BOOL is_map_mp_obj = (map->kind == MP_MAP_OBJ);
mp_map_elem_t* mp_map_lookup_helper(mp_map_t *map, mp_obj_t index, bool add_if_not_found) {
bool is_map_mp_obj = (map->kind == MP_MAP_OBJ);
machine_uint_t hash;
if (is_map_mp_obj) {
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, MP_BOOL add_i
map->table = m_new0(mp_map_elem_t, map->alloc);
for (int i = 0; i < old_alloc; i++) {
if (old_table[i].key != NULL) {
mp_map_lookup_helper(map, old_table[i].key, MP_TRUE)->value = old_table[i].value;
mp_map_lookup_helper(map, old_table[i].key, true)->value = old_table[i].value;
}
}
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, MP_BOOL add_i
}
}
mp_map_elem_t* mp_qstr_map_lookup(mp_map_t *map, qstr 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_obj_t o = (mp_obj_t)(machine_uint_t)index;
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) {
set->table = m_new0(mp_obj_t, set->alloc);
}
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, MP_BOOL add_if_not_found) {
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found) {
int hash = mp_obj_hash(index);
int pos = hash % set->alloc;
for (;;) {
@ -121,7 +121,7 @@ mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, MP_BOOL add_if_not_found)
set->table = m_new(mp_obj_t, set->alloc);
for (int i = 0; i < old_alloc; i++) {
if (old_table[i] != NULL) {
mp_set_lookup(set, old_table[i], MP_TRUE);
mp_set_lookup(set, old_table[i], true);
}
}
m_del(mp_obj_t, old_table, old_alloc);

View File

@ -26,8 +26,8 @@ typedef struct _mp_set_t {
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);
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, MP_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_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_qstr_map_lookup(mp_map_t *map, qstr index, bool add_if_not_found);
void mp_set_init(mp_set_t *set, int n);
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, MP_BOOL add_if_not_found);
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, bool add_if_not_found);

View File

@ -5,11 +5,7 @@
/** types *******************************************************/
typedef int MP_BOOL;
enum {
MP_FALSE = 0,
MP_TRUE = 1
};
#include <stdbool.h>
typedef unsigned char byte;
typedef unsigned int uint;
@ -42,10 +38,10 @@ typedef int unichar; // TODO
unichar utf8_get_char(const char *s);
char *utf8_next_char(const char *s);
MP_BOOL unichar_isspace(unichar c);
MP_BOOL unichar_isalpha(unichar c);
MP_BOOL unichar_isprint(unichar c);
MP_BOOL unichar_isdigit(unichar c);
bool unichar_isspace(unichar c);
bool unichar_isalpha(unichar c);
bool unichar_isprint(unichar c);
bool unichar_isdigit(unichar c);
/** string ******************************************************/
@ -59,7 +55,7 @@ typedef struct _vstr_t {
int alloc;
int len;
char *buf;
MP_BOOL had_error;
bool had_error;
} vstr_t;
void vstr_init(vstr_t *vstr);
@ -67,7 +63,7 @@ void vstr_clear(vstr_t *vstr);
vstr_t *vstr_new(void);
void vstr_free(vstr_t *vstr);
void vstr_reset(vstr_t *vstr);
MP_BOOL vstr_had_error(vstr_t *vstr);
bool vstr_had_error(vstr_t *vstr);
char *vstr_str(vstr_t *vstr);
int vstr_len(vstr_t *vstr);
void vstr_hint_size(vstr_t *vstr, int size);

View File

@ -46,9 +46,9 @@ void mp_obj_print(mp_obj_t o_in) {
mp_obj_print_helper(printf_wrapper, NULL, o_in);
}
MP_BOOL mp_obj_is_callable(mp_obj_t o_in) {
bool mp_obj_is_callable(mp_obj_t o_in) {
if (MP_OBJ_IS_SMALL_INT(o_in)) {
return MP_FALSE;
return false;
} else {
mp_obj_base_t *o = o_in;
return o->type->call_n != NULL;
@ -77,13 +77,13 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) {
// "The objects need not have the same type. If both are numbers, they are converted
// to a common type. Otherwise, the == and != operators always consider objects of
// different types to be unequal."
// note also that False==0 and True==1 are MP_TRUE expressions
MP_BOOL mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
// note also that False==0 and True==1 are true expressions
bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
if (o1 == o2) {
return MP_TRUE;
return true;
} else if (MP_OBJ_IS_SMALL_INT(o1) || MP_OBJ_IS_SMALL_INT(o2)) {
if (MP_OBJ_IS_SMALL_INT(o1) && MP_OBJ_IS_SMALL_INT(o2)) {
return MP_FALSE;
return false;
} else {
if (MP_OBJ_IS_SMALL_INT(o2)) {
mp_obj_t temp = o1; o1 = o2; o2 = temp;
@ -95,25 +95,25 @@ MP_BOOL mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
} else if (o2 == mp_const_true) {
return val == 1;
} else {
return MP_FALSE;
return false;
}
}
} else if (MP_OBJ_IS_TYPE(o1, &str_type) && MP_OBJ_IS_TYPE(o2, &str_type)) {
return mp_obj_str_get(o1) == mp_obj_str_get(o2);
} else {
assert(0);
return MP_FALSE;
return false;
}
}
MP_BOOL mp_obj_less(mp_obj_t o1, mp_obj_t o2) {
bool mp_obj_less(mp_obj_t o1, mp_obj_t o2) {
if (MP_OBJ_IS_SMALL_INT(o1) && MP_OBJ_IS_SMALL_INT(o2)) {
mp_small_int_t i1 = MP_OBJ_SMALL_INT_VALUE(o1);
mp_small_int_t i2 = MP_OBJ_SMALL_INT_VALUE(o2);
return i1 < i2;
} else {
assert(0);
return MP_FALSE;
return false;
}
}

View File

@ -126,7 +126,7 @@ struct _mp_map_t;
// General API for objects
mp_obj_t mp_obj_new_none(void);
mp_obj_t mp_obj_new_bool(MP_BOOL value);
mp_obj_t mp_obj_new_bool(bool value);
mp_obj_t mp_obj_new_cell(mp_obj_t obj);
mp_obj_t mp_obj_new_int(machine_int_t value);
mp_obj_t mp_obj_new_str(qstr qstr);
@ -162,10 +162,10 @@ const char *mp_obj_get_type_str(mp_obj_t o_in);
void mp_obj_print_helper(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in);
void mp_obj_print(mp_obj_t o);
MP_BOOL mp_obj_is_callable(mp_obj_t o_in);
bool mp_obj_is_callable(mp_obj_t o_in);
machine_int_t mp_obj_hash(mp_obj_t o_in);
MP_BOOL mp_obj_equal(mp_obj_t o1, mp_obj_t o2);
MP_BOOL mp_obj_less(mp_obj_t o1, mp_obj_t o2);
bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2);
bool mp_obj_less(mp_obj_t o1, mp_obj_t o2);
machine_int_t mp_obj_get_int(mp_obj_t arg);
#if MICROPY_ENABLE_FLOAT

View File

@ -10,7 +10,7 @@
typedef struct _mp_obj_bool_t {
mp_obj_base_t base;
MP_BOOL value;
bool value;
} mp_obj_bool_t;
static void bool_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) {
@ -44,8 +44,8 @@ const mp_obj_type_t bool_type = {
.methods = NULL,
};
static const mp_obj_bool_t false_obj = {{&bool_type}, MP_FALSE};
static const mp_obj_bool_t true_obj = {{&bool_type}, MP_TRUE};
static const mp_obj_bool_t false_obj = {{&bool_type}, false};
static const mp_obj_bool_t true_obj = {{&bool_type}, true};
const mp_obj_t mp_const_false = (mp_obj_t)&false_obj;
const mp_obj_t mp_const_true = (mp_obj_t)&true_obj;

View File

@ -26,7 +26,7 @@ mp_obj_t class_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) {
mp_obj_t o = mp_obj_new_instance(self_in);
// look for __init__ function
mp_map_elem_t *init_fn = mp_qstr_map_lookup(self->locals, MP_QSTR___init__, MP_FALSE);
mp_map_elem_t *init_fn = mp_qstr_map_lookup(self->locals, MP_QSTR___init__, false);
if (init_fn != NULL) {
// call __init__ function

View File

@ -19,14 +19,14 @@ typedef struct _mp_obj_dict_t {
static void dict_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) {
mp_obj_dict_t *self = self_in;
MP_BOOL first = MP_TRUE;
bool first = true;
print(env, "{");
for (int i = 0; i < self->map.alloc; i++) {
if (self->map.table[i].key != NULL) {
if (!first) {
print(env, ", ");
}
first = MP_FALSE;
first = false;
mp_obj_print_helper(print, env, self->map.table[i].key);
print(env, ": ");
mp_obj_print_helper(print, env, self->map.table[i].value);
@ -47,7 +47,7 @@ static mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
case RT_BINARY_OP_SUBSCR:
{
// dict load
mp_map_elem_t *elem = mp_map_lookup_helper(&o->map, rhs_in, MP_FALSE);
mp_map_elem_t *elem = mp_map_lookup_helper(&o->map, rhs_in, false);
if (elem == NULL) {
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_KeyError, "<value>"));
} else {
@ -91,6 +91,6 @@ uint mp_obj_dict_len(mp_obj_t self_in) {
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value) {
assert(MP_OBJ_IS_TYPE(self_in, &dict_type));
mp_obj_dict_t *self = self_in;
mp_map_lookup_helper(&self->map, key, MP_TRUE)->value = value;
mp_map_lookup_helper(&self->map, key, true)->value = value;
return self_in;
}

View File

@ -78,7 +78,7 @@ mp_obj_t gen_instance_getiter(mp_obj_t self_in) {
mp_obj_t gen_instance_iternext(mp_obj_t self_in) {
mp_obj_gen_instance_t *self = self_in;
MP_BOOL yield = mp_execute_byte_code_2(&self->ip, &self->state[0], &self->sp);
bool yield = mp_execute_byte_code_2(&self->ip, &self->state[0], &self->sp);
if (yield) {
return *self->sp;
} else {

View File

@ -21,7 +21,7 @@ typedef struct _mp_obj_instance_t {
type needs to be specified dynamically
case O_OBJ:
{
py_map_elem_t *qn = py_qstr_map_lookup(o->u_obj.class->u_class.locals, qstr_from_str_static("__qualname__"), MP_FALSE); assert(qn != NULL);
py_map_elem_t *qn = py_qstr_map_lookup(o->u_obj.class->u_class.locals, qstr_from_str_static("__qualname__"), false); assert(qn != NULL);
assert(IS_O(qn->value, O_STR));
return qstr_str(((py_obj_base_t*)qn->value)->u_str);
}
@ -30,12 +30,12 @@ type needs to be specified dynamically
mp_obj_t mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr) {
// logic: look in obj members then class locals (TODO check this against CPython)
mp_obj_instance_t *self = self_in;
mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, MP_FALSE);
mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, false);
if (elem != NULL) {
// object member, always treated as a value
return elem->value;
}
elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, MP_FALSE);
elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, false);
if (elem != NULL) {
if (mp_obj_is_callable(elem->value)) {
// class member is callable so build a bound method
@ -51,14 +51,14 @@ mp_obj_t mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr) {
void mp_obj_instance_load_method(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
// logic: look in obj members then class locals (TODO check this against CPython)
mp_obj_instance_t *self = self_in;
mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, MP_FALSE);
mp_map_elem_t *elem = mp_qstr_map_lookup(self->members, attr, false);
if (elem != NULL) {
// object member, always treated as a value
dest[1] = elem->value;
dest[0] = NULL;
return;
}
elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, MP_FALSE);
elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, false);
if (elem != NULL) {
if (mp_obj_is_callable(elem->value)) {
// class member is callable so build a bound method
@ -81,11 +81,11 @@ void mp_obj_instance_load_method(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
void mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
// logic: look in class locals (no add) then obj members (add) (TODO check this against CPython)
mp_obj_instance_t *self = self_in;
mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, MP_FALSE);
mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(self->class), attr, false);
if (elem != NULL) {
elem->value = value;
} else {
mp_qstr_map_lookup(self->members, attr, MP_TRUE)->value = value;
mp_qstr_map_lookup(self->members, attr, true)->value = value;
}
}

View File

@ -57,6 +57,7 @@ static mp_obj_t list_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args
default:
nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_TypeError, "list takes at most 1 argument, %d given", (void*)(machine_int_t)n_args));
}
return NULL;
}
static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
@ -266,6 +267,7 @@ const mp_method_t list_type_methods[] = {
{ "copy", &list_copy_obj },
{ "count", &list_count_obj },
{ "index", &list_index_obj },
{ "insert", &list_insert_obj },
{ "pop", &list_pop_obj },
{ "remove", &list_remove_obj },
{ "reverse", &list_reverse_obj },

View File

@ -17,14 +17,14 @@ typedef struct _mp_obj_set_t {
void set_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) {
mp_obj_set_t *self = self_in;
MP_BOOL first = MP_TRUE;
bool first = true;
print(env, "{");
for (int i = 0; i < self->set.alloc; i++) {
if (self->set.table[i] != MP_OBJ_NULL) {
if (!first) {
print(env, ", ");
}
first = MP_FALSE;
first = false;
mp_obj_print_helper(print, env, self->set.table[i]);
}
}
@ -72,7 +72,7 @@ mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) {
o->base.type = &set_type;
mp_set_init(&o->set, n_args);
for (int i = 0; i < n_args; i++) {
mp_set_lookup(&o->set, items[i], MP_TRUE);
mp_set_lookup(&o->set, items[i], true);
}
return o;
}
@ -80,5 +80,5 @@ mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) {
void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item) {
assert(MP_OBJ_IS_TYPE(self_in, &set_type));
mp_obj_set_t *self = self_in;
mp_set_lookup(&self->set, item, MP_TRUE);
mp_set_lookup(&self->set, item, true);
}

View File

@ -165,14 +165,8 @@ static mp_obj_t tuple_it_iternext(mp_obj_t self_in) {
static const mp_obj_type_t tuple_it_type = {
{ &mp_const_type },
"tuple_iterator",
NULL, // print
NULL, // make_new
NULL, // call_n
NULL, // unary_op
NULL, // binary_op
NULL, // getiter
tuple_it_iternext,
NULL, // method list
.iternext = tuple_it_iternext,
.methods = NULL,
};
static mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, int cur) {

View File

@ -189,8 +189,8 @@ static void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
if (tok->kind == MP_TOKEN_NAME) {
pn = mp_parse_node_new_leaf(MP_PARSE_NODE_ID, qstr_from_strn_copy(tok->str, tok->len));
} else if (tok->kind == MP_TOKEN_NUMBER) {
MP_BOOL dec = MP_FALSE;
MP_BOOL small_int = MP_TRUE;
bool dec = false;
bool small_int = true;
int int_val = 0;
int len = tok->len;
const char *str = tok->str;
@ -219,10 +219,10 @@ static void push_result_token(parser_t *parser, const mp_lexer_t *lex) {
} else if (base == 16 && 'A' <= str[i] && str[i] <= 'F') {
int_val = base * int_val + str[i] - 'A' + 10;
} else if (str[i] == '.' || str[i] == 'e' || str[i] == 'E' || str[i] == 'j' || str[i] == 'J') {
dec = MP_TRUE;
dec = true;
break;
} else {
small_int = MP_FALSE;
small_int = false;
break;
}
}
@ -269,11 +269,11 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
push_rule(parser, rules[top_level_rule], 0);
uint n, i;
MP_BOOL backtrack = MP_FALSE;
bool backtrack = false;
const rule_t *rule;
mp_token_kind_t tok_kind;
MP_BOOL emit_rule;
MP_BOOL had_trailing_sep;
bool emit_rule;
bool had_trailing_sep;
for (;;) {
next_rule:
@ -298,7 +298,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
if (i > 0 && !backtrack) {
goto next_rule;
} else {
backtrack = MP_FALSE;
backtrack = false;
}
for (; i < n - 1; ++i) {
switch (rule->arg[i] & RULE_ARG_KIND_MASK) {
@ -322,7 +322,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
push_result_token(parser, lex);
mp_lexer_to_next(lex);
} else {
backtrack = MP_TRUE;
backtrack = true;
goto next_rule;
}
} else {
@ -338,7 +338,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
if ((rule->arg[i - 1] & RULE_ARG_KIND_MASK) == RULE_ARG_OPT_RULE) {
// an optional rule that failed, so continue with next arg
push_result_node(parser, MP_PARSE_NODE_NULL);
backtrack = MP_FALSE;
backtrack = false;
} else {
// a mandatory rule that failed, so propagate backtrack
if (i > 1) {
@ -369,7 +369,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
goto syntax_error;
} else {
// this rule failed, so backtrack
backtrack = MP_TRUE;
backtrack = true;
goto next_rule;
}
}
@ -395,12 +395,12 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
// count number of arguments for the parse_node
i = 0;
emit_rule = MP_FALSE;
emit_rule = false;
for (int x = 0; x < n; ++x) {
if ((rule->arg[x] & RULE_ARG_KIND_MASK) == RULE_ARG_TOK) {
tok_kind = rule->arg[x] & RULE_ARG_ARG_MASK;
if (tok_kind >= MP_TOKEN_NAME) {
emit_rule = MP_TRUE;
emit_rule = true;
}
if (tok_kind == MP_TOKEN_NAME) {
// only tokens which were names are pushed to stack
@ -414,19 +414,19 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
// always emit these rules, even if they have only 1 argument
if (rule->rule_id == RULE_expr_stmt || rule->rule_id == RULE_yield_stmt) {
emit_rule = MP_TRUE;
emit_rule = true;
}
// never emit these rules if they have only 1 argument
// NOTE: can't put atom_paren here because we need it to distinguisg, for example, [a,b] from [(a,b)]
// TODO possibly put varargslist_name, varargslist_equal here as well
if (rule->rule_id == RULE_else_stmt || rule->rule_id == RULE_testlist_comp_3b || rule->rule_id == RULE_import_as_names_paren || rule->rule_id == RULE_typedargslist_name || rule->rule_id == RULE_typedargslist_colon || rule->rule_id == RULE_typedargslist_equal || rule->rule_id == RULE_dictorsetmaker_colon || rule->rule_id == RULE_classdef_2 || rule->rule_id == RULE_with_item_as || rule->rule_id == RULE_assert_stmt_extra || rule->rule_id == RULE_as_name || rule->rule_id == RULE_raise_stmt_from || rule->rule_id == RULE_vfpdef) {
emit_rule = MP_FALSE;
emit_rule = false;
}
// always emit these rules, and add an extra blank node at the end (to be used by the compiler to store data)
if (rule->rule_id == RULE_funcdef || rule->rule_id == RULE_classdef || rule->rule_id == RULE_comp_for || rule->rule_id == RULE_lambdef || rule->rule_id == RULE_lambdef_nocond) {
emit_rule = MP_TRUE;
emit_rule = true;
push_result_node(parser, MP_PARSE_NODE_NULL);
i += 1;
}
@ -465,14 +465,14 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
// n=3 is: item (sep item)* [sep]
if (backtrack) {
list_backtrack:
had_trailing_sep = MP_FALSE;
had_trailing_sep = false;
if (n == 2) {
if (i == 1) {
// fail on item, first time round; propagate backtrack
goto next_rule;
} else {
// fail on item, in later rounds; finish with this rule
backtrack = MP_FALSE;
backtrack = false;
}
} else {
if (i == 1) {
@ -482,15 +482,15 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
// fail on item, in later rounds; have eaten tokens so can't backtrack
if (n == 3) {
// list allows trailing separator; finish parsing list
had_trailing_sep = MP_TRUE;
backtrack = MP_FALSE;
had_trailing_sep = true;
backtrack = false;
} else {
// list doesn't allowing trailing separator; fail
goto syntax_error;
}
} else {
// fail on separator; finish parsing list
backtrack = MP_FALSE;
backtrack = false;
}
}
} else {
@ -510,7 +510,7 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) {
} else {
// couldn't get element of list
i += 1;
backtrack = MP_TRUE;
backtrack = true;
goto list_backtrack;
}
break;

View File

@ -1,17 +1,17 @@
#include "misc.h"
#include "repl.h"
MP_BOOL str_startswith_word(const char *str, const char *head) {
bool str_startswith_word(const char *str, const char *head) {
int i;
for (i = 0; str[i] && head[i]; i++) {
if (str[i] != head[i]) {
return MP_FALSE;
return false;
}
}
return head[i] == '\0' && (str[i] == '\0' || !unichar_isalpha(str[i]));
}
MP_BOOL mp_repl_is_compound_stmt(const char *line) {
bool mp_repl_is_compound_stmt(const char *line) {
// compound if line starts with a certain keyword
if (
str_startswith_word(line, "if")
@ -23,7 +23,7 @@ MP_BOOL mp_repl_is_compound_stmt(const char *line) {
|| str_startswith_word(line, "class")
|| str_startswith_word(line, "@")
) {
return MP_TRUE;
return true;
}
// also "compound" if unmatched open bracket

View File

@ -1 +1 @@
MP_BOOL mp_repl_is_compound_stmt(const char *line);
bool mp_repl_is_compound_stmt(const char *line);

View File

@ -45,7 +45,7 @@ typedef struct _mp_code_t {
int n_args;
int n_locals;
int n_stack;
MP_BOOL is_generator;
bool is_generator;
union {
struct {
byte *code;
@ -70,60 +70,60 @@ FILE *fp_write_code = NULL;
void rt_init(void) {
// locals = globals for outer module (see Objects/frameobject.c/PyFrame_New())
map_locals = map_globals = mp_map_new(MP_MAP_QSTR, 1);
mp_qstr_map_lookup(map_globals, MP_QSTR___name__, MP_TRUE)->value = mp_obj_new_str(MP_QSTR___main__);
mp_qstr_map_lookup(map_globals, MP_QSTR___name__, true)->value = mp_obj_new_str(MP_QSTR___main__);
// init built-in hash table
mp_map_init(&map_builtins, MP_MAP_QSTR, 3);
// built-in exceptions (TODO, make these proper classes)
mp_qstr_map_lookup(&map_builtins, MP_QSTR_AttributeError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_AttributeError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_IndexError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_IndexError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_KeyError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_KeyError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_NameError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_NameError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_TypeError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_TypeError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_SyntaxError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_SyntaxError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_ValueError, MP_TRUE)->value = mp_obj_new_exception(MP_QSTR_ValueError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_AttributeError, true)->value = mp_obj_new_exception(MP_QSTR_AttributeError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_IndexError, true)->value = mp_obj_new_exception(MP_QSTR_IndexError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_KeyError, true)->value = mp_obj_new_exception(MP_QSTR_KeyError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_NameError, true)->value = mp_obj_new_exception(MP_QSTR_NameError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_TypeError, true)->value = mp_obj_new_exception(MP_QSTR_TypeError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_SyntaxError, true)->value = mp_obj_new_exception(MP_QSTR_SyntaxError);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_ValueError, true)->value = mp_obj_new_exception(MP_QSTR_ValueError);
// built-in objects
mp_qstr_map_lookup(&map_builtins, MP_QSTR_Ellipsis, MP_TRUE)->value = mp_const_ellipsis;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_Ellipsis, true)->value = mp_const_ellipsis;
// built-in core functions
mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, MP_TRUE)->value = rt_make_function_2(mp_builtin___build_class__);
mp_qstr_map_lookup(&map_builtins, MP_QSTR___repl_print__, MP_TRUE)->value = rt_make_function_1(mp_builtin___repl_print__);
mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, true)->value = rt_make_function_2(mp_builtin___build_class__);
mp_qstr_map_lookup(&map_builtins, MP_QSTR___repl_print__, true)->value = rt_make_function_1(mp_builtin___repl_print__);
// built-in types
mp_qstr_map_lookup(&map_builtins, MP_QSTR_bool, MP_TRUE)->value = (mp_obj_t)&bool_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_bool, true)->value = (mp_obj_t)&bool_type;
#if MICROPY_ENABLE_FLOAT
mp_qstr_map_lookup(&map_builtins, MP_QSTR_complex, MP_TRUE)->value = (mp_obj_t)&complex_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_complex, true)->value = (mp_obj_t)&complex_type;
#endif
mp_qstr_map_lookup(&map_builtins, MP_QSTR_dict, MP_TRUE)->value = (mp_obj_t)&dict_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_dict, true)->value = (mp_obj_t)&dict_type;
#if MICROPY_ENABLE_FLOAT
mp_qstr_map_lookup(&map_builtins, MP_QSTR_float, MP_TRUE)->value = (mp_obj_t)&float_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_float, true)->value = (mp_obj_t)&float_type;
#endif
mp_qstr_map_lookup(&map_builtins, MP_QSTR_int, MP_TRUE)->value = (mp_obj_t)&int_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_list, MP_TRUE)->value = (mp_obj_t)&list_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_set, MP_TRUE)->value = (mp_obj_t)&set_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_tuple, MP_TRUE)->value = (mp_obj_t)&tuple_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_type, MP_TRUE)->value = (mp_obj_t)&mp_builtin_type_obj; // TODO
mp_qstr_map_lookup(&map_builtins, MP_QSTR_int, true)->value = (mp_obj_t)&int_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_list, true)->value = (mp_obj_t)&list_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_set, true)->value = (mp_obj_t)&set_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_tuple, true)->value = (mp_obj_t)&tuple_type;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_type, true)->value = (mp_obj_t)&mp_builtin_type_obj; // TODO
// built-in user functions; TODO covert all to &mp_builtin_xxx's
mp_qstr_map_lookup(&map_builtins, MP_QSTR_abs, MP_TRUE)->value = rt_make_function_1(mp_builtin_abs);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_all, MP_TRUE)->value = rt_make_function_1(mp_builtin_all);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_any, MP_TRUE)->value = rt_make_function_1(mp_builtin_any);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_callable, MP_TRUE)->value = rt_make_function_1(mp_builtin_callable);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_chr, MP_TRUE)->value = rt_make_function_1(mp_builtin_chr);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_divmod, MP_TRUE)->value = rt_make_function_2(mp_builtin_divmod);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_hash, MP_TRUE)->value = (mp_obj_t)&mp_builtin_hash_obj;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_iter, MP_TRUE)->value = (mp_obj_t)&mp_builtin_iter_obj;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_len, MP_TRUE)->value = rt_make_function_1(mp_builtin_len);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_max, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_max);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_min, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_min);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_next, MP_TRUE)->value = (mp_obj_t)&mp_builtin_next_obj;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_ord, MP_TRUE)->value = rt_make_function_1(mp_builtin_ord);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_pow, MP_TRUE)->value = rt_make_function_var(2, mp_builtin_pow);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_print, MP_TRUE)->value = rt_make_function_var(0, mp_builtin_print);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_range, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_range);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_sum, MP_TRUE)->value = rt_make_function_var(1, mp_builtin_sum);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_abs, true)->value = rt_make_function_1(mp_builtin_abs);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_all, true)->value = rt_make_function_1(mp_builtin_all);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_any, true)->value = rt_make_function_1(mp_builtin_any);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_callable, true)->value = rt_make_function_1(mp_builtin_callable);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_chr, true)->value = rt_make_function_1(mp_builtin_chr);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_divmod, true)->value = rt_make_function_2(mp_builtin_divmod);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_hash, true)->value = (mp_obj_t)&mp_builtin_hash_obj;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_iter, true)->value = (mp_obj_t)&mp_builtin_iter_obj;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_len, true)->value = rt_make_function_1(mp_builtin_len);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_max, true)->value = rt_make_function_var(1, mp_builtin_max);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_min, true)->value = rt_make_function_var(1, mp_builtin_min);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_next, true)->value = (mp_obj_t)&mp_builtin_next_obj;
mp_qstr_map_lookup(&map_builtins, MP_QSTR_ord, true)->value = rt_make_function_1(mp_builtin_ord);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_pow, true)->value = rt_make_function_var(2, mp_builtin_pow);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_print, true)->value = rt_make_function_var(0, mp_builtin_print);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_range, true)->value = rt_make_function_var(1, mp_builtin_range);
mp_qstr_map_lookup(&map_builtins, MP_QSTR_sum, true)->value = rt_make_function_var(1, mp_builtin_sum);
next_unique_code_id = 1; // 0 indicates "no code"
unique_codes = NULL;
@ -154,7 +154,7 @@ static void alloc_unique_codes(void) {
}
}
void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, MP_BOOL is_generator) {
void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, bool is_generator) {
alloc_unique_codes();
assert(1 <= unique_code_id && unique_code_id < next_unique_code_id);
@ -197,7 +197,7 @@ void rt_assign_native_code(int unique_code_id, void *fun, uint len, int n_args)
unique_codes[unique_code_id].n_args = n_args;
unique_codes[unique_code_id].n_locals = 0;
unique_codes[unique_code_id].n_stack = 0;
unique_codes[unique_code_id].is_generator = MP_FALSE;
unique_codes[unique_code_id].is_generator = false;
unique_codes[unique_code_id].u_native.fun = fun;
//printf("native code: %d bytes\n", len);
@ -230,7 +230,7 @@ void rt_assign_inline_asm_code(int unique_code_id, void *fun, uint len, int n_ar
unique_codes[unique_code_id].n_args = n_args;
unique_codes[unique_code_id].n_locals = 0;
unique_codes[unique_code_id].n_stack = 0;
unique_codes[unique_code_id].is_generator = MP_FALSE;
unique_codes[unique_code_id].is_generator = false;
unique_codes[unique_code_id].u_inline_asm.fun = fun;
#ifdef DEBUG_PRINT
@ -252,8 +252,8 @@ void rt_assign_inline_asm_code(int unique_code_id, void *fun, uint len, int n_ar
#endif
}
static MP_BOOL fit_small_int(mp_small_int_t o) {
return MP_TRUE;
static bool fit_small_int(mp_small_int_t o) {
return true;
}
int rt_is_true(mp_obj_t arg) {
@ -290,10 +290,10 @@ mp_obj_t rt_load_const_dec(qstr qstr) {
const char *s = qstr_str(qstr);
int in = PARSE_DEC_IN_INTG;
mp_float_t dec_val = 0;
MP_BOOL exp_neg = MP_FALSE;
bool exp_neg = false;
int exp_val = 0;
int exp_extra = 0;
MP_BOOL imag = MP_FALSE;
bool imag = false;
for (; *s; s++) {
int dig = *s;
if ('0' <= dig && dig <= '9') {
@ -314,11 +314,11 @@ mp_obj_t rt_load_const_dec(qstr qstr) {
s++;
} else if (s[1] == '-') {
s++;
exp_neg = MP_TRUE;
exp_neg = true;
}
} else if (dig == 'J' || dig == 'j') {
s++;
imag = MP_TRUE;
imag = true;
break;
} else {
// unknown character
@ -356,11 +356,11 @@ mp_obj_t rt_load_const_str(qstr qstr) {
mp_obj_t rt_load_name(qstr qstr) {
// logic: search locals, globals, builtins
DEBUG_OP_printf("load name %s\n", qstr_str(qstr));
mp_map_elem_t *elem = mp_qstr_map_lookup(map_locals, qstr, MP_FALSE);
mp_map_elem_t *elem = mp_qstr_map_lookup(map_locals, qstr, false);
if (elem == NULL) {
elem = mp_qstr_map_lookup(map_globals, qstr, MP_FALSE);
elem = mp_qstr_map_lookup(map_globals, qstr, false);
if (elem == NULL) {
elem = mp_qstr_map_lookup(&map_builtins, qstr, MP_FALSE);
elem = mp_qstr_map_lookup(&map_builtins, qstr, false);
if (elem == NULL) {
nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_NameError, "name '%s' is not defined", qstr_str(qstr)));
}
@ -372,9 +372,9 @@ mp_obj_t rt_load_name(qstr qstr) {
mp_obj_t rt_load_global(qstr qstr) {
// logic: search globals, builtins
DEBUG_OP_printf("load global %s\n", qstr_str(qstr));
mp_map_elem_t *elem = mp_qstr_map_lookup(map_globals, qstr, MP_FALSE);
mp_map_elem_t *elem = mp_qstr_map_lookup(map_globals, qstr, false);
if (elem == NULL) {
elem = mp_qstr_map_lookup(&map_builtins, qstr, MP_FALSE);
elem = mp_qstr_map_lookup(&map_builtins, qstr, false);
if (elem == NULL) {
nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_NameError, "name '%s' is not defined", qstr_str(qstr)));
}
@ -384,7 +384,7 @@ mp_obj_t rt_load_global(qstr qstr) {
mp_obj_t rt_load_build_class(void) {
DEBUG_OP_printf("load_build_class\n");
mp_map_elem_t *elem = mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, MP_FALSE);
mp_map_elem_t *elem = mp_qstr_map_lookup(&map_builtins, MP_QSTR___build_class__, false);
if (elem == NULL) {
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_NameError, "name '__build_class__' is not defined"));
}
@ -401,12 +401,12 @@ void rt_set_cell(mp_obj_t cell, mp_obj_t val) {
void rt_store_name(qstr qstr, mp_obj_t obj) {
DEBUG_OP_printf("store name %s <- %p\n", qstr_str(qstr), obj);
mp_qstr_map_lookup(map_locals, qstr, MP_TRUE)->value = obj;
mp_qstr_map_lookup(map_locals, qstr, true)->value = obj;
}
void rt_store_global(qstr qstr, mp_obj_t obj) {
DEBUG_OP_printf("store global %s <- %p\n", qstr_str(qstr), obj);
mp_qstr_map_lookup(map_globals, qstr, MP_TRUE)->value = obj;
mp_qstr_map_lookup(map_globals, qstr, true)->value = obj;
}
mp_obj_t rt_unary_op(int op, mp_obj_t arg) {
@ -750,7 +750,7 @@ mp_obj_t rt_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value) {
mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) {
DEBUG_OP_printf("load attr %s\n", qstr_str(attr));
if (MP_OBJ_IS_TYPE(base, &class_type)) {
mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(base), attr, MP_FALSE);
mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_class_get_locals(base), attr, false);
if (elem == NULL) {
// TODO what about generic method lookup?
goto no_attr;
@ -760,7 +760,7 @@ mp_obj_t rt_load_attr(mp_obj_t base, qstr attr) {
return mp_obj_instance_load_attr(base, attr);
} else if (MP_OBJ_IS_TYPE(base, &module_type)) {
DEBUG_OP_printf("lookup module map %p\n", mp_obj_module_get_globals(base));
mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_module_get_globals(base), attr, MP_FALSE);
mp_map_elem_t *elem = mp_qstr_map_lookup(mp_obj_module_get_globals(base), attr, false);
if (elem == NULL) {
// TODO what about generic method lookup?
goto no_attr;
@ -817,13 +817,13 @@ void rt_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
if (MP_OBJ_IS_TYPE(base, &class_type)) {
// TODO CPython allows STORE_ATTR to a class, but is this the correct implementation?
mp_map_t *locals = mp_obj_class_get_locals(base);
mp_qstr_map_lookup(locals, attr, MP_TRUE)->value = value;
mp_qstr_map_lookup(locals, attr, true)->value = value;
} else if (MP_OBJ_IS_TYPE(base, &instance_type)) {
mp_obj_instance_store_attr(base, attr, value);
} else if (MP_OBJ_IS_TYPE(base, &module_type)) {
// TODO CPython allows STORE_ATTR to a module, but is this the correct implementation?
mp_map_t *globals = mp_obj_module_get_globals(base);
mp_qstr_map_lookup(globals, attr, MP_TRUE)->value = value;
mp_qstr_map_lookup(globals, attr, true)->value = value;
} else {
nlr_jump(mp_obj_new_exception_msg_2_args(MP_QSTR_AttributeError, "'%s' object has no attribute '%s'", mp_obj_get_type_str(base), qstr_str(attr)));
}

View File

@ -82,6 +82,6 @@ extern void *const rt_fun_table[RT_F_NUMBER_OF];
void rt_init(void);
void rt_deinit(void);
int rt_get_unique_code_id(void);
void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, MP_BOOL is_generator);
void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, int n_locals, int n_stack, bool is_generator);
void rt_assign_native_code(int unique_code_id, void *f, uint len, int n_args);
void rt_assign_inline_asm_code(int unique_code_id, void *f, uint len, int n_args);

View File

@ -58,10 +58,10 @@ scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, uint unique_code_id, u
return scope;
}
id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, MP_BOOL *added) {
id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) {
for (int i = 0; i < scope->id_info_len; i++) {
if (scope->id_info[i].qstr == qstr) {
*added = MP_FALSE;
*added = false;
return &scope->id_info[i];
}
}
@ -100,11 +100,11 @@ id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, MP_BOOL *added) {
id_info = &scope->id_info[scope->id_info_len++];
}
id_info->param = MP_FALSE;
id_info->param = false;
id_info->kind = 0;
id_info->qstr = qstr;
id_info->local_num = 0;
*added = MP_TRUE;
*added = true;
return id_info;
}
@ -155,7 +155,7 @@ void scope_close_over_in_parents(scope_t *scope, qstr qstr) {
}
if (id == NULL) {
// variable not declared in this scope, so declare it as free and keep searching parents
MP_BOOL added;
bool added;
id = scope_find_or_add_id(s, qstr, &added);
assert(added);
id->kind = ID_INFO_KIND_FREE;
@ -178,7 +178,7 @@ void scope_declare_global(scope_t *scope, qstr qstr) {
printf("SyntaxError?: can't declare global in outer code\n");
return;
}
MP_BOOL added;
bool added;
id_info_t *id_info = scope_find_or_add_id(scope, qstr, &added);
if (!added) {
printf("SyntaxError?: identifier already declared something\n");
@ -198,7 +198,7 @@ void scope_declare_nonlocal(scope_t *scope, qstr qstr) {
printf("SyntaxError?: can't declare nonlocal in outer code\n");
return;
}
MP_BOOL added;
bool added;
id_info_t *id_info = scope_find_or_add_id(scope, qstr, &added);
if (!added) {
printf("SyntaxError?: identifier already declared something\n");

View File

@ -8,7 +8,7 @@ enum {
typedef struct _id_info_t {
// TODO compress this info to make structure smaller in memory
MP_BOOL param;
bool param;
int kind;
qstr qstr;
@ -55,7 +55,7 @@ typedef struct _scope_t {
} scope_t;
scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, uint unique_code_id, uint emit_options);
id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, MP_BOOL *added);
id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added);
id_info_t *scope_find(scope_t *scope, qstr qstr);
id_info_t *scope_find_global(scope_t *scope, qstr qstr);
id_info_t *scope_find_local_in_parent(scope_t *scope, qstr qstr);

View File

@ -46,32 +46,32 @@ char *utf8_next_char(const char *s) {
return (char*)(s + 1);
}
MP_BOOL unichar_isspace(unichar c) {
bool unichar_isspace(unichar c) {
return c < 128 && (attr[c] & FL_SPACE) != 0;
}
MP_BOOL unichar_isalpha(unichar c) {
bool unichar_isalpha(unichar c) {
return c < 128 && (attr[c] & FL_ALPHA) != 0;
}
MP_BOOL unichar_isprint(unichar c) {
bool unichar_isprint(unichar c) {
return c < 128 && (attr[c] & FL_PRINT) != 0;
}
MP_BOOL unichar_isdigit(unichar c) {
bool unichar_isdigit(unichar c) {
return c < 128 && (attr[c] & FL_DIGIT) != 0;
}
/*
MP_BOOL char_is_alpha_or_digit(unichar c) {
bool char_is_alpha_or_digit(unichar c) {
return c < 128 && (attr[c] & (FL_ALPHA | FL_DIGIT)) != 0;
}
MP_BOOL char_is_upper(unichar c) {
bool char_is_upper(unichar c) {
return c < 128 && (attr[c] & FL_UPPER) != 0;
}
MP_BOOL char_is_lower(unichar c) {
bool char_is_lower(unichar c) {
return c < 128 && (attr[c] & FL_LOWER) != 0;
}
*/

View File

@ -65,7 +65,7 @@ mp_obj_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_arg
// fastn has items in normal order
// sp points to top of stack which grows down
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) {
// careful: be sure to declare volatile any variables read in the exception handler (written is ok, I think)
const byte *ip = *ip_in_out;
@ -472,7 +472,7 @@ MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t
nlr_pop();
*sp_in_out = sp;
assert(exc_sp == &exc_stack[0] - 1);
return MP_FALSE;
return false;
case MP_BC_YIELD_VALUE:
nlr_pop();
@ -481,7 +481,7 @@ MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t
fastn[1] = fast1;
fastn[2] = fast2;
*sp_in_out = sp;
return MP_TRUE;
return true;
case MP_BC_IMPORT_NAME:
DECODE_QSTR;
@ -499,7 +499,7 @@ MP_BOOL mp_execute_byte_code_2(const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t
printf("code %p, byte code 0x%02x not implemented\n", ip, op);
assert(0);
nlr_pop();
return MP_FALSE;
return false;
}
}

View File

@ -11,11 +11,11 @@ void vstr_init(vstr_t *vstr) {
vstr->len = 0;
vstr->buf = m_new(char, vstr->alloc);
if (vstr->buf == NULL) {
vstr->had_error = MP_TRUE;
vstr->had_error = true;
return;
}
vstr->buf[0] = 0;
vstr->had_error = MP_FALSE;
vstr->had_error = false;
}
void vstr_clear(vstr_t *vstr) {
@ -42,10 +42,10 @@ void vstr_free(vstr_t *vstr) {
void vstr_reset(vstr_t *vstr) {
vstr->len = 0;
vstr->buf[0] = 0;
vstr->had_error = MP_FALSE;
vstr->had_error = false;
}
MP_BOOL vstr_had_error(vstr_t *vstr) {
bool vstr_had_error(vstr_t *vstr) {
return vstr->had_error;
}
@ -63,23 +63,23 @@ int vstr_len(vstr_t *vstr) {
return vstr->len;
}
MP_BOOL vstr_ensure_extra(vstr_t *vstr, int size) {
bool vstr_ensure_extra(vstr_t *vstr, int size) {
if (vstr->len + size + 1 > vstr->alloc) {
int new_alloc = ROUND_ALLOC((vstr->len + size + 1) * 2);
char *new_buf = m_renew(char, vstr->buf, vstr->alloc, new_alloc);
if (new_buf == NULL) {
vstr->had_error = MP_TRUE;
return MP_FALSE;
vstr->had_error = true;
return false;
}
vstr->alloc = new_alloc;
vstr->buf = new_buf;
}
return MP_TRUE;
return true;
}
void vstr_hint_size(vstr_t *vstr, int size) {
// it's not an error if we fail to allocate for the size hint
MP_BOOL er = vstr->had_error;
bool er = vstr->had_error;
vstr_ensure_extra(vstr, size);
vstr->had_error = er;
}

View File

@ -22,7 +22,7 @@ int sample_buf_in;
int sample_buf_out;
byte sample_buf[SAMPLE_BUF_SIZE];
MP_BOOL audio_is_full(void) {
bool audio_is_full(void) {
return ((sample_buf_in + 1) % SAMPLE_BUF_SIZE) == sample_buf_out;
}

View File

@ -165,11 +165,11 @@ void pyb_cc3000_spi_init(void) {
/*
// WLAN CS, EN and WALN IRQ Configuration
jshSetPinStateIsManual(WLAN_CS_PIN, MP_FALSE);
jshSetPinStateIsManual(WLAN_CS_PIN, false);
jshPinOutput(WLAN_CS_PIN, 1); // de-assert CS
jshSetPinStateIsManual(WLAN_EN_PIN, MP_FALSE);
jshSetPinStateIsManual(WLAN_EN_PIN, false);
jshPinOutput(WLAN_EN_PIN, 0); // disable WLAN
jshSetPinStateIsManual(WLAN_IRQ_PIN, MP_TRUE);
jshSetPinStateIsManual(WLAN_IRQ_PIN, true);
jshPinSetState(WLAN_IRQ_PIN, JSHPINSTATE_GPIO_IN_PULLUP); // flip into read mode with pullup
*/
// configure wlan CS and EN pins

View File

@ -20,9 +20,9 @@ typedef enum {
I2C_STATE_READ = 2,
} i2c_state_t;
// set to MP_TRUE if the port has already been initialized
MP_BOOL i2c1_port_initialized = MP_FALSE;
MP_BOOL i2c2_port_initialized = MP_FALSE;
// set to true if the port has already been initialized
bool i2c1_port_initialized = false;
bool i2c2_port_initialized = false;
static I2C_TypeDef * _i2c_port_addr(pyb_i2c_t i2c_port) {
if (i2c_port == PYB_I2C_1) {
@ -37,17 +37,17 @@ static I2C_TypeDef * _i2c_port_addr(pyb_i2c_t i2c_port) {
// todo - perhaps there should be some global resource management for gpio
// this function would fail if the i2c pins have already been defined for
// use by another python object
// as it is, this always returns MP_TRUE (unless i2c_port is invalid)
static MP_BOOL _i2c_init(pyb_i2c_t i2c_port) {
// as it is, this always returns true (unless i2c_port is invalid)
static bool _i2c_init(pyb_i2c_t i2c_port) {
GPIO_InitTypeDef GPIO_InitStructure;
I2C_TypeDef *i2c = _i2c_port_addr(i2c_port);
if (i2c == NULL)
return MP_FALSE;
return false;
if (i2c_port == PYB_I2C_1) {
if (i2c1_port_initialized == MP_TRUE) {
return MP_TRUE;
if (i2c1_port_initialized == true) {
return true;
}
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; // enable I2C1
@ -64,12 +64,12 @@ static MP_BOOL _i2c_init(pyb_i2c_t i2c_port) {
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1);
i2c1_port_initialized = MP_TRUE;
i2c1_port_initialized = true;
}
if (i2c_port == PYB_I2C_2) {
if (i2c2_port_initialized == MP_TRUE) {
return MP_TRUE;
if (i2c2_port_initialized == true) {
return true;
}
RCC->APB1ENR |= RCC_APB1ENR_I2C2EN; // enable I2C2
@ -85,7 +85,7 @@ static MP_BOOL _i2c_init(pyb_i2c_t i2c_port) {
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2);
i2c2_port_initialized = MP_TRUE;
i2c2_port_initialized = true;
}
// get clock speeds
@ -108,7 +108,7 @@ static MP_BOOL _i2c_init(pyb_i2c_t i2c_port) {
// enable the I2C peripheral
i2c->CR1 |= I2C_CR1_PE;
return MP_TRUE;
return true;
}
static uint32_t _i2c_get_sr(pyb_i2c_t i2c_port) {
@ -121,9 +121,9 @@ static uint32_t _i2c_get_sr(pyb_i2c_t i2c_port) {
return (sr2 << 16) | sr1;
}
static MP_BOOL _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) {
static bool _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) {
I2C_TypeDef *i2c = _i2c_port_addr(i2c_port);
if (i2c == NULL) return MP_FALSE;
if (i2c == NULL) return false;
// send start condition
i2c->CR1 |= I2C_CR1_START;
@ -133,7 +133,7 @@ static MP_BOOL _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) {
while ((_i2c_get_sr(i2c_port) & 0x00030001) != 0x00030001) {
if (--timeout == 0) {
//printf("timeout in _i2c_restart\n");
return MP_FALSE;
return false;
}
}
@ -145,7 +145,7 @@ static MP_BOOL _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) {
while ((_i2c_get_sr(i2c_port) & 0x00070082) != 0x00070082) {
if (--timeout == 0) {
//printf("timeout in _i2c_restart write\n");
return MP_FALSE;
return false;
}
}
} else {
@ -156,16 +156,16 @@ static MP_BOOL _i2c_restart(pyb_i2c_t i2c_port, uint8_t addr, int write) {
while ((_i2c_get_sr(i2c_port) & 0x00030002) != 0x00030002) {
if (--timeout == 0) {
//printf("timeout in _i2c_restart read\n");
return MP_FALSE;
return false;
}
}
}
return MP_TRUE;
return true;
}
static MP_BOOL _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) {
static bool _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) {
I2C_TypeDef *i2c = _i2c_port_addr(i2c_port);
if (i2c == NULL) return MP_FALSE;
if (i2c == NULL) return false;
// send byte
i2c->DR = data;
@ -174,10 +174,10 @@ static MP_BOOL _i2c_send_byte(pyb_i2c_t i2c_port, uint8_t data) {
while ((_i2c_get_sr(i2c_port) & 0x00070084) != 0x00070084) {
if (--timeout == 0) {
//printf("timeout in _i2c_send_byte\n");
return MP_FALSE;
return false;
}
}
return MP_TRUE;
return true;
}
static uint8_t _i2c_read_ack(pyb_i2c_t i2c_port) {
@ -220,18 +220,18 @@ static uint8_t _i2c_read_nack(pyb_i2c_t i2c_port) {
return data;
}
static MP_BOOL _i2c_start(pyb_i2c_t i2c_port) {
static bool _i2c_start(pyb_i2c_t i2c_port) {
I2C_TypeDef *i2c = _i2c_port_addr(i2c_port);
if (i2c == NULL) return MP_FALSE;
if (i2c == NULL) return false;
// wait until I2C is not busy
uint32_t timeout = 1000000;
while (i2c->SR2 & I2C_SR2_BUSY) {
if (--timeout == 0) {
return MP_FALSE;
return false;
}
}
return MP_TRUE;
return true;
}
static void _i2c_stop(pyb_i2c_t i2c_port) {
@ -264,7 +264,7 @@ mp_obj_t i2c_obj_start(mp_obj_t self_in) {
_i2c_stop(self->i2c_port);
self->i2c_state = I2C_STATE_IDLE;
}
if (_i2c_start(self->i2c_port) == MP_TRUE)
if (_i2c_start(self->i2c_port) == true)
return mp_const_true;
return mp_const_false;
}
@ -272,7 +272,7 @@ mp_obj_t i2c_obj_start(mp_obj_t self_in) {
mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) {
pyb_i2c_obj_t *self = self_in;
if (self->i2c_state != I2C_STATE_WRITE) {
if (_i2c_restart(self->i2c_port, self->i2c_addr, 1) == MP_FALSE) {
if (_i2c_restart(self->i2c_port, self->i2c_addr, 1) == false) {
_i2c_stop(self->i2c_port);
self->i2c_state = I2C_STATE_IDLE;
return mp_const_false;
@ -280,7 +280,7 @@ mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) {
self->i2c_state = I2C_STATE_WRITE;
}
uint8_t data = mp_obj_get_int(data_in);
if (_i2c_send_byte(self->i2c_port, data) == MP_FALSE)
if (_i2c_send_byte(self->i2c_port, data) == false)
return mp_const_false;
return mp_const_true;
}
@ -288,7 +288,7 @@ mp_obj_t i2c_obj_write(mp_obj_t self_in, mp_obj_t data_in) {
mp_obj_t i2c_obj_read(mp_obj_t self_in) {
pyb_i2c_obj_t *self = self_in;
if (self->i2c_state != I2C_STATE_READ) {
if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == MP_FALSE) {
if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == false) {
_i2c_stop(self->i2c_port);
self->i2c_state = I2C_STATE_IDLE;
return mp_const_false;
@ -302,7 +302,7 @@ mp_obj_t i2c_obj_read(mp_obj_t self_in) {
mp_obj_t i2c_obj_readAndStop(mp_obj_t self_in) {
pyb_i2c_obj_t *self = self_in;
if (self->i2c_state != I2C_STATE_READ) {
if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == MP_FALSE) {
if (_i2c_restart(self->i2c_port, self->i2c_addr, 0) == false) {
_i2c_stop(self->i2c_port);
self->i2c_state = I2C_STATE_IDLE;
return mp_const_false;
@ -326,19 +326,18 @@ static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_read_obj, i2c_obj_read);
static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_readAndStop_obj, i2c_obj_readAndStop);
static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_stop_obj, i2c_obj_stop);
static const mp_method_t i2c_obj_type_type_methods[] = {
{ "start", &i2c_obj_start_obj },
{ "write", &i2c_obj_write_obj },
{ "read", &i2c_obj_read_obj },
{ "readAndStop", &i2c_obj_readAndStop_obj },
{ "stop", &i2c_obj_stop_obj },
{ NULL, NULL },
};
static const mp_obj_type_t i2c_obj_type = {
{ &mp_const_type },
"I2C",
.print = i2c_obj_print,
.methods = i2c_obj_type_type_methods,
.methods = {
{ "start", &i2c_obj_start_obj },
{ "write", &i2c_obj_write_obj },
{ "read", &i2c_obj_read_obj },
{ "readAndStop", &i2c_obj_readAndStop_obj },
{ "stop", &i2c_obj_stop_obj },
{ NULL, NULL },
}
};
// create the I2C object
@ -351,7 +350,7 @@ mp_obj_t pyb_I2C(mp_obj_t i2c_id, mp_obj_t i2c_addr) {
case 1: i2c_port = PYB_I2C_2; break;
default: return mp_const_none;
}
if (_i2c_init(i2c_port) == MP_FALSE) {
if (_i2c_init(i2c_port) == false) {
return mp_const_none;
}
pyb_i2c_obj_t *o = m_new_obj(pyb_i2c_obj_t);

View File

@ -176,16 +176,15 @@ mp_obj_t led_obj_off(mp_obj_t self_in) {
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_on_obj, led_obj_on);
static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
static const mp_method_t led_obj_type_methods[] = {
{ "on", &led_obj_on_obj },
{ "off", &led_obj_off_obj },
{ NULL, NULL },
};
static const mp_obj_type_t led_obj_type = {
{ &mp_const_type },
"Led",
.print = led_obj_print,
.methods = led_obj_type_methods,
.methods = {
{ "on", &led_obj_on_obj },
{ "off", &led_obj_off_obj },
{ NULL, NULL },
}
};
mp_obj_t pyb_Led(mp_obj_t led_id) {

View File

@ -21,7 +21,7 @@ void str_buf_free(mp_lexer_str_buf_t *sb) {
}
}
mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str, mp_lexer_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_str_buf_t *sb) {
sb->free = free_str;
sb->src_beg = str;
sb->src_cur = str;

View File

@ -1,5 +1,5 @@
typedef struct _py_lexer_str_buf_t {
MP_BOOL free; // free src_beg when done
bool free; // free src_beg when done
const char *src_beg; // beginning of source
const char *src_cur; // current location in source
const char *src_end; // end (exclusive) of source
@ -12,5 +12,5 @@ typedef struct _py_lexer_file_buf_t {
uint16_t pos;
} mp_lexer_file_buf_t;
mp_lexer_t *mp_lexer_new_from_str_len(const char *src_name, const char *str, uint len, MP_BOOL free_str, mp_lexer_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_str_buf_t *sb);
mp_lexer_t *mp_lexer_new_from_file(const char *filename, mp_lexer_file_buf_t *fb);

View File

@ -359,7 +359,7 @@ int readline(vstr_t *line, const char *prompt) {
readline_hist[0] = strdup(vstr_str(line));
return 1;
} else if (c == 27) {
escape = MP_TRUE;
escape = true;
} else if (c == 127) {
if (vstr_len(line) > len) {
vstr_cut_tail(line, 1);
@ -432,12 +432,12 @@ void do_repl(void) {
}
mp_lexer_str_buf_t sb;
mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", vstr_str(&line), vstr_len(&line), MP_FALSE, &sb);
mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", vstr_str(&line), vstr_len(&line), false, &sb);
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT);
mp_lexer_free(lex);
if (pn != MP_PARSE_NODE_NULL) {
mp_obj_t module_fun = mp_compile(pn, MP_TRUE);
mp_obj_t module_fun = mp_compile(pn, true);
if (module_fun != mp_const_none) {
nlr_buf_t nlr;
uint32_t start = sys_tick_counter;
@ -461,37 +461,37 @@ void do_repl(void) {
stdout_tx_str("\r\n");
}
MP_BOOL do_file(const char *filename) {
bool do_file(const char *filename) {
mp_lexer_file_buf_t fb;
mp_lexer_t *lex = mp_lexer_new_from_file(filename, &fb);
if (lex == NULL) {
printf("could not open file '%s' for reading\n", filename);
return MP_FALSE;
return false;
}
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_FILE_INPUT);
mp_lexer_free(lex);
if (pn == MP_PARSE_NODE_NULL) {
return MP_FALSE;
return false;
}
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) {
return MP_FALSE;
return false;
}
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
rt_call_function_0(module_fun);
nlr_pop();
return MP_TRUE;
return true;
} else {
// uncaught exception
mp_obj_print((mp_obj_t)nlr.ret_val);
printf("\n");
return MP_FALSE;
return false;
}
}
@ -689,12 +689,6 @@ static MP_DEFINE_CONST_FUN_OBJ_1(file_obj_close_obj, file_obj_close);
// TODO gc hook to close the file if not already closed
static const mp_method_t file_obj_type_methods[] = {
{ "read", &file_obj_read_obj },
{ "write", &file_obj_write_obj },
{ "close", &file_obj_close_obj },
{ NULL, NULL },
};
static const mp_obj_type_t file_obj_type = {
{ &mp_const_type },
"File",
@ -705,7 +699,12 @@ static const mp_obj_type_t file_obj_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
.methods = file_obj_type_methods,
.methods = {
{ "read", &file_obj_read_obj },
{ "write", &file_obj_write_obj },
{ "close", &file_obj_close_obj },
{NULL, NULL},
}
};
mp_obj_t pyb_io_open(mp_obj_t o_filename, mp_obj_t o_mode) {
@ -779,7 +778,7 @@ int main(void) {
//usart_init(); disabled while wi-fi is enabled
int first_soft_reset = MP_TRUE;
int first_soft_reset = true;
soft_reset:
@ -848,12 +847,12 @@ soft_reset:
lcd_print_str(" micro py board\n");
// check if user switch held (initiates reset of filesystem)
MP_BOOL reset_filesystem = MP_FALSE;
bool reset_filesystem = false;
if (switch_get()) {
reset_filesystem = MP_TRUE;
reset_filesystem = true;
for (int i = 0; i < 50; i++) {
if (!switch_get()) {
reset_filesystem = MP_FALSE;
reset_filesystem = false;
break;
}
sys_tick_delay_ms(10);
@ -1064,7 +1063,7 @@ soft_reset:
"f()\n";
mp_lexer_str_buf_t mp_lexer_str_buf;
mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", pysrc, strlen(pysrc), MP_FALSE, &mp_lexer_str_buf);
mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", pysrc, strlen(pysrc), false, &mp_lexer_str_buf);
// nalloc=1740;6340;6836 -> 140;4600;496 bytes for lexer, parser, compiler
printf("lex; al=%u\n", m_get_total_bytes_allocated());
@ -1075,7 +1074,7 @@ soft_reset:
printf("pars;al=%u\n", m_get_total_bytes_allocated());
sys_tick_delay_ms(1000);
//parse_node_show(pn, 0);
mp_obj_t module_fun = mp_compile(pn, MP_FALSE);
mp_obj_t module_fun = mp_compile(pn, false);
printf("comp;al=%u\n", m_get_total_bytes_allocated());
sys_tick_delay_ms(1000);
@ -1172,7 +1171,7 @@ soft_reset:
printf("PYB: soft reboot\n");
first_soft_reset = MP_FALSE;
first_soft_reset = false;
goto soft_reset;
}

View File

@ -152,10 +152,10 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
}
// parse long specifiers (current not used)
//MP_BOOL long_arg = MP_FALSE;
//bool long_arg = false;
if (*fmt == 'l') {
++fmt;
//long_arg = MP_TRUE;
//long_arg = true;
}
if (*fmt == '\0') {
@ -215,14 +215,14 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
void stdout_print_strn(void *data, const char *str, unsigned int len) {
// send stdout to USART, USB CDC VCP, and LCD if nothing else
MP_BOOL any = MP_FALSE;
bool any = false;
if (usart_is_enabled()) {
usart_tx_strn_cooked(str, len);
any = MP_TRUE;
any = true;
}
if (usb_vcp_is_enabled()) {
usb_vcp_send_strn_cooked(str, len);
any = MP_TRUE;
any = true;
}
if (!any) {
lcd_print_strn(str, len);

View File

@ -336,7 +336,7 @@ void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length)
socketnum = data[0];
//PRINT_F("TCP Close wait #"); printDec(socketnum);
if (socketnum < MAX_SOCKETS)
closed_sockets[socketnum] = MP_TRUE;
closed_sockets[socketnum] = true;
*/
}
}

View File

@ -137,15 +137,14 @@ static mp_obj_t servo_obj_angle(mp_obj_t self_in, mp_obj_t angle) {
static MP_DEFINE_CONST_FUN_OBJ_2(servo_obj_angle_obj, servo_obj_angle);
static const mp_method_t servo_obj_type_methods[] = {
{ "angle", &servo_obj_angle_obj },
{ NULL, NULL },
};
static const mp_obj_type_t servo_obj_type = {
{ &mp_const_type },
"Servo",
.print = servo_obj_print,
.methods = servo_obj_type_methods,
.methods = {
{ "angle", &servo_obj_angle_obj },
{ NULL, NULL },
}
};
mp_obj_t pyb_Servo(mp_obj_t servo_id) {

View File

@ -15,18 +15,18 @@
#define FLASH_PART1_NUM_BLOCKS (224) // 16k+16k+16k+64k=112k
#define FLASH_MEM_START_ADDR (0x08004000) // sector 1, 16k
static MP_BOOL is_initialised = MP_FALSE;
static bool is_initialised = false;
static uint32_t cache_flash_sector_id;
static uint32_t cache_flash_sector_start;
static uint32_t cache_flash_sector_size;
static MP_BOOL cache_dirty;
static bool cache_dirty;
static uint32_t sys_tick_counter_last_write;
static void cache_flush(void) {
if (cache_dirty) {
// sync the cache RAM buffer by writing it to the flash page
flash_write(cache_flash_sector_start, (const uint32_t*)CACHE_MEM_START_ADDR, cache_flash_sector_size / 4);
cache_dirty = MP_FALSE;
cache_dirty = false;
// indicate a clean cache with LED off
led_state(PYB_LED_R1, 0);
}
@ -43,7 +43,7 @@ static uint8_t *cache_get_addr_for_write(uint32_t flash_addr) {
cache_flash_sector_start = flash_sector_start;
cache_flash_sector_size = flash_sector_size;
}
cache_dirty = MP_TRUE;
cache_dirty = true;
// indicate a dirty cache with LED on
led_state(PYB_LED_R1, 1);
return (uint8_t*)CACHE_MEM_START_ADDR + flash_addr - flash_sector_start;
@ -64,8 +64,8 @@ static uint8_t *cache_get_addr_for_read(uint32_t flash_addr) {
void storage_init(void) {
if (!is_initialised) {
cache_flash_sector_id = 0;
cache_dirty = MP_FALSE;
is_initialised = MP_TRUE;
cache_dirty = false;
is_initialised = true;
sys_tick_counter_last_write = 0;
}
}
@ -78,7 +78,7 @@ uint32_t storage_get_block_count(void) {
return FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS;
}
MP_BOOL storage_needs_flush(void) {
bool storage_needs_flush(void) {
// wait 2 seconds after last write to flush
return cache_dirty && sys_tick_has_passed(sys_tick_counter_last_write, 2000);
}
@ -123,7 +123,7 @@ static void build_partition(uint8_t *buf, int boot, int type, uint32_t start_blo
buf[15] = num_blocks >> 24;
}
MP_BOOL storage_read_block(uint8_t *dest, uint32_t block) {
bool storage_read_block(uint8_t *dest, uint32_t block) {
//printf("RD %u\n", block);
if (block == 0) {
// fake the MBR so we can decide on our own partition table
@ -140,26 +140,26 @@ MP_BOOL storage_read_block(uint8_t *dest, uint32_t block) {
dest[510] = 0x55;
dest[511] = 0xaa;
return MP_TRUE;
return true;
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) {
// non-MBR block, get data from flash memory, possibly via cache
uint32_t flash_addr = FLASH_MEM_START_ADDR + (block - FLASH_PART1_START_BLOCK) * BLOCK_SIZE;
uint8_t *src = cache_get_addr_for_read(flash_addr);
memcpy(dest, src, BLOCK_SIZE);
return MP_TRUE;
return true;
} else {
// bad block number
return MP_FALSE;
return false;
}
}
MP_BOOL storage_write_block(const uint8_t *src, uint32_t block) {
bool storage_write_block(const uint8_t *src, uint32_t block) {
//printf("WR %u\n", block);
if (block == 0) {
// can't write MBR, but pretend we did
return MP_TRUE;
return true;
} else if (FLASH_PART1_START_BLOCK <= block && block < FLASH_PART1_START_BLOCK + FLASH_PART1_NUM_BLOCKS) {
// non-MBR block, copy to cache
@ -167,10 +167,10 @@ MP_BOOL storage_write_block(const uint8_t *src, uint32_t block) {
uint8_t *dest = cache_get_addr_for_write(flash_addr);
memcpy(dest, src, BLOCK_SIZE);
sys_tick_counter_last_write = sys_tick_counter;
return MP_TRUE;
return true;
} else {
// bad block number
return MP_FALSE;
return false;
}
}

View File

@ -1,7 +1,7 @@
void storage_init(void);
uint32_t storage_get_block_size(void);
uint32_t storage_get_block_count(void);
MP_BOOL storage_needs_flush(void);
bool storage_needs_flush(void);
void storage_flush(void);
MP_BOOL storage_read_block(uint8_t *dest, uint32_t block);
MP_BOOL storage_write_block(const uint8_t *src, uint32_t block);
bool storage_read_block(uint8_t *dest, uint32_t block);
bool storage_write_block(const uint8_t *src, uint32_t block);

View File

@ -43,7 +43,7 @@ void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms) {
}
}
MP_BOOL sys_tick_has_passed(uint32_t stc, uint32_t delay_ms) {
bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms) {
// stc_wait is the value of sys_tick_counter that we wait for
uint32_t stc_wait = stc + delay_ms;
if (stc_wait < stc) {

View File

@ -4,4 +4,4 @@ void sys_tick_init(void);
void SysTick_Handler(void);
void sys_tick_delay_ms(uint32_t delay_ms);
void sys_tick_wait_at_least(uint32_t stc, uint32_t delay_ms);
MP_BOOL sys_tick_has_passed(uint32_t stc, uint32_t delay_ms);
bool sys_tick_has_passed(uint32_t stc, uint32_t delay_ms);

View File

@ -5,7 +5,7 @@
#include "misc.h"
#include "usart.h"
static MP_BOOL is_enabled;
static bool is_enabled;
// USART6 on PC6 (TX), PC7 (RX)
void usart_init(void) {
@ -33,14 +33,14 @@ void usart_init(void) {
USART_Cmd(USART6, ENABLE);
is_enabled = MP_TRUE;
is_enabled = true;
}
MP_BOOL usart_is_enabled(void) {
bool usart_is_enabled(void) {
return is_enabled;
}
MP_BOOL usart_rx_any(void) {
bool usart_rx_any(void) {
return USART_GetFlagStatus(USART6, USART_FLAG_RXNE) == SET;
}

View File

@ -1,6 +1,6 @@
void usart_init(void);
MP_BOOL usart_is_enabled(void);
MP_BOOL usart_rx_any(void);
bool usart_is_enabled(void);
bool usart_rx_any(void);
int usart_rx_char(void);
void usart_tx_char(int c);
void usart_tx_str(const char *str);

View File

@ -30,7 +30,7 @@ void usb_init(void) {
is_enabled = 1;
}
MP_BOOL usb_vcp_is_enabled(void) {
bool usb_vcp_is_enabled(void) {
return is_enabled;
}

View File

@ -1,5 +1,5 @@
void usb_init(void);
MP_BOOL usb_vcp_is_enabled(void);
bool usb_vcp_is_enabled(void);
int usb_vcp_rx_any(void);
char usb_vcp_rx_get(void);
void usb_vcp_send_str(const char* str);

View File

@ -37,7 +37,7 @@ void do_file(const char *file) {
//printf("----------------\n");
//parse_node_show(pn, 0);
//printf("----------------\n");
mp_obj_t module_fun = mp_compile(pn, MP_FALSE);
mp_obj_t module_fun = mp_compile(pn, false);
//printf("----------------\n");
if (module_fun == mp_const_none) {

View File

@ -79,13 +79,13 @@ static void do_repl(void) {
}
}
mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", line, strlen(line), MP_FALSE);
mp_lexer_t *lex = mp_lexer_new_from_str_len("<stdin>", line, strlen(line), false);
mp_parse_node_t pn = mp_parse(lex, MP_PARSE_SINGLE_INPUT);
mp_lexer_free(lex);
if (pn != MP_PARSE_NODE_NULL) {
//mp_parse_node_show(pn, 0);
mp_obj_t module_fun = mp_compile(pn, MP_TRUE);
mp_obj_t module_fun = mp_compile(pn, true);
if (module_fun != mp_const_none) {
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
@ -139,7 +139,7 @@ void do_file(const char *file) {
//printf("----------------\n");
//parse_node_show(pn, 0);
//printf("----------------\n");
mp_obj_t module_fun = mp_compile(pn, MP_FALSE);
mp_obj_t module_fun = mp_compile(pn, false);
//printf("----------------\n");
#if MICROPY_EMIT_CPYTHON
@ -166,7 +166,7 @@ void do_file(const char *file) {
typedef struct _test_obj_t {
mp_obj_base_t base;
MP_BOOL value;
bool value;
} test_obj_t;
static void test_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) {