Skip to content

Commit a5a84e1

Browse files
committed
py/emitnative: Use assertions and mp_not_implemented correctly.
Assertions are used to check expressions that should always be true, and mp_not_implemented is used for code that can be reached.
1 parent 8a57cac commit a5a84e1

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

py/emitnative.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,9 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
385385
ASM_MOV_REG_REG(emit->as, REG_LOCAL_2, REG_ARG_2);
386386
} else if (i == 2) {
387387
ASM_MOV_REG_REG(emit->as, REG_LOCAL_3, REG_ARG_3);
388-
} else if (i == 3) {
389-
ASM_MOV_REG_TO_LOCAL(emit->as, REG_ARG_4, i - REG_LOCAL_NUM);
390388
} else {
391-
// TODO not implemented
392-
mp_not_implemented("more than 4 viper args");
389+
assert(i == 3); // should be true; max 4 args is checked above
390+
ASM_MOV_REG_TO_LOCAL(emit->as, REG_ARG_4, i - REG_LOCAL_NUM);
393391
}
394392
}
395393
#endif
@@ -527,9 +525,7 @@ STATIC void emit_native_end_pass(emit_t *emit) {
527525
ASM_END_PASS(emit->as);
528526

529527
// check stack is back to zero size
530-
if (emit->stack_size != 0) {
531-
mp_printf(&mp_plat_print, "ERROR: stack size not back to zero; got %d\n", emit->stack_size);
532-
}
528+
assert(emit->stack_size == 0);
533529

534530
if (emit->pass == MP_PASS_EMIT) {
535531
void *f = mp_asm_base_get_code(&emit->as->base);
@@ -867,7 +863,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_de
867863
break;
868864
default:
869865
// not handled
870-
assert(0);
866+
mp_not_implemented("conversion to object");
871867
}
872868
}
873869

@@ -2202,7 +2198,8 @@ STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_u
22022198
emit_post_top_set_vtype(emit, vtype_cast);
22032199
break;
22042200
default:
2205-
assert(!"TODO: convert obj to int");
2201+
// this can happen when casting a cast: int(int)
2202+
mp_not_implemented("casting");
22062203
}
22072204
} else {
22082205
assert(vtype_fun == VTYPE_PYOBJ);

0 commit comments

Comments
 (0)