Allow &[ty; _] to be cast into *ty
This commit is contained in:
parent
baa068a371
commit
7234cad5f0
@ -2,7 +2,8 @@ import std::String;
|
|||||||
import std::print;
|
import std::print;
|
||||||
|
|
||||||
fn main() -> u8 {
|
fn main() -> u8 {
|
||||||
|
// - TODO possibly allow to cast between &[ty] and *ty
|
||||||
let bytes = test_macro!("./macro_easy_file.txt");
|
let bytes = test_macro!("./macro_easy_file.txt");
|
||||||
print(String::new() + bytes.length());
|
print(String::new() + bytes.length());
|
||||||
return *bytes[0];
|
return (bytes as *u8)[0];
|
||||||
}
|
}
|
||||||
|
@ -1313,7 +1313,7 @@ impl mir::Expression {
|
|||||||
Some(val)
|
Some(val)
|
||||||
} else {
|
} else {
|
||||||
match (&val.1, type_kind) {
|
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(
|
TypeKind::UserPtr(_) => Some(StackValue(
|
||||||
val.0.derive(
|
val.0.derive(
|
||||||
scope
|
scope
|
||||||
@ -1326,6 +1326,27 @@ impl mir::Expression {
|
|||||||
),
|
),
|
||||||
TypeKind::CodegenPtr(Box::new(type_kind.clone())),
|
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!(),
|
_ => panic!(),
|
||||||
},
|
},
|
||||||
(TypeKind::UserPtr(_), TypeKind::UserPtr(_))
|
(TypeKind::UserPtr(_), TypeKind::UserPtr(_))
|
||||||
|
@ -244,7 +244,6 @@ impl MacroFunction for TestMacro {
|
|||||||
.parent()
|
.parent()
|
||||||
.expect("Module path has no parent!")
|
.expect("Module path has no parent!")
|
||||||
.join(path);
|
.join(path);
|
||||||
dbg!(&path);
|
|
||||||
|
|
||||||
let contents = match std::fs::read(path) {
|
let contents = match std::fs::read(path) {
|
||||||
Ok(content) => content,
|
Ok(content) => content,
|
||||||
|
@ -256,6 +256,16 @@ impl TypeKind {
|
|||||||
let other_cat = other.category();
|
let other_cat = other.category();
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(TypeKind::UserPtr(_), TypeKind::UserPtr(_)) => Ok(other.clone()),
|
(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::Char, TypeKind::U8) => Ok(other.clone()),
|
||||||
(TypeKind::U8, TypeKind::Char) => Ok(other.clone()),
|
(TypeKind::U8, TypeKind::Char) => Ok(other.clone()),
|
||||||
_ => match (&self_cat, &other_cat) {
|
_ => match (&self_cat, &other_cat) {
|
||||||
|
Loading…
Reference in New Issue
Block a user