Skip to content

Commit 02d95d7

Browse files
committed
py: Fix 2 bugs in native emitter: jump_or_pop and stack settling.
Addresses issue adafruit#838.
1 parent eb4e18f commit 02d95d7

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

py/emitnative.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ STATIC void need_stack_settled(emit_t *emit) {
503503
for (int i = 0; i < emit->stack_size; i++) {
504504
stack_info_t *si = &emit->stack_info[i];
505505
if (si->kind == STACK_IMM) {
506+
si->kind = STACK_VALUE;
506507
ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + i, REG_TEMP0);
507508
}
508509
}
@@ -1131,10 +1132,10 @@ STATIC void emit_native_jump_helper(emit_t *emit, uint label, bool pop) {
11311132
}
11321133
} else if (vtype == VTYPE_PYOBJ) {
11331134
emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
1134-
emit_call(emit, MP_F_OBJ_IS_TRUE);
11351135
if (!pop) {
1136-
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
1136+
adjust_stack(emit, 1);
11371137
}
1138+
emit_call(emit, MP_F_OBJ_IS_TRUE);
11381139
} else {
11391140
printf("ViperTypeError: expecting a bool or pyobj, got %d\n", vtype);
11401141
assert(0);

tests/basics/andor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# test short circuit expressions outside if conditionals
2+
print(() or 1)
3+
print((1,) or 1)
4+
print(() and 1)
5+
print((1,) and 1)

tests/basics/ifcond.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# test if conditions which are optimised by the compiler
2+
3+
f2 = 0
4+
5+
def f(t1, t2, f1):
6+
if False:
7+
print(1)
8+
if True:
9+
print(1)
10+
if ():
11+
print(1)
12+
if (1,):
13+
print(1)
14+
if (1, 2):
15+
print(1)
16+
if t1 and t2:
17+
print(1)
18+
if (t1 and t2): # parsed differently to above
19+
print(1)
20+
if not (t1 and f1):
21+
print(1)
22+
if t1 or t2:
23+
print(1)
24+
if (t1 or t2): # parse differently to above
25+
print(1)
26+
if f1 or t1:
27+
print(1)
28+
if not (f1 or f2):
29+
print(1)
30+
if t1 and f1 or t1 and t2:
31+
print(1)
32+
if (f1 or t1) and (f2 or t2):
33+
print(1)
34+
35+
f(True, 1, False)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy