summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/compile.c2
-rw-r--r--py/grammar.h4
-rw-r--r--py/malloc.c17
-rw-r--r--py/objlist.c4
-rw-r--r--py/objtype.c2
-rw-r--r--py/qstrdefs.h3
-rw-r--r--py/runtime.c2
-rw-r--r--py/sequence.c4
8 files changed, 16 insertions, 22 deletions
diff --git a/py/compile.c b/py/compile.c
index 1abe08c432..521c5290cd 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -2764,7 +2764,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
apply_to_single_or_list(comp, pns->nodes[1], PN_typedargslist, compile_scope_func_param);
}
- assert(MP_PARSE_NODE_IS_NULL(pns->nodes[2])); // 2 is something...
+ // pns->nodes[2] is return/whole function annotation
compile_node(comp, pns->nodes[3]); // 3 is function body
// emit return if it wasn't the last opcode
diff --git a/py/grammar.h b/py/grammar.h
index c58ad9e069..4823ccb12b 100644
--- a/py/grammar.h
+++ b/py/grammar.h
@@ -33,8 +33,8 @@ DEF_RULE(decorator, nc, and(4), tok(DEL_AT), rule(dotted_name), opt_rule(trailer
DEF_RULE(decorators, nc, one_or_more, rule(decorator))
DEF_RULE(decorated, c(decorated), and(2), rule(decorators), rule(decorated_body))
DEF_RULE(decorated_body, nc, or(2), rule(classdef), rule(funcdef))
-DEF_RULE(funcdef, c(funcdef), and(8), tok(KW_DEF), tok(NAME), tok(DEL_PAREN_OPEN), opt_rule(typedargslist), tok(DEL_PAREN_CLOSE), opt_rule(funcdef_2), tok(DEL_COLON), rule(suite))
-DEF_RULE(funcdef_2, nc, and(2), tok(DEL_MINUS_MORE), rule(test))
+DEF_RULE(funcdef, c(funcdef), and(8), tok(KW_DEF), tok(NAME), tok(DEL_PAREN_OPEN), opt_rule(typedargslist), tok(DEL_PAREN_CLOSE), opt_rule(funcdefrettype), tok(DEL_COLON), rule(suite))
+DEF_RULE(funcdefrettype, nc, and(2), tok(DEL_MINUS_MORE), rule(test))
// TODO typedargslist lets through more than is allowed
DEF_RULE(typedargslist, nc, list_with_end, rule(typedargslist_item), tok(DEL_COMMA))
DEF_RULE(typedargslist_item, nc, or(3), rule(typedargslist_name), rule(typedargslist_star), rule(typedargslist_dbl_star))
diff --git a/py/malloc.c b/py/malloc.c
index 59570243f0..c87d91c0a0 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "misc.h"
#include "mpconfig.h"
@@ -37,20 +38,10 @@ void *m_malloc(int num_bytes) {
}
void *m_malloc0(int num_bytes) {
- if (num_bytes == 0) {
- return NULL;
- }
- void *ptr = calloc(1, num_bytes);
- if (ptr == NULL) {
- printf("could not allocate memory, allocating %d bytes\n", num_bytes);
- return NULL;
+ void *ptr = m_malloc(num_bytes);
+ if (ptr != NULL) {
+ memset(ptr, 0, num_bytes);
}
-#if MICROPY_MEM_STATS
- total_bytes_allocated += num_bytes;
- current_bytes_allocated += num_bytes;
- UPDATE_PEAK();
-#endif
- DEBUG_printf("malloc0 %d : %p\n", num_bytes, ptr);
return ptr;
}
diff --git a/py/objlist.c b/py/objlist.c
index 4e8944d35e..35bab2a398 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -233,8 +233,8 @@ mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
}
mp_obj_list_t *self = args[0];
if (self->len > 1) {
- mp_map_elem_t *keyfun = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(QSTR_FROM_STR_STATIC("key")), MP_MAP_LOOKUP);
- mp_map_elem_t *reverse = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(QSTR_FROM_STR_STATIC("reverse")), MP_MAP_LOOKUP);
+ mp_map_elem_t *keyfun = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(MP_QSTR_key), MP_MAP_LOOKUP);
+ mp_map_elem_t *reverse = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(MP_QSTR_reverse), MP_MAP_LOOKUP);
mp_quicksort(self->items, self->items + self->len - 1,
keyfun ? keyfun->value : NULL,
reverse && reverse->value ? rt_is_true(reverse->value) : false);
diff --git a/py/objtype.c b/py/objtype.c
index 6ff18b47bf..55f4227364 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -239,7 +239,7 @@ static bool class_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
bool class_store_item(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
mp_obj_class_t *self = self_in;
- mp_obj_t member = mp_obj_class_lookup(self->base.type, QSTR_FROM_STR_STATIC("__setitem__"));
+ mp_obj_t member = mp_obj_class_lookup(self->base.type, MP_QSTR___setitem__);
if (member != MP_OBJ_NULL) {
mp_obj_t args[3] = {self_in, index, value};
rt_call_function_n_kw(member, 3, 0, args);
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index afd238c1ae..680c4bcf73 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -17,6 +17,7 @@ Q(__repl_print__)
Q(__bool__)
Q(__len__)
Q(__getitem__)
+Q(__setitem__)
Q(__add__)
Q(__sub__)
@@ -97,6 +98,8 @@ Q(sort)
Q(join)
Q(strip)
Q(format)
+Q(key)
+Q(reverse)
Q(<module>)
Q(<lambda>)
diff --git a/py/runtime.c b/py/runtime.c
index ab83e380cc..aaac884d65 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -969,7 +969,7 @@ mp_obj_t rt_getiter(mp_obj_t o_in) {
} else {
// check for __getitem__ method
mp_obj_t dest[2];
- rt_load_method_maybe(o_in, qstr_from_str("__getitem__"), dest);
+ rt_load_method_maybe(o_in, MP_QSTR___getitem__, dest);
if (dest[0] != MP_OBJ_NULL) {
// __getitem__ exists, create an iterator
return mp_obj_new_getitem_iter(dest);
diff --git a/py/sequence.c b/py/sequence.c
index d8cfd9f3e9..f5310737a7 100644
--- a/py/sequence.c
+++ b/py/sequence.c
@@ -155,7 +155,7 @@ mp_obj_t mp_seq_index_obj(const mp_obj_t *items, uint len, uint n_args, const mp
}
}
- for (uint i = start; i < stop; i++) {
+ for (machine_uint_t i = start; i < stop; i++) {
if (mp_obj_equal(items[i], value)) {
// Common sense says this cannot overflow small int
return MP_OBJ_NEW_SMALL_INT(i);
@@ -166,7 +166,7 @@ mp_obj_t mp_seq_index_obj(const mp_obj_t *items, uint len, uint n_args, const mp
}
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, uint len, mp_obj_t value) {
- uint count = 0;
+ machine_uint_t count = 0;
for (uint i = 0; i < len; i++) {
if (mp_obj_equal(items[i], value)) {
count++;