Berry fix compiler bug in complex compound assignments

This commit is contained in:
Stephan Hadinger 2021-09-18 16:00:56 +02:00
parent e4d3dedd8c
commit 60d9b95ff4
2 changed files with 23 additions and 2 deletions

View File

@ -900,10 +900,12 @@ static void suffix_expr(bparser *parser, bexpdesc *e)
static void suffix_alloc_reg(bparser *parser, bexpdesc *l)
{
bfuncinfo *finfo = parser->finfo;
bbool suffix = l->type == ETINDEX || l->type == ETMEMBER;
bbool is_suffix = l->type == ETINDEX || l->type == ETMEMBER; /* is suffix */
bbool is_suffix_reg = l->v.ss.tt == ETREG || l->v.ss.tt == ETLOCAL || l->v.ss.tt == ETGLOBAL || l->v.ss.tt == ETNGLOBAL; /* if suffix, does it need a register */
bbool is_global = l->type == ETGLOBAL || l->type == ETNGLOBAL;
/* in the suffix expression, if the object is a temporary
* variable (l->v.ss.tt == ETREG), it needs to be cached. */
if (suffix && l->v.ss.tt == ETREG) {
if (is_global || (is_suffix && is_suffix_reg)) {
be_code_allocregs(finfo, 1);
}
}

View File

@ -0,0 +1,19 @@
# test bug in compound statements
a = 0
assert(a == 0)
a += 1
assert(a == 1)
a += 10/2
assert(a == 6)
class A var a def init() self.a = 1 end def f(x) self.a+=x/2 end def g(x) self.a = self.a + x/2 end end
a = A()
assert(a.a == 1)
a.f(10)
assert(a.a == 6)
b=A()
assert(b.a == 1)
b.g(10)
assert(b.a == 6)