From 1aa5daae7c8b18b2ff4128c7bcc49db676e7e293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Tue, 2 Feb 2021 20:30:46 +0100 Subject: remove as_type() --- src/vm.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/vm.rs') diff --git a/src/vm.rs b/src/vm.rs index 221c3e0..b6ee10e 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -487,7 +487,7 @@ impl VM { if *is_up { types.push(ty.clone()); } else { - types.push(self.stack[*slot].as_type()); + types.push(Type::from(&self.stack[*slot])); } } @@ -550,7 +550,7 @@ impl VM { Op::AssignUpvalue(slot) => { let var = self.frame().block.borrow().ups[slot].2.clone(); - let up = self.pop().as_type(); + let up = self.pop().into(); if var != up { error!(self, ErrorKind::TypeError(op, vec![var, up]), "Incorrect type for upvalue.".to_string()); @@ -561,8 +561,8 @@ impl VM { let a = self.pop(); let inner = self.frame().block.borrow(); let ret = inner.ret(); - if a.as_type() != *ret { - error!(self, ErrorKind::TypeError(op, vec![a.as_type(), + if Type::from(&a) != *ret { + error!(self, ErrorKind::TypeError(op, vec![a.into(), ret.clone()]), "Not matching return type.".to_string()); } @@ -573,7 +573,7 @@ impl VM { } Op::Define(ref ty) => { - let top_type = self.stack.last().unwrap().as_type(); + let top_type = self.stack.last().unwrap().into(); match (ty, top_type) { (Type::UnknownType, top_type) if top_type != Type::UnknownType => {} @@ -618,7 +618,7 @@ impl VM { } let stack_args = &self.stack[self.stack.len() - args.len()..]; - let stack_args: Vec<_> = stack_args.iter().map(|x| x.as_type()).collect(); + let stack_args: Vec<_> = stack_args.iter().map(|x| x.into()).collect(); if args != &stack_args { error!(self, ErrorKind::TypeError(op.clone(), vec![]), @@ -645,7 +645,7 @@ impl VM { } _ => { error!(self, - ErrorKind::TypeError(op.clone(), vec![self.stack[new_base].as_type()]), + ErrorKind::TypeError(op.clone(), vec![Type::from(&self.stack[new_base])]), format!("Tried to call non-function {:?}", self.stack[new_base])); } } @@ -654,7 +654,7 @@ impl VM { Op::JmpFalse(_) => { match self.pop() { Value::Bool(_) => {}, - a => { error!(self, ErrorKind::TypeError(op.clone(), vec![a.as_type()])) }, + a => { error!(self, ErrorKind::TypeError(op.clone(), vec![a.into()])) }, } } _ => { -- cgit v1.2.1 From e49df17d1159507e50434d9d3f866a0c41dd59b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Tue, 2 Feb 2021 20:40:15 +0100 Subject: as_value -> from --- src/vm.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/vm.rs') diff --git a/src/vm.rs b/src/vm.rs index b6ee10e..474c51d 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -517,7 +517,7 @@ impl VM { Op::Get(field) => { let inst = self.pop(); if let Value::BlobInstance(ty, _) = inst { - let value = self.blobs[ty].name_to_field.get(&field).unwrap().1.as_value(); + let value = Value::from(&self.blobs[ty].name_to_field.get(&field).unwrap().1); self.push(value); } else { self.push(Value::Nil); @@ -544,7 +544,7 @@ impl VM { } Op::ReadUpvalue(slot) => { - let value = self.frame().block.borrow().ups[slot].2.as_value(); + let value = Value::from(&self.frame().block.borrow().ups[slot].2); self.push(value); } @@ -601,7 +601,7 @@ impl VM { } for (slot, ty) in blob.name_to_field.values() { - values[*slot] = ty.as_value(); + values[*slot] = ty.into(); } self.pop(); @@ -626,7 +626,7 @@ impl VM { args, stack_args)); } - self.stack[new_base] = block.borrow().ret().as_value(); + self.stack[new_base] = block.borrow().ret().into(); self.stack.truncate(new_base + 1); } @@ -672,7 +672,7 @@ impl VM { self.push(Value::Function(Vec::new(), Rc::clone(&block))); for arg in block.borrow().args() { - self.push(arg.as_value()); + self.push(arg.into()); } self.frames.push(Frame { -- cgit v1.2.1