Commit Graph

115 Commits

Author SHA1 Message Date
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
c203324e6c objarray: Refactor to use array accessors from binary.c . 2014-02-14 20:38:46 +02: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
c1d9bbc345 Implement __bool__ and __len__ via unary_op virtual method for all types.
__bool__() and __len__() are just the same as __neg__() or __invert__(),
and require efficient dispatching implementation (not requiring search/lookup).
type->unary_op() is just the right choice for this short of adding
standalone virtual method(s) to already big mp_obj_type_t structure.
2014-01-30 04:37:19 +02:00
Paul Sokolovsky
7f11c794a5 mp_obj_new_bytearray_by_ref(): Allow to create array by reference.
This is special feature for FFI.
2014-01-29 00:21:41 +02:00
Paul Sokolovsky
1801421f6d bytearray: Print objects properly. 2014-01-28 03:40:48 +02:00
Paul Sokolovsky
7e652af242 array: CPython prints empty arrays inconsistently (only typecode, no []). 2014-01-28 03:19:13 +02:00
Paul Sokolovsky
11973b48b5 array.array: Allow to create empty arrays. 2014-01-28 03:18:30 +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
Paul Sokolovsky
09ce05996a array: Implement iterator. 2014-01-21 23:59:50 +02:00
Paul Sokolovsky
33996685df Add len() support for arrays. 2014-01-21 23:59:50 +02: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
427905cedd Add skeleton implementation of array.array and bytearray.
So far, only storage, initialization, repr() and buffer protocol is
implemented - alredy suitable for passing binary data around.
2014-01-18 19:27:38 +02:00