Compare commits
No commits in common. "64418635a5d3372489a2b3e4c1596505afbedde3" and "bbdfae081debfef2018cca3f9b56e3e6fb4cd574" have entirely different histories.
64418635a5
...
bbdfae081d
@ -31,21 +31,9 @@ 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);
|
|
||||||
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) {
|
pub fn add_char(string: &mut String, c: char) {
|
||||||
if ((*string).length + 1) >= (*string).max_length {
|
if ((*string).length + 1) >= (*string).max_length {
|
||||||
let new = allocate((*string).max_length + 4) as *char;
|
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);
|
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;
|
||||||
@ -73,9 +57,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn str_length(string: *char, position: u32) -> u32 {
|
pub fn free_string(string: &mut String) {
|
||||||
if ((string[position] as u8) == 0) {
|
free((*string).inner as *u8);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return str_length(string, position + 1) + 1;
|
|
||||||
}
|
}
|
@ -1083,9 +1083,7 @@ impl mir::Expression {
|
|||||||
)),
|
)),
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
},
|
},
|
||||||
(TypeKind::UserPtr(_), TypeKind::UserPtr(_))
|
(TypeKind::UserPtr(_), TypeKind::UserPtr(_)) => Some(StackValue(
|
||||||
| (TypeKind::Char, TypeKind::U8)
|
|
||||||
| (TypeKind::U8, TypeKind::Char) => Some(StackValue(
|
|
||||||
val.0.derive(
|
val.0.derive(
|
||||||
scope
|
scope
|
||||||
.block
|
.block
|
||||||
|
@ -394,8 +394,6 @@ 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))
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
import std::print;
|
import std::print;
|
||||||
import std::from_str;
|
import std::new_string;
|
||||||
import std::add_char;
|
import std::add_char;
|
||||||
import std::free_string;
|
import std::free_string;
|
||||||
|
|
||||||
fn main() -> i32 {
|
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);
|
print(&test);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user