Compare commits

..

No commits in common. "64418635a5d3372489a2b3e4c1596505afbedde3" and "bbdfae081debfef2018cca3f9b56e3e6fb4cd574" have entirely different histories.

4 changed files with 11 additions and 29 deletions

View File

@ -31,21 +31,9 @@ pub fn new_string() -> String {
String {
inner: allocate(0),
length: 0,
max_length: 0,
}
}
pub fn from_str(str: *char) -> String {
let length = str_length(str, 0);
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) {
if ((*string).length + 1) >= (*string).max_length {
let new = allocate((*string).max_length + 4) as *char;
@ -54,17 +42,13 @@ pub fn add_char(string: &mut String, c: char) {
free((*string).inner as *u8);
(*string).max_length = (*string).max_length + 4;
(*string).inner = new;
}
}
(*string).inner[(*string).length] = c;
(((*string).inner) as *u8)[((*string).length + 1)] = 0;
(*string).length = (*string).length + 1;
}
pub fn free_string(string: &mut String) {
free((*string).inner as *u8);
}
fn copy_bits(from: *char, to: *char, pos: u64, max: u64) -> u8 {
if (pos >= max) {
return 0;
@ -73,9 +57,6 @@ fn copy_bits(from: *char, to: *char, pos: u64, max: u64) -> u8 {
return copy_bits(from, to, pos + 1, max);
}
fn str_length(string: *char, position: u32) -> u32 {
if ((string[position] as u8) == 0) {
return 0;
}
return str_length(string, position + 1) + 1;
pub fn free_string(string: &mut String) {
free((*string).inner as *u8);
}

View File

@ -1083,9 +1083,7 @@ impl mir::Expression {
)),
_ => panic!(),
},
(TypeKind::UserPtr(_), TypeKind::UserPtr(_))
| (TypeKind::Char, TypeKind::U8)
| (TypeKind::U8, TypeKind::Char) => Some(StackValue(
(TypeKind::UserPtr(_), TypeKind::UserPtr(_)) => Some(StackValue(
val.0.derive(
scope
.block

View File

@ -394,8 +394,6 @@ impl Expression {
let expr_type = expression.return_type(refs, mod_id)?;
if let TypeKind::Array(elem_ty, _) = expr_type.1.resolve_weak(refs) {
Ok((ReturnKind::Soft, *elem_ty))
} else if let TypeKind::UserPtr(_) = expr_type.1.resolve_weak(refs) {
Ok((ReturnKind::Soft, expr_type.1))
} else {
Err(ReturnTypeOther::IndexingNonArray(expression.1))
}

View File

@ -1,10 +1,15 @@
import std::print;
import std::from_str;
import std::new_string;
import std::add_char;
import std::free_string;
fn main() -> i32 {
let mut test = from_str("hello world");
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');
print(&test);