aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compiler.rs6
-rw-r--r--src/lib.rs29
-rw-r--r--src/vm.rs22
3 files changed, 55 insertions, 2 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index 35fedf3..128b4a8 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -838,7 +838,11 @@ impl Compiler {
if let Some(var) = self.find_variable(&name) {
if let Some(op) = op {
- add_op(self, block, Op::Copy);
+ if var.upvalue {
+ add_op(self, block, Op::ReadUpvalue(var.slot));
+ } else {
+ add_op(self, block, Op::ReadLocal(var.slot));
+ }
self.expression(block);
add_op(self, block, op);
} else {
diff --git a/src/lib.rs b/src/lib.rs
index 96ed6fd..862e9fa 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1058,4 +1058,33 @@ a.a <=> 0"
simple: "a := 1 // blargh \na += 1 // blargh \n a <=> 2 // HARGH",
expressions: "1 + 1 // blargh \n 2 // blargh \n // HARGH \n",
);
+
+ test_multiple!(
+ assignment_op_regression,
+ simple_add: "
+a := 0
+b := 99999
+a += 1
+a <=> 1
+",
+
+ simple_sub: "
+a := 0
+b := 99999
+a -= 1
+a <=> -1
+",
+
+ strange: "
+a := 0
+{
+ b := 99999
+ {
+ a := 99999
+ }
+ a -= 1
+}
+a <=> -1
+",
+ );
}
diff --git a/src/vm.rs b/src/vm.rs
index e5c7b2e..d238087 100644
--- a/src/vm.rs
+++ b/src/vm.rs
@@ -63,9 +63,10 @@ pub struct VM {
pub print_blocks: bool,
pub print_ops: bool,
+ runtime: bool,
- extern_functions: Vec<RustFunction>,
+ extern_functions: Vec<RustFunction>,
}
#[derive(Eq, PartialEq)]
@@ -92,6 +93,7 @@ impl VM {
print_blocks: false,
print_ops: false,
+ runtime: false,
extern_functions: Vec::new()
}
@@ -158,10 +160,25 @@ impl VM {
self.frame().block.borrow().ops[ip]
}
+ fn print_stacktrace(&self) {
+ if !self.runtime { return; }
+
+ println!("\n<{}>", "STACK".red());
+ for (i, frame) in self.frames.iter().enumerate() {
+ println!(" {:>3}. {}:{:<4} in {:10}",
+ i,
+ frame.block.borrow().file.display(),
+ frame.block.borrow().line(self.frame().ip),
+ frame.block.borrow().name.blue());
+ }
+ println!("")
+ }
+
/// Stop the program, violently
fn crash_and_burn(&self) -> ! {
self.print_stack();
println!("\n");
+ self.print_stacktrace();
self.frame().block.borrow().debug_print();
println!(" ip: {}, line: {}\n",
self.frame().ip.blue(),
@@ -171,6 +188,7 @@ impl VM {
fn error(&self, kind: ErrorKind, message: Option<String>) -> Error {
let frame = self.frames.last().unwrap();
+ self.print_stacktrace();
Error {
kind,
file: frame.block.borrow().file.clone(),
@@ -458,6 +476,7 @@ impl VM {
self.extern_functions = prog.functions.clone();
self.stack.clear();
self.frames.clear();
+ self.runtime = true;
self.push(Value::Function(Vec::new(), Rc::clone(&block)));
@@ -738,6 +757,7 @@ impl VM {
self.blobs = prog.blobs.clone();
self.constants = prog.constants.clone();
self.strings = prog.strings.clone();
+ self.runtime = false;
self.extern_functions = prog.functions.clone();
for block in prog.blocks.iter() {