summaryrefslogtreecommitdiff
path: root/py/misc.h
AgeCommit message (Collapse)Author
2016-12-27cc3200: Re-add support for UART REPL (MICROPY_STDIO_UART setting).Paul Sokolovsky
UART REPL support was lost in os.dupterm() refactorings, etc. As os.dupterm() is there, implement UART REPL support at the high level - if MICROPY_STDIO_UART is set, make default boot.py contain os.dupterm() call for a UART. This means that changing MICROPY_STDIO_UART value will also require erasing flash on a module to force boot.py re-creation.
2016-12-27py/misc.h: Typo fix in comment.Paul Sokolovsky
2016-10-14py/vstr: Combine vstr_new_size with vstr_new since they are rarely used.Damien George
Now there is just one function to allocate a new vstr, namely vstr_new (in addition to vstr_init etc). The caller of this function should know what initial size to allocate for the buffer, or at least have some policy or config option, instead of leaving it to a default (as it was before).
2016-09-19py/vstr: Remove vstr.had_error flag and inline basic vstr functions.Damien George
The vstr.had_error flag was a relic from the very early days which assumed that the malloc functions (eg m_new, m_renew) returned NULL if they failed to allocate. But that's no longer the case: these functions will raise an exception if they fail. Since it was impossible for had_error to be set, this patch introduces no change in behaviour. An alternative option would be to change the malloc calls to the _maybe variants, which return NULL instead of raising, but then a lot of code will need to explicitly check if the vstr had an error and raise if it did. The code-size savings for this patch are, in bytes: bare-arm:188, minimal:456, unix(NDEBUG,x86-64):368, stmhal:228, esp8266:360.
2016-02-17py/repl: Check for an identifier char after the keyword.Alex March
- As described in the #1850. - Add cmdline tests.
2015-12-08py/misc.h: Include stdint.h only once (unconditionally at the top).Paul Sokolovsky
2015-12-07py/misc.h: Include stdint.h, as large share of code now depends on it.Paul Sokolovsky
2015-11-29py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George
This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
2015-07-14py: Improve allocation policy of qstr data.Damien George
Previous to this patch all interned strings lived in their own malloc'd chunk. On average this wastes N/2 bytes per interned string, where N is the number-of-bytes for a quanta of the memory allocator (16 bytes on 32 bit archs). With this patch interned strings are concatenated into the same malloc'd chunk when possible. Such chunks are enlarged inplace when possible, and shrunk to fit when a new chunk is needed. RAM savings with this patch are highly varied, but should always show an improvement (unless only 3 or 4 strings are interned). New version typically uses about 70% of previous memory for the qstr data, and can lead to savings of around 10% of total memory footprint of a running script. Costs about 120 bytes code size on Thumb2 archs (depends on how many calls to gc_realloc are made).
2015-05-20extmod: Add ubinascii.unhexlifyDave Hylands
This also pulls out hex_digit from py/lexer.c and makes unichar_hex_digit
2015-04-16py: Overhaul and simplify printf/pfenv mechanism.Damien George
Previous to this patch the printing mechanism was a bit of a tangled mess. This patch attempts to consolidate printing into one interface. All (non-debug) printing now uses the mp_print* family of functions, mainly mp_printf. All these functions take an mp_print_t structure as their first argument, and this structure defines the printing backend through the "print_strn" function of said structure. Printing from the uPy core can reach the platform-defined print code via two paths: either through mp_sys_stdout_obj (defined pert port) in conjunction with mp_stream_write; or through the mp_plat_print structure which uses the MP_PLAT_PRINT_STRN macro to define how string are printed on the platform. The former is only used when MICROPY_PY_IO is defined. With this new scheme printing is generally more efficient (less layers to go through, less arguments to pass), and, given an mp_print_t* structure, one can call mp_print_str for efficiency instead of mp_printf("%s", ...). Code size is also reduced by around 200 bytes on Thumb2 archs.
2015-03-03py: Add MICROPY_MALLOC_USES_ALLOCATED_SIZE to allow simpler malloc API.Damien George
2015-01-29py: Change vstr_null_terminate -> vstr_null_terminated_str, returns str.Damien George
2015-01-28py: Change vstr so that it doesn't null terminate buffer by default.Damien George
This cleans up vstr so that it's a pure "variable buffer", and the user can decide whether they need to add a terminating null byte. In most places where vstr is used, the vstr did not need to be null terminated and so this patch saves code size, a tiny bit of RAM, and makes vstr usage more efficient. When null termination is needed it must be done explicitly using vstr_null_terminate.
2015-01-28py: Be more precise about unicode type and disabled unicode behaviour.Damien George
2015-01-24py: Move mp_float_t related defines to misc.hDavid Steinberg
2015-01-21py: Remove mp_obj_str_builder and use vstr instead.Damien George
With this patch str/bytes construction is streamlined. Always use a vstr to build a str/bytes object. If the size is known beforehand then use vstr_init_len to allocate only required memory. Otherwise use vstr_init and the vstr will grow as needed. Then use mp_obj_new_str_from_vstr to create a str/bytes object using the vstr memory. Saves code ROM: 68 bytes on stmhal, 108 bytes on bare-arm, and 336 bytes on unix x64.
2015-01-21py: Add mp_obj_new_str_from_vstr, and use it where relevant.Damien George
This patch allows to reuse vstr memory when creating str/bytes object. This improves memory usage. Also saves code ROM: 128 bytes on stmhal, 92 bytes on bare-arm, and 88 bytes on unix x64.
2014-12-29py: Add include guards to mpconfig,misc,qstr,obj,runtime,parsehelper.Damien George
2014-10-09py: Add further checks for failed malloc in lexer init functions.Damien George
2014-09-28Fix error: unknown type name 'size_t'bvernoux
2014-09-25py: For malloc and vstr functions, use size_t exclusively for int type.Damien George
It seems most sensible to use size_t for measuring "number of bytes" in malloc and vstr functions (since that's what size_t is for). We don't use mp_uint_t because malloc and vstr are not Micro Python specific.
2014-07-12py: Add generic helper to align a pointer.Paul Sokolovsky
2014-07-03Rename machine_(u)int_t to mp_(u)int_t.Damien George
See discussion in issue #50.
2014-06-28py: Make unichar_charlen() accept/return machine_uint_t.Paul Sokolovsky
2014-06-28py: Small comments, name changes, use of machine_int_t.Damien George
2014-06-27misc: Add count_lead_ones() function, useful for UTF-8 handling.Paul Sokolovsky
2014-06-27py: Implement basic unicode functions.Chris Angelico
2014-06-19Prefix ARRAY_SIZE with micropython prefix MP_Emmanuel Blot
2014-06-14unicode: Add trivial implementation of unichar_charlen().Paul Sokolovsky
2014-06-14unicode: String API is const byte*.Paul Sokolovsky
We still have that char vs byte dichotomy, but majority of string operations now use byte.
2014-05-31add methods isspace(), isalpha(), isdigit(), isupper() and islower() to strKim Bauters
2014-05-10objstr: Implement .lower() and .upper().Paul Sokolovsky
2014-05-10py: Improve handling of memory error in parser.Damien George
Parser shouldn't raise exceptions, so needs to check when memory allocation fails. This patch does that for the initial set up of the parser state. Also, we now put the parser object on the stack. It's small enough to go there instead of on the heap. This partially addresses issue #558.
2014-05-05py, unix: Add -v option, print bytecode dump if used.Paul Sokolovsky
This will work if MICROPY_DEBUG_PRINTERS is defined, which is only for unix/windows ports. This makes it convenient to user uPy normally, but easily get bytecode dump on the spot if needed, without constant recompiles back and forth. TODO: Add more useful debug output, adjust verbosity level on which specifically bytecode dump happens.
2014-05-03Add license header to (almost) all files.Damien George
Blanket wide to all .c and .h files. Some files originating from ST are difficult to deal with (license wise) so it was left out of those. Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
2014-04-26Add ARRAY_SIZE macro, and use it where possible.Damien George
2014-04-10py: Check explicitly for memory allocation failure in parser.Damien George
Previously, a failed malloc/realloc would throw an exception, which was not caught. I think it's better to keep the parser free from NLR (exception throwing), hence this patch.
2014-04-10py: Add emergency exception object for when heap allocation fails.Damien George
2014-04-05Improve GC finalisation code; add option to disable it.Damien George
2014-04-05Merge pull request #425 from iabdalkader/delDamien George
Implement del
2014-04-04py: Add m_malloc_fail function to handle memory allocation error.Damien George
A malloc/realloc fail now throws MemoryError.
2014-04-03Implement delmux
2014-04-02py: Wrap compile_scope_inline_asm in #if; remove comment from misc.h.Damien George
2014-03-15Add vstr_ins and vstr_cut_out; improve stmhal readline.Damien George
2014-02-26py: Take out bitfield entries from their own structure.Damien George
Don't need to wrap bitfields in their own struct. Compiler does the correct thing without it.
2014-02-22py: Rename strtonum to mp_strtonum.Damien George
strtonum clashes with BSD function of same name, and our version is different so warrants a unique name. Addresses Issue #305.
2014-02-16Make DEBUG_printf() a proper function, implementation is port-dependent.Paul Sokolovsky
In particular, unix outputs to stderr, to allow to run testsuite against micropython built with debug output (by redirecting stderr to /dev/null).
2014-02-06Implement fixed buffer vstrs; use them for import path.Damien George
2014-02-05Search paths properly on import and execute __init__.py if it exists.Damien George