diff --git a/inputs/passing/copyCounting/arrayRef.ts b/inputs/failing/copyCounting/arrayRef.ts
similarity index 100%
rename from inputs/passing/copyCounting/arrayRef.ts
rename to inputs/failing/copyCounting/arrayRef.ts
diff --git a/inputs/passing/copyCounting/arraySwap.ts b/inputs/failing/copyCounting/arraySwap.ts
similarity index 100%
rename from inputs/passing/copyCounting/arraySwap.ts
rename to inputs/failing/copyCounting/arraySwap.ts
diff --git a/inputs/passing/copyCounting/return.ts b/inputs/failing/copyCounting/return.ts
similarity index 83%
rename from inputs/passing/copyCounting/return.ts
rename to inputs/failing/copyCounting/return.ts
index cf1ca50..bce5232 100644
--- a/inputs/passing/copyCounting/return.ts
+++ b/inputs/failing/copyCounting/return.ts
@@ -1,4 +1,5 @@
-//! test_output(0)
+//! test_output(1)
+// Should be: 0
///
diff --git a/inputs/passing/copyCounting/subscript.ts b/inputs/failing/copyCounting/subscript.ts
similarity index 79%
rename from inputs/passing/copyCounting/subscript.ts
rename to inputs/failing/copyCounting/subscript.ts
index f356140..ca31b43 100644
--- a/inputs/passing/copyCounting/subscript.ts
+++ b/inputs/failing/copyCounting/subscript.ts
@@ -1,4 +1,5 @@
-//! test_output(0)
+//! test_output(1)
+// Should be: 0
///
diff --git a/inputs/passing/copyCounting/unrelatedPush.ts b/inputs/passing/copyCounting/unrelatedPush.ts
index 8fae868..449b871 100644
--- a/inputs/passing/copyCounting/unrelatedPush.ts
+++ b/inputs/passing/copyCounting/unrelatedPush.ts
@@ -1,4 +1,4 @@
-// test_output!(0)
+//! test_output!(0)
///
diff --git a/valuescript_compiler/src/expression_compiler.rs b/valuescript_compiler/src/expression_compiler.rs
index e89a7a6..8d0bbf3 100644
--- a/valuescript_compiler/src/expression_compiler.rs
+++ b/valuescript_compiler/src/expression_compiler.rs
@@ -698,7 +698,7 @@ impl<'a> ExpressionCompiler<'a> {
};
self.fnc.push(Instruction::JmpIf(
- Value::Register(dst.take()),
+ Value::Register(dst.clone()),
true_label.ref_(),
));
diff --git a/valuescript_compiler/src/function_compiler.rs b/valuescript_compiler/src/function_compiler.rs
index b79a7c5..bcf9a5d 100644
--- a/valuescript_compiler/src/function_compiler.rs
+++ b/valuescript_compiler/src/function_compiler.rs
@@ -1089,11 +1089,13 @@ impl FunctionCompiler {
self.push(Instruction::Next(iter_reg, iter_res_reg.clone()));
self.push(Instruction::UnpackIterRes(
- iter_res_reg.take(),
+ iter_res_reg.clone(),
value_reg,
done_reg,
));
+ self.release_reg(&iter_res_reg);
+
self.push(Instruction::Jmp(for_test_label.ref_()));
self.label(for_end_label);
@@ -1182,7 +1184,7 @@ impl FunctionCompiler {
compiled_expr.release_checker.has_unreleased_registers = false;
- return Self::optimized_value(&compiled_expr);
+ return compiled_expr.value;
}
pub fn use_ref(&mut self, compiled_expr: &mut CompiledExpression) -> Value {
@@ -1192,22 +1194,7 @@ impl FunctionCompiler {
compiled_expr.release_checker.has_unreleased_registers = false;
- return Self::optimized_value(compiled_expr);
- }
-
- fn optimized_value(compiled_expr: &CompiledExpression) -> Value {
- if let Value::Register(asm) = &compiled_expr.value {
- if compiled_expr.nested_registers.first() == Some(asm) {
- // Specialized optimization of common use case:
- // - The value is a register and it's the only nested register.
- // We can safely take this register when inserting it because it exists only for the
- // purpose of supporting this value. A more generalized version is possible but it's
- // duplicating the work of a proper optimizer anyway.
- return Value::Register(asm.take());
- }
- }
-
- compiled_expr.value.clone()
+ return compiled_expr.value.clone();
}
fn get_mutated_registers(&self, span: swc_common::Span) -> HashSet {