summaryrefslogtreecommitdiff
path: root/py/emitnative.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2022-07-09 00:05:59 +1000
committerDamien George <damien@micropython.org>2022-07-12 17:18:27 +1000
commit9714a0ead5c74649d676986836ee27fb418aac9e (patch)
tree5465ae77dfe68ecdb3e7232fad11d41b86d5ea76 /py/emitnative.c
parente1282556e82ed470941a845af447065502a2c5ad (diff)
py/emitnative: Fix STORE_ATTR viper code-gen when value is not a pyobj.
There was a missing call to MP_F_CONVERT_NATIVE_TO_OBJ. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/emitnative.c')
-rw-r--r--py/emitnative.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index 957e713fd..7e98ba155 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -1683,10 +1683,18 @@ STATIC void emit_native_store_global(emit_t *emit, qstr qst, int kind) {
}
STATIC void emit_native_store_attr(emit_t *emit, qstr qst) {
- vtype_kind_t vtype_base, vtype_val;
- emit_pre_pop_reg_reg(emit, &vtype_base, REG_ARG_1, &vtype_val, REG_ARG_3); // arg1 = base, arg3 = value
+ vtype_kind_t vtype_base;
+ vtype_kind_t vtype_val = peek_vtype(emit, 1);
+ if (vtype_val == VTYPE_PYOBJ) {
+ emit_pre_pop_reg_reg(emit, &vtype_base, REG_ARG_1, &vtype_val, REG_ARG_3); // arg1 = base, arg3 = value
+ } else {
+ emit_access_stack(emit, 2, &vtype_val, REG_ARG_1); // arg1 = value
+ emit_call_with_imm_arg(emit, MP_F_CONVERT_NATIVE_TO_OBJ, vtype_val, REG_ARG_2); // arg2 = type
+ ASM_MOV_REG_REG(emit->as, REG_ARG_3, REG_RET); // arg3 = value (converted)
+ emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
+ adjust_stack(emit, -1); // pop value
+ }
assert(vtype_base == VTYPE_PYOBJ);
- assert(vtype_val == VTYPE_PYOBJ);
emit_call_with_qstr_arg(emit, MP_F_STORE_ATTR, qst, REG_ARG_2); // arg2 = attribute name
emit_post(emit);
}