diff options
author | Damien George <damien.p.george@gmail.com> | 2014-08-15 16:45:41 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-08-15 16:45:41 +0100 |
commit | 2ac4af6946543ae96cf3659468e1b8cabb057f85 (patch) | |
tree | 2e19460fec67666259afe529e7f4dff71b6451cf /py/emitglue.c | |
parent | 6be0b0a8ec9a6badc601190ccee876755ce7efb7 (diff) | |
download | micropython-2ac4af6946543ae96cf3659468e1b8cabb057f85.tar.gz micropython-2ac4af6946543ae96cf3659468e1b8cabb057f85.zip |
py: Allow viper to have type annotations.
Viper functions can now be annotated with the type of their arguments
and return value. Eg:
@micropython.viper
def f(x:int) -> int:
return x + 1
Diffstat (limited to 'py/emitglue.c')
-rw-r--r-- | py/emitglue.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/py/emitglue.c b/py/emitglue.c index 91570bc63d..5be54a6fc5 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -86,12 +86,14 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, byte *code, uint len, uint #endif } -void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun, uint len, int n_args) { +#if MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_THUMB +void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun, uint len, int n_args, mp_uint_t type_sig) { assert(kind == MP_CODE_NATIVE_PY || kind == MP_CODE_NATIVE_VIPER || kind == MP_CODE_NATIVE_ASM); rc->kind = kind; rc->scope_flags = 0; rc->n_pos_args = n_args; rc->u_native.fun = fun; + rc->u_native.type_sig = type_sig; #ifdef DEBUG_PRINT DEBUG_printf("assign native: kind=%d fun=%p len=%u n_args=%d\n", kind, fun, len, n_args); @@ -111,6 +113,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void #endif #endif } +#endif mp_obj_t mp_make_function_from_raw_code(mp_raw_code_t *rc, mp_obj_t def_args, mp_obj_t def_kw_args) { DEBUG_OP_printf("make_function_from_raw_code %p\n", rc); @@ -128,13 +131,19 @@ mp_obj_t mp_make_function_from_raw_code(mp_raw_code_t *rc, mp_obj_t def_args, mp case MP_CODE_BYTECODE: fun = mp_obj_new_fun_bc(rc->scope_flags, rc->arg_names, rc->n_pos_args, rc->n_kwonly_args, def_args, def_kw_args, rc->u_byte.code); break; + #if MICROPY_EMIT_NATIVE case MP_CODE_NATIVE_PY: fun = mp_make_function_n(rc->n_pos_args, rc->u_native.fun); break; case MP_CODE_NATIVE_VIPER: + fun = mp_obj_new_fun_viper(rc->n_pos_args, rc->u_native.fun, rc->u_native.type_sig); + break; + #endif + #if MICROPY_EMIT_INLINE_THUMB case MP_CODE_NATIVE_ASM: fun = mp_obj_new_fun_asm(rc->n_pos_args, rc->u_native.fun); break; + #endif default: // raw code was never set (this should not happen) assert(0); |