Compare commits
No commits in common. "7027ee36454ee52a24f0c217d172fc0336b14b79" and "de803e90246a28369b371c00dd7768c170869b30" have entirely different histories.
7027ee3645
...
de803e9024
@ -16,9 +16,6 @@ fn test() -> Test {
|
|||||||
fn main() -> u32 {
|
fn main() -> u32 {
|
||||||
let mut value = test();
|
let mut value = test();
|
||||||
|
|
||||||
let beep = [2, 3, 4];
|
|
||||||
let boop = 3;
|
|
||||||
|
|
||||||
let mut a = &mut value;
|
let mut a = &mut value;
|
||||||
|
|
||||||
*a.second[2] = 5;
|
*a.second[2] = 5;
|
||||||
|
@ -9,17 +9,18 @@ import std::concat_strings;
|
|||||||
|
|
||||||
fn main() -> i32 {
|
fn main() -> i32 {
|
||||||
let mut test = from_str("hello");
|
let mut test = from_str("hello");
|
||||||
|
let mut other = from_str(" world");
|
||||||
|
|
||||||
concat_strings(&mut test, from_str(" world"));
|
concat_strings(&mut test, &other);
|
||||||
|
|
||||||
add_char(&mut test, '!');
|
add_char(&mut test, '!');
|
||||||
add_char(&mut test, '\n');
|
add_char(&mut test, '\n');
|
||||||
|
|
||||||
add_num_to_str(&mut test, 175);
|
add_num_to_str(&mut test, 175);
|
||||||
|
|
||||||
print(test);
|
print(&test);
|
||||||
|
|
||||||
free_string(&test);
|
free_string(&mut test);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ fn main() -> u32 {
|
|||||||
for i in 0 .. 15 {
|
for i in 0 .. 15 {
|
||||||
let mut text = from_str("num: ");
|
let mut text = from_str("num: ");
|
||||||
add_num_to_str(&mut text, i);
|
add_num_to_str(&mut text, i);
|
||||||
print(text);
|
print(&text);
|
||||||
free_string(&text);
|
free_string(&mut text);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut num = 0;
|
let mut num = 0;
|
||||||
|
@ -6,7 +6,7 @@ import std::int_div;
|
|||||||
fn main() -> i32 {
|
fn main() -> i32 {
|
||||||
let hello = from_str("hello world");
|
let hello = from_str("hello world");
|
||||||
|
|
||||||
print(hello);
|
print(&hello);
|
||||||
|
|
||||||
return int_div(15, 5).quotient;
|
return int_div(15, 5).quotient;
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ struct div_t {
|
|||||||
remainder: i32,
|
remainder: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print(message: String) {
|
pub fn print(message: &String) {
|
||||||
puts(message.inner);
|
puts(*message.inner);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn int_div(numerator: i32, denominator: i32) -> div_t {
|
pub fn int_div(numerator: i32, denominator: i32) -> div_t {
|
||||||
@ -46,7 +46,7 @@ pub fn from_str(str: *char) -> String {
|
|||||||
max_length: length,
|
max_length: length,
|
||||||
must_be_freed: false,
|
must_be_freed: false,
|
||||||
};
|
};
|
||||||
concat_strings(&mut new, static);
|
concat_strings(&mut new, &static);
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ pub fn set_char(string: &mut String, c: char, position: u64) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn free_string(string: &String) {
|
pub fn free_string(string: &mut String) {
|
||||||
free((*string).inner as *u8);
|
free((*string).inner as *u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,12 +110,6 @@ pub fn add_num_to_str(string: &mut String, num: u64) {
|
|||||||
else if rem == 9 { add_char(string, '9'); }
|
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 {
|
pub fn clamp(min: f32, max: f32, value: f32) -> f32 {
|
||||||
if value > max {
|
if value > max {
|
||||||
return max;
|
return max;
|
||||||
@ -132,3 +126,9 @@ pub fn abs(f: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
return f;
|
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,25 +596,15 @@ impl TypeKind {
|
|||||||
/// Try to collapse a type on itself producing a default type if one exists,
|
/// Try to collapse a type on itself producing a default type if one exists,
|
||||||
/// Error if not.
|
/// Error if not.
|
||||||
pub fn or_default(&self) -> Result<TypeKind, ErrorKind> {
|
pub fn or_default(&self) -> Result<TypeKind, ErrorKind> {
|
||||||
Ok(match self {
|
match self {
|
||||||
TypeKind::Vague(vague_type) => match &vague_type {
|
TypeKind::Vague(vague_type) => match &vague_type {
|
||||||
Vague::Unknown => Err(ErrorKind::TypeIsVague(*vague_type))?,
|
Vague::Unknown => Err(ErrorKind::TypeIsVague(*vague_type)),
|
||||||
Vague::Integer => TypeKind::I32,
|
Vague::Integer => Ok(TypeKind::I32),
|
||||||
Vague::TypeRef(_) => panic!("Hinted default!"),
|
Vague::TypeRef(_) => panic!("Hinted default!"),
|
||||||
VagueType::Decimal => TypeKind::F32,
|
VagueType::Decimal => Ok(TypeKind::F32),
|
||||||
},
|
},
|
||||||
TypeKind::Array(type_kind, len) => {
|
_ => Ok(self.clone()),
|
||||||
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 {
|
pub fn resolve_weak(&self, refs: &TypeRefs) -> TypeKind {
|
||||||
|
@ -222,11 +222,7 @@ impl Block {
|
|||||||
let ret = match &mut statement.0 {
|
let ret = match &mut statement.0 {
|
||||||
StmtKind::Let(variable_reference, mutable, expression) => {
|
StmtKind::Let(variable_reference, mutable, expression) => {
|
||||||
// Resolve possible hint in var reference
|
// Resolve possible hint in var reference
|
||||||
let var_t_resolved = state.or_else(
|
let var_t_resolved = variable_reference.0.resolve_ref(&typerefs);
|
||||||
variable_reference.0.resolve_ref(&typerefs).or_default(),
|
|
||||||
TypeKind::Vague(VagueType::Unknown),
|
|
||||||
variable_reference.2,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Typecheck (and coerce) expression with said type
|
// Typecheck (and coerce) expression with said type
|
||||||
let res = expression.typecheck(&mut state, &typerefs, Some(&var_t_resolved));
|
let res = expression.typecheck(&mut state, &typerefs, Some(&var_t_resolved));
|
||||||
|
Loading…
Reference in New Issue
Block a user