diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index 5c9cae6c..23fc846e 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -205,7 +205,7 @@ impl ExecEnv { } => { self.decl_var( &ident.ident, - Value::Functio(Functio::AbleFunctio { + Value::Functio(Functio::Able { params: params.iter().map(|ident| ident.ident.to_owned()).collect(), body: body.block.to_owned(), }), @@ -218,7 +218,7 @@ impl ExecEnv { } => { self.decl_var( &ident.ident, - Value::Functio(Functio::BfFunctio { + Value::Functio(Functio::Bf { instructions: code.to_owned(), tape_len: tape_len .as_ref() @@ -351,7 +351,7 @@ impl ExecEnv { .collect::, Error>>()?; match func { - Functio::BfFunctio { + Functio::Bf { instructions, tape_len, } => { @@ -377,7 +377,7 @@ impl ExecEnv { .write_all(&output) .expect("Failed to write to stdout"); } - Functio::AbleFunctio { params, body } => { + Functio::Able { params, body } => { if params.len() != args.len() { return Err(Error { kind: ErrorKind::MismatchedArgumentError, diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index a34f3cba..e1f44597 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -36,11 +36,11 @@ impl From for bool { #[derive(Debug, PartialEq, Clone, Hash)] pub enum Functio { - BfFunctio { + Bf { instructions: Vec, tape_len: usize, }, - AbleFunctio { + Able { params: Vec, body: Vec, }, @@ -103,11 +103,11 @@ impl Value { // BfFunctio - Sum of lengths of instructions and length of tape // AbleFunctio - Sum of argument count and body length // Eval - Length of input code - Functio::BfFunctio { + Functio::Bf { instructions, tape_len, } => (instructions.len() + tape_len) as _, - Functio::AbleFunctio { params, body } => { + Functio::Able { params, body } => { (params.len() + format!("{:?}", body).len()) as _ } Functio::Eval(s) => s.len() as _, @@ -166,14 +166,14 @@ impl Value { } Value::Abool(a) => a, Value::Functio(f) => match f { - Functio::BfFunctio { + Functio::Bf { instructions, tape_len, } => Value::Int( (instructions.iter().map(|x| *x as usize).sum::() * tape_len) as _, ) .into_abool(), - Functio::AbleFunctio { params, body } => { + Functio::Able { params, body } => { let str_to_i32 = |x: String| -> i32 { x.as_bytes().into_iter().map(|x| *x as i32).sum() }; @@ -201,12 +201,12 @@ impl Value { /// Coerce a value to a functio. pub fn into_functio(self) -> Functio { match self { - Value::Nul => Functio::AbleFunctio { + Value::Nul => Functio::Able { body: vec![], params: vec![], }, Value::Str(s) => Functio::Eval(s), - Value::Int(i) => Functio::BfFunctio { + Value::Int(i) => Functio::Bf { instructions: { let instruction_mappings = b"[]+-,.<>"; std::iter::successors(Some(i as usize), |i| { @@ -260,7 +260,7 @@ impl Value { Value::Bool(b) => Value::Str(b.to_string()).into_cart(), Value::Abool(a) => Value::Str(a.to_string()).into_cart(), Value::Functio(f) => match f { - Functio::AbleFunctio { params, body } => { + Functio::Able { params, body } => { let params: Cart = params .into_iter() .enumerate() @@ -296,7 +296,7 @@ impl Value { cart } - Functio::BfFunctio { + Functio::Bf { instructions, tape_len, } => { @@ -494,25 +494,25 @@ impl ops::Not for Value { Abool::Always => Abool::Never, }), Value::Functio(f) => Value::Functio(match f { - Functio::BfFunctio { + Functio::Bf { mut instructions, tape_len, } => { instructions.reverse(); - Functio::BfFunctio { + Functio::Bf { instructions, tape_len, } } - Functio::AbleFunctio { + Functio::Able { mut params, mut body, } => { params.reverse(); body.reverse(); - Functio::AbleFunctio { params, body } + Functio::Able { params, body } } Functio::Eval(code) => Functio::Eval(code.chars().rev().collect()), }), @@ -575,7 +575,7 @@ impl Display for Value { Value::Bool(v) => write!(f, "{}", v), Value::Abool(v) => write!(f, "{}", v), Value::Functio(v) => match v { - Functio::BfFunctio { + Functio::Bf { instructions, tape_len, } => { @@ -587,7 +587,7 @@ impl Display for Value { .expect("Brainfuck functio source should be UTF-8") ) } - Functio::AbleFunctio { params, body } => { + Functio::Able { params, body } => { write!( f, "({}) -> {:?}",