aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-02-06 10:07:21 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-02-06 10:07:21 +0100
commit1c9674e1a718397e48363743eb21638e2ccd6281 (patch)
tree45944ffa84770f3bf4ef09a3bbf5a002130e4468
parent5bf578ba093e6fe272d132f6de2ffb57f2b0f2fe (diff)
downloadsylt-1c9674e1a718397e48363743eb21638e2ccd6281.tar.gz
make op copy
-rw-r--r--src/lib.rs2
-rw-r--r--src/vm.rs38
2 files changed, 20 insertions, 20 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e49e653..b34b87e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -288,7 +288,7 @@ impl Blob {
/// machine carries out when running the
/// "byte-code".
///
-#[derive(Debug, Clone)]
+#[derive(Debug, Copy, Clone)]
pub enum Op {
/// This instruction should never be run.
/// Finding it in a program is a critical error.
diff --git a/src/vm.rs b/src/vm.rs
index cb2c40d..e5c7b2e 100644
--- a/src/vm.rs
+++ b/src/vm.rs
@@ -155,7 +155,7 @@ impl VM {
fn op(&self) -> Op {
let ip = self.frame().ip;
- self.frame().block.borrow().ops[ip].clone()
+ self.frame().block.borrow().ops[ip]
}
/// Stop the program, violently
@@ -262,25 +262,25 @@ impl VM {
}
}
- Op::Get(field_ident) => {
+ Op::Get(field) => {
let inst = self.pop();
- let field = self.string(field_ident);
+ let field = self.string(field);
if let Value::BlobInstance(ty, values) = inst {
let slot = self.blobs[ty].fields.get(field).unwrap().0;
self.push(values.borrow()[slot].clone());
} else {
- error!(self, ErrorKind::RuntimeTypeError(Op::Get(field_ident), vec![inst]));
+ error!(self, ErrorKind::RuntimeTypeError(op, vec![inst]));
}
}
- Op::Set(field_ident) => {
+ Op::Set(field) => {
let (inst, value) = self.poppop();
- let field = self.string(field_ident);
+ let field = self.string(field);
if let Value::BlobInstance(ty, values) = inst {
let slot = self.blobs[ty].fields.get(field).unwrap().0;
values.borrow_mut()[slot] = value;
} else {
- error!(self, ErrorKind::RuntimeTypeError(Op::Get(field_ident), vec![inst]));
+ error!(self, ErrorKind::RuntimeTypeError(op, vec![inst]));
}
}
@@ -520,7 +520,7 @@ impl VM {
} else {
if ty != suggestion {
error!(self,
- ErrorKind::TypeError(op.clone(),
+ ErrorKind::TypeError(op,
vec![ty.clone(), suggestion.clone()]),
"Failed to infer type.".to_string());
}
@@ -533,29 +533,29 @@ impl VM {
}
}
- Op::Get(field_ident) => {
+ Op::Get(field) => {
let inst = self.pop();
- let field = self.string(field_ident);
+ let field = self.string(field);
if let Value::BlobInstance(ty, _) = inst {
let value = Value::from(&self.blobs[ty].fields.get(field).unwrap().1);
self.push(value);
} else {
self.push(Value::Nil);
- error!(self, ErrorKind::RuntimeTypeError(Op::Get(field_ident), vec![inst]));
+ error!(self, ErrorKind::RuntimeTypeError(op, vec![inst]));
}
}
- Op::Set(field_ident) => {
+ Op::Set(field) => {
let (inst, value) = self.poppop();
- let field = self.string(field_ident);
+ let field = self.string(field);
if let Value::BlobInstance(ty, _) = inst {
let ty = &self.blobs[ty].fields.get(field).unwrap().1;
if ty != &Type::from(&value) {
- error!(self, ErrorKind::RuntimeTypeError(Op::Set(field_ident), vec![inst]));
+ error!(self, ErrorKind::RuntimeTypeError(op, vec![inst]));
}
} else {
- error!(self, ErrorKind::RuntimeTypeError(Op::Set(field_ident), vec![inst]));
+ error!(self, ErrorKind::RuntimeTypeError(op, vec![inst]));
}
}
@@ -601,7 +601,7 @@ impl VM {
(a, b) if a != &b => {
error!(self,
ErrorKind::TypeError(
- op.clone(),
+ op,
vec![a.clone(), b.clone()]),
format!("Tried to assign a type {:?} to type {:?}.", a, b)
);
@@ -642,7 +642,7 @@ impl VM {
let stack_args: Vec<_> = stack_args.iter().map(|x| x.into()).collect();
if args != &stack_args {
error!(self,
- ErrorKind::TypeError(op.clone(), vec![]),
+ ErrorKind::TypeError(op, vec![]),
format!("Expected args of type {:?} but got {:?}.",
args, stack_args));
}
@@ -666,7 +666,7 @@ impl VM {
}
_ => {
error!(self,
- ErrorKind::TypeError(op.clone(), vec![Type::from(&self.stack[new_base])]),
+ ErrorKind::TypeError(op, vec![Type::from(&self.stack[new_base])]),
format!("Tried to call non-function {:?}", self.stack[new_base]));
}
}
@@ -675,7 +675,7 @@ impl VM {
Op::JmpFalse(_) => {
match self.pop() {
Value::Bool(_) => {},
- a => { error!(self, ErrorKind::TypeError(op.clone(), vec![a.into()])) },
+ a => { error!(self, ErrorKind::TypeError(op, vec![a.into()])) },
}
}
_ => {