Paul Sokolovsky
a47b64ae2d
objstringio: Implement io.BytesIO.
...
Done in generalized manner, allowing any stream class to be specified as
working with bytes.
2014-05-15 07:28:19 +03:00
Paul Sokolovsky
2a27365854
objstr.c: Partial implementation of .rsplit().
...
sep=None is TODO.
2014-05-14 02:42:20 +03:00
Paul Sokolovsky
da9f0924ef
py, unix: Add copyright for modules I worked closely on.
2014-05-13 18:41:25 +03:00
Paul Sokolovsky
5ebd5f0f19
objstr: Slice indexing: support bytes properly.
2014-05-11 21:22:59 +03:00
Paul Sokolovsky
bfb8819c0c
objstr: Make .split() support bytes.
2014-05-11 21:17:28 +03:00
Paul Sokolovsky
5e5d69b35e
objstr: Make .join() support bytes.
2014-05-11 21:13:01 +03:00
Paul Sokolovsky
eea0118654
py: Give up and make mp_obj_str_get_data() deal with bytes too.
...
This is not fully correct re: error handling, because we should check that
that types are used consistently (only str's or only bytes), but magically
makes lot of functions support bytes.
2014-05-11 13:51:24 +03:00
Paul Sokolovsky
b2d4fc06fc
objstr: Make *strip() accept bytes.
2014-05-11 13:17:29 +03:00
Paul Sokolovsky
69f3eb2c96
objstr: Make .[r]partition() work with bytes.
2014-05-11 03:33:19 +03:00
Paul Sokolovsky
d915a52eb6
py: Fix prefix on few sequence helpers, was incorrectly "mp_".
2014-05-10 21:36:33 +03:00
Paul Sokolovsky
6913521911
objstr: Implement .lower() and .upper().
2014-05-10 19:49:07 +03:00
Damien George
d0a5bf34f7
py: Tidy up returning NULL which should be MP_OBJ_NOT_SUPPORTED.
2014-05-10 13:55:11 +01:00
Paul Sokolovsky
7b0f9a7d9b
bytes: Implement comparison and other binary operations.
...
Should support everything supported by strings.
2014-05-10 04:45:02 +03:00
Paul Sokolovsky
b473d0ae86
py: bytes(), str(): Add NotImplementedError for kwargs.
...
Addresses #567 .
2014-05-06 19:31:58 +03:00
Damien George
04b9147e15
Add license header to (almost) all files.
...
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-05-03 23:27:38 +01:00
Paul Sokolovsky
f54bcbf099
py, unix: Make "mpconfig.h" be first included, as other headers depend on it.
...
Specifically, nlr.h does.
2014-05-02 17:48:40 +03:00
Paul Sokolovsky
e908591baa
py: Abstract no-return attribute for functions a bit.
2014-04-30 05:35:18 +03:00
Paul Sokolovsky
e14d096cb7
objstr: Optimize .rstrip() by scanning string from end.
2014-04-26 06:48:31 +03:00
Paul Sokolovsky
881078403e
objstr: Implement .lstrip() & .rstrip().
...
Share code with .strip(). TODO: optimize .rstrip().
2014-04-26 06:20:08 +03:00
Paul Sokolovsky
504e23388c
objstr: Init hash in mp_obj_str_builder_start() to 0.
2014-04-19 03:21:06 +03:00
Damien George
57a4b4f178
py: Add typecode to buffer protocol.
...
When querying an object that supports the buffer protocol, that object
must now return a typecode (as per binary.[ch]). This does not have to
be honoured by the caller, but can be useful for determining element
size.
2014-04-18 22:29:21 +01:00
Damien George
ea8d06c39d
py: Add MP_OBJ_STOP_ITERATION and make good use of it.
...
Also make consistent use of MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL.
This helps a lot in debugging and understanding of function API.
2014-04-17 23:19:36 +01:00
Damien George
729f7b42d6
py: Merge BINARY_OP_SUBSCR and store_subscr (w/ delete) into subscr.
...
mp_obj_t->subscr now does load/store/delete.
2014-04-17 22:10:53 +01:00
Damien George
ee01411036
py: Add len(bytes).
2014-04-15 23:10:00 +01:00
Damien George
897fe0c0d0
py: Add builtin functions bin and oct, and some tests for them.
2014-04-15 22:03:55 +01:00
Damien George
3bb8bd899b
Make USE_COMPUTED_GOTO a config option in mpconfig.h.
...
Disabled by default. Enabled in unix port.
2014-04-14 21:20:30 +01:00
Paul Sokolovsky
58676fc2c7
objstr: Allow to define statically allocated str objects.
...
Similar to tuples, lists, dicts. Statically allocated strings don't have hash
computed.
2014-04-14 01:45:06 +03:00
Paul Sokolovsky
59e269cfec
qstr, objstr: Make sure that valid hash != 0, treat 0 as "not computed".
...
This feature was proposed with initial hashing RFC, and is prerequisite for
seamless static str object definition.
2014-04-14 01:43:01 +03:00
Paul Sokolovsky
f130ca1f60
py: Make bytes type hashable.
2014-04-13 06:45:12 +03:00
Paul Sokolovsky
73b7027b83
objstr: Add str.encode() and bytes.decode() methods.
...
These largely duplicate str() & bytes() constructors' functionality,
but can be used to achieve Python2 compatibility.
2014-04-13 06:45:02 +03:00
Damien George
a9ddd6d9df
py: Simplify and improve mp_get_index.
...
It has (again) a fast path for ints, and a simplified "slow" path for
everything else.
Also simplify the way str indexing is done (now matches tuple and list).
2014-04-11 10:40:38 +00:00
Paul Sokolovsky
881d9af05e
objstr: Add TODO-optimize for using .join with arbitrary iterable.
2014-04-10 01:42:40 +03:00
Damien George
038fd52faa
Merge branch 'str-index' of github.com:xbe/micropython into xbe-str-index
2014-04-09 20:44:37 +01:00
Damien George
b5fbd0ba87
py: Add mp_obj_is_integer; make mp_get_index check for long int.
...
mp_obj_is_integer should be used to check if an object is of integral
type. It returns true for bool, small int and long int.
2014-04-09 19:55:33 +01:00
Damien George
a157e4caba
py: str.join can now take arbitrary iterable as argument.
2014-04-09 19:17:53 +01:00
xbe
3d9a39e211
py: Implement str.[r]index() and add tests for them.
2014-04-08 11:51:41 -07:00
xbe
729be9b3c7
py: Update comment in str.replace().
2014-04-08 11:25:32 -07:00
Paul Sokolovsky
7a70a3ae9a
bytes: Support buffer protocol.
2014-04-08 19:08:34 +03:00
Andrew Scheller
12968fb6b2
Display \r and \t escape codes in string repr
2014-04-08 02:42:50 +01:00
Damien George
a12a0f78b0
py: Rename pfenv_print_int to pfenv_print_mp_int, and add back former.
...
stmhal relies on pfenv_* to implement its printf. Thus, it needs a
pfenv_print_int which prints a proper 32-bit integer. With latest
change to pfenv, this function became one that took mp_obj_t, and
extracted the integer value from that object.
To fix temporarily, pfenv_print_int has been renamed to
pfenv_print_mp_int (to indicate it takes a mp_obj_t for the int), and
pfenv_print_int has been added (which takes a normal C int). Currently,
pfenv_print_int proxies to pfenv_print_mp_int, but this means it looses
the MSB. Need to find a way to fix this, but the only way I can think
of will duplicate lots of code.
2014-04-08 01:29:53 +01:00
Dave Hylands
c4029e5079
Add string formatting support for longlong and mpz.
2014-04-07 11:38:45 -07:00
Damien George
ff715429ea
py: Fix str.replace for case when arg 0 or 1 is empty string.
2014-04-07 00:39:13 +01:00
Damien George
deed087e2c
py: str.split: handle non-default separator.
2014-04-06 11:11:15 +01: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
Dave Hylands
f81a49e464
Allow floating point arguments with %d,i,u,o,x,X formats
2014-04-05 08:26:51 -07:00
Dave Hylands
6756a37a77
Implements most of str.modulo
...
The alternate form for floating point doesn't work yet.
The %(name)s form doesn't work yet.
2014-04-03 23:55:02 -07:00
Damien George
cc7085c1ce
Merge branch 'fix-format-int' of github.com:dhylands/micropython into dhylands-fix-format-int
...
Conflicts:
py/objstr.c
2014-04-02 20:37:05 +01:00
Dave Hylands
22fe4d7344
Fix str.format to work with {:f/g/e} and ints
...
Also fix objstr.c to compile when floats disabled.
2014-04-02 12:10:18 -07:00
Damien George
c322c5f07f
py: Fix regress for printing of floats and #if.
...
Also change formating modifier in test script (it still passes with
original format though).
2014-04-02 20:04:15 +01:00
Damien George
70f33cde48
py: Fix up so that it can compile without float.
2014-04-02 17:06:05 +01:00
Dave Hylands
baf6f14deb
Enhance str.format support
...
This adds support for almost everything (the comma isn't currently
supported).
The "unspecified" type with floats also doesn't behave exactly like
python.
Tested under unix with float and double
Spot tested on stmhal
2014-04-01 01:17:33 -07:00
Paul Sokolovsky
4db727afea
objstr: Very basic implementation of % string formatting operator.
2014-03-31 21:20:52 +03:00
Damien George
15d18069c5
py: Remove old "run time" functions that were 1 liners.
2014-03-31 16:28:13 +01:00
Paul Sokolovsky
f7eaf605c0
py: Fix "TypeError: 'iterator' object is not iterable", doh.
2014-03-30 23:37:24 +03:00
Damien George
df6567e634
Merge map.h into obj.h.
...
Pretty much everyone needs to include map.h, since it's such an integral
part of the Micro Python object implementation. Thus, the definitions
are now in obj.h instead. map.h is removed.
2014-03-30 13:54:02 +01:00
Damien George
d17926db71
Rename rt_* to mp_*.
...
Mostly just a global search and replace. Except rt_is_true which
becomes mp_obj_is_true.
Still would like to tidy up some of the names, but this will do for now.
2014-03-30 13:35:08 +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
07ddab529c
py: Change mp_const_* objects to macros.
...
Addresses issue #388 .
2014-03-29 13:15:08 +00:00
Damien George
9b196cddab
Remove mp_obj_type_t.methods entry and use .locals_dict instead.
...
Originally, .methods was used for methods in a ROM class, and
locals_dict for methods in a user-created class. That distinction is
unnecessary, and we can use locals_dict for ROM classes now that we have
ROMable maps.
This removes an entry in the bloated mp_obj_type_t struct, saving a word
for each ROM object and each RAM object. ROM objects that have a
methods table (now a locals_dict) need an extra word in total (removed
the methods pointer (1 word), no longer need the sentinel (2 words), but
now need an mp_obj_dict_t wrapper (4 words)). But RAM objects save a
word because they never used the methods entry.
Overall the ROM usage is down by a few hundred bytes, and RAM usage is
down 1 word per user-defined type/class.
There is less code (no need to check 2 tables), and now consistent with
the way ROM modules have their tables initialised.
Efficiency is very close to equivaluent.
2014-03-26 21:47:19 +00:00
Damien George
c12b2213c1
Change mp_method_t.name from const char * to qstr.
...
Addresses issue #377 .
2014-03-26 20:15:40 +00:00
Damien George
66eaf84b8c
py: Replace mp_const_stop_iteration object with MP_OBJ_NULL.
2014-03-26 19:27:58 +00:00
xbe
17a5a83fb4
Implement str.rfind() and add tests for it.
2014-03-24 01:00:00 -07:00
xbe
8562de6c48
py/objstr.c: Remove done TODOs.
2014-03-23 22:56:21 -07:00
Paul Sokolovsky
1ecea7c753
py: Make 'bytes' be a proper type, support standard constructor args.
2014-03-22 00:07:04 +02:00
Paul Sokolovsky
be020c27a8
py: Make 'str' be a proper type, support standard constructor args.
2014-03-22 00:07:04 +02:00
Paul Sokolovsky
5972b4c05f
objstr: Switch from in-object string data to ptr to separate memory area.
...
This is pre-requisite for having efficient implementation of str<->bytes
conversion, and having that efficient is required with unfortunare
str vs bytes dichotomy in Python3.
2014-03-22 00:07:04 +02:00
Damien George
b035db355a
py: Make str.[r]partition more efficient.
2014-03-21 20:39:40 +00:00
xbe
0a6894c24b
str.(r)partition: factor out duplicate code.
...
Switch str.rpartition to search from left to right. Factor the
duplicate code into one helper function.
2014-03-21 03:17:09 -07:00
xbe
4504ea8007
Implement str.rpartition and add tests for it.
2014-03-21 02:58:09 -07:00
xbe
613a8e3edf
Implement str.partition and add tests for it.
2014-03-21 02:57:18 -07:00
xbe
c55388823f
objstr.c: Replace size_t with machine_uint_t.
2014-03-17 02:43:50 -07: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
536dde254b
py: In string.count, handle case of zero-length needle.
2014-03-13 22:07:55 +00:00
xbe
c5d70ba48b
Fix issues in str.count implementation.
...
See pull request #343 .
2014-03-13 00:33:07 -07:00
xbe
9e1e8cd642
Implement str.count and add tests for it.
...
Also modify mp_get_index to accept:
1. Indices that are or evaluate to a boolean.
2. Slice indices.
Add tests for these two cases.
2014-03-12 22:57:16 -07:00
Damien George
2da9830b92
py: Make objstr support buffer protocol (read only).
2014-03-09 19:58:18 +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
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
Paul Sokolovsky
4e2460852a
objstr: Mark few local symbols as static, cleanup codestyle.
...
Please don't submit patches with tab indentation!
2014-02-11 15:34:32 +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
ea2509d92c
Fix assert() usage.
2014-02-02 08:58:16 +02:00
Paul Sokolovsky
87e85b7dc7
Implement str/bytes rich comparisons.
2014-02-02 08:58:16 +02:00
Paul Sokolovsky
7364af2d8c
Factor out m_seq_get_fast_slice_indexes() fucntions as sequence helper.
...
Takes slice object and sequence length and computes subsequence indexes
for case of slice step=1.
2014-02-02 02:38:22 +02:00
Damien George
9aa2a527b5
py: Tidy up BINARY_OPs; negation done by special NOT bytecode.
...
IS_NOT and NOT_IN are now compiled to IS + NOT and IN + NOT, with a new
special NOT bytecode.
2014-02-01 23:04:09 +00:00
Damien George
94f68300f9
py: Make str.replace do 2 passes over the string.
2014-01-31 23:45:12 +00:00
xbe
480c15afb5
Implement str.replace and add tests for it.
2014-01-30 22:17:30 -08:00
Paul Sokolovsky
0b7e29c025
Factor out quoted string print function for reuse (mp_str_print_quoted()).
2014-01-28 03:40:06 +02:00
Damien George
b829b5caec
Implement mp_parse_node_free; print properly repr(string).
2014-01-25 13:51:19 +00:00
Damien George
7c9c667633
py: Implement iterator support for object that has __getitem__.
...
Addresses Issue #203 .
2014-01-25 00:17:36 +00:00
Paul Sokolovsky
91fb1c9b13
Add basic implementation of bytes type, piggybacking on str.
...
This reuses as much str implementation as possible, from this we
can make them more separate as needed.
2014-01-24 22:56:26 +02:00
Damien George
1e708fed18
py: Implement bool unary op; tidy up unary op dispatch.
2014-01-23 18:27:51 +00:00
Paul Sokolovsky
1eacefe5bc
Implement simplest case of str.startswith().
2014-01-23 02:47:10 +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
12eaccacda
Merge branch 'master' of github.com:micropython/micropython
...
Conflicts:
py/objstr.c
py/py.mk
py/stream.c
unix/main.c
unix/socket.c
2014-01-21 21:54:15 +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
Paul Sokolovsky
4c316552c1
Implement str.split(None).
...
Note that splitting by explicit string is not implemented so far.
2014-01-21 05:01:21 +02:00
Paul Sokolovsky
7380a83780
str: Implement proper string (instead of byte string) indexing.
...
Also, support negative indexes.
2014-01-21 02:25:59 +02:00
Paul Sokolovsky
545591a696
Implement string multiplication.
2014-01-21 00:39:12 +02:00
Paul Sokolovsky
8965a5eb1e
objstr: More support for MP_OBJ_QSTR.
2014-01-20 23:34:17 +02:00