berry
berry copied to clipboard
Fix walrus with member or index
Fix a bug when using walrus operator with SETMEMBER or SETINDEX:
a = 1 import global def f() print(global.a := 42) end
When dumping f:
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_str(global),
/* K1 */ be_nested_str(a),
}),
&be_const_str_f,
&be_const_str_solidified,
( &(const binstruction[ 6]) { /* code */
0x60000001, // 0000 GETGBL R0 G1
0xB8060000, // 0001 GETNGBL R1 K0
0x540A0029, // 0002 LDINT R2 42
0x90060202, // 0003 SETMBR R1 K1 R2 <-- the result is in R2, and R1 contains `global`
0x7C000200, // 0004 CALL R0 1
0x80000000, // 0005 RET 0
})
With the fix, in such case an additional MOVE is added:
( &(const bvalue[ 2]) { /* constants */
/* K0 */ be_nested_str(global),
/* K1 */ be_nested_str(a),
}),
&be_const_str_f,
&be_const_str_solidified,
( &(const binstruction[ 7]) { /* code */
0x60000001, // 0000 GETGBL R0 G1
0xB8060000, // 0001 GETNGBL R1 K0
0x540A0029, // 0002 LDINT R2 42
0x90060202, // 0003 SETMBR R1 K1 R2
0x5C040400, // 0004 MOVE R1 R2 <-- this brings back the result in R1
0x7C000200, // 0005 CALL R0 1
0x80000000, // 0006 RET 0
})
@skiars would you be kind enough to approve all the open PRs, I can't merge them otherwise
I'm looking at these PRs.
Fixing a regression bug (found by sfromis):
class confused_walrus
var b
def f()
var c = 1
if self.b := true
c = 2
end
return self
end
end
print(confused_walrus().f())
# prints 'true' instead of the instance
Now fixed with latest commit.