summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorGlenn Ruben Bakke <glennbakke@gmail.com>2017-02-07 22:27:32 +0100
committerGlenn Ruben Bakke <glennbakke@gmail.com>2017-02-07 22:27:32 +0100
commit122d0430db4d103dfb8bc9958b7df4d9803038c8 (patch)
tree856ac0d4950b0154cc6aae8cf022fd29b2402073 /py
parent723943abde3e9de5e14ee40df5e0d5fe25352c97 (diff)
parent4cf7fd151e98a3d842eb5c9428545cb67ddd57ee (diff)
Merge branch 'nrf52' into nrf5_no_sdk
Diffstat (limited to 'py')
-rw-r--r--py/bc.h4
-rw-r--r--py/lexer.c2
-rw-r--r--py/modbuiltins.c9
-rw-r--r--py/mpconfig.h17
-rw-r--r--py/mpstate.h6
-rw-r--r--py/mpz.c6
-rw-r--r--py/mpz.h1
-rw-r--r--py/nlrx64.S3
-rw-r--r--py/nlrx86.S3
-rw-r--r--py/nlrxtensa.S3
-rw-r--r--py/objcomplex.c4
-rw-r--r--py/objfloat.c7
-rw-r--r--py/objint.c2
-rw-r--r--py/objint.h1
-rw-r--r--py/objint_mpz.c33
-rw-r--r--py/objmodule.c8
-rw-r--r--py/objmodule.h2
-rw-r--r--py/objset.c28
-rw-r--r--py/objstr.c40
-rw-r--r--py/objstringio.c23
-rw-r--r--py/py.mk9
-rw-r--r--py/qstrdefs.h1
-rw-r--r--py/runtime.c12
-rw-r--r--py/showbc.c6
-rw-r--r--py/vm.c3
25 files changed, 166 insertions, 67 deletions
diff --git a/py/bc.h b/py/bc.h
index 4707da179..c7dffbac5 100644
--- a/py/bc.h
+++ b/py/bc.h
@@ -94,9 +94,9 @@ mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t func, size_t n_args, s
struct _mp_obj_fun_bc_t;
void mp_setup_code_state(mp_code_state_t *code_state, struct _mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args);
void mp_bytecode_print(const void *descr, const byte *code, mp_uint_t len, const mp_uint_t *const_table);
-void mp_bytecode_print2(const byte *code, mp_uint_t len);
+void mp_bytecode_print2(const byte *code, size_t len, const mp_uint_t *const_table);
const byte *mp_bytecode_print_str(const byte *ip);
-#define mp_bytecode_print_inst(code) mp_bytecode_print2(code, 1)
+#define mp_bytecode_print_inst(code, const_table) mp_bytecode_print2(code, 1, const_table)
// Helper macros to access pointer with least significant bits holding flags
#define MP_TAGPTR_PTR(x) ((void*)((uintptr_t)(x) & ~((uintptr_t)3)))
diff --git a/py/lexer.c b/py/lexer.c
index 458fba090..33af21e9c 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -753,7 +753,7 @@ mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, mp_uint_t
return mp_lexer_new(src_name, reader);
}
-#if MICROPY_READER_POSIX || MICROPY_READER_FATFS
+#if MICROPY_READER_POSIX || MICROPY_READER_VFS
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
mp_reader_t reader;
diff --git a/py/modbuiltins.c b/py/modbuiltins.c
index f62afd807..a0c68930d 100644
--- a/py/modbuiltins.c
+++ b/py/modbuiltins.c
@@ -378,7 +378,14 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);
STATIC mp_obj_t mp_builtin_pow(size_t n_args, const mp_obj_t *args) {
switch (n_args) {
case 2: return mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]);
- default: return mp_binary_op(MP_BINARY_OP_MODULO, mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]), args[2]); // TODO optimise...
+ default:
+#if !MICROPY_PY_BUILTINS_POW3
+ mp_raise_msg(&mp_type_NotImplementedError, "3-arg pow() not supported");
+#elif MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_MPZ
+ return mp_binary_op(MP_BINARY_OP_MODULO, mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]), args[2]);
+#else
+ return mp_obj_int_pow3(args[0], args[1], args[2]);
+#endif
}
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_pow_obj, 2, 3, mp_builtin_pow);
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 3bccada11..afd9a0be5 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -398,9 +398,9 @@
#define MICROPY_READER_POSIX (0)
#endif
-// Whether to use the FatFS reader for importing files
-#ifndef MICROPY_READER_FATFS
-#define MICROPY_READER_FATFS (0)
+// Whether to use the VFS reader for importing files
+#ifndef MICROPY_READER_VFS
+#define MICROPY_READER_VFS (0)
#endif
// Hook for the VM at the start of the opcode loop (can contain variable
@@ -616,9 +616,9 @@ typedef double mp_float_t;
#define MICROPY_USE_INTERNAL_PRINTF (1)
#endif
-// Support for user-space VFS mount (selected ports)
-#ifndef MICROPY_FSUSERMOUNT
-#define MICROPY_FSUSERMOUNT (0)
+// Support for generic VFS sub-system
+#ifndef MICROPY_VFS
+#define MICROPY_VFS (0)
#endif
/*****************************************************************************/
@@ -759,6 +759,11 @@ typedef double mp_float_t;
#define MICROPY_PY_BUILTINS_MIN_MAX (1)
#endif
+// Support for calls to pow() with 3 integer arguments
+#ifndef MICROPY_PY_BUILTINS_POW3
+#define MICROPY_PY_BUILTINS_POW3 (0)
+#endif
+
// Whether to provide the help function
#ifndef MICROPY_PY_BUILTINS_HELP
#define MICROPY_PY_BUILTINS_HELP (0)
diff --git a/py/mpstate.h b/py/mpstate.h
index 91fb68b3a..54392a994 100644
--- a/py/mpstate.h
+++ b/py/mpstate.h
@@ -160,9 +160,9 @@ typedef struct _mp_state_vm_t {
mp_obj_t lwip_slip_stream;
#endif
- #if MICROPY_FSUSERMOUNT
- // for user-mountable block device (max fixed at compile time)
- struct _fs_user_mount_t *fs_user_mount[MICROPY_FATFS_VOLUMES];
+ #if MICROPY_VFS
+ struct _mp_vfs_mount_t *vfs_cur;
+ struct _mp_vfs_mount_t *vfs_mount_table;
#endif
//
diff --git a/py/mpz.c b/py/mpz.c
index 6477c3f8d..230eb921c 100644
--- a/py/mpz.c
+++ b/py/mpz.c
@@ -1395,9 +1395,6 @@ void mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs) {
mpz_free(n);
}
-#if 0
-these functions are unused
-
/* computes dest = (lhs ** rhs) % mod
can have dest, lhs, rhs the same; mod can't be the same as dest
*/
@@ -1436,6 +1433,9 @@ void mpz_pow3_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs, const mpz_t
mpz_free(n);
}
+#if 0
+these functions are unused
+
/* computes gcd(z1, z2)
based on Knuth's modified gcd algorithm (I think?)
gcd(z1, z2) >= 0
diff --git a/py/mpz.h b/py/mpz.h
index a26cbea5c..8facb1a0f 100644
--- a/py/mpz.h
+++ b/py/mpz.h
@@ -123,6 +123,7 @@ void mpz_add_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_sub_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_mul_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
+void mpz_pow3_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs, const mpz_t *mod);
void mpz_and_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_or_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
void mpz_xor_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
diff --git a/py/nlrx64.S b/py/nlrx64.S
index caea35de2..fc8b8e344 100644
--- a/py/nlrx64.S
+++ b/py/nlrx64.S
@@ -257,3 +257,6 @@ nlr_jump:
#endif // !defined(NLR_OS_WINDOWS)
#endif // defined(__x86_64__) && !MICROPY_NLR_SETJMP
+#if defined(linux)
+ .section .note.GNU-stack,"",@progbits
+#endif
diff --git a/py/nlrx86.S b/py/nlrx86.S
index 8c538ba17..f1de61e11 100644
--- a/py/nlrx86.S
+++ b/py/nlrx86.S
@@ -190,3 +190,6 @@ nlr_jump:
#endif
#endif // defined(__i386__) && !MICROPY_NLR_SETJMP
+#if defined(linux)
+ .section .note.GNU-stack,"",@progbits
+#endif
diff --git a/py/nlrxtensa.S b/py/nlrxtensa.S
index 289996cce..73af4832f 100644
--- a/py/nlrxtensa.S
+++ b/py/nlrxtensa.S
@@ -114,3 +114,6 @@ nlr_jump:
.size nlr_jump, .-nlr_jump
#endif // defined(__xtensa__)
+#if defined(linux)
+ .section .note.GNU-stack,"",@progbits
+#endif
diff --git a/py/objcomplex.c b/py/objcomplex.c
index 96be25255..426e76e5f 100644
--- a/py/objcomplex.c
+++ b/py/objcomplex.c
@@ -222,8 +222,8 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
// = exp(x3)*(cos(y3) + i*sin(y3))
mp_float_t abs1 = MICROPY_FLOAT_C_FUN(sqrt)(lhs_real*lhs_real + lhs_imag*lhs_imag);
if (abs1 == 0) {
- if (rhs_imag == 0) {
- lhs_real = 1;
+ if (rhs_imag == 0 && rhs_real >= 0) {
+ lhs_real = (rhs_real == 0);
rhs_real = 0;
} else {
mp_raise_msg(&mp_type_ZeroDivisionError, "0.0 to a complex power");
diff --git a/py/objfloat.c b/py/objfloat.c
index 73d07feac..9292490a9 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -228,7 +228,12 @@ mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs_i
}
break;
case MP_BINARY_OP_POWER:
- case MP_BINARY_OP_INPLACE_POWER: lhs_val = MICROPY_FLOAT_C_FUN(pow)(lhs_val, rhs_val); break;
+ case MP_BINARY_OP_INPLACE_POWER:
+ if (lhs_val == 0 && rhs_val < 0) {
+ goto zero_division_error;
+ }
+ lhs_val = MICROPY_FLOAT_C_FUN(pow)(lhs_val, rhs_val);
+ break;
case MP_BINARY_OP_DIVMOD: {
if (rhs_val == 0) {
goto zero_division_error;
diff --git a/py/objint.c b/py/objint.c
index a61ed8e27..222aa1de7 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -383,7 +383,7 @@ STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *args) {
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
// If result guaranteedly fits in small int, use that
- if (!MP_SMALL_INT_FITS(1 << (bufinfo.len * 8 - 1))) {
+ if (bufinfo.len >= sizeof(mp_uint_t) || !MP_SMALL_INT_FITS(1 << (bufinfo.len * 8 - 1))) {
return mp_obj_int_from_bytes_impl(args[2] != MP_OBJ_NEW_QSTR(MP_QSTR_little), bufinfo.len, bufinfo.buf);
} else
#endif
diff --git a/py/objint.h b/py/objint.h
index a84a33fa5..7205761ad 100644
--- a/py/objint.h
+++ b/py/objint.h
@@ -66,5 +66,6 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in);
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in);
mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
mp_obj_t mp_obj_int_binary_op_extra_cases(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in);
+mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus);
#endif // __MICROPY_INCLUDED_PY_OBJINT_H__
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index d465ef965..2b27df4f6 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -326,6 +326,39 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
}
+#if MICROPY_PY_BUILTINS_POW3
+STATIC mpz_t *mp_mpz_for_int(mp_obj_t arg, mpz_t *temp) {
+ if (MP_OBJ_IS_SMALL_INT(arg)) {
+ mpz_init_from_int(temp, MP_OBJ_SMALL_INT_VALUE(arg));
+ return temp;
+ } else {
+ mp_obj_int_t *arp_p = MP_OBJ_TO_PTR(arg);
+ return &(arp_p->mpz);
+ }
+}
+
+mp_obj_t mp_obj_int_pow3(mp_obj_t base, mp_obj_t exponent, mp_obj_t modulus) {
+ if (!MP_OBJ_IS_INT(base) || !MP_OBJ_IS_INT(exponent) || !MP_OBJ_IS_INT(modulus)) {
+ mp_raise_TypeError("pow() with 3 arguments requires integers");
+ } else {
+ mp_obj_t result = mp_obj_new_int_from_ull(0); // Use the _from_ull version as this forces an mpz int
+ mp_obj_int_t *res_p = (mp_obj_int_t *) MP_OBJ_TO_PTR(result);
+
+ mpz_t l_temp, r_temp, m_temp;
+ mpz_t *lhs = mp_mpz_for_int(base, &l_temp);
+ mpz_t *rhs = mp_mpz_for_int(exponent, &r_temp);
+ mpz_t *mod = mp_mpz_for_int(modulus, &m_temp);
+
+ mpz_pow3_inpl(&(res_p->mpz), lhs, rhs, mod);
+
+ if (lhs == &l_temp) { mpz_deinit(lhs); }
+ if (rhs == &r_temp) { mpz_deinit(rhs); }
+ if (mod == &m_temp) { mpz_deinit(mod); }
+ return result;
+ }
+}
+#endif
+
mp_obj_t mp_obj_new_int(mp_int_t value) {
if (MP_SMALL_INT_FITS(value)) {
return MP_OBJ_NEW_SMALL_INT(value);
diff --git a/py/objmodule.c b/py/objmodule.c
index a0a179de4..43bb36b98 100644
--- a/py/objmodule.c
+++ b/py/objmodule.c
@@ -237,14 +237,6 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_weak_links_table[] = {
MP_DEFINE_CONST_MAP(mp_builtin_module_weak_links_map, mp_builtin_module_weak_links_table);
#endif
-void mp_module_init(void) {
- mp_obj_dict_init(&MP_STATE_VM(mp_loaded_modules_dict), 3);
-}
-
-void mp_module_deinit(void) {
- //mp_map_deinit(&MP_STATE_VM(mp_loaded_modules_map));
-}
-
// returns MP_OBJ_NULL if not found
mp_obj_t mp_module_get(qstr module_name) {
mp_map_t *mp_loaded_modules_map = &MP_STATE_VM(mp_loaded_modules_dict).map;
diff --git a/py/objmodule.h b/py/objmodule.h
index 937ff8416..4e6612adc 100644
--- a/py/objmodule.h
+++ b/py/objmodule.h
@@ -31,8 +31,6 @@
extern const mp_map_t mp_builtin_module_map;
extern const mp_map_t mp_builtin_module_weak_links_map;
-void mp_module_init(void);
-void mp_module_deinit(void);
mp_obj_t mp_module_get(qstr module_name);
void mp_module_register(qstr qstr, mp_obj_t module);
diff --git a/py/objset.c b/py/objset.c
index fc124fcd8..778bbe15b 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -479,6 +479,11 @@ STATIC mp_obj_t set_unary_op(mp_uint_t op, mp_obj_t self_in) {
STATIC mp_obj_t set_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_t args[] = {lhs, rhs};
+ #if MICROPY_PY_BUILTINS_FROZENSET
+ bool update = MP_OBJ_IS_TYPE(lhs, &mp_type_set);
+ #else
+ bool update = true;
+ #endif
switch (op) {
case MP_BINARY_OP_OR:
return set_union(lhs, rhs);
@@ -489,13 +494,28 @@ STATIC mp_obj_t set_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
case MP_BINARY_OP_SUBTRACT:
return set_diff(2, args);
case MP_BINARY_OP_INPLACE_OR:
- return set_union(lhs, rhs);
+ if (update) {
+ set_update(2, args);
+ return lhs;
+ } else {
+ return set_union(lhs, rhs);
+ }
case MP_BINARY_OP_INPLACE_XOR:
- return set_symmetric_difference(lhs, rhs);
+ if (update) {
+ set_symmetric_difference_update(lhs, rhs);
+ return lhs;
+ } else {
+ return set_symmetric_difference(lhs, rhs);
+ }
case MP_BINARY_OP_INPLACE_AND:
- return set_intersect(lhs, rhs);
+ rhs = set_intersect_int(lhs, rhs, update);
+ if (update) {
+ return lhs;
+ } else {
+ return rhs;
+ }
case MP_BINARY_OP_INPLACE_SUBTRACT:
- return set_diff(2, args);
+ return set_diff_int(2, args, update);
case MP_BINARY_OP_LESS:
return set_issubset_proper(lhs, rhs);
case MP_BINARY_OP_MORE:
diff --git a/py/objstr.c b/py/objstr.c
index f082e9559..b437d9795 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -36,7 +36,7 @@
#include "py/runtime.h"
#include "py/stackctrl.h"
-STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_obj_t *args, mp_obj_t dict);
+STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict);
STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str);
STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in);
@@ -282,19 +282,14 @@ const byte *find_subbytes(const byte *haystack, mp_uint_t hlen, const byte *need
mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
// check for modulo
if (op == MP_BINARY_OP_MODULO) {
- mp_obj_t *args;
- mp_uint_t n_args;
+ mp_obj_t *args = &rhs_in;
+ mp_uint_t n_args = 1;
mp_obj_t dict = MP_OBJ_NULL;
if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_tuple)) {
// TODO: Support tuple subclasses?
mp_obj_tuple_get(rhs_in, &n_args, &args);
} else if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_dict)) {
- args = NULL;
- n_args = 0;
dict = rhs_in;
- } else {
- args = &rhs_in;
- n_args = 1;
}
return str_modulo_format(lhs_in, n_args, args, dict);
}
@@ -358,6 +353,13 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
switch (op) {
case MP_BINARY_OP_ADD:
case MP_BINARY_OP_INPLACE_ADD: {
+ if (lhs_len == 0) {
+ return rhs_in;
+ }
+ if (rhs_len == 0) {
+ return lhs_in;
+ }
+
vstr_t vstr;
vstr_init_len(&vstr, lhs_len + rhs_len);
memcpy(vstr.buf, lhs_data, lhs_len);
@@ -652,7 +654,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) {
return MP_OBJ_FROM_PTR(res);
}
-STATIC mp_obj_t str_finder(mp_uint_t n_args, const mp_obj_t *args, mp_int_t direction, bool is_index) {
+STATIC mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, mp_int_t direction, bool is_index) {
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0]));
@@ -738,7 +740,7 @@ STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) {
enum { LSTRIP, RSTRIP, STRIP };
-STATIC mp_obj_t str_uni_strip(int type, mp_uint_t n_args, const mp_obj_t *args) {
+STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) {
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(args[0]));
const mp_obj_type_t *self_type = mp_obj_get_type(args[0]);
@@ -890,7 +892,7 @@ STATIC NORETURN void terse_str_format_value_error(void) {
#define terse_str_format_value_error()
#endif
-STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *arg_i, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
+STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *arg_i, size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
vstr_t vstr;
mp_print_t print;
vstr_init_print(&vstr, 16, &print);
@@ -1342,13 +1344,13 @@ mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
}
-STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_obj_t *args, mp_obj_t dict) {
+STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict) {
mp_check_self(MP_OBJ_IS_STR_OR_BYTES(pattern));
GET_STR_DATA_LEN(pattern, str, len);
const byte *start_str = str;
bool is_bytes = MP_OBJ_IS_TYPE(pattern, &mp_type_bytes);
- int arg_i = 0;
+ size_t arg_i = 0;
vstr_t vstr;
mp_print_t print;
vstr_init_print(&vstr, 16, &print);
@@ -1369,6 +1371,10 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
// Dictionary value lookup
if (*str == '(') {
+ if (dict == MP_OBJ_NULL) {
+ mp_raise_TypeError("format requires a dict");
+ }
+ arg_i = 1; // we used up the single dict argument
const byte *key = ++str;
while (*str != ')') {
if (str >= top) {
@@ -1403,7 +1409,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
int width = 0;
if (str < top) {
if (*str == '*') {
- if ((uint)arg_i >= n_args) {
+ if (arg_i >= n_args) {
goto not_enough_args;
}
width = mp_obj_get_int(args[arg_i++]);
@@ -1416,7 +1422,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, mp_uint_t n_args, const mp_o
if (str < top && *str == '.') {
if (++str < top) {
if (*str == '*') {
- if ((uint)arg_i >= n_args) {
+ if (arg_i >= n_args) {
goto not_enough_args;
}
prec = mp_obj_get_int(args[arg_i++]);
@@ -1439,7 +1445,7 @@ incomplete_format:
// Tuple value lookup
if (arg == MP_OBJ_NULL) {
- if ((uint)arg_i >= n_args) {
+ if (arg_i >= n_args) {
not_enough_args:
mp_raise_TypeError("not enough arguments for format string");
}
@@ -1527,7 +1533,7 @@ not_enough_args:
}
}
- if ((uint)arg_i != n_args) {
+ if (arg_i != n_args) {
mp_raise_TypeError("not all arguments converted during string formatting");
}
diff --git a/py/objstringio.c b/py/objstringio.c
index a430fca3b..a77ffae24 100644
--- a/py/objstringio.c
+++ b/py/objstringio.c
@@ -147,21 +147,34 @@ STATIC mp_obj_t stringio___exit__(size_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(stringio___exit___obj, 4, 4, stringio___exit__);
-STATIC mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type) {
+STATIC mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type, mp_uint_t alloc) {
mp_obj_stringio_t *o = m_new_obj(mp_obj_stringio_t);
o->base.type = type;
- o->vstr = vstr_new(16);
+ o->vstr = vstr_new(alloc);
o->pos = 0;
return o;
}
STATIC mp_obj_t stringio_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
(void)n_kw; // TODO check n_kw==0
- mp_obj_stringio_t *o = stringio_new(type_in);
+
+ mp_uint_t sz = 16;
+ bool initdata = false;
+ mp_buffer_info_t bufinfo;
if (n_args > 0) {
- mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
+ if (MP_OBJ_IS_INT(args[0])) {
+ sz = mp_obj_get_int(args[0]);
+ } else {
+ mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ);
+ sz = bufinfo.len;
+ initdata = true;
+ }
+ }
+
+ mp_obj_stringio_t *o = stringio_new(type_in, sz);
+
+ if (initdata) {
stringio_write(MP_OBJ_FROM_PTR(o), bufinfo.buf, bufinfo.len, NULL);
// Cur ptr is always at the beginning of buffer at the construction
o->pos = 0;
diff --git a/py/py.mk b/py/py.mk
index b78cdba35..01a802674 100644
--- a/py/py.mk
+++ b/py/py.mk
@@ -19,6 +19,9 @@ CSUPEROPT = -O3
INC += -I../lib
INC += -I../lib/netutils
+# this sets the config file for FatFs
+CFLAGS_MOD += -DFFCONF_H=\"lib/oofatfs/ffconf.h\"
+
ifeq ($(MICROPY_PY_USSL),1)
CFLAGS_MOD += -DMICROPY_PY_USSL=1
ifeq ($(MICROPY_SSL_AXTLS),1)
@@ -219,6 +222,7 @@ PY_O_BASENAME = \
../extmod/virtpin.o \
../extmod/machine_mem.o \
../extmod/machine_pinbase.o \
+ ../extmod/machine_signal.o \
../extmod/machine_pulse.o \
../extmod/machine_i2c.o \
../extmod/machine_spi.o \
@@ -229,12 +233,11 @@ PY_O_BASENAME = \
../extmod/modwebsocket.o \
../extmod/modwebrepl.o \
../extmod/modframebuf.o \
- ../extmod/fsusermount.o \
+ ../extmod/vfs.o \
+ ../extmod/vfs_reader.o \
../extmod/vfs_fat.o \
- ../extmod/vfs_fat_ffconf.o \
../extmod/vfs_fat_diskio.o \
../extmod/vfs_fat_file.o \
- ../extmod/vfs_fat_reader.o \
../extmod/vfs_fat_misc.o \
../extmod/utime_mphal.o \
../extmod/uos_dupterm.o \
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index c98a253a6..4581e5e1b 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -36,6 +36,7 @@ QCFG(BYTES_IN_HASH, MICROPY_QSTR_BYTES_IN_HASH)
Q()
Q(*)
Q(_)
+Q(/)
Q(%#o)
Q(%#x)
Q({:#b})
diff --git a/py/runtime.c b/py/runtime.c
index 9d2c0ef46..e6aef21d7 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -85,8 +85,8 @@ void mp_init(void) {
// optimization disabled by default
MP_STATE_VM(mp_optimise_value) = 0;
- // init global module stuff
- mp_module_init();
+ // init global module dict
+ mp_obj_dict_init(&MP_STATE_VM(mp_loaded_modules_dict), 3);
// initialise the __main__ module
mp_obj_dict_init(&MP_STATE_VM(dict_main), 1);
@@ -105,6 +105,12 @@ void mp_init(void) {
memset(MP_STATE_VM(fs_user_mount), 0, sizeof(MP_STATE_VM(fs_user_mount)));
#endif
+ #if MICROPY_VFS
+ // initialise the VFS sub-system
+ MP_STATE_VM(vfs_cur) = NULL;
+ MP_STATE_VM(vfs_mount_table) = NULL;
+ #endif
+
#if MICROPY_PY_THREAD_GIL
mp_thread_mutex_init(&MP_STATE_VM(gil_mutex));
#endif
@@ -114,7 +120,7 @@ void mp_init(void) {
void mp_deinit(void) {
//mp_obj_dict_free(&dict_main);
- mp_module_deinit();
+ //mp_map_deinit(&MP_STATE_VM(mp_loaded_modules_map));
// call port specific deinitialization if any
#ifdef MICROPY_PORT_INIT_FUNC
diff --git a/py/showbc.c b/py/showbc.c
index 684d9af0c..9d20decdc 100644
--- a/py/showbc.c
+++ b/py/showbc.c
@@ -82,7 +82,6 @@ const mp_uint_t *mp_showbc_const_table;
void mp_bytecode_print(const void *descr, const byte *ip, mp_uint_t len, const mp_uint_t *const_table) {
mp_showbc_code_start = ip;
- mp_showbc_const_table = const_table;
// get bytecode parameters
mp_uint_t n_state = mp_decode_uint(&ip);
@@ -159,7 +158,7 @@ void mp_bytecode_print(const void *descr, const byte *ip, mp_uint_t len, const m
printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
}
}
- mp_bytecode_print2(ip, len - 0);
+ mp_bytecode_print2(ip, len - 0, const_table);
}
const byte *mp_bytecode_print_str(const byte *ip) {
@@ -547,8 +546,9 @@ const byte *mp_bytecode_print_str(const byte *ip) {
return ip;
}
-void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
+void mp_bytecode_print2(const byte *ip, size_t len, const mp_uint_t *const_table) {
mp_showbc_code_start = ip;
+ mp_showbc_const_table = const_table;
while (ip < len + mp_showbc_code_start) {
printf("%02u ", (uint)(ip - mp_showbc_code_start));
ip = mp_bytecode_print_str(ip);
diff --git a/py/vm.c b/py/vm.c
index 363824e5f..f4cfa2cd6 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -38,8 +38,7 @@
#include "py/bc.h"
#if 0
-//#define TRACE(ip) printf("sp=" INT_FMT " ", sp - code_state->sp); mp_bytecode_print2(ip, 1);
-#define TRACE(ip) printf("sp=%d ", sp - code_state->sp); mp_bytecode_print2(ip, 1);
+#define TRACE(ip) printf("sp=%d ", (int)(sp - code_state->sp)); mp_bytecode_print2(ip, 1, code_state->const_table);
#else
#define TRACE(ip)
#endif