Commit Graph

85 Commits

Author SHA1 Message Date
Paul Sokolovsky
ff30666c69 py: Add basic implementation of hasattr() function. 2014-05-11 20:51:30 +03:00
Paul Sokolovsky
6913521911 objstr: Implement .lower() and .upper(). 2014-05-10 19:49:07 +03:00
Paul Sokolovsky
d99e9083cb modsys, unix: Add sys.exit(), should be implemented by a port. 2014-05-10 16:56:21 +03:00
Paul Sokolovsky
b181b581aa objset: Give up and implement frozenset.
Tired of patching CPython stdlib for it.
2014-05-10 16:56:20 +03:00
Damien George
3417bc2f25 py: Rename byte_code to bytecode everywhere.
bytecode is the more widely used.  See issue #590.
2014-05-10 10:36:38 +01:00
Damien George
8c1c7488b2 Add gc.enable, gc.disable; remove pyb.gc. 2014-05-08 23:04:49 +01:00
Damien George
ffae48d750 py, compiler: Add basic support for A=const(123).
You can now do:

    X = const(123)
    Y = const(456 + X)

and the compiler will replace X and Y with their values.

See discussion in issue #266 and issue #573.
2014-05-08 15:58:39 +00:00
Damien George
491cbd6a7c py: Add keyword arg support to enumerate constructor.
Need to have a policy as to how far we go adding keyword support to
built ins.  It's nice to have, and gets better CPython compatibility,
but hurts the micro nature of uPy.

Addresses issue #577.
2014-05-06 16:38:54 +00:00
Paul Sokolovsky
f9e54e0ea5 modgc: Add new module for GC-related functionality. 2014-05-06 02:28:49 +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
Damien George
d5f5b2f766 py, stream: Implement readlines for a stream. 2014-05-03 22:01:32 +01:00
Damien George
0c8fcb9c49 py: Remove silly comment about interning keywords.
Of course, keywords are turned into lexer tokens in the lexer, so will
never need to be interned (unless you do something like x="def").

As it is now, the following on pyboard makes no new qstrs:

    import pyb
    pyb.info()
2014-04-28 09:56:31 +01:00
Damien George
708c073250 py: Add '*' qstr for 'import *'; use blank qstr for comprehension arg. 2014-04-27 19:23:46 +01:00
Paul Sokolovsky
27f5bdd6d4 py: "read" & "write" are so common that make them core.
Few other strings move to core, but make depend on "io" module.
2014-04-26 21:15:56 +03:00
Paul Sokolovsky
cb9dc086a3 modio: Implement io.StringIO class. 2014-04-26 20:26:14 +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
755565d2cb py: Support instance __call__ method. 2014-04-25 21:17:42 +03:00
Damien George
e5f8a77db6 py: Add 'align' and 'data' meta-instructions to inline assembler. 2014-04-21 13:33:15 +01:00
Paul Sokolovsky
6204460461 modstruct: Initial implementation of struct.pack(). 2014-04-19 03:22:08 +03:00
Damien George
dbdfee15a1 py: Add cmath module, for complex math. Disabled by default.
Not all functions implemented.  Not enabled on pyboard.
2014-04-17 17:11:03 +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
b013aea809 py: Fix builtin hex to print prefix.
I was too hasty.  Still a one-liner though.
2014-04-15 12:50:21 +01:00
Damien George
5805111732 py: Add hex builtin function.
A one-liner, added especially for @pfalcon :)
2014-04-15 12:42:52 +01:00
Paul Sokolovsky
bbae42d62f modsys: Implement sys.version.
The logic appears to be that (at least beginning of) sys.versions is the
version of reference Python language implemented, not version of particular
implementation.

Also, bump set versions at 3.4.0, based on @dpgeorge preference.
2014-04-14 01:46:45 +03:00
Paul Sokolovsky
14de114ba8 objdict: Add __delitem__. 2014-04-13 23:55:59 +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
Paul Sokolovsky
978d2c0267 modsys: Implement sys.byteorder. 2014-04-13 15:25:00 +03:00
Paul Sokolovsky
baaaf65eaa modsys: Implement basic sys.version_info. 2014-04-13 15:25:00 +03:00
Damien George
640e7e4779 Merge pull request #476 from pfalcon/static-sys
Convert sys module to static allocation
2014-04-13 12:52:39 +01:00
Paul Sokolovsky
036ad76659 objset: Implement __contains__() op-method. 2014-04-13 11:34:40 +03:00
Paul Sokolovsky
48fdaad824 py: Rename collections module to _collections.
We're not going to implement all the plethora of types in there in C.
Funnily, CPython implements defaultdict in C, and namedtuple in Python.
2014-04-13 10:24:00 +03:00
Paul Sokolovsky
a3e50eacca py: Move sys attribute qstrs's to core. 2014-04-13 07:02:57 +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
Paul Sokolovsky
13d52df4c5 builtinimport: Set __path__ attribute on packages.
Per https://docs.python.org/3.3/reference/import.html , this is the way to
tell module from package: "Specifically, any module that contains a __path__
attribute is considered a package." And it for sure will be needed to
implement relative imports.
2014-04-12 00:39:55 +03:00
Paul Sokolovsky
a925cb54f1 py: Preprocess qstrdefs.h before feeding to makeqstrdata.py.
This is alternative implementation of supporting conditionals in qstrdefs.h,
hard to say if it's much cleaner than munging #ifdef's in Python code...
2014-04-12 00:39:55 +03:00
Paul Sokolovsky
e9db840480 py: Start implementing "struct" module.
Only calcsize() and unpack() functions provided so far, for little-endian
byte order. Format strings don't support repition spec (like "2b3i").

Unfortunately, dealing with all the various binary type sizes and alignments
will lead to quite a bloated "binary" helper functions  - if optimizing for
speed. Need to think if using dynamic parametrized algos makes more sense.
2014-04-10 03:58:03 +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
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
xbe
3d9a39e211 py: Implement str.[r]index() and add tests for them. 2014-04-08 11:51:41 -07:00
Damien George
09af5364d4 Merge branch 'master' of github.com:micropython/micropython 2014-04-05 23:04:22 +01:00
Damien George
27e735fd18 py: Replace stream_p with *stream_p in mp_obj_type_t.
This is to reduce ROM usage.  stream_p is used in file and socket types
only (at the moment), so seems a good idea to make the protocol
functions a pointer instead of the actual structure.

It saves 308 bytes of ROM in the stmhal/ port, 928 in unix/.
2014-04-05 23:02:23 +01:00
Paul Sokolovsky
cc0af3d727 py: Implement globals() and locals() builtins. 2014-04-06 01:01:36 +03:00
Damien George
8123a3339d Merge pull request #425 from iabdalkader/del
Implement del
2014-04-05 18:49:39 +01:00
mux
cc849f70f4 Move del to locals 2014-04-05 15:49:03 +02:00
Paul Sokolovsky
98a627dc03 py: Add "io" module.
So far just includes "open" function, which should be supplied by a port.

TODO: Make the module #ifdef'ed.
2014-04-03 22:08:57 +03:00
Damien George
4881566874 py: Add support for sep and end keywords in print. 2014-04-02 10:34:44 +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
44307d5ef8 vm: Implement "with" statement (SETUP_WITH and WITH_CLEANUP bytecodes). 2014-03-29 04:39:24 +02:00
Paul Sokolovsky
e9137b94f2 py: Implement getattr() builtin. 2014-03-27 00:11:36 +02: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