From aeca557b6f9ca1fce3b6b642c1c89045bfa70736 Mon Sep 17 00:00:00 2001 From: sofia Date: Wed, 23 Jul 2025 22:04:34 +0300 Subject: [PATCH] Make breaking changes to stdlib --- examples/hello_world.reid | 7 +++---- reid/lib/std.reid | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/examples/hello_world.reid b/examples/hello_world.reid index 4c8a10d..f6792e1 100644 --- a/examples/hello_world.reid +++ b/examples/hello_world.reid @@ -9,18 +9,17 @@ import std::concat_strings; fn main() -> i32 { let mut test = from_str("hello"); - let mut other = from_str(" world"); - concat_strings(&mut test, &other); + concat_strings(&mut test, from_str(" world")); add_char(&mut test, '!'); add_char(&mut test, '\n'); add_num_to_str(&mut test, 175); - print(&test); + print(test); - free_string(&mut test); + free_string(&test); return 0; } diff --git a/reid/lib/std.reid b/reid/lib/std.reid index 59ec5dd..0c8501e 100644 --- a/reid/lib/std.reid +++ b/reid/lib/std.reid @@ -9,8 +9,8 @@ struct div_t { remainder: i32, } -pub fn print(message: &String) { - puts(*message.inner); +pub fn print(message: String) { + puts(message.inner); } pub fn int_div(numerator: i32, denominator: i32) -> div_t { @@ -46,7 +46,7 @@ pub fn from_str(str: *char) -> String { max_length: length, must_be_freed: false, }; - concat_strings(&mut new, &static); + concat_strings(&mut new, static); return new; } @@ -74,7 +74,7 @@ pub fn set_char(string: &mut String, c: char, position: u64) { } } -pub fn free_string(string: &mut String) { +pub fn free_string(string: &String) { free((*string).inner as *u8); } @@ -110,6 +110,12 @@ pub fn add_num_to_str(string: &mut String, num: u64) { else if rem == 9 { add_char(string, '9'); } } +pub fn concat_strings(destination: &mut String, source: String) { + for i in 0 .. (str_length(source.inner) - 1) { + add_char(destination, source.inner[i]); + } +} + pub fn clamp(min: f32, max: f32, value: f32) -> f32 { if value > max { return max; @@ -126,9 +132,3 @@ pub fn abs(f: f32) -> f32 { } return f; } - -pub fn concat_strings(destination: &mut String, source: &String) { - for i in 0 .. (str_length((*source).inner) - 1) { - add_char(destination, (*source).inner[i]); - } -}