This commit is contained in:
2024-10-21 09:41:57 -07:00
committed by Adam Wick
parent 6deccd5529
commit b72b2eddb4
7 changed files with 11409 additions and 73 deletions

View File

@@ -28,14 +28,14 @@ impl Program {
interior = interior.indent(9);
let start = allocator.text("struct")
let start = allocator
.text("struct")
.append(allocator.space())
.append(allocator.text(definition.name.original_name().to_string()))
.append(allocator.space())
.append(allocator.text("{"));
let conclusion = allocator.text("}")
.append(allocator.hardline());
let conclusion = allocator.text("}").append(allocator.hardline());
result = result.append(start.append(interior).append(conclusion));
}
@@ -113,7 +113,8 @@ impl TopLevel {
.append(type_bit)
.append(allocator.text(";"))
.append(allocator.hardline())
})).indent(2)
}))
.indent(2),
)
.append(allocator.text("}"))
.append(allocator.hardline()),
@@ -141,7 +142,7 @@ impl Expression {
.append(allocator.text(";"))
.append(allocator.hardline())
}))
.indent(2)
.indent(2),
)
.append(allocator.text("}")),
Expression::Reference(var) => allocator.text(var.to_string()),
@@ -158,7 +159,10 @@ impl Expression {
let mut args = args.iter().map(|x| x.pretty(allocator)).collect::<Vec<_>>();
match fun.as_ref() {
Expression::Primitive(_, name) if ["/", "*", "+", "-"].contains(&name.current_name()) && args.len() == 2 => {
Expression::Primitive(_, name)
if ["/", "*", "+", "-"].contains(&name.current_name())
&& args.len() == 2 =>
{
let second = args.pop().unwrap();
args.pop()
.unwrap()
@@ -168,14 +172,21 @@ impl Expression {
.append(second)
.parens()
}
Expression::Primitive(_, name) if ["negate"].contains(&name.current_name()) && args.len() == 1 =>
allocator.text("-").append(args.pop().unwrap()),
Expression::Primitive(_, name) if ["print"].contains(&&name.current_name()) && args.len() == 1 =>
allocator.text("print")
.append(allocator.space())
.append(args.pop().unwrap()),
Expression::Primitive(_, name)
if ["negate"].contains(&name.current_name()) && args.len() == 1 =>
{
allocator.text("-").append(args.pop().unwrap())
}
Expression::Primitive(_, name)
if ["print"].contains(&&name.current_name()) && args.len() == 1 =>
{
allocator
.text("print")
.append(allocator.space())
.append(args.pop().unwrap())
}
_ => {
let comma_sepped_args = allocator.intersperse(args, allocator.text(","));
@@ -273,7 +284,7 @@ impl Value {
allocator.text(value_str)
}
Value::Void => allocator.text("<void>"),
Value::Void => allocator.text("void()"),
}
}
}
@@ -281,7 +292,7 @@ impl Value {
fn type_suffix(x: &Option<ConstantType>) -> &'static str {
match x {
None => "",
Some(ConstantType::Void) => "<void>",
Some(ConstantType::Void) => panic!("Should never get a void type suffix."),
Some(ConstantType::I8) => "i8",
Some(ConstantType::I16) => "i16",
Some(ConstantType::I32) => "i32",
@@ -314,8 +325,7 @@ impl Type {
.append(allocator.text(";"))
}),
allocator.hardline(),
))
.braces(),
).braces())
}
}
}