basic support for structures through the IR

This commit is contained in:
2024-03-16 16:41:23 -07:00
parent b0cc2fc26b
commit a7b85d37da
12 changed files with 572 additions and 94 deletions

View File

@@ -65,11 +65,7 @@ impl TopLevel {
TopLevel::Structure(_, name, fields) => allocator
.text("struct")
.append(allocator.space())
.append(
name.as_ref()
.map(|x| allocator.text(x.to_string()))
.unwrap_or_else(|| allocator.nil()),
)
.append(allocator.text(name.to_string()))
.append(allocator.space())
.append(allocator.text("{"))
.append(allocator.hardline())
@@ -224,22 +220,13 @@ impl Type {
pub fn pretty<'a>(&self, allocator: &'a Allocator<'a>) -> DocBuilder<'a, Allocator<'a>> {
match self {
Type::Named(x) => allocator.text(x.to_string()),
Type::Struct(name, fields) => allocator
Type::Struct(fields) => allocator
.text("struct")
.append(allocator.space())
.append(
name.as_ref()
.map(|x| allocator.text(x.to_string()))
.unwrap_or_else(|| allocator.nil()),
)
.append(allocator.intersperse(
fields.iter().map(|(name, ty)| {
allocator
.text(
name.as_ref()
.map(|x| x.to_string())
.unwrap_or_else(|| "_".to_string()),
)
.text(name.to_string())
.append(allocator.text(":"))
.append(allocator.space())
.append(