Test nested assignment (that it fails as expected)

This commit is contained in:
Andrew Morris
2023-03-01 16:44:39 +11:00
parent b170587576
commit d594aaf407
2 changed files with 24 additions and 3 deletions

View File

@@ -0,0 +1,23 @@
// test_output! [9,9,9]
// This is not correct - it should be [1,4,9]. The problem is that the rhs
// *value* is supposed to be the result of the assignment, but when each rhs is
// compiled %x is used to store the result directly (e.g. op* 1 1 %x), and so %x
// is then used as the result of the expression.
//
// This could be easily fixed by simply creating an extra register for the rhs
// of each assignment and doing an extra mov to get it into the variable
// register. However, that makes the assembly extremely verbose. I'm hoping
// there's a nice way to generate relatively neat and tidy assembly directly,
// but it might make sense in the end, and just deal with it in assembly-level
// optimization.
export default function main() {
let x = 0;
return [
x = 1 * 1,
x = 2 * 2,
x = 3 * 3,
];
}

View File

@@ -431,9 +431,7 @@ impl<'a> ExpressionCompiler<'a> {
match at {
AssignTarget::Register(treg) => {
self.compile(&assign_expr.right, Some(treg.clone()));
return CompiledExpression::new(format!("%{}", treg), vec![]);
return self.compile(&assign_expr.right, Some(treg.clone()));
}
AssignTarget::Member(mut obj_accessor, prop) => {
let subscript = match prop {