Skip to content

Commit 5104775

Browse files
committed
py: Take out bitfield entries from their own structure.
Don't need to wrap bitfields in their own struct. Compiler does the correct thing without it.
1 parent 98fb893 commit 5104775

7 files changed

Lines changed: 22 additions & 38 deletions

File tree

py/map.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ typedef struct _mp_map_elem_t {
44
} mp_map_elem_t;
55

66
typedef struct _mp_map_t {
7-
struct {
8-
machine_uint_t all_keys_are_qstrs : 1;
9-
machine_uint_t table_is_fixed_array : 1;
10-
machine_uint_t used : (8 * sizeof(machine_uint_t) - 2);
11-
};
7+
machine_uint_t all_keys_are_qstrs : 1;
8+
machine_uint_t table_is_fixed_array : 1;
9+
machine_uint_t used : (8 * sizeof(machine_uint_t) - 2);
1210
machine_uint_t alloc;
1311
mp_map_elem_t *table;
1412
} mp_map_t;

py/misc.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ typedef struct _vstr_t {
6666
int alloc;
6767
int len;
6868
char *buf;
69-
struct {
70-
bool had_error : 1;
71-
bool fixed_buf : 1;
72-
};
69+
bool had_error : 1;
70+
bool fixed_buf : 1;
7371
} vstr_t;
7472

7573
// convenience macro to declare a vstr with a fixed size buffer on the stack

py/mpz.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ typedef uint32_t mpz_dbl_dig_t;
33
typedef int32_t mpz_dbl_dig_signed_t;
44

55
typedef struct _mpz_t {
6-
struct {
7-
machine_uint_t neg : 1;
8-
machine_uint_t alloc : 31;
9-
};
6+
machine_uint_t neg : 1;
7+
machine_uint_t alloc : 31;
108
machine_uint_t len;
119
mpz_dig_t *dig;
1210
} mpz_t;

py/obj.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
5454

5555
#define MP_DECLARE_CONST_FUN_OBJ(obj_name) extern const mp_obj_fun_native_t obj_name
5656

57-
#define MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, is_kw, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, {is_kw, n_args_min}, n_args_max, (void *)fun_name}
57+
#define MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, is_kw, n_args_min, n_args_max, fun_name) const mp_obj_fun_native_t obj_name = {{&fun_native_type}, is_kw, n_args_min, n_args_max, (void *)fun_name}
5858
#define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 0, 0, (mp_fun_0_t)fun_name)
5959
#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 1, 1, (mp_fun_1_t)fun_name)
6060
#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 2, 2, (mp_fun_2_t)fun_name)
@@ -374,10 +374,8 @@ mp_obj_t mp_obj_new_bytearray_by_ref(uint n, void *items);
374374
// functions
375375
typedef struct _mp_obj_fun_native_t { // need this so we can define const objects (to go in ROM)
376376
mp_obj_base_t base;
377-
struct {
378-
bool is_kw : 1;
379-
machine_uint_t n_args_min : (8 * sizeof(machine_uint_t) - 1); // inclusive
380-
};
377+
bool is_kw : 1;
378+
machine_uint_t n_args_min : (8 * sizeof(machine_uint_t) - 1); // inclusive
381379
machine_uint_t n_args_max; // inclusive
382380
void *fun;
383381
// TODO add mp_map_t *globals

py/objarray.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616

1717
typedef struct _mp_obj_array_t {
1818
mp_obj_base_t base;
19-
struct {
20-
machine_uint_t typecode : 8;
21-
// free is number of unused elements after len used elements
22-
// alloc size = len + free
23-
machine_uint_t free : (8 * sizeof(machine_uint_t) - 8);
24-
};
19+
machine_uint_t typecode : 8;
20+
// free is number of unused elements after len used elements
21+
// alloc size = len + free
22+
machine_uint_t free : (8 * sizeof(machine_uint_t) - 8);
2523
machine_uint_t len; // in elements
2624
void *items;
2725
} mp_obj_array_t;

py/objfun.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,10 @@ mp_obj_t rt_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var
143143
typedef struct _mp_obj_fun_bc_t {
144144
mp_obj_base_t base;
145145
mp_map_t *globals; // the context within which this function was defined
146-
struct {
147-
machine_uint_t n_args : 15; // number of arguments this function takes
148-
machine_uint_t n_def_args : 15; // number of default arguments
149-
machine_uint_t takes_var_args : 1; // set if this function takes variable args
150-
machine_uint_t takes_kw_args : 1; // set if this function takes keyword args
151-
};
146+
machine_uint_t n_args : 15; // number of arguments this function takes
147+
machine_uint_t n_def_args : 15; // number of default arguments
148+
machine_uint_t takes_var_args : 1; // set if this function takes variable args
149+
machine_uint_t takes_kw_args : 1; // set if this function takes keyword args
152150
uint n_state; // total state size for the executing function (incl args, locals, stack)
153151
const byte *bytecode; // bytecode for the function
154152
qstr *args; // argument names (needed to resolve positional args passed as keywords)

py/runtime.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ typedef enum {
4545
} mp_code_kind_t;
4646

4747
typedef struct _mp_code_t {
48-
struct {
49-
mp_code_kind_t kind : 8;
50-
uint scope_flags : 8;
51-
};
52-
struct {
53-
uint n_args : 16;
54-
uint n_state : 16;
55-
};
48+
mp_code_kind_t kind : 8;
49+
uint scope_flags : 8;
50+
uint n_args : 16;
51+
uint n_state : 16;
5652
union {
5753
struct {
5854
byte *code;

0 commit comments

Comments
 (0)