diff options
| -rw-r--r-- | src/compiler.rs | 20 | ||||
| -rw-r--r-- | src/typer.rs | 12 | ||||
| -rw-r--r-- | src/vm.rs | 2 |
3 files changed, 17 insertions, 17 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index df816c9..caa72cd 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -48,8 +48,8 @@ nextable_enum!(Prec { #[derive(Debug, Clone)] pub enum Type { - NoType, - UnkownType, + Void, + UnknownType, Int, Float, Bool, @@ -60,7 +60,7 @@ pub enum Type { impl PartialEq for Type { fn eq(&self, other: &Self) -> bool { match (self, other) { - (Type::NoType, Type::NoType) => true, + (Type::Void, Type::Void) => true, (Type::Int, Type::Int) => true, (Type::Float, Type::Float) => true, (Type::Bool, Type::Bool) => true, @@ -81,7 +81,7 @@ impl From<&Value> for Type { Value::String(_) => Type::String, Value::Function(args, ret, _) => Type::Function(args.clone(), Box::new(ret.clone())), - _ => Type::NoType, + _ => Type::Void, } } } @@ -120,7 +120,7 @@ macro_rules! push_frame { }); // Return value stored as a variable - $compiler.define_variable("", Type::UnkownType, &mut $block).unwrap(); + $compiler.define_variable("", Type::UnknownType, &mut $block).unwrap(); $code $compiler.frames.pop().unwrap(); @@ -422,7 +422,7 @@ impl Compiler { }; let mut args = Vec::new(); - let mut return_type = Type::NoType; + let mut return_type = Type::Void; let mut function_block = Block::new(name, &self.current_file, self.line()); let _ret = push_frame!(self, function_block, { loop { @@ -575,7 +575,7 @@ impl Compiler { (Token::Identifier(name), Token::ColonEqual, ..) => { self.eat(); self.eat(); - self.definition_statement(&name, Type::UnkownType, block); + self.definition_statement(&name, Type::UnknownType, block); } (Token::Comma, ..) => {} @@ -627,10 +627,10 @@ impl Compiler { } Token::Arrow => { self.eat(); - break self.parse_type().unwrap_or(Type::NoType); + break self.parse_type().unwrap_or(Type::Void); } Token::Comma | Token::Equal => { - break Type::NoType; + break Type::Void; } token => { error!(self, format!("Function type signature contains non-type {:?}.", token)); @@ -686,7 +686,7 @@ impl Compiler { tokens!(Token::Identifier(name), Token::ColonEqual) => { self.eat(); self.eat(); - self.definition_statement(&name, Type::UnkownType, block); + self.definition_statement(&name, Type::UnknownType, block); } tokens!(Token::Identifier(name), Token::Equal) => { diff --git a/src/typer.rs b/src/typer.rs index c7d0d92..44aaabb 100644 --- a/src/typer.rs +++ b/src/typer.rs @@ -203,7 +203,7 @@ impl VM { Op::Equal | Op::Less | Op::Greater => { match self.pop_twice() { - (a, b) if (&[&a, &b]).contains(&&Type::UnkownType) => + (a, b) if (&[&a, &b]).contains(&&Type::UnknownType) => error!(self, ErrorKind::TypeError(op.clone(), vec![a, b])), (a, b) if a == b => self.stack.push(Type::Bool), (a, b) => error!(self, ErrorKind::TypeError(op.clone(), vec![a, b])), @@ -251,8 +251,8 @@ impl VM { let lhs = self.stack[slot].clone(); let rhs = self.pop(); match (&lhs, &rhs) { - (Type::UnkownType, rhs) => { - if rhs == &Type::UnkownType { + (Type::UnknownType, rhs) => { + if rhs == &Type::UnknownType { error!(self, ErrorKind::TypeError(op.clone(), vec![lhs, rhs.clone()]), ""); } else { self.stack[slot] = rhs.clone(); @@ -270,8 +270,8 @@ impl VM { Op::Define(ref ty) => { let top_type = self.stack.last().unwrap(); match (ty, top_type) { - (Type::UnkownType, top_type) - if top_type != &Type::UnkownType => {} + (Type::UnknownType, top_type) + if top_type != &Type::UnknownType => {} (a, b) if a != b => { error!(self, ErrorKind::TypeError( @@ -322,7 +322,7 @@ impl VM { return Ok(()); } - let a = self.stack.pop().unwrap_or(Type::NoType); + let a = self.stack.pop().unwrap_or(Type::Void); if a != return_type { error!(self, ErrorKind::TypeError(op, vec![a, return_type.clone()]), "Not matching return type."); } @@ -232,7 +232,7 @@ impl VM { pub fn run(&mut self, block: Rc<Block>) -> Result<(), Error>{ crate::typer::VM::new().print_ops(self.print_ops) .print_blocks(self.print_blocks) - .typecheck(Type::NoType, Rc::clone(&block))?; + .typecheck(Type::Void, Rc::clone(&block))?; self.frames.push(Frame { stack_offset: 0, |
