diff --git a/examples/macro_easy.reid b/examples/macro_easy.reid index af43000..def121f 100644 --- a/examples/macro_easy.reid +++ b/examples/macro_easy.reid @@ -2,7 +2,8 @@ import std::String; import std::print; fn main() -> u8 { + // - TODO possibly allow to cast between &[ty] and *ty let bytes = test_macro!("./macro_easy_file.txt"); print(String::new() + bytes.length()); - return *bytes[0]; + return (bytes as *u8)[0]; } diff --git a/reid/src/codegen/mod.rs b/reid/src/codegen/mod.rs index 173b663..5e60dfc 100644 --- a/reid/src/codegen/mod.rs +++ b/reid/src/codegen/mod.rs @@ -1313,7 +1313,7 @@ impl mir::Expression { Some(val) } else { match (&val.1, type_kind) { - (TypeKind::CodegenPtr(inner), TypeKind::UserPtr(_)) => match *inner.clone() { + (TypeKind::CodegenPtr(inner), TypeKind::UserPtr(ty2)) => match *inner.clone() { TypeKind::UserPtr(_) => Some(StackValue( val.0.derive( scope @@ -1326,6 +1326,27 @@ impl mir::Expression { ), TypeKind::CodegenPtr(Box::new(type_kind.clone())), )), + TypeKind::Borrow(ty1, _) => match *ty1.clone() { + TypeKind::Array(ty1, _) => { + if ty1 == *ty2 { + Some(StackValue( + val.0.derive( + scope + .block + .build(Instr::BitCast( + val.instr(), + Type::Ptr(Box::new(type_kind.get_type(scope.type_values))), + )) + .unwrap(), + ), + TypeKind::CodegenPtr(Box::new(type_kind.clone())), + )) + } else { + return Err(ErrorKind::Null); + } + } + _ => return Err(ErrorKind::Null), + }, _ => panic!(), }, (TypeKind::UserPtr(_), TypeKind::UserPtr(_)) diff --git a/reid/src/mir/macros.rs b/reid/src/mir/macros.rs index 0e41f4e..8d7bd4b 100644 --- a/reid/src/mir/macros.rs +++ b/reid/src/mir/macros.rs @@ -244,7 +244,6 @@ impl MacroFunction for TestMacro { .parent() .expect("Module path has no parent!") .join(path); - dbg!(&path); let contents = match std::fs::read(path) { Ok(content) => content, diff --git a/reid/src/mir/typecheck/mod.rs b/reid/src/mir/typecheck/mod.rs index 37c0693..cbf51bb 100644 --- a/reid/src/mir/typecheck/mod.rs +++ b/reid/src/mir/typecheck/mod.rs @@ -256,6 +256,16 @@ impl TypeKind { let other_cat = other.category(); match (self, other) { (TypeKind::UserPtr(_), TypeKind::UserPtr(_)) => Ok(other.clone()), + (TypeKind::Borrow(ty1, _), TypeKind::UserPtr(ty2)) => match *ty1.clone() { + TypeKind::Array(ty1, _) => { + if ty1 == *ty2 { + Ok(other.clone()) + } else { + Err(ErrorKind::NotCastableTo(self.clone(), other.clone())) + } + } + _ => Err(ErrorKind::NotCastableTo(self.clone(), other.clone())), + }, (TypeKind::Char, TypeKind::U8) => Ok(other.clone()), (TypeKind::U8, TypeKind::Char) => Ok(other.clone()), _ => match (&self_cat, &other_cat) {