From a8c603164cb30721800029f8d951365d1185579d Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 29 Aug 2021 00:10:44 +0200 Subject: [PATCH 1/2] AbleFunctio's body length is now by it's string representation --- ablescript/src/variables.rs | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 3a5b186b..5d3eada3 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -93,11 +93,16 @@ impl Value { Value::Abool(a) => a as _, Value::Bool(b) => b as _, Value::Functio(func) => match func { + // Compares lengths of functions: + // 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 { instructions, tape_len, } => (instructions.len() + tape_len) as _, - Functio::AbleFunctio { params, body } => (params.len() + body.len()) as _, + Functio::AbleFunctio { params, body } => (params.len() + format!("{:?}", body).len()) as _, Functio::Eval(s) => s.len() as _, }, Value::Int(i) => i, @@ -361,32 +366,7 @@ impl PartialOrd for Value { Value::Int(i) => Some(i.cmp(&other.into_i32())), Value::Bool(b) => Some(b.cmp(&other.into_bool())), Value::Abool(a) => a.partial_cmp(&other.into_abool()), - Value::Functio(f) => { - // Compares lengths of functions: - // BfFunctio - Sum of lengths of instructions and length of tape - // AbleFunctio - Sum of argument count and body length - // Eval - Length of input code - - let selfl = match f { - Functio::BfFunctio { - instructions, - tape_len, - } => instructions.len() + tape_len, - Functio::AbleFunctio { params, body } => params.len() + body.len(), - Functio::Eval(s) => s.len(), - }; - - let otherl = match other.into_functio() { - Functio::BfFunctio { - instructions, - tape_len, - } => instructions.len() + tape_len, - Functio::AbleFunctio { params, body } => params.len() + body.len(), - Functio::Eval(s) => s.len(), - }; - - Some(selfl.cmp(&otherl)) - } + Value::Functio(_) => self.clone().into_i32().partial_cmp(&other.into_i32()), Value::Cart(c) => Some(c.len().cmp(&other.into_cart().len())), } } From 3ce85a11ee786b8135f3cb7feb99d98f8abbd8da Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 29 Aug 2021 00:16:15 +0200 Subject: [PATCH 2/2] Eval errors are now correctly spanned --- ablescript/src/interpret.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index 656583a9..cf85a10f 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -355,7 +355,10 @@ impl ExecEnv { } let stmts = crate::parser::Parser::new(&code).init()?; - self.eval_stmts(&stmts)?; + self.eval_stmts(&stmts).map_err(|x| Error { + span: span.clone(), + ..x + })?; } } Ok(())