diff options
author | Damien George <damien.p.george@gmail.com> | 2014-08-15 22:39:08 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-08-15 22:39:08 +0100 |
commit | a5190a7dac7a73e676d6d649035f846ea92d2d2d (patch) | |
tree | 92d64dc58f1515327ae484129a66847f669c6757 /py/emitnative.c | |
parent | 2ac4af6946543ae96cf3659468e1b8cabb057f85 (diff) | |
download | micropython-a5190a7dac7a73e676d6d649035f846ea92d2d2d.tar.gz micropython-a5190a7dac7a73e676d6d649035f846ea92d2d2d.zip |
py: Fix typing of viper locals; allow default types in annotation.
Diffstat (limited to 'py/emitnative.c')
-rw-r--r-- | py/emitnative.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/py/emitnative.c b/py/emitnative.c index 7f3c73c2e4..eb5b6b1f4b 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -241,12 +241,19 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop // set default type for return and arguments emit->return_vtype = VTYPE_PYOBJ; - for (int i = 0; i < emit->local_vtype_alloc; i++) { + for (mp_uint_t i = 0; i < emit->scope->num_pos_args; i++) { emit->local_vtype[i] = VTYPE_PYOBJ; } - for (int i = 0; i < emit->stack_info_alloc; i++) { + + // local variables begin unbound, and have unknown type + for (mp_uint_t i = emit->scope->num_pos_args; i < emit->local_vtype_alloc; i++) { + emit->local_vtype[i] = VTYPE_UNBOUND; + } + + // values on stack begin unbound + for (mp_uint_t i = 0; i < emit->stack_info_alloc; i++) { emit->stack_info[i].kind = STACK_VALUE; - emit->stack_info[i].vtype = VTYPE_PYOBJ; + emit->stack_info[i].vtype = VTYPE_UNBOUND; } #if N_X64 @@ -844,7 +851,6 @@ STATIC void emit_native_load_subscr(emit_t *emit) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } else { printf("ViperTypeError: can't do subscr of types %d and %d\n", vtype_lhs, vtype_rhs); - assert(0); } } @@ -1212,7 +1218,7 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } else { printf("ViperTypeError: can't do binary op between types %d and %d\n", vtype_lhs, vtype_rhs); - assert(0); + emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } } |