diff options
author | Damien George <damien.p.george@gmail.com> | 2016-01-15 15:20:43 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-01-27 14:27:10 +0000 |
commit | 8f54c08691faa3dd859852d211230fd7d9791abd (patch) | |
tree | 5cc82db6ea4d9d6538c6a876a09592a85fca4242 /py/compile.c | |
parent | 3d42aa07dd6e94942b3721ee42ba5454cd0edf55 (diff) |
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)
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/py/compile.c b/py/compile.c index 8a30518b3..7f9689102 100644 --- a/py/compile.c +++ b/py/compile.c @@ -2936,7 +2936,24 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind } } - assert(MP_PARSE_NODE_IS_NULL(pns->nodes[2])); // type + // pns->nodes[2] is function return annotation + mp_uint_t type_sig = MP_NATIVE_TYPE_INT; + mp_parse_node_t pn_annotation = pns->nodes[2]; + if (!MP_PARSE_NODE_IS_NULL(pn_annotation)) { + // nodes[2] can be null or a test-expr + if (MP_PARSE_NODE_IS_ID(pn_annotation)) { + qstr ret_type = MP_PARSE_NODE_LEAF_ARG(pn_annotation); + switch (ret_type) { + case MP_QSTR_object: type_sig = MP_NATIVE_TYPE_OBJ; break; + case MP_QSTR_bool: type_sig = MP_NATIVE_TYPE_BOOL; break; + case MP_QSTR_int: type_sig = MP_NATIVE_TYPE_INT; break; + case MP_QSTR_uint: type_sig = MP_NATIVE_TYPE_UINT; break; + default: compile_syntax_error(comp, pn_annotation, "unknown type"); return; + } + } else { + compile_syntax_error(comp, pn_annotation, "return annotation must be an identifier"); + } + } mp_parse_node_t pn_body = pns->nodes[3]; // body mp_parse_node_t *nodes; @@ -3028,7 +3045,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind } if (comp->pass > MP_PASS_SCOPE) { - EMIT_INLINE_ASM(end_pass); + EMIT_INLINE_ASM_ARG(end_pass, type_sig); } if (comp->compile_error != MP_OBJ_NULL) { |