py/inlineasm: Add ability to specify return type of asm_thumb funcs.

Supported return types are: object, bool, int, uint.

For example:

@micropython.asm_thumb
def foo(r0, r1) -> uint:
    add(r0, r0, r1)
This commit is contained in:
Damien George
2016-01-15 15:20:43 +00:00
parent 3d42aa07dd
commit 8f54c08691
10 changed files with 65 additions and 16 deletions

View File

@@ -34,14 +34,14 @@
#include "py/emitglue.h"
#include "py/bc.h"
#if MICROPY_EMIT_NATIVE
#if 0 // print debugging info
#define DEBUG_printf DEBUG_printf
#else // don't print debugging info
#define DEBUG_printf(...) (void)0
#endif
#if MICROPY_EMIT_NATIVE
// convert a Micro Python object to a valid native value based on type
mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
DEBUG_printf("mp_convert_obj_to_native(%p, " UINT_FMT ")\n", obj, type);
@@ -61,6 +61,10 @@ mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
}
}
#endif
#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_THUMB
// convert a native value to a Micro Python object based on type
mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type) {
DEBUG_printf("mp_convert_native_to_obj(" UINT_FMT ", " UINT_FMT ")\n", val, type);
@@ -73,6 +77,10 @@ mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type) {
}
}
#endif
#if MICROPY_EMIT_NATIVE
// wrapper that accepts n_args and n_kw in one argument
// (native emitter can only pass at most 3 arguments to a function)
mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, mp_uint_t n_args_kw, const mp_obj_t *args) {