Wykres commitów

225 Commity (48ffd6596e7a4c185a81be233b46d3c99a83a7ac)

Autor SHA1 Wiadomość Data
Damien George 56606f3475 py: Implement delete for property and descriptors.
Without this patch deleting a property, or class with descriptor, will
call the setter with a NULL value and lead to a crash.
2015-04-04 20:15:31 +01:00
Damien George 2801e6fad8 py: Some trivial cosmetic changes, for code style consistency. 2015-04-04 15:53:11 +01:00
Paul Sokolovsky 1bc534247c objtype: Add special unary methods __pos__, __neg__, __invert__.
Conditional on MICROPY_PY_ALL_SPECIAL_METHODS.
2015-03-31 01:05:03 +03:00
stijn 28fa84b445 py: Add optional support for descriptors' __get__ and __set__ methods.
Disabled by default.  Enabled on unix and windows ports.
2015-03-26 23:55:14 +00:00
Damien George 55b74d1ff5 py: Combine duplicated code that converts members from a lookup.
Despite initial guess, this code factoring does not hamper performance.
In fact it seems to improve speed by a little: running pystone(1.2) on
pyboard (which gives a very stable result) this patch takes pystones
from 1729.51 up to 1742.16.  Also, pystones on x64 increase by around
the same proportion (but it's much noisier).

Taking a look at the generated machine code, stack usage with this patch
is unchanged, and call is tail-optimised with all arguments in
registers.  Code size decreases by about 50 bytes on Thumb2 archs.
2015-03-21 14:21:54 +00:00
Paul Sokolovsky 3425431370 objtype: More comment clarification for attribute lookup. 2015-03-20 00:51:55 +02:00
Paul Sokolovsky 1954d8021f objtype: Clarify comment why we call mp_load_method_maybe() for native sub-obj. 2015-03-17 02:08:08 +02:00
Paul Sokolovsky 3cb766344d objtype: Refactor dealing with native sub-objects for clarity. 2015-03-16 14:00:01 +02:00
Paul Sokolovsky f0dc0d50e3 objtype: mp_obj_class_lookup: Remove implausible condition.
We already have branch for lookup->is_type == true, so here it's guaranteed
to be false.
2015-03-16 13:41:57 +02:00
Paul Sokolovsky 2b67a40fdb objtype: Clarify comment for mp_obj_class_lookup(). 2015-03-16 13:36:58 +02:00
Paul Sokolovsky 66c11ec581 objtype: Clarify code by consistently using common subexpression. 2015-03-16 13:36:58 +02:00
Paul Sokolovsky e06cf89f04 py: Add few more special methods. 2015-02-22 01:21:08 +02:00
Damien George f6532bb9e0 py: Simplify and remove redundant code for __iter__ method lookup. 2015-02-15 01:10:13 +00:00
stijn 1b8e76b8e6 py: Cleanup duplication in instance_is_callable/instance_call. 2015-02-14 23:49:04 +00:00
Damien George d0df10b2c6 py: Don't unnecessarily create a bound method. 2015-02-09 16:59:15 +00:00
Damien George 48244044a2 py: Allow subclass of native object to delegate to the native buffer_p.
Addresses issue #1109.
2015-02-09 15:08:00 +00:00
Damien George 5f97aaeca4 py: Fix instance lookup, since object is not a real type. 2015-02-08 00:42:13 +00:00
Paul Sokolovsky 98c4bc3fac py: Add MICROPY_PY_ALL_SPECIAL_METHODS and __iadd__ special method under it. 2015-01-31 00:35:56 +02:00
Damien George a5efcd4745 py: Specify unary/binary op name in TypeError error message.
Eg, "() + 1" now tells you that __add__ is not supported for tuple and
int types (before it just said the generic "binary operator").  We reuse
the table of names for slot lookup because it would be a waste of code
space to store the pretty name for each operator.
2015-01-27 18:02:25 +00:00
Damien George 50149a5730 py: Use mp_arg_check_num in some _make_new functions.
Reduces stmhal code size by about 250 bytes.
2015-01-20 14:11:27 +00:00
Damien George ff8dd3f486 py, unix: Allow to compile with -Wunused-parameter.
See issue #699.
2015-01-20 12:47:20 +00:00
Damien George e233a55a29 py: Remove unnecessary BINARY_OP_EQUAL code that just checks pointers.
Previous patch c38dc3ccc7 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.
2015-01-11 21:07:15 +00:00
Damien George c33ecb83ba tests: Add test for when instance member overrides class member. 2015-01-08 17:48:44 +00:00
Damien George 7ee91cf861 py: Add option to cache map lookup results in bytecode.
This is a simple optimisation inspired by JITing technology: we cache in
the bytecode (using 1 byte) the offset of the last successful lookup in
a map. This allows us next time round to check in that location in the
hash table (mp_map_t) for the desired entry, and if it's there use that
entry straight away.  Otherwise fallback to a normal map lookup.

Works for LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR and STORE_ATTR opcodes.

On a few tests it gives >90% cache hit and greatly improves speed of
code.

Disabled by default.  Enabled for unix and stmhal ports.
2015-01-07 21:07:23 +00:00
Damien George 51dfcb4bb7 py: Move to guarded includes, everywhere in py/ core.
Addresses issue #1022.
2015-01-01 20:32:09 +00:00
Paul Sokolovsky 1ee1785bed showbc: Print operation mnemonic in BINARY_OP. 2014-12-28 21:43:44 +02:00
Damien George 1e9a92f84f py: Use shorter, static error msgs when ERROR_REPORTING_TERSE enabled.
Going from MICROPY_ERROR_REPORTING_NORMAL to
MICROPY_ERROR_REPORTING_TERSE now saves 2020 bytes ROM for ARM Thumb2,
and 2200 bytes ROM for 32-bit x86.

This is about a 2.5% code size reduction for bare-arm.
2014-11-06 17:36:16 +00:00
Damien George 7860c2a68a py: Fix some macros defines; cleanup some includes. 2014-11-05 21:16:41 +00:00
Damien George ff319dffad py: Explicitly set uninitialised struct member to false.
Uninitialised struct members get a default value of 0/false, so this is
not strictly needed.  But it actually decreases code size because when
all members are initialised the compiler doesn't need to insert a call
to memset to clear everything.  In other words, setting 1 extra member
to 0 uses less code than calling memset.

ROM savings in bytes: 32-bit unix: 100; bare-arm: 44; stmhal: 52.
2014-11-03 16:18:51 +00:00
Damien George 0344fa1ddf py: Fix builtin callable so it checks user-defined instances correctly.
Addresses issue #953.
2014-11-03 16:09:39 +00:00
Damien George 3aa09f5784 py: Use MP_OBJ_NULL instead of NULL in a few places. 2014-10-23 12:06:53 +01:00
Damien George 9c4cbe2ac0 py: Make tuple and list use mp_int_t/mp_uint_t.
Part of code cleanup, to resolve issue #50.
2014-08-30 14:04:14 +01:00
Damien George ecc88e949c Change some parts of the core API to use mp_uint_t instead of uint/int.
Addressing issue #50, still some way to go yet.
2014-08-30 00:35:11 +01:00
Damien George 779794a680 py: Add dispatch for user defined ==, >, <=, >=.
Addresses issue #827.
2014-08-26 09:31:26 +01:00
Damien George 3c658a4e75 py: Fix bug where GC collected native/viper/asm function data.
Because (for Thumb) a function pointer has the LSB set, pointers to
dynamic functions in RAM (eg native, viper or asm functions) were not
being traced by the GC.  This patch is a comprehensive fix for this.

Addresses issue #820.
2014-08-24 16:28:17 +01:00
Damien George 0182385ab0 py: Automatically ake __new__ a staticmethod.
Addresses issue #622.
2014-07-05 05:55:00 +01:00
Damien George 40f3c02682 Rename machine_(u)int_t to mp_(u)int_t.
See discussion in issue #50.
2014-07-03 13:25:24 +01:00
Damien George 58cbb4d661 py: Implement __contains__ special method. 2014-06-10 23:07:56 +01:00
Paul Sokolovsky 195de3247b objtype: Fix passing of class param to inherited classmethods.
This is getting more and more tangled, but that's old news.
2014-06-08 22:28:44 +03:00
Paul Sokolovsky 639863d36e objtype: Optimize stack usage mp_obj_class_lookup().
As before, instead of pushing constant values on stack again and again, just
pass around pointer to a structure.
2014-06-08 20:50:12 +03:00
Paul Sokolovsky 5473f743f3 objtype: Enable __lt__ method support for instances. 2014-06-08 00:01:46 +03:00
Chris Angelico daf973ae00 Change comments (mainly URLs) to no longer specifically say Python 3.3 2014-06-06 03:51:03 +10:00
Damien George 3f52262465 py: Allow tail call optimisation in mp_call_function_n_kw.
This saves 4 words of stack space per Python call.
2014-06-03 13:40:16 +01:00
Damien George fb510b3bf9 Rename bultins config variables to MICROPY_PY_BUILTINS_*.
This renames:
MICROPY_PY_FROZENSET -> MICROPY_PY_BUILTINS_FROZENSET
MICROPY_PY_PROPERTY -> MICROPY_PY_BUILTINS_PROPERTY
MICROPY_PY_SLICE -> MICROPY_PY_BUILTINS_SLICE
MICROPY_ENABLE_FLOAT -> MICROPY_PY_BUILTINS_FLOAT

See issue #35 for discussion.
2014-06-01 13:32:54 +01:00
Damien George ee3fd46f13 Rename configuration variables controling Python features.
Now of the form MICROPY_PY_*.  See issue #35.
2014-05-24 23:03:12 +01:00
Paul Sokolovsky 806ea1f6ca py: Initial attempts to actually allow implementing __new__ in Python.
Caveat is that __new__ should recurse to base class __new__, and ultimately,
object.__new__ is what handles instance allocation.
2014-05-22 00:32:00 +03:00
Paul Sokolovsky a8408a8abe objtype: super: Fall back to "object" lookup as last resort.
Also, define object.__init__() (semantically empty, purely CPython compat
measure). Addresses #520.
2014-05-21 22:27:03 +03:00
Paul Sokolovsky 6a410789b8 objtype: super: Add stop condition for looking up in base types. 2014-05-21 22:27:03 +03:00
Damien George 6ac5dced24 py: Rename MP_OBJ_NOT_SUPPORTED to MP_OBJ_NULL.
See issue #608 for justification.
2014-05-21 19:42:43 +01:00
Paul Sokolovsky 13684fd60b objtype: Separate __new__ and __init__ methods.
Now schedule is: for native types, we call ->make_new() C-level method, which
should perform actions of __new__ and __init__ (note that this is not
compliant, but is efficient), but for user types, __new__ and __init__ are
called as expected.

Also, make sure we convert scalar attribute value to a bound-pair tight in
mp_obj_class_lookup() method, which avoids converting it again and again in
its callers.
2014-05-19 21:56:06 +03:00
Paul Sokolovsky da9f0924ef py, unix: Add copyright for modules I worked closely on. 2014-05-13 18:41:25 +03:00
Damien George ee7a880d6e py: Use mp_arg_check_num in more places.
Updated functions now do proper checking that n_kw==0, and are simpler
because they don't have to explicitly raise an exception.  Down side is
that the error messages no longer include the function name, but that's
acceptable.

Saves order 300 text bytes on x64 and ARM.
2014-05-11 18:37:21 +01:00
Paul Sokolovsky ea9708092e objtuple: Go out of the way to support comparison of subclasses.
Two things are handled here: allow to compare native subtypes of tuple,
e.g. namedtuple (TODO: should compare type too, currently compared
duck-typedly by content). Secondly, allow user sunclasses of tuples
(and its subtypes) be compared either. "Magic" I did previously in
objtype.c covers only one argument (lhs is many), so we're in trouble
when lhs is native type - there's no other option besides handling
rhs in special manner. Fortunately, this patch outlines approach with
fast path for native types.
2014-05-11 03:33:19 +03:00
Paul Sokolovsky 9511f60f01 py: Don't try to "bind" types store as attributes of objects.
This was hit when trying to make urlparse.py from stdlib run. Took
quite some time to debug.

TODO: Reconsile bound method creation process better, maybe callable is
to generic type to bind at all?
2014-05-11 03:33:19 +03:00
Paul Sokolovsky aa4d19a05c objtype: Comments for duplicating code in runtime.c. 2014-05-10 21:26:08 +03:00
Paul Sokolovsky 1a7403bb74 objtype: Implement ->getiter() method for instances.
Includes support for native bases.
2014-05-10 21:26:08 +03:00
Paul Sokolovsky d86020ac4f objtype: Don't treat inheritance from "object" as from native type.
"object" type in MicroPython currently doesn't implement any methods, and
hopefully, we'll try to stay like that for as long as possible. Even if we
have to add something eventually, look up from there might be handled in
adhoc manner, as last resort (that's not compliant with Python3 MRO, but
we're already non-compliant). Hence: 1) no need to spend type trying to
lookup anything in object; 2) no need to allocate subobject when explicitly
inheriting from object; 3) and having multiple bases inheriting from object
is not a case of incompatible multiple inheritance.
2014-05-10 16:56:20 +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
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
Damien George 9c5fc83e6a py, objtype.c: Rename class_ to instance_ following change of typedef.
This follows up 0a7e01ae3c.
2014-05-03 17:19:35 +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 e0954d426f objtype: Work around stupid strict aliasing check. 2014-05-02 17:48:40 +03:00
Paul Sokolovsky 0a7e01ae3c objtype: Rename mp_obj_class_t -> mp_obj_instance_t and move to local header.
TODO: Rename methods.
2014-05-02 02:14:38 +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 7f0419c0e5 objtype: Support calling normal methods inherited from native base class.
Biggest part of this support is refactoring mp_obj_class_lookup() to return
standard "bound member" pair (mp_obj_t[2]). Actual support of inherited
native methods is 3 lines then. Some inherited features may be not supported
yet (e.g. native class methods, native properties, etc., etc.). There may
be opportunities for further optimization too.
2014-04-30 02:14:30 +03:00
Paul Sokolovsky 443857de98 objtype: Add support for looking up non-method attrs in native base class. 2014-04-29 20:31:13 +03:00
Paul Sokolovsky 6ead0d2fbc objtype: Implement basic framework for subclassing native types.
This implements checking of base types, allocation and basic initialization,
and optimized support for special method lookups. Other features are not yet
supported.
2014-04-29 20:31:13 +03:00
Paul Sokolovsky 755565d2cb py: Support instance __call__ method. 2014-04-25 21:17:42 +03:00
Damien George 806f4aef9a py: Fix super() bug, where it didn't allow instance access.
This is a one-liner fix.  It gets the class-super.py test passing, but
is probably not a complete fix.
2014-04-21 02:11:07 +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
Paul Sokolovsky 75ffcaeace py: Implement __delitem__ method for classes. 2014-04-15 01:30:25 +03:00
Damien George 777b0f32f4 py: Add property object, with basic functionality.
Enabled by MICROPY_ENABLE_PROPERTY.
2014-04-13 18:59:45 +01:00
Damien George f4c9b33abf py: Remove DELETE_SUBSCR opcode, combine with STORE_SUBSCR.
This makes the runtime and object APIs more consistent.  mp_store_subscr
functionality now moved into objects (ie list and dict store_item).
2014-04-08 21:32:29 +01:00
Damien George 1d24ea5207 py: Finish implementation of all del opcodes.
At this point, all opcodes are now implemented!

Some del opcodes have been combined with store opcodes, with the value
to store being MP_OBJ_NULL.
2014-04-08 21:11:49 +01:00
Damien George 17520224fa py: Make all objects and instances derive from object.
This makes isinstance(X, object) and issubclass(X, object) true for all
X.
2014-04-05 22:45:23 +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
Paul Sokolovsky 438d504e27 objtype: Add equality test for type types. 2014-04-05 13:10:56 +03:00
Damien George 93b7faa29a py: Factor out static/class method unwrapping code; add tests. 2014-04-02 14:13:26 +01:00
Damien George e44d26ae0c py: Implement __getattr__.
It's not completely satisfactory, because a failed call to __getattr__
should not raise an exception.

__setattr__ could be implemented, but it would slow down all stores to a
user created object.  Need to implement some caching system.
2014-03-31 22:57:56 +01:00
Paul Sokolovsky b509f73982 objtype: Wrap .__name__ handling in MICROPY_CPYTHON_COMPAT.
Because it's runtime reflection feature, not required for many apps.
Rant time:
Python could really use better str() vs repr() distinction, for example,
repr(type) could be "<class 'foo'>" (as it is now), and str(type) just
"foo". But alas, getting straight name requires adhoc attribute.
2014-03-31 20:40:31 +03:00
Paul Sokolovsky e566670153 objtype: Add virtual __name__ attribute.
It's virtual because it's not shown in dir(...). (That's also how CPython
has it).
2014-03-31 17:22:38 +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 945a01c4e3 py: Fix bug in type_store_attr, trying to store to ROM. 2014-03-27 09:32:26 +00:00
Damien George c3f1126ee8 py: Fix logic bugs in object attribute/method extraction. 2014-03-26 22:35:10 +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 9e6e935df0 py: Add support for user-defined iterators via __iter__, __next__. 2014-03-26 18:37:06 +00:00
xbe efe3422394 py: Clean up includes.
Remove unnecessary includes. Add includes that improve portability.
2014-03-17 02:43:40 -07:00
Paul Sokolovsky 51bbf6a006 Implement support for __str__ and __repr__ special methods in classes. 2014-03-16 15:18:22 +02:00
Damien George 715101580b py: Factor and improve issubclass. 2014-03-03 22:38:13 +00:00
Paul Sokolovsky d86d22e1e7 Add mp_obj_is_subclass_fast() - intended for fast argument checking.
I.e. as replacement of MP_OBJ_IS_TYPE(), which takes into account subclassing.
2014-03-03 11:42:53 +08: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 7d0bfbedd2 py: Add some qstrs to the global table. 2014-02-08 19:01:47 +00:00
Damien George 64131f3215 Add staticmethod and classmethod to builtin namespace. 2014-02-06 20:31:44 +00:00
Damien George b8ec17c2d1 py: Fix bug with dual initialisation of RT_UNARY_OP_NOT.
Fixes Issue #261.
2014-02-05 00:57:31 +00:00
Damien George 35e2a4e6bb py: Add built-in super. 2014-02-05 00:51:47 +00:00
Damien George 4acb2452b3 py: Add very basic implementation of dir() builtin.
Only works on modules and class instances.
2014-02-02 22:07:44 +00:00
Damien George cd82e02e84 py: Partially fix native emitter to work with latest runtime.
Native emitter has been broken since stack order has changed from
reverse to standard.  This fix gets it partially working.
2014-02-02 13:11:48 +00: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 09a0c64bce py: Improve __bool__ and __len__ dispatch; add slots for them. 2014-01-30 10:05:33 +00:00
Damien George 2259e62c37 Remove obsoleted comment. 2014-01-25 00:25:32 +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
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 f49ba1bd9c Improve method lookup in mp_obj_class_lookup.
Now searches both locals_dict and methods.  Partly addresses Issue #145.
2014-01-18 17:52:41 +00:00
Damien George 1d6fc94c16 Implement framework for class-defined built-in operators.
Now working for class-defined methods: __getitem__, __setitem__,
__add__, __sub__.  Easy to add others.
2014-01-18 15:31:13 +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
Damien George eae16445d5 py: Implement staticmethod and classmethod (internally).
Still need to make built-ins by these names, and write tests.
2014-01-11 19:22:29 +00:00
Damien George 004cdcebfe py: Implement base class lookup, issubclass, isinstance. 2014-01-09 21:43:51 +00:00
Damien George 062478e66d Improved type/class/instance code; mp_obj_type_t now has load_attr, store_attr.
Creating of classes (types) and instances is much more like CPython now.
You can use "type('name', (), {...})" to create classes.
2014-01-09 20:57:50 +00:00
Damien George 93a9b5b64d py: Proper framework for built-in 'type'. 2014-01-08 18:48:12 +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
Damien George 40563d56bd py: Add framework for built-in "type()" function. 2014-01-02 16:01:17 +00:00
Damien d99b05282d Change object representation from 1 big union to individual structs.
A big change.  Micro Python objects are allocated as individual structs
with the first element being a pointer to the type information (which
is itself an object).  This scheme follows CPython.  Much more flexible,
not necessarily slower, uses same heap memory, and can allocate objects
statically.

Also change name prefix, from py_ to mp_ (mp for Micro Python).
2013-12-21 18:17:45 +00:00