Skip to content

Commit

Permalink
Update to latest MicroPython core, v1.7-9.
Browse files Browse the repository at this point in the history
Main changes are:

- nested str formatting with {}
- complete bignum support for negative args to and/or/xor
- fix for failed map reallocation
- improved float formatting, and fixes for buffer overflows
- inline asm funcs can take 4 args, and specify a return type
  • Loading branch information
dpgeorge committed Apr 18, 2016
1 parent 616b4da commit 1e1ea9d
Show file tree
Hide file tree
Showing 57 changed files with 1,214 additions and 377 deletions.
10 changes: 5 additions & 5 deletions inc/genhdr/mpversion.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// This file was generated by py/makeversionhdr.py
#define MICROPY_GIT_TAG "v1.6-11-gfa67b52"
#define MICROPY_GIT_HASH "fa67b52"
#define MICROPY_BUILD_DATE "2016-02-01"
#define MICROPY_GIT_TAG "v1.7-9-gbe020eb"
#define MICROPY_GIT_HASH "be020eb"
#define MICROPY_BUILD_DATE "2016-04-18"
#define MICROPY_VERSION_MAJOR (1)
#define MICROPY_VERSION_MINOR (6)
#define MICROPY_VERSION_MINOR (7)
#define MICROPY_VERSION_MICRO (0)
#define MICROPY_VERSION_STRING "1.6.0"
#define MICROPY_VERSION_STRING "1.7.0"
37 changes: 33 additions & 4 deletions inc/genhdr/qstrdefs.generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,39 @@ QDEF(MP_QSTR_label, (const byte*)"\x43\x05" "label")
QDEF(MP_QSTR_align, (const byte*)"\xa8\x05" "align")
QDEF(MP_QSTR_data, (const byte*)"\x15\x04" "data")
QDEF(MP_QSTR_uint, (const byte*)"\xe3\x04" "uint")
QDEF(MP_QSTR_nop, (const byte*)"\xb4\x03" "nop")
QDEF(MP_QSTR_mov, (const byte*)"\xf1\x03" "mov")
QDEF(MP_QSTR_and_, (const byte*)"\x91\x04" "and_")
QDEF(MP_QSTR_cmp, (const byte*)"\x3b\x03" "cmp")
QDEF(MP_QSTR_add, (const byte*)"\x44\x03" "add")
QDEF(MP_QSTR_sub, (const byte*)"\x21\x03" "sub")
QDEF(MP_QSTR_lsl, (const byte*)"\xb6\x03" "lsl")
QDEF(MP_QSTR_lsr, (const byte*)"\xa8\x03" "lsr")
QDEF(MP_QSTR_asr, (const byte*)"\x65\x03" "asr")
QDEF(MP_QSTR_ldr, (const byte*)"\x5f\x03" "ldr")
QDEF(MP_QSTR_ldrb, (const byte*)"\x5d\x04" "ldrb")
QDEF(MP_QSTR_ldrh, (const byte*)"\x57\x04" "ldrh")
QDEF(MP_QSTR_str, (const byte*)"\x50\x03" "str")
QDEF(MP_QSTR_strb, (const byte*)"\x32\x04" "strb")
QDEF(MP_QSTR_strh, (const byte*)"\x38\x04" "strh")
QDEF(MP_QSTR_b, (const byte*)"\xc7\x01" "b")
QDEF(MP_QSTR_bl, (const byte*)"\xcb\x02" "bl")
QDEF(MP_QSTR_bx, (const byte*)"\xdf\x02" "bx")
QDEF(MP_QSTR_push, (const byte*)"\xbb\x04" "push")
QDEF(MP_QSTR_pop, (const byte*)"\x2a\x03" "pop")
QDEF(MP_QSTR_cpsid, (const byte*)"\xe8\x05" "cpsid")
QDEF(MP_QSTR_cpsie, (const byte*)"\xe9\x05" "cpsie")
QDEF(MP_QSTR_wfi, (const byte*)"\x9d\x03" "wfi")
QDEF(MP_QSTR_clz, (const byte*)"\x50\x03" "clz")
QDEF(MP_QSTR_rbit, (const byte*)"\xe8\x04" "rbit")
QDEF(MP_QSTR_movw, (const byte*)"\x66\x04" "movw")
QDEF(MP_QSTR_movt, (const byte*)"\x65\x04" "movt")
QDEF(MP_QSTR_movwt, (const byte*)"\x52\x05" "movwt")
QDEF(MP_QSTR_mrs, (const byte*)"\x89\x03" "mrs")
QDEF(MP_QSTR_sdiv, (const byte*)"\xcd\x04" "sdiv")
QDEF(MP_QSTR_udiv, (const byte*)"\x8b\x04" "udiv")
QDEF(MP_QSTR_ldrex, (const byte*)"\xe2\x05" "ldrex")
QDEF(MP_QSTR_strex, (const byte*)"\xad\x05" "strex")
QDEF(MP_QSTR_builtins, (const byte*)"\xf7\x08" "builtins")
QDEF(MP_QSTR_Ellipsis, (const byte*)"\xf0\x08" "Ellipsis")
QDEF(MP_QSTR_StopIteration, (const byte*)"\xea\x0d" "StopIteration")
Expand Down Expand Up @@ -149,7 +182,6 @@ QDEF(MP_QSTR_sorted, (const byte*)"\x5e\x06" "sorted")
QDEF(MP_QSTR_staticmethod, (const byte*)"\x62\x0c" "staticmethod")
QDEF(MP_QSTR_sum, (const byte*)"\x2e\x03" "sum")
QDEF(MP_QSTR_super, (const byte*)"\xc4\x05" "super")
QDEF(MP_QSTR_str, (const byte*)"\x50\x03" "str")
QDEF(MP_QSTR_sys, (const byte*)"\xbc\x03" "sys")
QDEF(MP_QSTR_to_bytes, (const byte*)"\xd8\x08" "to_bytes")
QDEF(MP_QSTR_tuple, (const byte*)"\xfd\x05" "tuple")
Expand All @@ -167,7 +199,6 @@ QDEF(MP_QSTR_fromkeys, (const byte*)"\x37\x08" "fromkeys")
QDEF(MP_QSTR_get, (const byte*)"\x33\x03" "get")
QDEF(MP_QSTR_items, (const byte*)"\xe3\x05" "items")
QDEF(MP_QSTR_keys, (const byte*)"\x01\x04" "keys")
QDEF(MP_QSTR_pop, (const byte*)"\x2a\x03" "pop")
QDEF(MP_QSTR_popitem, (const byte*)"\xbf\x07" "popitem")
QDEF(MP_QSTR_setdefault, (const byte*)"\x6c\x0a" "setdefault")
QDEF(MP_QSTR_update, (const byte*)"\xb4\x06" "update")
Expand All @@ -189,7 +220,6 @@ QDEF(MP_QSTR_rstrip, (const byte*)"\x3b\x06" "rstrip")
QDEF(MP_QSTR_format, (const byte*)"\x26\x06" "format")
QDEF(MP_QSTR_key, (const byte*)"\x32\x03" "key")
QDEF(MP_QSTR_reverse, (const byte*)"\x25\x07" "reverse")
QDEF(MP_QSTR_add, (const byte*)"\x44\x03" "add")
QDEF(MP_QSTR_find, (const byte*)"\x01\x04" "find")
QDEF(MP_QSTR_rfind, (const byte*)"\xd2\x05" "rfind")
QDEF(MP_QSTR_rindex, (const byte*)"\xe9\x06" "rindex")
Expand Down Expand Up @@ -516,7 +546,6 @@ QDEF(MP_QSTR_a_colon_1, (const byte*)"\x0f\x03" "a:1")
QDEF(MP_QSTR_a_colon_2, (const byte*)"\x0c\x03" "a:2")
QDEF(MP_QSTR_a_colon_4, (const byte*)"\x0a\x03" "a:4")
QDEF(MP_QSTR_a_colon_5, (const byte*)"\x0b\x03" "a:5")
QDEF(MP_QSTR_b, (const byte*)"\xc7\x01" "b")
QDEF(MP_QSTR_b2_colon_1, (const byte*)"\xde\x04" "b2:1")
QDEF(MP_QSTR_b3, (const byte*)"\x94\x02" "b3")
QDEF(MP_QSTR_b4, (const byte*)"\x93\x02" "b4")
Expand Down
1 change: 1 addition & 0 deletions inc/lib/utils/pyexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int pyexec_file(const char *filename);
int pyexec_frozen_module(const char *name);
void pyexec_event_repl_init(void);
int pyexec_event_repl_process_char(int c);
extern uint8_t pyexec_repl_active;

MP_DECLARE_CONST_FUN_OBJ(pyb_set_repl_info_obj);

Expand Down
1 change: 1 addition & 0 deletions inc/py/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ extern const mp_obj_module_t mp_module_urandom;
extern const mp_obj_module_t mp_module_ussl;
extern const mp_obj_module_t mp_module_machine;
extern const mp_obj_module_t mp_module_lwip;
extern const mp_obj_module_t mp_module_websocket;

// extmod functions
MP_DECLARE_CONST_FUN_OBJ(pyb_mount_obj);
Expand Down
4 changes: 2 additions & 2 deletions inc/py/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ typedef struct _emit_method_table_t {
void (*break_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
void (*continue_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
void (*setup_with)(emit_t *emit, mp_uint_t label);
void (*with_cleanup)(emit_t *emit);
void (*with_cleanup)(emit_t *emit, mp_uint_t label);
void (*setup_except)(emit_t *emit, mp_uint_t label);
void (*setup_finally)(emit_t *emit, mp_uint_t label);
void (*end_finally)(emit_t *emit);
Expand Down Expand Up @@ -227,7 +227,7 @@ void mp_emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_dept
#define mp_emit_bc_break_loop mp_emit_bc_unwind_jump
#define mp_emit_bc_continue_loop mp_emit_bc_unwind_jump
void mp_emit_bc_setup_with(emit_t *emit, mp_uint_t label);
void mp_emit_bc_with_cleanup(emit_t *emit);
void mp_emit_bc_with_cleanup(emit_t *emit, mp_uint_t label);
void mp_emit_bc_setup_except(emit_t *emit, mp_uint_t label);
void mp_emit_bc_setup_finally(emit_t *emit, mp_uint_t label);
void mp_emit_bc_end_finally(emit_t *emit);
Expand Down
2 changes: 1 addition & 1 deletion inc/py/grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ DEF_RULE(factor_2, c(factor_2), and(2), rule(factor_op), rule(factor))
DEF_RULE(factor_op, nc, or(3), tok(OP_PLUS), tok(OP_MINUS), tok(OP_TILDE))
DEF_RULE(power, c(power), and(3), rule(atom), opt_rule(power_trailers), opt_rule(power_dbl_star))
DEF_RULE(power_trailers, c(power_trailers), one_or_more, rule(trailer))
DEF_RULE(power_dbl_star, c(power_dbl_star), and(2), tok(OP_DBL_STAR), rule(factor))
DEF_RULE(power_dbl_star, nc, ident | and(2), tok(OP_DBL_STAR), rule(factor))

// atom: '(' [yield_expr|testlist_comp] ')' | '[' [testlist_comp] ']' | '{' [dictorsetmaker] '}' | NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False'
// testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
Expand Down
1 change: 1 addition & 0 deletions inc/py/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ bool unichar_isalpha(unichar c);
bool unichar_isprint(unichar c);
bool unichar_isdigit(unichar c);
bool unichar_isxdigit(unichar c);
bool unichar_isident(unichar c);
bool unichar_isupper(unichar c);
bool unichar_islower(unichar c);
unichar unichar_tolower(unichar c);
Expand Down
45 changes: 45 additions & 0 deletions inc/py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,20 @@
#define MICROPY_ENABLE_COMPILER (1)
#endif

// Whether the compiler is dynamically configurable (ie at runtime)
#ifndef MICROPY_DYNAMIC_COMPILER
#define MICROPY_DYNAMIC_COMPILER (0)
#endif

// Configure dynamic compiler macros
#if MICROPY_DYNAMIC_COMPILER
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC (mp_dynamic_compiler.opt_cache_map_lookup_in_bytecode)
#define MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC (mp_dynamic_compiler.py_builtins_str_unicode)
#else
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE_DYNAMIC MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE
#define MICROPY_PY_BUILTINS_STR_UNICODE_DYNAMIC MICROPY_PY_BUILTINS_STR_UNICODE
#endif

// Whether to enable constant folding; eg 1+2 rewritten as 3
#ifndef MICROPY_COMP_CONST_FOLDING
#define MICROPY_COMP_CONST_FOLDING (1)
Expand Down Expand Up @@ -342,9 +356,31 @@
#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (0)
#endif

// Whether to use fast versions of bitwise operations (and, or, xor) when the
// arguments are both positive. Increases Thumb2 code size by about 250 bytes.
#ifndef MICROPY_OPT_MPZ_BITWISE
#define MICROPY_OPT_MPZ_BITWISE (0)
#endif

/*****************************************************************************/
/* Python internal features */

// Hook for the VM at the start of the opcode loop (can contain variable
// definitions usable by the other hook functions)
#ifndef MICROPY_VM_HOOK_INIT
#define MICROPY_VM_HOOK_INIT
#endif

// Hook for the VM during the opcode loop (but only after jump opcodes)
#ifndef MICROPY_VM_HOOK_LOOP
#define MICROPY_VM_HOOK_LOOP
#endif

// Hook for the VM just before return opcode is finished being interpreted
#ifndef MICROPY_VM_HOOK_RETURN
#define MICROPY_VM_HOOK_RETURN
#endif

// Whether to include the garbage collector
#ifndef MICROPY_ENABLE_GC
#define MICROPY_ENABLE_GC (0)
Expand Down Expand Up @@ -711,6 +747,11 @@ typedef double mp_float_t;
#define MICROPY_PY_IO_BYTESIO (1)
#endif

// Whether to provide "io.BufferedWriter" class
#ifndef MICROPY_PY_IO_BUFFEREDWRITER
#define MICROPY_PY_IO_BUFFEREDWRITER (0)
#endif

// Whether to provide "struct" module
#ifndef MICROPY_PY_STRUCT
#define MICROPY_PY_STRUCT (1)
Expand Down Expand Up @@ -800,6 +841,10 @@ typedef double mp_float_t;
#define MICROPY_PY_USSL (0)
#endif

#ifndef MICROPY_PY_WEBSOCKET
#define MICROPY_PY_WEBSOCKET (0)
#endif

/*****************************************************************************/
/* Hooks for a port to add builtins */

Expand Down
15 changes: 15 additions & 0 deletions inc/py/mpstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
// memory system, runtime and virtual machine. The state is a global
// variable, but in the future it is hoped that the state can become local.

// This structure contains dynamic configuration for the compiler.
#if MICROPY_DYNAMIC_COMPILER
typedef struct mp_dynamic_compiler_t {
uint8_t small_int_bits; // must be <= host small_int_bits
bool opt_cache_map_lookup_in_bytecode;
bool py_builtins_str_unicode;
} mp_dynamic_compiler_t;
extern mp_dynamic_compiler_t mp_dynamic_compiler;
#endif

// This structure hold information about the memory allocation system.
typedef struct _mp_state_mem_t {
#if MICROPY_MEM_STATS
Expand Down Expand Up @@ -132,6 +142,11 @@ 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];
#endif

//
// END ROOT POINTER SECTION
////////////////////////////////////////////////////////////
Expand Down
18 changes: 5 additions & 13 deletions inc/py/obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ typedef mp_obj_t (*mp_fun_1_t)(mp_obj_t);
typedef mp_obj_t (*mp_fun_2_t)(mp_obj_t, mp_obj_t);
typedef mp_obj_t (*mp_fun_3_t)(mp_obj_t, mp_obj_t, mp_obj_t);
typedef mp_obj_t (*mp_fun_var_t)(size_t n, const mp_obj_t *);
// mp_fun_kw_t takes mp_map_t* (and not const mp_map_t*) to ease passing
// this arg to mp_map_lookup().
typedef mp_obj_t (*mp_fun_kw_t)(size_t n, const mp_obj_t *, mp_map_t *);

typedef enum {
Expand Down Expand Up @@ -452,7 +454,7 @@ typedef struct _mp_buffer_info_t {
//int ver; // ?

void *buf; // can be NULL if len == 0
mp_uint_t len; // in bytes
size_t len; // in bytes
int typecode; // as per binary.h

// Rationale: to load arbitrary-sized sprites directly to LCD
Expand All @@ -469,7 +471,6 @@ bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);

// Stream protocol
#define MP_STREAM_ERROR ((mp_uint_t)-1)
typedef struct _mp_stream_p_t {
// On error, functions should return MP_STREAM_ERROR and fill in *errcode (values
// are implementation-dependent, but will be exposed to user, e.g. via exception).
Expand All @@ -479,17 +480,6 @@ typedef struct _mp_stream_p_t {
mp_uint_t is_text : 1; // default is bytes, set this for text stream
} mp_stream_p_t;

// Stream ioctl request codes
#define MP_STREAM_FLUSH (1)
#define MP_STREAM_SEEK (2)
#define MP_STREAM_POLL (3)

// Argument structure for MP_STREAM_SEEK
struct mp_stream_seek_t {
mp_off_t offset;
int whence;
};

struct _mp_obj_type_t {
mp_obj_base_t base;
qstr name;
Expand Down Expand Up @@ -737,6 +727,8 @@ mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs);
// complex
void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); // can return MP_OBJ_NULL if op not supported
#else
#define mp_obj_is_float(o) (false)
#endif

// tuple
Expand Down
1 change: 1 addition & 0 deletions inc/py/objstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_u

const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, size_t self_len,
mp_obj_t index, bool is_slice);
const byte *find_subbytes(const byte *haystack, mp_uint_t hlen, const byte *needle, mp_uint_t nlen, mp_int_t direction);

MP_DECLARE_CONST_FUN_OBJ(str_encode_obj);
MP_DECLARE_CONST_FUN_OBJ(str_find_obj);
Expand Down
6 changes: 2 additions & 4 deletions inc/py/parsenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
#include "py/lexer.h"
#include "py/obj.h"

mp_uint_t mp_parse_num_base(const char *str, mp_uint_t len, mp_uint_t *base);

// these functions raise a SyntaxError if lex!=NULL, else a ValueError
mp_obj_t mp_parse_num_integer(const char *restrict str, mp_uint_t len, mp_uint_t base, mp_lexer_t *lex);
mp_obj_t mp_parse_num_decimal(const char *str, mp_uint_t len, bool allow_imag, bool force_complex, mp_lexer_t *lex);
mp_obj_t mp_parse_num_integer(const char *restrict str, size_t len, int base, mp_lexer_t *lex);
mp_obj_t mp_parse_num_decimal(const char *str, size_t len, bool allow_imag, bool force_complex, mp_lexer_t *lex);

#endif // __MICROPY_INCLUDED_PY_PARSENUM_H__
8 changes: 4 additions & 4 deletions inc/py/parsenumbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __MICROPY_INCLUDED_PY_PARSENUM_H__
#define __MICROPY_INCLUDED_PY_PARSENUM_H__
#ifndef __MICROPY_INCLUDED_PY_PARSENUMBASE_H__
#define __MICROPY_INCLUDED_PY_PARSENUMBASE_H__

#include "py/mpconfig.h"

mp_uint_t mp_parse_num_base(const char *str, mp_uint_t len, mp_uint_t *base);
size_t mp_parse_num_base(const char *str, size_t len, int *base);

#endif // __MICROPY_INCLUDED_PY_PARSENUM_H__
#endif // __MICROPY_INCLUDED_PY_PARSENUMBASE_H__

0 comments on commit 1e1ea9d

Please sign in to comment.