Commit Graph

52 Commits

Author SHA1 Message Date
Damien George
2323ef9182 py: Rename globally-accessible tuple functions, prefix with mp_obj_.
Likely there are other functions that should be renamed, but this is a
start.
2014-05-11 18:00:45 +01: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
91e556af23 objexcept: Support tracebacks for user Exception subclasses. 2014-05-02 02:31:30 +03:00
Paul Sokolovsky
d8351ca8a0 objtype: .print() Exception instances in adhoc way.
This is ugly, just as expected.
2014-05-02 02:00:47 +03:00
Paul Sokolovsky
1acf22f17b objexcept: Don't store args tuple within exception object.
To avoid pointer-to-field GC problem.
2014-04-23 04:07:00 +03:00
Paul Sokolovsky
dec31bb872 objexcept: Add mp_obj_new_exception_arg1() convenience function. 2014-04-22 00:02:51 +03:00
Damien George
58ba4c3b4c py: Check explicitly for memory allocation failure in parser.
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-10 14:27:31 +00:00
Damien George
f0954e3fac py: Add emergency exception object for when heap allocation fails. 2014-04-10 14:38:25 +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
Damien George
6902eeda25 py: Add m_malloc_fail function to handle memory allocation error.
A malloc/realloc fail now throws MemoryError.
2014-04-04 10:52:59 +00:00
Paul Sokolovsky
a96d3d0840 objexcept: No more magic messages in exceptions, only exception arguments.
One of the reason for separate "message" (besides still unfulfilled desire to
optimize memory usage) was apparent special handling of exception with
messages by CPython. Well, the message is still just an exception argument,
it just printed specially. Implement that with PRINT_EXC printing format.
2014-03-31 02:23:56 +03: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
Paul Sokolovsky
24a140a444 objexcept: Fix another place missing proper args tuple initialization. 2014-03-30 13:29:33 +03:00
Damien George
07ddab529c py: Change mp_const_* objects to macros.
Addresses issue #388.
2014-03-29 13:15:08 +00:00
Paul Sokolovsky
c4d589e2bb objgenerator: close(): Throw instance of GeneratorExit (not type).
To comply with Python semantics and allow use of mp_obj_is_subclass_fast()
for exception matching.
2014-03-28 02:40:26 +02:00
Damien George
c63f984647 py: Thin out predefined exceptions.
Only exceptions that are actually used are left prefedined.  Hierarchy
is still there, and removed exceptions are just commented out.
2014-03-27 23:49:06 +00:00
Damien George
9c817b9465 Merge branch 'master' of github.com:micropython/micropython 2014-03-26 18:56:02 +00:00
Damien George
752ba554cc Merge branch 'gen-close-ret-val' of github.com:pfalcon/micropython into pfalcon-gen-close-ret-val 2014-03-26 18:46:06 +00:00
Damien George
9e6e935df0 py: Add support for user-defined iterators via __iter__, __next__. 2014-03-26 18:37:06 +00:00
Paul Sokolovsky
af1ae30399 objexcept: Add mp_obj_exception_get_value() convenience function.
This gets "value" of exceptions in the sense as it's defined for
StopIteration.value (i.e. args[0] or None).

TODO: This really should be inline function.
2014-03-26 19:29:36 +02:00
Paul Sokolovsky
962b1cd1b1 objgenerator: Implement return with value and .close() method.
Return with value gets converted to StopIteration(value). Implementation
keeps optimizing against creating of possibly unneeded exception objects,
so there're considerable refactoring to implement these features.
2014-03-26 15:40:58 +02:00
Damien George
ffb5cfc8d8 py: Removed some unnecessary exception objects.
They still exist in commented-out form in objexcept.c if they are ever
needed.
2014-03-25 14:29:40 +00:00
Paul Sokolovsky
9512e9e817 objexcept: Add "args" exception attribute, as well as StopIteration.value. 2014-03-25 01:42:01 +02:00
Damien George
c91097223d py: Remove some unnecessary exception objects. 2014-03-22 23:40:02 +00:00
Rachel Dowdall
721c55dced Added exception hierarchy except for OSError and UnicodeError (requires arguments). Comment out the errors that aren't needed if memory becomes an issue. 2014-03-22 15:28:16 +00:00
Rachel Dowdall
300c8bd4c2 Added ZeroDivisionError to float division. 2014-03-20 22:40:38 +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
0ec6bd47cb py: Fix printing of type name. 2014-03-09 16:29:36 +00:00
Damien George
c8f78bc280 py: VM never throws an exception, instead returns a status and value.
Addresses issue #290, and hopefully sets up things to allow generators
throwing exceptions, etc.
2014-02-15 22:55:00 +00:00
Damien George
22a0865d54 py: Improve exception bases, reduces ROM usage.
Thanks to @pfalcon for the tip!
2014-02-15 21:05:25 +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
60a0d3f1db objexcept: Fix a case of initialized object field. 2014-02-15 00:29:50 +02: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
Paul Sokolovsky
027594e1a7 Typo fixes in comments. 2014-01-31 19:47:23 +02:00
Damien George
1ba1facaaa py: Msg in exception is no longer interned. 2014-01-29 18:57:20 +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
136b149e41 py: Add full traceback to exception printing. 2014-01-19 12:38:49 +00:00
Damien George
cbd2f7482c py: Add module/function/class name to exceptions.
Exceptions know source file, line and block name.

Also tidy up some debug printing functions and provide a global
flag to enable/disable them.
2014-01-19 11:48:48 +00:00
Damien George
08335004cf Add source file name and line number to error messages.
Byte code has a map from byte-code offset to source-code line number,
used to give better error messages.
2014-01-18 23:24:36 +00: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
76d982ef34 type->print(): Distinguish str() and repr() variety by passing extra param. 2014-01-15 02:15:38 +02:00
Paul Sokolovsky
ddf2178d83 Refactor exception objects to have better impl of Python-side interface.
This implements internal args tuple of arguments, while still keeping
object useful for reporting C-side errors.

Further elaboration is needed.
2014-01-15 00:03:23 +02:00
Damien George
6c73ca1e75 py: add variable argument exception constructor function.
Addresses issue #104.
2014-01-08 18:11:23 +00: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
71c5181a8d Convert Python types to proper Python type hierarchy.
Now much more inline with how CPython does types.
2014-01-04 20:21:15 +00:00