Skip to content

Commit 97209d3

Browse files
committed
Merge branch 'cplusplus' of https://github.com/ian-v/micropython into ian-v-cplusplus
Conflicts: py/objcomplex.c
2 parents d49420e + a5a01df commit 97209d3

30 files changed

Lines changed: 117 additions & 244 deletions

py/misc.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55

66
/** types *******************************************************/
77

8-
typedef int bool;
9-
enum {
10-
false = 0,
11-
true = 1
12-
};
8+
#include <stdbool.h>
139

1410
typedef unsigned char byte;
1511
typedef unsigned int uint;

py/obj.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ typedef machine_int_t mp_small_int_t;
1515
typedef machine_float_t mp_float_t;
1616
#endif
1717

18-
// Anything that wants to be a Micro Python object must
19-
// have mp_obj_base_t as its first member (except NULL and small ints)
20-
21-
typedef struct _mp_obj_base_t mp_obj_base_t;
22-
typedef struct _mp_obj_type_t mp_obj_type_t;
18+
// Anything that wants to be a Micro Python object must have
19+
// mp_obj_base_t as its first member (except NULL and small ints)
2320

21+
struct _mp_obj_type_t;
2422
struct _mp_obj_base_t {
25-
const mp_obj_type_t *type;
23+
const struct _mp_obj_type_t *type;
2624
};
25+
typedef struct _mp_obj_base_t mp_obj_base_t;
2726

2827
// The NULL object is used to indicate the absence of an object
2928
// It *cannot* be used when an mp_obj_t is expected, except where explicitly allowed
@@ -43,12 +42,13 @@ struct _mp_obj_base_t {
4342

4443
#define MP_DECLARE_CONST_FUN_OBJ(obj_name) extern const mp_obj_fun_native_t obj_name
4544

46-
#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 0, 0, fun_name}
47-
#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 1, 1, fun_name}
48-
#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 2, 2, fun_name}
49-
#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, 3, 3, fun_name}
50-
#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, n_args_min, (~((machine_uint_t)0)), fun_name}
51-
#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, n_args_min, n_args_max, fun_name}
45+
#define MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, n_args_min, n_args_max, (void *)fun_name}
46+
#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, 0, 0, (mp_fun_0_t)fun_name)
47+
#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, 1, 1, (mp_fun_1_t)fun_name)
48+
#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, 2, 2, (mp_fun_2_t)fun_name)
49+
#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, 3, 3, (mp_fun_3_t)fun_name)
50+
#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, n_args_min, (~((machine_uint_t)0)), (mp_fun_var_t)fun_name)
51+
#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, n_args_min, n_args_max, (mp_fun_var_t)fun_name)
5252

5353
// Type definitions for methods
5454

@@ -83,7 +83,7 @@ struct _mp_obj_type_t {
8383
mp_fun_1_t getiter;
8484
mp_fun_1_t iternext;
8585

86-
const mp_method_t methods[];
86+
const mp_method_t *methods;
8787

8888
/*
8989
What we might need to add here:
@@ -108,6 +108,8 @@ struct _mp_obj_type_t {
108108
*/
109109
};
110110

111+
typedef struct _mp_obj_type_t mp_obj_type_t;
112+
111113
// Constant objects, globally accessible
112114

113115
extern const mp_obj_type_t mp_const_type;
@@ -241,6 +243,7 @@ typedef struct _mp_obj_fun_native_t { // need this so we can define const object
241243
// for const function objects, make an empty, const map
242244
// such functions won't be able to access the global scope, but that's probably okay
243245
} mp_obj_fun_native_t;
246+
244247
extern const mp_obj_type_t fun_native_type;
245248
extern const mp_obj_type_t fun_bc_type;
246249
void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, uint *n_state, const byte **code);

py/objbool.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,8 @@ static mp_obj_t bool_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args
3434
const mp_obj_type_t bool_type = {
3535
{ &mp_const_type },
3636
"bool",
37-
bool_print, // print
38-
bool_make_new, // make_new
39-
NULL, // call_n
40-
NULL, // unary_op
41-
NULL, // binary_op
42-
NULL, // getiter
43-
NULL, // iternext
44-
.methods = {{NULL, NULL},},
37+
.print = bool_print,
38+
.make_new = bool_make_new,
4539
};
4640

4741
static const mp_obj_bool_t false_obj = {{&bool_type}, false};

py/objboundmeth.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,7 @@ mp_obj_t bound_meth_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) {
3636
const mp_obj_type_t bound_meth_type = {
3737
{ &mp_const_type },
3838
"bound_method",
39-
NULL, // print
40-
NULL, // make_new
41-
bound_meth_call_n, // call_n
42-
NULL, // unary_op
43-
NULL, // binary_op
44-
NULL, // getiter
45-
NULL, // iternext
46-
.methods = {{NULL, NULL},},
39+
.call_n = bound_meth_call_n,
4740
};
4841

4942
mp_obj_t mp_obj_new_bound_meth(mp_obj_t self, mp_obj_t meth) {

py/objcell.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj) {
2626
const mp_obj_type_t cell_type = {
2727
{ &mp_const_type },
2828
"cell",
29-
NULL, // print
30-
NULL, // make_new
31-
NULL, // call_n
32-
NULL, // unary_op
33-
NULL, // binary_op
34-
NULL, // getiter
35-
NULL, // iternext
36-
.methods = {{NULL, NULL},},
3729
};
3830

3931
mp_obj_t mp_obj_new_cell(mp_obj_t obj) {

py/objclass.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,7 @@ mp_map_t *mp_obj_class_get_locals(mp_obj_t self_in) {
6363
const mp_obj_type_t class_type = {
6464
{ &mp_const_type },
6565
"class",
66-
NULL, // print
67-
NULL, // make_new
68-
class_call_n, // call_n
69-
NULL, // unary_op
70-
NULL, // binary_op
71-
NULL, // getiter
72-
NULL, // iternext
73-
.methods = {{NULL, NULL},},
66+
.call_n = class_call_n,
7467
};
7568

7669
mp_obj_t mp_obj_new_class(mp_map_t *class_locals) {

py/objclosure.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,7 @@ mp_obj_t closure_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args) {
3535
const mp_obj_type_t closure_type = {
3636
{ &mp_const_type },
3737
"closure",
38-
NULL, // print
39-
NULL, // make_new
40-
closure_call_n, // call_n
41-
NULL, // unary_op
42-
NULL, // binary_op
43-
NULL, // getiter
44-
NULL, // iternext
45-
.methods = {{NULL, NULL},},
38+
.call_n = closure_call_n,
4639
};
4740

4841
mp_obj_t mp_obj_new_closure(mp_obj_t fun, mp_obj_t closure_tuple) {

py/objcomplex.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,10 @@ static mp_obj_t complex_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
8787
const mp_obj_type_t complex_type = {
8888
{ &mp_const_type },
8989
"complex",
90-
complex_print, // print
91-
complex_make_new, // make_new
92-
NULL, // call_n
93-
complex_unary_op, // unary_op
94-
complex_binary_op, // binary_op
95-
NULL, // getiter
96-
NULL, // iternext
97-
.methods = { { NULL, NULL }, },
90+
.print = complex_print,
91+
.make_new = complex_make_new,
92+
.unary_op = complex_unary_op,
93+
.binary_op = complex_binary_op,
9894
};
9995

10096
mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) {

py/objdict.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ const mp_obj_type_t dict_type = {
6666
.print = dict_print,
6767
.make_new = dict_make_new,
6868
.binary_op = dict_binary_op,
69-
.getiter = NULL,
70-
.methods = {{NULL, NULL},},
7169
};
7270

7371
mp_obj_t mp_obj_new_dict(int n_args) {

py/objexcept.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ void exception_print(void (*print)(void *env, const char *fmt, ...), void *env,
3838
const mp_obj_type_t exception_type = {
3939
{ &mp_const_type },
4040
"exception",
41-
exception_print, // print
42-
NULL, // make_new
43-
NULL, // call_n
44-
NULL, // unary_op
45-
NULL, // binary_op
46-
NULL, // getiter
47-
NULL, // iternext
48-
.methods = {{NULL, NULL},},
41+
.print = exception_print,
4942
};
5043

5144
mp_obj_t mp_obj_new_exception(qstr id) {

0 commit comments

Comments
 (0)