diff --git a/inputs/failing/nested_assignment.ts b/inputs/failing/nested_assignment.ts new file mode 100644 index 0000000..e49e4b8 --- /dev/null +++ b/inputs/failing/nested_assignment.ts @@ -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, + ]; +} diff --git a/valuescript_compiler/src/expression_compiler.rs b/valuescript_compiler/src/expression_compiler.rs index dbb970f..a0cc27a 100644 --- a/valuescript_compiler/src/expression_compiler.rs +++ b/valuescript_compiler/src/expression_compiler.rs @@ -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 {