summaryrefslogtreecommitdiff
path: root/py/obj.h
AgeCommit message (Collapse)Author
2015-09-03py: Inline single use of mp_obj_str_get_len in mp_obj_len_maybe.Damien George
Gets rid of redundant double check for string type. Also remove obsolete declaration of mp_obj_str_get_hash.
2015-07-02py: Add TimeoutError exception subclassed from OSError.Daniel Campora
The TimeoutError is useful for some modules, specially the the socket module. TimeoutError can then be alised to socket.timeout and then Python code can differentiate between socket.error and socket.timeout.
2015-06-13py: Add MP_BINARY_OP_DIVMOD to simplify and consolidate divmod builtin.Damien George
2015-05-17py: Change _mp_obj_fun_builtin_t.fun to function pointer.Kaspar Schleiser
ISO C forbids conversion between function pointers and void*, gcc -pedantic triggers a warning.
2015-05-12py: Add mp_obj_get_int_truncated and use it where appropriate.Damien George
mp_obj_get_int_truncated will raise a TypeError if the argument is not an integral type. Use mp_obj_int_get_truncated only when you know the argument is a small or big int.
2015-05-12py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.Damien George
Hashing is now done using mp_unary_op function with MP_UNARY_OP_HASH as the operator argument. Hashing for int, str and bytes still go via fast-path in mp_unary_op since they are the most common objects which need to be hashed. This lead to quite a bit of code cleanup, and should be more efficient if anything. It saves 176 bytes code space on Thumb2, and 360 bytes on x86. The only loss is that the error message "unhashable type" is now the more generic "unsupported type for __hash__".
2015-05-05objsingleton: New home for Ellipsis and NotImplemented.Paul Sokolovsky
Having NotImplemented as MP_OBJ_SENTINEL turned out to be problematic (it needs to be checked for in a lot of places, otherwise it'll crash as would pass MP_OBJ_IS_OBJ()), so made a proper singleton value like Ellipsis, both of them sharing the same type.
2015-04-20py: Make viper codegen raise proper exception (ViperTypeError) on error.Damien George
This fixes a long standing problem that viper code generation gave terrible error messages, and actually no errors on pyboard where assertions are disabled. Now all compile-time errors are raised as proper Python exceptions, and are of type ViperTypeError. Addresses issue #940.
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-04-11py: Combine load_attr and store_attr type methods into one (attr).Damien George
This simplifies the API for objects and reduces code size (by around 400 bytes on Thumb2, and around 2k on x86). Performance impact was measured with Pystone score, but change was barely noticeable.
2015-04-07py: Implement full func arg passing for native emitter.Damien George
This patch gets full function argument passing working with native emitter. Includes named args, keyword args, default args, var args and var keyword args. Fully Python compliant. It reuses the bytecode mp_setup_code_state function to do all the hard work. This function is slightly adjusted to accommodate native calls, and the native emitter is forced a bit to emit similar prelude and code-info as bytecode.
2015-04-04py: Some trivial cosmetic changes, for code style consistency.Damien George
2015-04-03py: Allow configurable object representation, with 2 different options.Damien George
2015-03-25py: Cast mp_obj_t to concrete types explicitly.Paul Sokolovsky
mp_obj_t internal representation doesn't have to be a pointer to object, it can be anything. There's also a support for back-conversion in the form of MP_OBJ_UNCAST. This is kind of optimization/status quo preserver to minimize patching the existing code and avoid doing potentially expensive MP_OBJ_CAST over and over. But then one may imagine implementations where MP_OBJ_UNCAST is very expensive. But such implementations are unlikely interesting in practice.
2015-03-20py: Allow retrieving a function's __name__.stijn
Disabled by default. Enabled on unix and stmhal ports.
2015-03-20py: Clarify API for map/set lookup when removing&adding at once.Damien George
Addresses issue #1160.
2015-03-20py: Implement core of OrderedDict type.Paul Sokolovsky
Given that there's already support for "fixed table" maps, which are essentially ordered maps, the implementation of OrderedDict just extends "fixed table" maps by adding an "is ordered" flag and add/remove operations, and reuses 95% of objdict code, just making methods tolerant to both dict and OrderedDict. Some things are missing so far, like CPython-compatible repr and comparison. OrderedDict is Disabled by default; enabled on unix and stmhal ports.
2015-03-06objmemoryview: Introduce mp_obj_new_memoryview().Paul Sokolovsky
This follows existing pattern for object constructor API and allows to create memoryview objects e.g. in external modules.
2015-02-27objarray: Implement array slice assignment.Paul Sokolovsky
This is rarely used feature which takes enough code to implement, so is controlled by MICROPY_PY_ARRAY_SLICE_ASSIGN config setting, default off. But otherwise it may be useful, as allows to update arbitrary-sized data buffers in-place. Slice is yet to implement, and actually, slice assignment implemented in such a way that RHS of assignment should be array of the exact same item typecode as LHS. CPython has it more relaxed, where RHS can be any sequence of compatible types (e.g. it's possible to assign list of int's to a bytearray slice). Overall, when all "slice write" features are implemented, it may cost ~1KB of code.
2015-02-23py: Implement UnicodeError.Paul Sokolovsky
Still too shy to implement UnicodeEncodeError which was really needed for micropython-lib case.
2015-02-21py: Expose mp_obj_list_remove as a public function.Damien George
2015-02-15py: Simplify and remove redundant code for __iter__ method lookup.Damien George
2015-02-08py: Add MICROPY_OBJ_BASE_ALIGNMENT to help with 16-bit ports.Damien George
2015-01-25py: Check for NDEBUG using #ifdef rather than #if.Damien George
Defining NDEBUG (to any value, even 0) disables debugging. Otherwise, if it's not defined, debugging is enabled.
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.
2015-01-16py, unix: Allow to compile with -Wsign-compare.Damien George
See issue #699.
2015-01-11py: Remove unnecessary BINARY_OP_EQUAL code that just checks pointers.Damien George
Previous patch c38dc3ccc76d1a9bf867704f43ea5d15da3fea7b allowed any object to be compared with any other, using pointer comparison for a fallback. As such, existing code which checked for this case is no longer needed.
2014-12-30py: mp_obj_new_int_from_float() supported only for MICROPY_PY_BUILTINS_FLOAT.Paul Sokolovsky
2014-12-30py: Partially fix float to int conversion.Paul Sokolovsky
This fixes conversion when float type has more mantissa bits than small int, and float value has small exponent. This is for example the case of 32-bit platform using doubles, and converting value of time.time(). Conversion of floats with larg exponnet is still not handled correctly.
2014-12-29py: Add include guards to mpconfig,misc,qstr,obj,runtime,parsehelper.Damien George
2014-12-10py: Tidy up a few function declarations.Damien George
2014-12-09py: Allow builtins to be overridden.Damien George
This patch adds a configuration option (MICROPY_CAN_OVERRIDE_BUILTINS) which, when enabled, allows to override all names within the builtins module. A builtins override dict is created the first time the user assigns to a name in the builtins model, and then that dict is searched first on subsequent lookups. Note that this implementation doesn't allow deleting of names. This patch also does some refactoring of builtins code, creating the modbuiltins.c file. Addresses issue #959.
2014-12-08modsys: Add sys.print_exception(exc, file=sys.stdout) function.Paul Sokolovsky
The function is modeled after traceback.print_exception(), but unbloated, and put into existing module to save overhead on adding another module. Compliant traceback.print_exception() is intended to be implemented in micropython-lib in terms of sys.print_exception(). This change required refactoring mp_obj_print_exception() to take pfenv_t interface arguments. Addresses #751.
2014-12-05py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.Damien George
mp_obj_int_get_truncated is used as a "fast path" int accessor that doesn't check for overflow and returns the int truncated to the machine word size, ie mp_int_t. Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word sized values. Addresses issues #779 and #998.
2014-11-29Use MP_DEFINE_CONST_DICT macro to define module dicts.Damien George
This is just a clean-up of the code. Generated code is exactly the same.
2014-11-27map: Add empty fixed map.Paul Sokolovsky
Useful when need to call kw-receiving functions without any keywords from C, etc.
2014-11-17stream: Implement seek operation support via ioctl, wrapped in generic method.Paul Sokolovsky
Also, implement for unix port.
2014-11-17stream: Convert .ioctl() to take fixed number of args.Paul Sokolovsky
This is more efficient, as allows to use register calling convention. If needed, a structure pointer can be passed as argument to pass more data.
2014-10-25py: Add mp_pending_exception global variable, for VM soft interrupt.Damien George
This allows to implement KeyboardInterrupt on unix, and a much safer ctrl-C in stmhal port. First ctrl-C is a soft one, with hope that VM will notice it; second ctrl-C is a hard one that kills anything (for both unix and stmhal). One needs to check for a pending exception in the VM only for jump opcodes. Others can't produce an infinite loop (infinite recursion is caught by stack check).
2014-10-25py: Factor out mp_obj_is_package() function.Paul Sokolovsky
2014-10-25py: Store bytecode arg names in bytecode (were in own array).Damien George
This saves a lot of RAM for 2 reasons: 1. For functions that don't have default values, var args or var kw args (which is a large number of functions in the general case), the mp_obj_fun_bc_t type now fits in 1 GC block (previously needed 2 because of the extra pointer to point to the arg_names array). So this saves 16 bytes per function (32 bytes on 64-bit machines). 2. Combining separate memory regions generally saves RAM because the unused bytes at the end of the GC block are saved for 1 of the blocks (since that block doesn't exist on its own anymore). So generally this saves 8 bytes per function. Tested by importing lots of modules: - 64-bit Linux gave about an 8% RAM saving for 86k of used RAM. - pyboard gave about a 6% RAM saving for 31k of used RAM.
2014-10-23py: Add builtin memoryview object (mostly using array code).Damien George
2014-10-22py: Remove unused and unneeded SystemError exception.Damien George
It's purpose is for internal errors that are not catastrophic (ie not as bad as RuntimeError). Since we don't use it, we don't need it.
2014-10-21py: Make mp_const_empty_bytes globally available.Damien George
2014-10-03py: Convert [u]int to mp_[u]int_t where appropriate.Damien George
Addressing issue #50.
2014-09-30py: Remove IOError since it's deprecated; use OSError instead.Damien George
In CPython IOError (and EnvironmentError) is deprecated and aliased to OSError. All modules that used to raise IOError now raise OSError (or a derived exception). In Micro Python we never used IOError (except 1 place, incorrectly) and so don't need to keep it. See http://legacy.python.org/dev/peps/pep-3151/ for background.
2014-09-25py: Tidy up exception matching; allow matching of tuple of exceptions.Damien George
Addresses issue #864.
2014-09-17py: Add native json printing using existing print framework.Damien George
Also add start of ujson module with dumps implemented. Enabled in unix and stmhal ports. Test passes on both.
2014-09-13py: Implement divmod, % and proper // for floating point.Damien George
Tested and working on unix and pyboard.