diff --git a/package/origlang-compiler-entrypoint/src/lib.rs b/package/origlang-compiler-entrypoint/src/lib.rs index 4d7a8c6..fb17f03 100644 --- a/package/origlang-compiler-entrypoint/src/lib.rs +++ b/package/origlang-compiler-entrypoint/src/lib.rs @@ -63,8 +63,8 @@ impl TheCompiler { self } - pub fn compile(&self, source: String) -> Result, PartialCompilation> { - let x = Parser::create(&source); + pub fn compile(&self, source: &str) -> Result, PartialCompilation> { + let x = Parser::create(source); let root = x.parse()?; let typeck = TypeChecker::new().check(root)?; let ir0_seq = typeck.into_ir(); diff --git a/package/origlang-compiler-scanner-example/src/lib.rs b/package/origlang-compiler-scanner-example/src/lib.rs index c95c892..2dba939 100644 --- a/package/origlang-compiler-scanner-example/src/lib.rs +++ b/package/origlang-compiler-scanner-example/src/lib.rs @@ -77,7 +77,7 @@ mod tests { s.ir1_scanner.push(PreOrPost::Pre(Box::new(MyScanner))); }) .register_diagnostic_receiver(Box::new(tdr)) - .compile("var foo = 1i32\n".to_string()); + .compile("var foo = 1i32\n"); assert!(a.is_ok()); } diff --git a/package/origlang-interop/src/lib.rs b/package/origlang-interop/src/lib.rs index d4902d1..bf815ba 100644 --- a/package/origlang-interop/src/lib.rs +++ b/package/origlang-interop/src/lib.rs @@ -35,6 +35,7 @@ struct PseudoStdout; impl OutputAccumulator for PseudoStdout { fn output(&mut self, tb: TypeBox) { + // TODO: this shall be Box whenever possible. let s: String = match tb { TypeBox::NonCoercedInteger(x) => x.to_string(), TypeBox::Int8(i) => i.to_string(), diff --git a/package/origlang-lexer/src/tests.rs b/package/origlang-lexer/src/tests.rs index 9f291a6..23fa8ac 100644 --- a/package/origlang-lexer/src/tests.rs +++ b/package/origlang-lexer/src/tests.rs @@ -9,11 +9,11 @@ fn test(str_lit: &str) { assert_eq!( p.next().data, Token::Identifier { - inner: Identifier::new("x".to_string()), + inner: Identifier::new("x".to_string().into_boxed_str()), } ); assert_eq!(p.next().data, Token::SymEq); - assert_eq!(p.next().data, Token::StringLiteral(str_lit.to_string())); + assert_eq!(p.next().data, Token::StringLiteral(str_lit.to_string().into_boxed_str())); } #[test] @@ -117,7 +117,7 @@ fn token_location() { lexer.next(), Pointed { data: Token::Identifier { - inner: Identifier::new("x".to_string()) + inner: Identifier::new("x".to_string().into_boxed_str()) }, position: SourcePosition::try_new((1, 5)).unwrap() } @@ -162,7 +162,7 @@ fn token_location() { lexer.next(), Pointed { data: Token::Identifier { - inner: Identifier::new("y".to_string()) + inner: Identifier::new("y".to_string().into_boxed_str()) }, position: SourcePosition::try_new((2, 5)).unwrap() } diff --git a/package/origlang-runtime/src/tests.rs b/package/origlang-runtime/src/tests.rs index 80e1f34..f4c7f58 100644 --- a/package/origlang-runtime/src/tests.rs +++ b/package/origlang-runtime/src/tests.rs @@ -6,7 +6,7 @@ mod display { #[test] fn empty() { let x = DisplayRecordValue { - name: Identifier::new("abcdef".to_string()), + name: Identifier::new("abcdef".to_string().into_boxed_str()), values: vec![], }; @@ -17,9 +17,9 @@ mod display { #[test] fn one() { let x = DisplayRecordValue { - name: Identifier::new("abcdef".to_string()), + name: Identifier::new("abcdef".to_string().into_boxed_str()), values: vec![ - TypeBox::String("defg".to_string()) + TypeBox::String("defg".to_string().into_boxed_str()) ], }; @@ -30,11 +30,11 @@ mod display { #[test] fn many() { let x = DisplayRecordValue { - name: Identifier::new("abcdef".to_string()), + name: Identifier::new("abcdef".to_string().into_boxed_str()), values: vec![ - TypeBox::String("abcdef".to_string()), - TypeBox::String("ghijkl".to_string()), - TypeBox::String("alice".to_string()) + TypeBox::String("abcdef".to_string().into_boxed_str()), + TypeBox::String("ghijkl".to_string().into_boxed_str()), + TypeBox::String("alice".to_string().into_boxed_str()) ], }; @@ -59,7 +59,7 @@ mod display { #[test] fn one() { let x = DisplayTupleValue { - boxes: Box::new([TypeBox::String("abcd".to_string())]), + boxes: Box::new([TypeBox::String("abcd".to_string().into_boxed_str())]), }; let x = format!("{x}"); @@ -69,7 +69,7 @@ mod display { #[test] fn many() { let x = DisplayTupleValue { - boxes: Box::new([TypeBox::String("abcd".to_string()), TypeBox::String("defg".to_string())]), + boxes: Box::new([TypeBox::String("abcd".to_string().into_boxed_str()), TypeBox::String("defg".to_string().into_boxed_str())]), }; let x = format!("{x}"); diff --git a/package/origlang-typecheck/src/type_check.rs b/package/origlang-typecheck/src/type_check.rs index e84cd88..bbdda4a 100644 --- a/package/origlang-typecheck/src/type_check.rs +++ b/package/origlang-typecheck/src/type_check.rs @@ -208,7 +208,7 @@ impl TryIntoTypeCheckedForm for Expression { } } else { Err(TypeCheckError::GenericTypeMismatch { - context: "The condition of if-expression".to_string(), + context: "The condition of if-expression".to_string().into_boxed_str(), expected_type: Type::Boolean, actual_type: cond_type, }) @@ -490,7 +490,7 @@ impl TryIntoTypeCheckedForm for Statement { }]) } else { Err(TypeCheckError::GenericTypeMismatch { - context: "variable assignment".to_string(), + context: "variable assignment".to_string().into_boxed_str(), expected_type, actual_type: checked.actual_type(), }) diff --git a/package/origlang-typecheck/src/type_check/error.rs b/package/origlang-typecheck/src/type_check/error.rs index ca9b97f..a04d176 100644 --- a/package/origlang-typecheck/src/type_check/error.rs +++ b/package/origlang-typecheck/src/type_check/error.rs @@ -30,7 +30,7 @@ pub enum TypeCheckError { }, #[error("{context} must be {expected_type}, got {actual_type}")] GenericTypeMismatch { - context: String, + context: Box, expected_type: Type, actual_type: Type, },