Damien George
4601759bf5
py/objstr: Remove "make_qstr_if_not_already" arg from mp_obj_new_str.
This patch simplifies the str creation API to favour the common case of
creating a str object that is not forced to be interned. To force
interning of a new str the new mp_obj_new_str_via_qstr function is added,
and should only be used if warranted.
Apart from simplifying the mp_obj_new_str function (and making it have the
same signature as mp_obj_new_bytes), this patch also reduces code size by a
bit (-16 bytes for bare-arm and roughly -40 bytes on the bare-metal archs).
7 years ago
Damien George
f4059dcc0c
all: Use NULL instead of "" when calling mp_raise exception helpers.
This is the established way of doing it and reduces code size by a little
bit.
7 years ago
Damien George
a3dc1b1957
all: Remove inclusion of internal py header files.
Header files that are considered internal to the py core and should not
normally be included directly are:
py/nlr.h - internal nlr configuration and declarations
py/bc0.h - contains bytecode macro definitions
py/runtime0.h - contains basic runtime enums
Instead, the top-level header files to include are one of:
py/obj.h - includes runtime0.h and defines everything to use the
mp_obj_t type
py/runtime.h - includes mpstate.h and hence nlr.h, obj.h, runtime0.h,
and defines everything to use the general runtime support functions
Additional, specific headers (eg py/objlist.h) can be included if needed.
7 years ago
Damien George
01dd7804b8
ports: Make new ports/ sub-directory and move all ports there.
This is to keep the top-level directory clean, to make it clear what is
core and what is a port, and to allow the repository to grow with new ports
in a sustainable way.
7 years ago
Damien George
71c9cfb028
all: Convert remaining "mp_uint_t n_args" to "size_t n_args".
This is to have consistency across the whole repository.
7 years ago
Damien George
58321dd985
all: Convert mp_uint_t to mp_unary_op_t/mp_binary_op_t where appropriate
The unary-op/binary-op enums are already defined, and there are no
arithmetic tricks used with these types, so it makes sense to use the
correct enum type for arguments that take these values. It also reduces
code size quite a bit for nan-boxing builds.
7 years ago
Javier Candeira
35a1fea90b
all: Raise exceptions via mp_raise_XXX
- Changed: ValueError, TypeError, NotImplementedError
- OSError invocations unchanged, because the corresponding utility
function takes ints, not strings like the long form invocation.
- OverflowError, IndexError and RuntimeError etc. not changed for now
until we decide whether to add new utility functions.
7 years ago
Alexander Steffen
55f33240f3
all: Use the name MicroPython consistently in comments
There were several different spellings of MicroPython present in comments,
when there should be only one.
7 years ago
Paul Sokolovsky
e280122b14
unix/modjni: Convert to mp_rom_map_elem_t.
7 years ago
Damien George
48d867b4a6
all: Make more use of mp_raise_{msg,TypeError,ValueError} helpers.
8 years ago
Paul Sokolovsky
eac22e29a5
all: Consistently update signatures of .make_new and .call methods.
Otherwise, they serve reoccurring source of copy-paste mistakes and
breaking nanbox build.
8 years ago
Damien George
93c4a6a3f7
all: Remove 'name' member from mp_obj_module_t struct.
One can instead lookup __name__ in the modules dict to get the value.
8 years ago
Paul Sokolovsky
5bf1b4e9d9
unix/modjni: array(): Support creation of object arrays.
8 years ago
Paul Sokolovsky
ee324c501e
unix/modjni: Add array() top-level function to create Java array.
Takes element primitive type encoded as a char per standard JNI encoding,
and array size. TODO: Support object arrays.
8 years ago
Paul Sokolovsky
3fea1f014c
unix/modjni: Implement subscription for object arrays.
8 years ago
Paul Sokolovsky
3c7e1b80ac
unix/modjni: Add missing get_jclass_name() function.
9 years ago
Paul Sokolovsky
91f2168dd5
unix/modjni: Actually check argument type when doing method resolution.
This is required to properly select among overloaded methods. It however
relies on java.lang.Object-overloaded method to come last, which appears
to be the case for OpenJDK.
9 years ago
Paul Sokolovsky
9ebd4dabf2
unix/modjni: Don't pass Java object to a method which doesn't expect it.
For example, don't pass Integer to double method. This is still not
selective enough to choose the right overloaded method maong those
taking objects.
9 years ago
Paul Sokolovsky
fe29cc192d
unix/modjni: Add iteration support for Java List objects.
Using generic iteration-via-subscription support (TODO: factor it out for
reuse).
9 years ago
Paul Sokolovsky
41eb705477
unix/modjni: call_method: Check for Java exception after method return.
9 years ago
Paul Sokolovsky
1b586f3a73
py: Rename MP_BOOL() to mp_obj_new_bool() for consistency in naming.
9 years ago
Paul Sokolovsky
7381b7ac71
unix/modjni: py2jvalue: Support bool and None values.
9 years ago
Paul Sokolovsky
02041bf2e0
unix/modjni: jvalue2py() is currently not used.
Not remove so far, may be needed later.
9 years ago
Paul Sokolovsky
216b6a494e
unix/modjni: Allow to access fields of objects.
9 years ago
Paul Sokolovsky
fd38799049
unix/modjni: After Call*Method(), Java exception should always be checked.
OpenJDK seemed to return NULL in case of exception, but Dalvik returns
arbitrary value, so skip such "optimizations".
9 years ago
Paul Sokolovsky
1ea4b77a9a
unix/modjni: jclass.__str__/__repr__: Return Java .toString() value.
9 years ago
Paul Sokolovsky
f22be4ebd9
unix/modjni: jobject.__str__/__repr__: Return Java .toString() value.
9 years ago
Paul Sokolovsky
9e0a3d46b6
unix/modjni: Convert Java's IndexOutOfBoundsException to Python's IndexError.
9 years ago
Paul Sokolovsky
c4489a0543
unix/modjni: Propagate Java exceptions on list access.
9 years ago
Paul Sokolovsky
0eba162ab5
unix/modjni: Fix method argument matching.
9 years ago
Paul Sokolovsky
f3ca8623f7
unix/modjni: Implement len() for objects with java.util.List interface.
9 years ago
Paul Sokolovsky
77020281ae
unix/modjni: call_method: Delete done local references in loop.
To avoid local ref table overflow.
9 years ago
Paul Sokolovsky
0d28a3edb9
unix/modjni: call_method: Better resource release.
9 years ago
Paul Sokolovsky
81d64ab939
unix/modjni: call_method(): If name doesn't match, cleanup via goto next_method.
9 years ago
Paul Sokolovsky
c0a79cc919
unix/modjni: Need to really use per-rettype Call*Method functions.
9 years ago
Paul Sokolovsky
7e18d3b6ff
unix/modjni: new_jobject(): Handle null reference.
9 years ago
Paul Sokolovsky
e632b1fda7
unix/modjni: Factor out is_object_type().
9 years ago
Paul Sokolovsky
ed22e9ba3e
unix/modjni: Move type analysis logic to new_jobject(), for reuse.
9 years ago
Paul Sokolovsky
b2d880d749
unix/modjni: Support for subscripting of Java lists (r/o so far).
9 years ago
Paul Sokolovsky
6196aa45ed
unix/modjni: jvalue2py: Handle boolean.
9 years ago
Paul Sokolovsky
1e9d8e110b
unix/modjni: py2jvalue: Pass jobject's down to Java.
So far, no signature check is done (TODO).
9 years ago
Paul Sokolovsky
011c7f5718
unix/modjni: py2jvalue: Handle both int and long java types (with TODO for long).
9 years ago
Paul Sokolovsky
1cb5de2cd5
unix/modjni: jvalue2py: Handle class-containing jvalues.
9 years ago
Paul Sokolovsky
cb6cf5e257
unix/modjni: Add env() module function.
Useful to load native method libraries not loaded by VM (as happens on
Android).
9 years ago
Paul Sokolovsky
b230a86d33
unix/modjni: Return any object type value as a jobject.
9 years ago
Paul Sokolovsky
5167332131
unix/modjni: Return Java null as Python None.
9 years ago
Paul Sokolovsky
7a4b10cc4c
unix/modjni: Support static methods.
9 years ago
Paul Sokolovsky
26a9b4d48e
unix/modjni: Factor out new_jobject(), jvalue2py() functions.
9 years ago
Paul Sokolovsky
4e7bde8c9e
unix/modjni: Factor out py2jvalue() function.
9 years ago
Paul Sokolovsky
e79c6b6312
unix/modjni: "jni" module to interface to JNI-compliant JavaVM.
This includes Android Dalvik VM for example.
Example usage:
import jni
System = jni.cls("java/lang/System")
System.out.println("Hello, Java!")
9 years ago