Compare commits
3 Commits
de803e9024
...
7027ee3645
Author | SHA1 | Date | |
---|---|---|---|
7027ee3645 | |||
f6ed39d4e5 | |||
aeca557b6f |
@ -16,6 +16,9 @@ fn test() -> Test {
|
||||
fn main() -> u32 {
|
||||
let mut value = test();
|
||||
|
||||
let beep = [2, 3, 4];
|
||||
let boop = 3;
|
||||
|
||||
let mut a = &mut value;
|
||||
|
||||
*a.second[2] = 5;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ fn main() -> u32 {
|
||||
for i in 0 .. 15 {
|
||||
let mut text = from_str("num: ");
|
||||
add_num_to_str(&mut text, i);
|
||||
print(&text);
|
||||
free_string(&mut text);
|
||||
print(text);
|
||||
free_string(&text);
|
||||
}
|
||||
|
||||
let mut num = 0;
|
||||
|
@ -6,7 +6,7 @@ import std::int_div;
|
||||
fn main() -> i32 {
|
||||
let hello = from_str("hello world");
|
||||
|
||||
print(&hello);
|
||||
print(hello);
|
||||
|
||||
return int_div(15, 5).quotient;
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -596,15 +596,25 @@ impl TypeKind {
|
||||
/// Try to collapse a type on itself producing a default type if one exists,
|
||||
/// Error if not.
|
||||
pub fn or_default(&self) -> Result<TypeKind, ErrorKind> {
|
||||
match self {
|
||||
Ok(match self {
|
||||
TypeKind::Vague(vague_type) => match &vague_type {
|
||||
Vague::Unknown => Err(ErrorKind::TypeIsVague(*vague_type)),
|
||||
Vague::Integer => Ok(TypeKind::I32),
|
||||
Vague::Unknown => Err(ErrorKind::TypeIsVague(*vague_type))?,
|
||||
Vague::Integer => TypeKind::I32,
|
||||
Vague::TypeRef(_) => panic!("Hinted default!"),
|
||||
VagueType::Decimal => Ok(TypeKind::F32),
|
||||
VagueType::Decimal => TypeKind::F32,
|
||||
},
|
||||
_ => Ok(self.clone()),
|
||||
}
|
||||
TypeKind::Array(type_kind, len) => {
|
||||
TypeKind::Array(Box::new(type_kind.or_default()?), *len)
|
||||
}
|
||||
TypeKind::Borrow(type_kind, mutable) => {
|
||||
TypeKind::Borrow(Box::new(type_kind.or_default()?), *mutable)
|
||||
}
|
||||
TypeKind::UserPtr(type_kind) => TypeKind::UserPtr(Box::new(type_kind.or_default()?)),
|
||||
TypeKind::CodegenPtr(type_kind) => {
|
||||
TypeKind::CodegenPtr(Box::new(type_kind.or_default()?))
|
||||
}
|
||||
_ => self.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn resolve_weak(&self, refs: &TypeRefs) -> TypeKind {
|
||||
|
@ -222,7 +222,11 @@ impl Block {
|
||||
let ret = match &mut statement.0 {
|
||||
StmtKind::Let(variable_reference, mutable, expression) => {
|
||||
// Resolve possible hint in var reference
|
||||
let var_t_resolved = variable_reference.0.resolve_ref(&typerefs);
|
||||
let var_t_resolved = state.or_else(
|
||||
variable_reference.0.resolve_ref(&typerefs).or_default(),
|
||||
TypeKind::Vague(VagueType::Unknown),
|
||||
variable_reference.2,
|
||||
);
|
||||
|
||||
// Typecheck (and coerce) expression with said type
|
||||
let res = expression.typecheck(&mut state, &typerefs, Some(&var_t_resolved));
|
||||
|
Loading…
Reference in New Issue
Block a user