Fix indexing return type and casting to and from a char
This commit is contained in:
parent
bbdfae081d
commit
28437aecb6
@ -31,6 +31,16 @@ pub fn new_string() -> String {
|
|||||||
String {
|
String {
|
||||||
inner: allocate(0),
|
inner: allocate(0),
|
||||||
length: 0,
|
length: 0,
|
||||||
|
max_length: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_str(str: *char) -> String {
|
||||||
|
let length = str_length(str, 0);
|
||||||
|
String {
|
||||||
|
inner: str,
|
||||||
|
length: length,
|
||||||
|
max_length: length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,13 +52,17 @@ pub fn add_char(string: &mut String, c: char) {
|
|||||||
free((*string).inner as *u8);
|
free((*string).inner as *u8);
|
||||||
(*string).max_length = (*string).max_length + 4;
|
(*string).max_length = (*string).max_length + 4;
|
||||||
(*string).inner = new;
|
(*string).inner = new;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(*string).inner[(*string).length] = c;
|
(*string).inner[(*string).length] = c;
|
||||||
(((*string).inner) as *u8)[((*string).length + 1)] = 0;
|
(((*string).inner) as *u8)[((*string).length + 1)] = 0;
|
||||||
(*string).length = (*string).length + 1;
|
(*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 {
|
fn copy_bits(from: *char, to: *char, pos: u64, max: u64) -> u8 {
|
||||||
if (pos >= max) {
|
if (pos >= max) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -57,6 +71,9 @@ fn copy_bits(from: *char, to: *char, pos: u64, max: u64) -> u8 {
|
|||||||
return copy_bits(from, to, pos + 1, max);
|
return copy_bits(from, to, pos + 1, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn free_string(string: &mut String) {
|
fn str_length(string: *char, position: u32) -> u32 {
|
||||||
free((*string).inner as *u8);
|
if ((string[position] as u8) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return str_length(string, position + 1) + 1;
|
||||||
}
|
}
|
@ -1083,7 +1083,9 @@ impl mir::Expression {
|
|||||||
)),
|
)),
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
},
|
},
|
||||||
(TypeKind::UserPtr(_), TypeKind::UserPtr(_)) => Some(StackValue(
|
(TypeKind::UserPtr(_), TypeKind::UserPtr(_))
|
||||||
|
| (TypeKind::Char, TypeKind::U8)
|
||||||
|
| (TypeKind::U8, TypeKind::Char) => Some(StackValue(
|
||||||
val.0.derive(
|
val.0.derive(
|
||||||
scope
|
scope
|
||||||
.block
|
.block
|
||||||
|
@ -394,6 +394,8 @@ impl Expression {
|
|||||||
let expr_type = expression.return_type(refs, mod_id)?;
|
let expr_type = expression.return_type(refs, mod_id)?;
|
||||||
if let TypeKind::Array(elem_ty, _) = expr_type.1.resolve_weak(refs) {
|
if let TypeKind::Array(elem_ty, _) = expr_type.1.resolve_weak(refs) {
|
||||||
Ok((ReturnKind::Soft, *elem_ty))
|
Ok((ReturnKind::Soft, *elem_ty))
|
||||||
|
} else if let TypeKind::UserPtr(_) = expr_type.1.resolve_weak(refs) {
|
||||||
|
Ok((ReturnKind::Soft, expr_type.1))
|
||||||
} else {
|
} else {
|
||||||
Err(ReturnTypeOther::IndexingNonArray(expression.1))
|
Err(ReturnTypeOther::IndexingNonArray(expression.1))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user