Skip to content

Commit e6ce10a

Browse files
committed
py: Native emitter now supports delete name & global, and end finally.
1 parent 17598d4 commit e6ce10a

3 files changed

Lines changed: 25 additions & 23 deletions

File tree

py/emitnative.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ STATIC void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int re
531531
}
532532
}
533533

534-
STATIC void emit_pre_pop_discard(emit_t *emit, vtype_kind_t *vtype) {
534+
STATIC void emit_pre_pop_discard(emit_t *emit) {
535535
emit->last_emit_was_return_value = false;
536536
adjust_stack(emit, -1);
537537
}
@@ -1040,34 +1040,32 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
10401040
emit_call(emit, MP_F_OBJ_SUBSCR);
10411041
}
10421042

1043-
STATIC void emit_native_delete_fast(emit_t *emit, qstr qstr, int local_num) {
1044-
// not implemented
1043+
STATIC void emit_native_delete_fast(emit_t *emit, qstr qst, int local_num) {
1044+
// TODO implement me!
10451045
// could support for Python types, just set to None (so GC can reclaim it)
1046-
assert(0);
10471046
}
10481047

1049-
STATIC void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) {
1050-
// not supported
1051-
assert(0);
1048+
STATIC void emit_native_delete_deref(emit_t *emit, qstr qst, int local_num) {
1049+
// TODO implement me!
10521050
}
10531051

1054-
STATIC void emit_native_delete_name(emit_t *emit, qstr qstr) {
1055-
// not implemented
1056-
// use mp_delete_name
1057-
assert(0);
1052+
STATIC void emit_native_delete_name(emit_t *emit, qstr qst) {
1053+
emit_native_pre(emit);
1054+
emit_call_with_imm_arg(emit, MP_F_DELETE_NAME, qst, REG_ARG_1);
1055+
emit_post(emit);
10581056
}
10591057

1060-
STATIC void emit_native_delete_global(emit_t *emit, qstr qstr) {
1061-
// not implemented
1062-
// use mp_delete_global
1063-
assert(0);
1058+
STATIC void emit_native_delete_global(emit_t *emit, qstr qst) {
1059+
emit_native_pre(emit);
1060+
emit_call_with_imm_arg(emit, MP_F_DELETE_GLOBAL, qst, REG_ARG_1);
1061+
emit_post(emit);
10641062
}
10651063

1066-
STATIC void emit_native_delete_attr(emit_t *emit, qstr qstr) {
1064+
STATIC void emit_native_delete_attr(emit_t *emit, qstr qst) {
10671065
vtype_kind_t vtype_base;
10681066
emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base
10691067
assert(vtype_base == VTYPE_PYOBJ);
1070-
emit_call_with_2_imm_args(emit, MP_F_STORE_ATTR, qstr, REG_ARG_2, (mp_uint_t)MP_OBJ_NULL, REG_ARG_3); // arg2 = attribute name, arg3 = value (null for delete)
1068+
emit_call_with_2_imm_args(emit, MP_F_STORE_ATTR, qst, REG_ARG_2, (mp_uint_t)MP_OBJ_NULL, REG_ARG_3); // arg2 = attribute name, arg3 = value (null for delete)
10711069
emit_post(emit);
10721070
}
10731071

@@ -1092,8 +1090,7 @@ STATIC void emit_native_dup_top_two(emit_t *emit) {
10921090
}
10931091

10941092
STATIC void emit_native_pop_top(emit_t *emit) {
1095-
vtype_kind_t vtype;
1096-
emit_pre_pop_discard(emit, &vtype);
1093+
emit_pre_pop_discard(emit);
10971094
emit_post(emit);
10981095
}
10991096

@@ -1243,11 +1240,12 @@ STATIC void emit_native_setup_except(emit_t *emit, uint label) {
12431240
}
12441241

12451242
STATIC void emit_native_setup_finally(emit_t *emit, uint label) {
1246-
assert(0);
1243+
emit_native_setup_except(emit, label);
12471244
}
12481245

12491246
STATIC void emit_native_end_finally(emit_t *emit) {
1250-
//assert(0);
1247+
emit_pre_pop_discard(emit);
1248+
emit_post(emit);
12511249
}
12521250

12531251
STATIC void emit_native_get_iter(emit_t *emit) {
@@ -1608,12 +1606,12 @@ STATIC void emit_native_start_except_handler(emit_t *emit) {
16081606
adjust_stack(emit, 2);
16091607
vtype_kind_t vtype_nlr;
16101608
emit_pre_pop_reg(emit, &vtype_nlr, REG_ARG_1); // get the thrown value
1611-
emit_pre_pop_discard(emit, &vtype_nlr); // discard the linked-list pointer in the nlr_buf
1609+
emit_pre_pop_discard(emit); // discard the linked-list pointer in the nlr_buf
16121610
emit_post_push_reg_reg_reg(emit, VTYPE_PYOBJ, REG_ARG_1, VTYPE_PYOBJ, REG_ARG_1, VTYPE_PYOBJ, REG_ARG_1); // push the 3 exception items
16131611
}
16141612

16151613
STATIC void emit_native_end_except_handler(emit_t *emit) {
1616-
adjust_stack(emit, -3); // stack adjust (not sure why it's this much...)
1614+
adjust_stack(emit, -2);
16171615
}
16181616

16191617
const emit_method_table_t EXPORT_FUN(method_table) = {

py/nativeglue.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ void *const mp_fun_table[MP_F_NUMBER_OF] = {
125125
#endif
126126
mp_unpack_sequence,
127127
mp_unpack_ex,
128+
mp_delete_name,
129+
mp_delete_global,
128130
};
129131

130132
/*

py/runtime0.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ typedef enum {
145145
#endif
146146
MP_F_UNPACK_SEQUENCE,
147147
MP_F_UNPACK_EX,
148+
MP_F_DELETE_NAME,
149+
MP_F_DELETE_GLOBAL,
148150
MP_F_NUMBER_OF,
149151
} mp_fun_kind_t;
150152

0 commit comments

Comments
 (0)