diff --git a/reid/lib/std.reid b/reid/lib/std.reid index 8960af8..4749871 100644 --- a/reid/lib/std.reid +++ b/reid/lib/std.reid @@ -37,11 +37,13 @@ pub fn new_string() -> String { pub fn from_str(str: *char) -> String { let length = str_length(str, 0); - String { - inner: str, + let cloned = malloc(length as u64) as *char; + copy_bits(str, cloned, 0, length as u64); + return String { + inner: cloned, length: length, max_length: length - } + }; } pub fn add_char(string: &mut String, c: char) { diff --git a/reid_src/hello_world.reid b/reid_src/hello_world.reid index 542f6e5..6dbce11 100644 --- a/reid_src/hello_world.reid +++ b/reid_src/hello_world.reid @@ -1,15 +1,10 @@ import std::print; -import std::new_string; +import std::from_str; import std::add_char; import std::free_string; fn main() -> i32 { - let mut test = new_string(); - add_char(&mut test, 'h'); - add_char(&mut test, 'e'); - add_char(&mut test, 'l'); - add_char(&mut test, 'l'); - add_char(&mut test, 'o'); + let mut test = from_str("hello world"); print(&test);