mirror of https://github.com/arendst/Tasmota.git
Merge pull request #13165 from s-hadinger/fix_berry_compound_assignment
Berry fix compiler bug in complex compound assignments
This commit is contained in:
commit
46a0d33ecf
|
@ -900,10 +900,12 @@ static void suffix_expr(bparser *parser, bexpdesc *e)
|
||||||
static void suffix_alloc_reg(bparser *parser, bexpdesc *l)
|
static void suffix_alloc_reg(bparser *parser, bexpdesc *l)
|
||||||
{
|
{
|
||||||
bfuncinfo *finfo = parser->finfo;
|
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
|
/* in the suffix expression, if the object is a temporary
|
||||||
* variable (l->v.ss.tt == ETREG), it needs to be cached. */
|
* 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);
|
be_code_allocregs(finfo, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue