forked from AbleScript/ablescript
Merge 'feature/forty-two' into master
This commit is contained in:
commit
09d551075a
|
@ -18,7 +18,6 @@ pub enum ErrorKind {
|
||||||
MeloVariable(String),
|
MeloVariable(String),
|
||||||
TypeError(String),
|
TypeError(String),
|
||||||
TopLevelBreak,
|
TopLevelBreak,
|
||||||
ArithmeticError,
|
|
||||||
BfInterpretError(InterpretError),
|
BfInterpretError(InterpretError),
|
||||||
MismatchedArgumentError,
|
MismatchedArgumentError,
|
||||||
MissingLhs,
|
MissingLhs,
|
||||||
|
|
|
@ -21,7 +21,7 @@ use rand::random;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{Expr, ExprKind, Iden, Stmt, StmtKind},
|
ast::{Expr, ExprKind, Iden, Stmt, StmtKind},
|
||||||
base_55,
|
base_55, consts,
|
||||||
error::{Error, ErrorKind},
|
error::{Error, ErrorKind},
|
||||||
variables::{Functio, Value, Variable},
|
variables::{Functio, Value, Variable},
|
||||||
};
|
};
|
||||||
|
@ -136,10 +136,7 @@ impl ExecEnv {
|
||||||
Divide => lhs.checked_div(rhs),
|
Divide => lhs.checked_div(rhs),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
.ok_or(Error {
|
.unwrap_or(consts::ANSWER);
|
||||||
kind: ErrorKind::ArithmeticError,
|
|
||||||
span: expr.span.clone(),
|
|
||||||
})?;
|
|
||||||
Int(res)
|
Int(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -501,7 +498,7 @@ mod tests {
|
||||||
// Integer overflow should throw a recoverable error instead
|
// Integer overflow should throw a recoverable error instead
|
||||||
// of panicking.
|
// of panicking.
|
||||||
let env = ExecEnv::new();
|
let env = ExecEnv::new();
|
||||||
assert!(matches!(
|
assert_eq!(
|
||||||
env.eval_expr(&Expr {
|
env.eval_expr(&Expr {
|
||||||
kind: ExprKind::BinOp {
|
kind: ExprKind::BinOp {
|
||||||
lhs: Box::new(Expr {
|
lhs: Box::new(Expr {
|
||||||
|
@ -515,15 +512,13 @@ mod tests {
|
||||||
kind: crate::ast::BinOpKind::Add,
|
kind: crate::ast::BinOpKind::Add,
|
||||||
},
|
},
|
||||||
span: 1..1
|
span: 1..1
|
||||||
}),
|
|
||||||
Err(Error {
|
|
||||||
kind: ErrorKind::ArithmeticError,
|
|
||||||
span: _,
|
|
||||||
})
|
})
|
||||||
));
|
.unwrap(),
|
||||||
|
Value::Int(42)
|
||||||
|
);
|
||||||
|
|
||||||
// And the same for divide by zero.
|
// And the same for divide by zero.
|
||||||
assert!(matches!(
|
assert_eq!(
|
||||||
env.eval_expr(&Expr {
|
env.eval_expr(&Expr {
|
||||||
kind: ExprKind::BinOp {
|
kind: ExprKind::BinOp {
|
||||||
lhs: Box::new(Expr {
|
lhs: Box::new(Expr {
|
||||||
|
@ -537,12 +532,10 @@ mod tests {
|
||||||
kind: crate::ast::BinOpKind::Divide,
|
kind: crate::ast::BinOpKind::Divide,
|
||||||
},
|
},
|
||||||
span: 1..1
|
span: 1..1
|
||||||
}),
|
|
||||||
Err(Error {
|
|
||||||
kind: ErrorKind::ArithmeticError,
|
|
||||||
span: _,
|
|
||||||
})
|
})
|
||||||
));
|
.unwrap(),
|
||||||
|
Value::Int(42)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// From here on out, I'll use this function to parse and run
|
// From here on out, I'll use this function to parse and run
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
mod ast;
|
mod ast;
|
||||||
mod base_55;
|
mod base_55;
|
||||||
mod brian;
|
mod brian;
|
||||||
|
mod consts;
|
||||||
mod error;
|
mod error;
|
||||||
mod interpret;
|
mod interpret;
|
||||||
mod lexer;
|
mod lexer;
|
||||||
|
|
Loading…
Reference in a new issue