Skip to content

Commit

Permalink
Implement Display for inline assembly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlamonster committed Dec 6, 2023
1 parent 17e8b16 commit 62b130f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 56 deletions.
19 changes: 10 additions & 9 deletions compiler/src/passes/atomize/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,21 @@ impl Display for AExpr<'_> {
}
AExpr::Struct { sym, fields } => {
writeln!(f, "{sym} {{")?;
writeln!(
indented(f),
"{}",
fields
.iter()
.map(|(sym, bnd)| format!("{sym}: {bnd},"))
.format("\n")
)?;
for (field_sym, field_bnd) in fields {
writeln!(indented(f), "{field_sym}: {field_bnd},")?;
}
write!(f, "}}")
}
AExpr::AccessField { strct, field } => {
write!(f, "{strct}.{field}")
}
AExpr::Asm { .. } => todo!(),
AExpr::Asm { instrs } => {
writeln!(f, "asm {{")?;
for instr in instrs {
writeln!(indented(f), "{instr}")?;
}
write!(f, "}}")
}
}
}
}
11 changes: 3 additions & 8 deletions compiler/src/passes/explicate/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@ impl Display for ExprExplicated<'_> {
}
ExprExplicated::Struct { sym, fields } => {
writeln!(f, "{sym} {{")?;
writeln!(
indented(f),
"{}",
fields
.iter()
.map(|(sym, bnd)| format!("{sym}: {bnd},"))
.format("\n")
)?;
for (field_sym, field_bnd) in fields {
writeln!(indented(f), "{field_sym}: {field_bnd},")?;
}
write!(f, "}}")
}
ExprExplicated::AccessField { strct, field } => {
Expand Down
45 changes: 20 additions & 25 deletions compiler/src/passes/parse/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,9 @@ impl<IdentVars: Display, IdentFields: Display, Expr: Display> Display
Def::TypeDef { sym, def } => match def {
TypeDef::Struct { fields } => {
writeln!(f, "struct {sym} {{")?;
writeln!(
indented(f),
"{}",
fields
.iter()
.map(|(sym, bnd)| format!("{sym}: {bnd},"))
.format("\n")
)?;
for (field_sym, field_typ) in fields {
writeln!(indented(f), "{field_sym}: {field_typ},")?;
}
writeln!(f, "}}")
}
TypeDef::Enum { .. } => todo!(),
Expand Down Expand Up @@ -66,14 +61,13 @@ impl<IdentVars: Display, IdentFields: Display, Lit: Display, M> Display
bnd,
bdy,
} => {
writeln!(
f,
"let {}{sym}{} = {bnd};",
if *mutable { "mut " } else { "" },
typ.as_ref()
.map(|typ| format!(": {typ}"))
.unwrap_or("".to_string())
)?;
let mutable = if *mutable { "mut " } else { "" };
let typ = typ
.as_ref()
.map(|typ| format!(": {typ}"))
.unwrap_or_default();

writeln!(f, "let {mutable}{sym}{typ} = {bnd};")?;
write!(f, "{bdy}")
}
Expr::If { cnd, thn, els } => {
Expand Down Expand Up @@ -109,22 +103,23 @@ impl<IdentVars: Display, IdentFields: Display, Lit: Display, M> Display
}
Expr::Struct { sym, fields } => {
writeln!(f, "{sym} {{")?;
writeln!(
indented(f),
"{}",
fields
.iter()
.map(|(sym, bnd)| format!("{sym}: {bnd},"))
.format("\n")
)?;
for (field_sym, field_bnd) in fields {
writeln!(indented(f), "{field_sym}: {field_bnd},")?;
}
write!(f, "}}")
}
Expr::AccessField { strct, field } => {
write!(f, "{strct}.{field}")
}
Expr::Asm { instrs } => {
writeln!(f, "asm {{")?;
for instr in instrs {
writeln!(indented(f), "{instr}")?;
}
write!(f, "}}")
}
Expr::Variant { .. } => todo!(),
Expr::Switch { .. } => todo!(),
Expr::Asm { .. } => todo!(),
}
}
}
27 changes: 13 additions & 14 deletions compiler/src/passes/reveal/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ impl Display for RExpr<'_> {
bnd,
bdy,
} => {
writeln!(
f,
"let {}{sym} = {bnd};",
if *mutable { "mut " } else { "" }
)?;
let mutable = if *mutable { "mut " } else { "" };

writeln!(f, "let {mutable}{sym} = {bnd};")?;
write!(f, "{bdy}")
}
RExpr::If { cnd, thn, els } => {
Expand Down Expand Up @@ -71,20 +69,21 @@ impl Display for RExpr<'_> {
}
RExpr::Struct { sym, fields } => {
writeln!(f, "{sym} {{")?;
writeln!(
indented(f),
"{}",
fields
.iter()
.map(|(sym, bnd)| format!("{sym}: {bnd},"))
.format("\n")
)?;
for (field_sym, field_bnd) in fields {
writeln!(indented(f), "{field_sym}: {field_bnd},")?;
}
write!(f, "}}")
}
RExpr::AccessField { strct, field } => {
write!(f, "{strct}.{field}")
}
RExpr::Asm { .. } => todo!(),
RExpr::Asm { instrs } => {
writeln!(f, "asm {{")?;
for instr in instrs {
writeln!(indented(f), "{instr}")?;
}
write!(f, "}}")
}
}
}
}

0 comments on commit 62b130f

Please sign in to comment.