Skip to content

Commit 2300537

Browse files
committed
Cleanup built-ins, and fix some compiler warnings/errors.
1 parent 3f5e1b3 commit 2300537

8 files changed

Lines changed: 101 additions & 65 deletions

File tree

py/builtin.c

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// args[0] is function from class body
1919
// args[1] is class name
2020
// args[2:] are base objects
21-
mp_obj_t mp_builtin___build_class__(int n_args, const mp_obj_t *args) {
21+
static mp_obj_t mp_builtin___build_class__(int n_args, const mp_obj_t *args) {
2222
assert(2 <= n_args);
2323

2424
// we differ from CPython: we set the new __locals__ object here
@@ -62,14 +62,16 @@ mp_obj_t mp_builtin___build_class__(int n_args, const mp_obj_t *args) {
6262

6363
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__);
6464

65-
mp_obj_t mp_builtin___repl_print__(mp_obj_t o) {
65+
static mp_obj_t mp_builtin___repl_print__(mp_obj_t o) {
6666
if (o != mp_const_none) {
6767
mp_obj_print(o);
6868
printf("\n");
6969
}
7070
return mp_const_none;
7171
}
7272

73+
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin___repl_print___obj, mp_builtin___repl_print__);
74+
7375
mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
7476
if (MP_OBJ_IS_SMALL_INT(o_in)) {
7577
mp_small_int_t val = MP_OBJ_SMALL_INT_VALUE(o_in);
@@ -97,7 +99,9 @@ mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
9799
}
98100
}
99101

100-
mp_obj_t mp_builtin_all(mp_obj_t o_in) {
102+
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs);
103+
104+
static mp_obj_t mp_builtin_all(mp_obj_t o_in) {
101105
mp_obj_t iterable = rt_getiter(o_in);
102106
mp_obj_t item;
103107
while ((item = rt_iternext(iterable)) != mp_const_stop_iteration) {
@@ -108,7 +112,9 @@ mp_obj_t mp_builtin_all(mp_obj_t o_in) {
108112
return mp_const_true;
109113
}
110114

111-
mp_obj_t mp_builtin_any(mp_obj_t o_in) {
115+
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_all_obj, mp_builtin_all);
116+
117+
static mp_obj_t mp_builtin_any(mp_obj_t o_in) {
112118
mp_obj_t iterable = rt_getiter(o_in);
113119
mp_obj_t item;
114120
while ((item = rt_iternext(iterable)) != mp_const_stop_iteration) {
@@ -119,15 +125,19 @@ mp_obj_t mp_builtin_any(mp_obj_t o_in) {
119125
return mp_const_false;
120126
}
121127

122-
mp_obj_t mp_builtin_callable(mp_obj_t o_in) {
128+
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_any_obj, mp_builtin_any);
129+
130+
static mp_obj_t mp_builtin_callable(mp_obj_t o_in) {
123131
if (mp_obj_is_callable(o_in)) {
124132
return mp_const_true;
125133
} else {
126134
return mp_const_false;
127135
}
128136
}
129137

130-
mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
138+
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable);
139+
140+
static mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
131141
int ord = mp_obj_get_int(o_in);
132142
if (0 <= ord && ord <= 0x10ffff) {
133143
char *str = m_new(char, 2);
@@ -139,7 +149,9 @@ mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
139149
}
140150
}
141151

142-
mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) {
152+
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_chr_obj, mp_builtin_chr);
153+
154+
static mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) {
143155
if (MP_OBJ_IS_SMALL_INT(o1_in) && MP_OBJ_IS_SMALL_INT(o2_in)) {
144156
mp_small_int_t i1 = MP_OBJ_SMALL_INT_VALUE(o1_in);
145157
mp_small_int_t i2 = MP_OBJ_SMALL_INT_VALUE(o2_in);
@@ -152,6 +164,8 @@ mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) {
152164
}
153165
}
154166

167+
MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_divmod_obj, mp_builtin_divmod);
168+
155169
static mp_obj_t mp_builtin_hash(mp_obj_t o_in) {
156170
// TODO hash will generally overflow small integer; can we safely truncate it?
157171
return mp_obj_new_int(mp_obj_hash(o_in));
@@ -165,7 +179,7 @@ static mp_obj_t mp_builtin_iter(mp_obj_t o_in) {
165179

166180
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter);
167181

168-
mp_obj_t mp_builtin_len(mp_obj_t o_in) {
182+
static mp_obj_t mp_builtin_len(mp_obj_t o_in) {
169183
mp_obj_t len = mp_obj_len_maybe(o_in);
170184
if (len == NULL) {
171185
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "object of type '%s' has no len()", mp_obj_get_type_str(o_in)));
@@ -174,7 +188,9 @@ mp_obj_t mp_builtin_len(mp_obj_t o_in) {
174188
}
175189
}
176190

177-
mp_obj_t mp_builtin_max(int n_args, const mp_obj_t *args) {
191+
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_len_obj, mp_builtin_len);
192+
193+
static mp_obj_t mp_builtin_max(int n_args, const mp_obj_t *args) {
178194
if (n_args == 1) {
179195
// given an iterable
180196
mp_obj_t iterable = rt_getiter(args[0]);
@@ -201,7 +217,9 @@ mp_obj_t mp_builtin_max(int n_args, const mp_obj_t *args) {
201217
}
202218
}
203219

204-
mp_obj_t mp_builtin_min(int n_args, const mp_obj_t *args) {
220+
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin_max_obj, 1, mp_builtin_max);
221+
222+
static mp_obj_t mp_builtin_min(int n_args, const mp_obj_t *args) {
205223
if (n_args == 1) {
206224
// given an iterable
207225
mp_obj_t iterable = rt_getiter(args[0]);
@@ -228,6 +246,8 @@ mp_obj_t mp_builtin_min(int n_args, const mp_obj_t *args) {
228246
}
229247
}
230248

249+
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin_min_obj, 1, mp_builtin_min);
250+
231251
static mp_obj_t mp_builtin_next(mp_obj_t o) {
232252
mp_obj_t ret = rt_iternext(o);
233253
if (ret == mp_const_stop_iteration) {
@@ -239,7 +259,7 @@ static mp_obj_t mp_builtin_next(mp_obj_t o) {
239259

240260
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next);
241261

242-
mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
262+
static mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
243263
const char *str = qstr_str(mp_obj_get_qstr(o_in));
244264
if (strlen(str) == 1) {
245265
return mp_obj_new_int(str[0]);
@@ -248,15 +268,19 @@ mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
248268
}
249269
}
250270

251-
mp_obj_t mp_builtin_pow(int n_args, const mp_obj_t *args) {
271+
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);
272+
273+
static mp_obj_t mp_builtin_pow(int n_args, const mp_obj_t *args) {
274+
assert(2 <= n_args && n_args <= 3);
252275
switch (n_args) {
253276
case 2: return rt_binary_op(RT_BINARY_OP_POWER, args[0], args[1]);
254-
case 3: return rt_binary_op(RT_BINARY_OP_MODULO, rt_binary_op(RT_BINARY_OP_POWER, args[0], args[1]), args[2]); // TODO optimise...
255-
default: nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "pow expected at most 3 arguments, got %d", n_args));
277+
default: return rt_binary_op(RT_BINARY_OP_MODULO, rt_binary_op(RT_BINARY_OP_POWER, args[0], args[1]), args[2]); // TODO optimise...
256278
}
257279
}
258280

259-
mp_obj_t mp_builtin_print(int n_args, const mp_obj_t *args) {
281+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_pow_obj, 2, 3, mp_builtin_pow);
282+
283+
static mp_obj_t mp_builtin_print(int n_args, const mp_obj_t *args) {
260284
for (int i = 0; i < n_args; i++) {
261285
if (i > 0) {
262286
printf(" ");
@@ -273,21 +297,25 @@ mp_obj_t mp_builtin_print(int n_args, const mp_obj_t *args) {
273297
return mp_const_none;
274298
}
275299

276-
mp_obj_t mp_builtin_range(int n_args, const mp_obj_t *args) {
300+
MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin_print_obj, 0, mp_builtin_print);
301+
302+
static mp_obj_t mp_builtin_range(int n_args, const mp_obj_t *args) {
303+
assert(1 <= n_args && n_args <= 3);
277304
switch (n_args) {
278305
case 1: return mp_obj_new_range(0, mp_obj_get_int(args[0]), 1);
279306
case 2: return mp_obj_new_range(mp_obj_get_int(args[0]), mp_obj_get_int(args[1]), 1);
280-
case 3: return mp_obj_new_range(mp_obj_get_int(args[0]), mp_obj_get_int(args[1]), mp_obj_get_int(args[2]));
281-
default: nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "range expected at most 3 arguments, got %d", n_args));
307+
default: return mp_obj_new_range(mp_obj_get_int(args[0]), mp_obj_get_int(args[1]), mp_obj_get_int(args[2]));
282308
}
283309
}
284310

285-
mp_obj_t mp_builtin_sum(int n_args, const mp_obj_t *args) {
311+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_range_obj, 1, 3, mp_builtin_range);
312+
313+
static mp_obj_t mp_builtin_sum(int n_args, const mp_obj_t *args) {
314+
assert(1 <= n_args && n_args <= 2);
286315
mp_obj_t value;
287316
switch (n_args) {
288317
case 1: value = mp_obj_new_int(0); break;
289-
case 2: value = args[1]; break;
290-
default: nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "sum expected at most 2 arguments, got %d", n_args));
318+
default: value = args[1]; break;
291319
}
292320
mp_obj_t iterable = rt_getiter(args[0]);
293321
mp_obj_t item;
@@ -296,3 +324,5 @@ mp_obj_t mp_builtin_sum(int n_args, const mp_obj_t *args) {
296324
}
297325
return value;
298326
}
327+
328+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum);

py/builtin.h

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
// TODO convert all these to objects using MP_DECLARE and MP_DEFINE
1+
mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args);
22

33
MP_DECLARE_CONST_FUN_OBJ(mp_builtin___build_class___obj);
4-
mp_obj_t mp_builtin___import__(int n, mp_obj_t *args);
5-
mp_obj_t mp_builtin___repl_print__(mp_obj_t o);
6-
mp_obj_t mp_builtin_abs(mp_obj_t o_in);
7-
mp_obj_t mp_builtin_all(mp_obj_t o_in);
8-
mp_obj_t mp_builtin_any(mp_obj_t o_in);
9-
mp_obj_t mp_builtin_callable(mp_obj_t o_in);
10-
mp_obj_t mp_builtin_chr(mp_obj_t o_in);
11-
mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in);
4+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin___repl_print___obj);
5+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_abs_obj);
6+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_all_obj);
7+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_any_obj);
8+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_callable_obj);
9+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj);
10+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_divmod_obj);
1211
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_hash_obj);
1312
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_isinstance_obj);
1413
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_issubclass_obj);
1514
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_iter_obj);
16-
mp_obj_t mp_builtin_len(mp_obj_t o_in);
17-
mp_obj_t mp_builtin_list(int n_args, const mp_obj_t *args);
18-
mp_obj_t mp_builtin_max(int n_args, const mp_obj_t *args);
19-
mp_obj_t mp_builtin_min(int n_args, const mp_obj_t *args);
15+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_len_obj);
16+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_list_obj);
17+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_max_obj);
18+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_min_obj);
2019
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_next_obj);
21-
mp_obj_t mp_builtin_ord(mp_obj_t o_in);
22-
mp_obj_t mp_builtin_pow(int n_args, const mp_obj_t *args);
23-
mp_obj_t mp_builtin_print(int n_args, const mp_obj_t *args);
24-
mp_obj_t mp_builtin_range(int n_args, const mp_obj_t *args);
25-
mp_obj_t mp_builtin_sum(int n_args, const mp_obj_t *args);
20+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_ord_obj);
21+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_pow_obj);
22+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_print_obj);
23+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_range_obj);
24+
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_sum_obj);

py/builtinimport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "map.h"
1919
#include "builtin.h"
2020

21-
mp_obj_t mp_builtin___import__(int n, mp_obj_t *args) {
21+
mp_obj_t mp_builtin___import__(int n_args, mp_obj_t *args) {
2222
/*
2323
printf("import:\n");
2424
for (int i = 0; i < n; i++) {

py/mpconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ typedef long long mp_longint_impl_t;
9191
#define BITS_PER_BYTE (8)
9292
#define BITS_PER_WORD (BITS_PER_BYTE * BYTES_PER_WORD)
9393
// machine_int_t value with most significant bit set
94-
#define WORD_MSBIT_HIGH (1 << (BYTES_PER_WORD * 8 - 1))
94+
#define WORD_MSBIT_HIGH (((machine_uint_t)1) << (BYTES_PER_WORD * 8 - 1))
9595

9696
// printf format spec to use for machine_int_t and friends
9797
#ifndef INT_FMT

py/objint.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ void int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj
5454
// This is called only for non-SMALL_INT
5555
mp_obj_t int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
5656
assert(0);
57+
return mp_const_none;
5758
}
5859

5960
// This is called only with strings whose value doesn't fit in SMALL_INT
6061
mp_obj_t mp_obj_new_int_from_long_str(const char *s) {
6162
assert(0);
63+
return mp_const_none;
6264
}
6365

6466
mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value) {
@@ -69,6 +71,7 @@ mp_obj_t mp_obj_new_int_from_uint(machine_uint_t value) {
6971
}
7072
// TODO: Raise exception
7173
assert(0);
74+
return mp_const_none;
7275
}
7376

7477
mp_obj_t mp_obj_new_int(machine_int_t value) {
@@ -77,5 +80,6 @@ mp_obj_t mp_obj_new_int(machine_int_t value) {
7780
}
7881
// TODO: Raise exception
7982
assert(0);
83+
return mp_const_none;
8084
}
8185
#endif

py/objstr.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ static mp_obj_t str_find(int n_args, const mp_obj_t *args) {
169169
const char* haystack = qstr_str(((mp_obj_str_t*)args[0])->qstr);
170170
const char* needle = qstr_str(((mp_obj_str_t*)args[1])->qstr);
171171

172-
ssize_t haystack_len = strlen(haystack);
173-
ssize_t needle_len = strlen(needle);
172+
size_t haystack_len = strlen(haystack);
173+
size_t needle_len = strlen(needle);
174174

175175
size_t start = 0;
176176
size_t end = haystack_len;
@@ -183,14 +183,17 @@ static mp_obj_t str_find(int n_args, const mp_obj_t *args) {
183183
}
184184

185185
char *p = strstr(haystack + start, needle);
186-
ssize_t pos = -1;
187-
if (p) {
188-
pos = p - haystack;
186+
if (p == NULL) {
187+
// not found
188+
return MP_OBJ_NEW_SMALL_INT(-1);
189+
} else {
190+
// found
191+
machine_int_t pos = p - haystack;
189192
if (pos + needle_len > end) {
190193
pos = -1;
191194
}
195+
return MP_OBJ_NEW_SMALL_INT(pos);
192196
}
193-
return MP_OBJ_NEW_SMALL_INT(pos);
194197
}
195198

196199
mp_obj_t str_strip(int n_args, const mp_obj_t *args) {

py/runtime.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void rt_init(void) {
9797

9898
// built-in core functions
9999
mp_map_add_qstr(&map_builtins, MP_QSTR___build_class__, (mp_obj_t)&mp_builtin___build_class___obj);
100-
mp_map_add_qstr(&map_builtins, MP_QSTR___repl_print__, rt_make_function_1(mp_builtin___repl_print__));
100+
mp_map_add_qstr(&map_builtins, MP_QSTR___repl_print__, (mp_obj_t)&mp_builtin___repl_print___obj);
101101

102102
// built-in types
103103
mp_map_add_qstr(&map_builtins, MP_QSTR_bool, (mp_obj_t)&bool_type);
@@ -114,26 +114,26 @@ void rt_init(void) {
114114
mp_map_add_qstr(&map_builtins, MP_QSTR_tuple, (mp_obj_t)&tuple_type);
115115
mp_map_add_qstr(&map_builtins, MP_QSTR_type, (mp_obj_t)&mp_const_type);
116116

117-
// built-in user functions; TODO covert all to &mp_builtin_xxx's
118-
mp_map_add_qstr(&map_builtins, MP_QSTR_abs, rt_make_function_1(mp_builtin_abs));
119-
mp_map_add_qstr(&map_builtins, MP_QSTR_all, rt_make_function_1(mp_builtin_all));
120-
mp_map_add_qstr(&map_builtins, MP_QSTR_any, rt_make_function_1(mp_builtin_any));
121-
mp_map_add_qstr(&map_builtins, MP_QSTR_callable, rt_make_function_1(mp_builtin_callable));
122-
mp_map_add_qstr(&map_builtins, MP_QSTR_chr, rt_make_function_1(mp_builtin_chr));
123-
mp_map_add_qstr(&map_builtins, MP_QSTR_divmod, rt_make_function_2(mp_builtin_divmod));
117+
// built-in user functions
118+
mp_map_add_qstr(&map_builtins, MP_QSTR_abs, (mp_obj_t)&mp_builtin_abs_obj);
119+
mp_map_add_qstr(&map_builtins, MP_QSTR_all, (mp_obj_t)&mp_builtin_all_obj);
120+
mp_map_add_qstr(&map_builtins, MP_QSTR_any, (mp_obj_t)&mp_builtin_any_obj);
121+
mp_map_add_qstr(&map_builtins, MP_QSTR_callable, (mp_obj_t)&mp_builtin_callable_obj);
122+
mp_map_add_qstr(&map_builtins, MP_QSTR_chr, (mp_obj_t)&mp_builtin_chr_obj);
123+
mp_map_add_qstr(&map_builtins, MP_QSTR_divmod, (mp_obj_t)&mp_builtin_divmod_obj);
124124
mp_map_add_qstr(&map_builtins, MP_QSTR_hash, (mp_obj_t)&mp_builtin_hash_obj);
125125
mp_map_add_qstr(&map_builtins, MP_QSTR_isinstance, (mp_obj_t)&mp_builtin_isinstance_obj);
126126
mp_map_add_qstr(&map_builtins, MP_QSTR_issubclass, (mp_obj_t)&mp_builtin_issubclass_obj);
127127
mp_map_add_qstr(&map_builtins, MP_QSTR_iter, (mp_obj_t)&mp_builtin_iter_obj);
128-
mp_map_add_qstr(&map_builtins, MP_QSTR_len, rt_make_function_1(mp_builtin_len));
129-
mp_map_add_qstr(&map_builtins, MP_QSTR_max, rt_make_function_var(1, mp_builtin_max));
130-
mp_map_add_qstr(&map_builtins, MP_QSTR_min, rt_make_function_var(1, mp_builtin_min));
128+
mp_map_add_qstr(&map_builtins, MP_QSTR_len, (mp_obj_t)&mp_builtin_len_obj);
129+
mp_map_add_qstr(&map_builtins, MP_QSTR_max, (mp_obj_t)&mp_builtin_max_obj);
130+
mp_map_add_qstr(&map_builtins, MP_QSTR_min, (mp_obj_t)&mp_builtin_min_obj);
131131
mp_map_add_qstr(&map_builtins, MP_QSTR_next, (mp_obj_t)&mp_builtin_next_obj);
132-
mp_map_add_qstr(&map_builtins, MP_QSTR_ord, rt_make_function_1(mp_builtin_ord));
133-
mp_map_add_qstr(&map_builtins, MP_QSTR_pow, rt_make_function_var(2, mp_builtin_pow));
134-
mp_map_add_qstr(&map_builtins, MP_QSTR_print, rt_make_function_var(0, mp_builtin_print));
135-
mp_map_add_qstr(&map_builtins, MP_QSTR_range, rt_make_function_var(1, mp_builtin_range));
136-
mp_map_add_qstr(&map_builtins, MP_QSTR_sum, rt_make_function_var(1, mp_builtin_sum));
132+
mp_map_add_qstr(&map_builtins, MP_QSTR_ord, (mp_obj_t)&mp_builtin_ord_obj);
133+
mp_map_add_qstr(&map_builtins, MP_QSTR_pow, (mp_obj_t)&mp_builtin_pow_obj);
134+
mp_map_add_qstr(&map_builtins, MP_QSTR_print, (mp_obj_t)&mp_builtin_print_obj);
135+
mp_map_add_qstr(&map_builtins, MP_QSTR_range, (mp_obj_t)&mp_builtin_range_obj);
136+
mp_map_add_qstr(&map_builtins, MP_QSTR_sum, (mp_obj_t)&mp_builtin_sum_obj);
137137

138138
next_unique_code_id = 1; // 0 indicates "no code"
139139
unique_codes_alloc = 0;

stm/printf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ int pfenv_printf(const pfenv_t *pfenv, const char *fmt, va_list args) {
213213
// usable. I expect that this will be replaced with something
214214
// more appropriate.
215215
char dot = '.';
216-
double d = va_arg(args, double);
216+
mp_float_t d = va_arg(args, double);
217217
int left = (int)d;
218-
int right = (int)((d - (double)(int)d) * 1000000.0);
218+
int right = (int)((d - (mp_float_t)(int)d) * 1000000.0);
219219
chrs += pfenv_print_int(pfenv, left, 1, 10, 'a', flags, width);
220220
chrs += pfenv_print_strn(pfenv, &dot, 1, flags, width);
221221
chrs += pfenv_print_int(pfenv, right, 0, 10, 'a', PF_FLAG_ZERO_PAD, 6);

0 commit comments

Comments
 (0)