mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-01-13 15:38:06 -05:00
Test nested assignment (that it fails as expected)
This commit is contained in:
23
inputs/failing/nested_assignment.ts
Normal file
23
inputs/failing/nested_assignment.ts
Normal 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,
|
||||
];
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user