Update String to be *str

This commit is contained in:
Sofia 2025-07-21 19:32:40 +03:00
parent eb99a4c74e
commit 069c277516
9 changed files with 19 additions and 28 deletions

View File

@ -1,5 +1,5 @@
extern fn puts(message: string) -> i32; extern fn puts(message: *str) -> i32;
struct DivT { struct DivT {
quotient: i32, quotient: i32,
@ -8,7 +8,7 @@ struct DivT {
extern fn div(numerator: i32, denominator: i32) -> DivT; extern fn div(numerator: i32, denominator: i32) -> DivT;
pub fn print(message: string) { pub fn print(message: *str) {
puts(message); puts(message);
} }

View File

@ -31,7 +31,7 @@ pub enum TypeKind {
F128, F128,
F80, F80,
F128PPC, F128PPC,
String, Str,
Array(Box<TypeKind>, u64), Array(Box<TypeKind>, u64),
Custom(String), Custom(String),
Borrow(Box<TypeKind>, bool), Borrow(Box<TypeKind>, bool),

View File

@ -60,7 +60,7 @@ impl Parse for Type {
"f80" => TypeKind::F80, "f80" => TypeKind::F80,
"f128" => TypeKind::F128, "f128" => TypeKind::F128,
"f128ppc" => TypeKind::F128PPC, "f128ppc" => TypeKind::F128PPC,
"string" => TypeKind::String, "str" => TypeKind::Str,
_ => TypeKind::Custom(ident), _ => TypeKind::Custom(ident),
} }
} else { } else {

View File

@ -307,7 +307,7 @@ impl From<ast::TypeKind> for mir::TypeKind {
ast::TypeKind::Array(type_kind, length) => { ast::TypeKind::Array(type_kind, length) => {
mir::TypeKind::Array(Box::new(mir::TypeKind::from(*type_kind.clone())), *length) mir::TypeKind::Array(Box::new(mir::TypeKind::from(*type_kind.clone())), *length)
} }
ast::TypeKind::String => mir::TypeKind::StringPtr, ast::TypeKind::Str => mir::TypeKind::Str,
ast::TypeKind::Custom(name) => mir::TypeKind::CustomType(name.clone()), ast::TypeKind::Custom(name) => mir::TypeKind::CustomType(name.clone()),
ast::TypeKind::Borrow(type_kind, mutable) => { ast::TypeKind::Borrow(type_kind, mutable) => {
mir::TypeKind::Borrow(Box::new(mir::TypeKind::from(*type_kind.clone())), *mutable) mir::TypeKind::Borrow(Box::new(mir::TypeKind::from(*type_kind.clone())), *mutable)

View File

@ -247,7 +247,7 @@ impl mir::Module {
insert_debug!(&TypeKind::I64); insert_debug!(&TypeKind::I64);
insert_debug!(&TypeKind::I128); insert_debug!(&TypeKind::I128);
insert_debug!(&TypeKind::Void); insert_debug!(&TypeKind::Void);
insert_debug!(&TypeKind::StringPtr); insert_debug!(&TypeKind::Str);
for typedef in &self.typedefs { for typedef in &self.typedefs {
let type_value = match &typedef.kind { let type_value = match &typedef.kind {
@ -1206,7 +1206,7 @@ impl TypeKind {
TypeKind::F128 => Type::F128, TypeKind::F128 => Type::F128,
TypeKind::F80 => Type::F80, TypeKind::F80 => Type::F80,
TypeKind::F128PPC => Type::F128PPC, TypeKind::F128PPC => Type::F128PPC,
TypeKind::StringPtr => Type::Ptr(Box::new(Type::I8)), TypeKind::Str => Type::I8,
TypeKind::Array(elem_t, len) => { TypeKind::Array(elem_t, len) => {
Type::Array(Box::new(elem_t.get_type(type_vals, typedefs)), *len) Type::Array(Box::new(elem_t.get_type(type_vals, typedefs)), *len)
} }
@ -1257,18 +1257,6 @@ impl TypeKind {
let name = format!("{}", self); let name = format!("{}", self);
let data = match self { let data = match self {
TypeKind::StringPtr => DebugTypeData::Pointer(DebugPointerType {
name,
pointee: TypeKind::I8.get_debug_type_hard(
scope,
debug_info,
debug_types,
type_values,
types,
tokens,
),
size_bits: self.size_of(),
}),
TypeKind::CodegenPtr(inner) | TypeKind::UserPtr(inner) | TypeKind::Borrow(inner, _) => { TypeKind::CodegenPtr(inner) | TypeKind::UserPtr(inner) | TypeKind::Borrow(inner, _) => {
DebugTypeData::Pointer(DebugPointerType { DebugTypeData::Pointer(DebugPointerType {
name, name,
@ -1358,7 +1346,7 @@ impl TypeKind {
| TypeKind::F128 | TypeKind::F128
| TypeKind::F128PPC => DwarfEncoding::Float, | TypeKind::F128PPC => DwarfEncoding::Float,
TypeKind::Void => DwarfEncoding::Address, TypeKind::Void => DwarfEncoding::Address,
TypeKind::StringPtr => DwarfEncoding::Address, TypeKind::Str => DwarfEncoding::UnsignedChar,
TypeKind::Array(_, _) => DwarfEncoding::Address, TypeKind::Array(_, _) => DwarfEncoding::Address,
TypeKind::CustomType(_) => DwarfEncoding::Address, TypeKind::CustomType(_) => DwarfEncoding::Address,
_ => panic!("tried fetching debug-type for non-supported type!"), _ => panic!("tried fetching debug-type for non-supported type!"),

View File

@ -335,7 +335,7 @@ impl Display for TypeKind {
TypeKind::U64 => write!(f, "u64"), TypeKind::U64 => write!(f, "u64"),
TypeKind::U128 => write!(f, "u128"), TypeKind::U128 => write!(f, "u128"),
TypeKind::Void => write!(f, "void"), TypeKind::Void => write!(f, "void"),
TypeKind::StringPtr => write!(f, "string"), TypeKind::Str => write!(f, "str"),
TypeKind::Array(type_kind, len) => { TypeKind::Array(type_kind, len) => {
f.write_char('[')?; f.write_char('[')?;
Display::fmt(type_kind, f)?; Display::fmt(type_kind, f)?;

View File

@ -43,7 +43,7 @@ impl TypeKind {
TypeKind::U64 => false, TypeKind::U64 => false,
TypeKind::U128 => false, TypeKind::U128 => false,
TypeKind::Void => false, TypeKind::Void => false,
TypeKind::StringPtr => false, TypeKind::Str => false,
TypeKind::Array(_, _) => false, TypeKind::Array(_, _) => false,
TypeKind::CustomType(_) => false, TypeKind::CustomType(_) => false,
TypeKind::CodegenPtr(_) => false, TypeKind::CodegenPtr(_) => false,
@ -74,7 +74,7 @@ impl TypeKind {
TypeKind::U64 => false, TypeKind::U64 => false,
TypeKind::U128 => false, TypeKind::U128 => false,
TypeKind::Void => false, TypeKind::Void => false,
TypeKind::StringPtr => false, TypeKind::Str => false,
TypeKind::Array(_, _) => false, TypeKind::Array(_, _) => false,
TypeKind::CustomType(_) => false, TypeKind::CustomType(_) => false,
TypeKind::CodegenPtr(_) => false, TypeKind::CodegenPtr(_) => false,
@ -105,7 +105,7 @@ impl TypeKind {
TypeKind::I128 => 128, TypeKind::I128 => 128,
TypeKind::U128 => 128, TypeKind::U128 => 128,
TypeKind::Void => 0, TypeKind::Void => 0,
TypeKind::StringPtr => 32, TypeKind::Str => 8,
TypeKind::Array(type_kind, len) => type_kind.size_of() * len, TypeKind::Array(type_kind, len) => type_kind.size_of() * len,
TypeKind::CustomType(_) => 32, TypeKind::CustomType(_) => 32,
TypeKind::CodegenPtr(_) => 64, TypeKind::CodegenPtr(_) => 64,
@ -136,7 +136,7 @@ impl TypeKind {
TypeKind::I128 => 128, TypeKind::I128 => 128,
TypeKind::U128 => 128, TypeKind::U128 => 128,
TypeKind::Void => 0, TypeKind::Void => 0,
TypeKind::StringPtr => 32, TypeKind::Str => 8,
TypeKind::Array(type_kind, _) => type_kind.alignment(), TypeKind::Array(type_kind, _) => type_kind.alignment(),
TypeKind::CustomType(_) => 32, TypeKind::CustomType(_) => 32,
TypeKind::CodegenPtr(_) => 64, TypeKind::CodegenPtr(_) => 64,

View File

@ -98,7 +98,7 @@ pub enum TypeKind {
F128, F128,
F80, F80,
F128PPC, F128PPC,
StringPtr, Str,
Array(Box<TypeKind>, u64), Array(Box<TypeKind>, u64),
CustomType(String), CustomType(String),
Borrow(Box<TypeKind>, bool), Borrow(Box<TypeKind>, bool),
@ -185,7 +185,7 @@ impl Literal {
Literal::U64(_) => TypeKind::U64, Literal::U64(_) => TypeKind::U64,
Literal::U128(_) => TypeKind::U128, Literal::U128(_) => TypeKind::U128,
Literal::Bool(_) => TypeKind::Bool, Literal::Bool(_) => TypeKind::Bool,
Literal::String(_) => TypeKind::StringPtr, Literal::String(_) => TypeKind::UserPtr(Box::new(TypeKind::Str)),
Literal::Vague(VagueLiteral::Number(_)) => TypeKind::Vague(VagueType::Integer), Literal::Vague(VagueLiteral::Number(_)) => TypeKind::Vague(VagueType::Integer),
Literal::Vague(VagueLiteral::Decimal(_)) => TypeKind::Vague(VagueType::Decimal), Literal::Vague(VagueLiteral::Decimal(_)) => TypeKind::Vague(VagueType::Decimal),
Literal::F16(_) => TypeKind::F16, Literal::F16(_) => TypeKind::F16,

View File

@ -742,7 +742,10 @@ impl Literal {
(L::F128(_), TypeKind::F128) => self, (L::F128(_), TypeKind::F128) => self,
(L::F128PPC(_), TypeKind::F128PPC) => self, (L::F128PPC(_), TypeKind::F128PPC) => self,
(L::Bool(_), TypeKind::Bool) => self, (L::Bool(_), TypeKind::Bool) => self,
(L::String(_), TypeKind::StringPtr) => self, (L::String(_), TypeKind::UserPtr(ptr)) => match *ptr.clone() {
TypeKind::Str => self,
_ => Err(ErrorKind::LiteralIncompatible(self, hint.clone()))?,
},
// TODO make sure that v is actually able to fit in the // TODO make sure that v is actually able to fit in the
// requested type // requested type
(L::Vague(VagueL::Number(v)), TypeKind::I8) => L::I8(v as i8), (L::Vague(VagueL::Number(v)), TypeKind::I8) => L::I8(v as i8),