Commit Graph

40 Commits

Author SHA1 Message Date
Damien George 88d7bba961 py: Make it so that printing a small int does not allocate heap memory.
With the implementation of proper string formatting, code to print a
small int was delegated to mpz_as_str_inpl (after first converting the
small int to an mpz using stack memory).  But mpz_as_str_inpl allocates
heap memory to do the conversion, so small ints needed heap memory just
to be printed.

This fix has a separate function to print small ints, which does not
allocate heap, and allocates less stack.

String formatting, printf and pfenv are now large beasts, with some
semi-duplicated code.
2014-04-08 23:30:46 +01:00
Paul Sokolovsky a985b4593d objint: Implement int.from_bytes() class method and .to_bytes() method.
These two are apprerently the most concise and efficient way to convert
int to/from bytes in Python. The alternatives are struct and array modules,
but methods using them are more verbose in Python code and less efficient
in memory/cycles.
2014-04-09 01:07:37 +03:00
Dave Hylands 23dc6d0ace Fix truncation problem when using longlong implementation. 2014-04-07 13:47:04 -07:00
Dave Hylands c4029e5079 Add string formatting support for longlong and mpz. 2014-04-07 11:38:45 -07:00
Damien George ea13f407a3 py: Change nlr_jump to nlr_raise, to aid in debugging.
This does not affect code size or performance when debugging turned off.

To address issue #420.
2014-04-05 18:32:08 +01:00
Damien George e8208a7f02 py: Make False and True act like 0 and 1 for integer arithmetic. 2014-04-04 15:08:23 +01:00
Damien George 660aef67c4 py: Allow multiple of str/list/tuple on left by an integer. 2014-04-02 12:22:07 +01:00
Damien George 6433bd927a py: Add explicit conversion from float to int via int(). 2014-03-30 23:13:16 +01:00
Damien George 3e1a5c10c5 py: Rename old const type objects to mp_type_* for consistency. 2014-03-29 13:43:38 +00:00
Damien George eabdf6718a py: Add function to convert long int to float. 2014-03-22 20:54:01 +00:00
xbe efe3422394 py: Clean up includes.
Remove unnecessary includes. Add includes that improve portability.
2014-03-17 02:43:40 -07:00
Damien George 9d68e9ccdd py: Implement integer overflow checking for * and << ops.
If operation will overflow, a multi-precision integer is created.
2014-03-12 15:38:15 +00:00
Damien George 438c88dd2f Add arbitrary precision integer support.
Some functionality is still missing (eg and, or, bit shift), and some
things are buggy (eg subtract).
2014-02-22 19:25:23 +00:00
Damien George 2077397118 py: Put number parsing code together in parsenum.c. 2014-02-22 18:12:43 +00:00
Damien George 2613ffde43 py: Rename strtonum to mp_strtonum.
strtonum clashes with BSD function of same name, and our version is
different so warrants a unique name.  Addresses Issue #305.
2014-02-22 17:49:15 +00:00
Damien George 0379b55ab0 py: Fix casting and printing of small int. 2014-02-22 17:34:09 +00:00
Damien George c5966128c7 Implement proper exception type hierarchy.
Each built-in exception is now a type, with base type BaseException.
C exceptions are created by passing a pointer to the exception type to
make an instance of.  When raising an exception from the VM, an
instance is created automatically if an exception type is raised (as
opposed to an exception instance).

Exception matching (RT_BINARY_OP_EXCEPTION_MATCH) is now proper.

Handling of parse error changed to match new exceptions.

mp_const_type renamed to mp_type_type for consistency.
2014-02-15 16:10:44 +00:00
Damien George a71c83a1d1 Change mp_obj_type_t.name from const char * to qstr.
Ultimately all static strings should be qstr.  This entry in the type
structure is only used for printing error messages (to tell the type of
the bad argument), and printing objects that don't supply a .print method.
2014-02-15 11:34:50 +00:00
Damien George 099a9cb575 Remove mp_obj_new_exception_msg_1_arg and _2_arg. 2014-02-12 23:02:19 +00:00
Paul Sokolovsky d5df6cd44a Replace global "static" -> "STATIC", to allow "analysis builds". Part 1.
Some tools do not support local/static symbols (one example is GNU ld map file).
Exposing all functions will allow to do detailed size comparisons, etc.

Also, added bunch of statics where they were missing, and replaced few identity
functions with global mp_identity().
2014-02-12 18:21:11 +02:00
Damien George 698ec21e46 Make mp_obj_str_get_data return char* instead of byte*.
Can't decide which is better for string type, char or byte pointer.
Changing to char removes a few casts.  Really need to do proper unicode.
2014-02-08 18:17:23 +00:00
Paul Sokolovsky 9b00dad7bb long int: Implement more operations. 2014-01-27 12:25:23 +02:00
Damien George 5fa93b6755 Second stage of qstr revamp: uPy str object can be qstr or not. 2014-01-22 14:35:10 +00:00
Damien George 55baff4c9b Revamp qstrs: they now include length and hash.
Can now have null bytes in strings.  Can define ROM qstrs per port using
qstrdefsport.h
2014-01-21 21:40:13 +00:00
Damien George 632cf5710c Merge branch 'master' of github.com:dpgeorge/micropython 2014-01-18 14:15:48 +00:00
Paul Sokolovsky d26b379eec int: Add value accessors: mp_obj_int_get() & mp_obj_int_get_checked().
mp_obj_int_get() can be used when just full resolution of C machine_int_t
is required (returns truncated value of long int). mp_obj_int_get_checked()
will throw exception if Python int value not representable in machine_int_t.
2014-01-18 16:12:12 +02:00
Damien George 20006dbba9 Make VM stack grow upwards, and so no reversed args arrays.
Change state layout in VM so the stack starts at state[0] and grows
upwards.  Locals are at the top end of the state and number downwards.
This cleans up a lot of the interface connecting the VM to C: now all
functions that take an array of Micro Python objects are in order (ie no
longer in reverse).

Also clean up C API with keyword arguments (call_n and call_n_kw
replaced with single call method that takes keyword arguments).  And now
make_new takes keyword arguments.

emitnative.c has not yet been changed to comply with the new order of
stack layout.
2014-01-18 14:10:48 +00:00
Paul Sokolovsky 166bb40fb2 Add OverflowError and use it for small int overflow instead of assert. 2014-01-18 12:46:43 +02:00
Damien George 5573f9f150 Merge branch 'str2int' of github.com:xyb/micropython into xyb-str2int
Conflicts:
	py/objint.c
	unix-cpy/Makefile
	unix/Makefile
2014-01-15 22:58:39 +00:00
xyb 3e4ed25138 add more tests and remove debug code 2014-01-15 20:37:17 +08:00
Paul Sokolovsky 76d982ef34 type->print(): Distinguish str() and repr() variety by passing extra param. 2014-01-15 02:15:38 +02:00
xyb 82e61bdc24 support int(str, basbase) 2014-01-14 22:43:18 +08:00
xyb c178ea471e Implemented int(str) in UNIX 2014-01-14 21:39:05 +08:00
Paul Sokolovsky 76a90f2f60 Move mp_obj_int_t definition to objint.h, to reuse in long int impls. 2014-01-13 22:36:49 +02:00
Damien George 2300537c79 Cleanup built-ins, and fix some compiler warnings/errors. 2014-01-13 19:39:01 +00:00
Paul Sokolovsky 48b3572f7e Add framework to support alternative implementations of long int Python type. 2014-01-12 22:04:21 +02:00
Damien George 97209d38e1 Merge branch 'cplusplus' of https://github.com/ian-v/micropython into ian-v-cplusplus
Conflicts:
	py/objcomplex.c
2014-01-07 15:58:30 +00:00
ian-v 7a16fadbf8 Co-exist with C++ (issue #85) 2014-01-06 09:52:29 -08:00
Paul Sokolovsky 860ffb0a43 Convert many object types structs to use C99 tagged initializer syntax. 2014-01-05 22:34:09 +02:00
Damien George 45b43c21c4 Oops: add objint.c 2014-01-05 01:50:45 +00:00