1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

Compare commits

..

No commits in common. "a956b8c7d2482b69e6fe80a4f62e3bac252f4bd5" and "a98cc8ca277c74a8d6c4d9b1370c2a7c02bcb534" have entirely different histories.

4 changed files with 11 additions and 30 deletions

View file

@ -4,7 +4,6 @@ let baz: bool = true;
fun qux (lhs: int rhs: int) -> int = lhs + rhs;
fun main () -> int = do
let msg: string = "Hello, World!";
write(msg);
puts("Hello, World");
0;
end;

View file

@ -8,7 +8,7 @@ pub struct Codegen {
}
const HEADER_INCLUDES: [&str; 3] = [
"<unistd.h>",
"<stdio.h>",
"<string.h>",
"<hycron/stdbool.h>",
];
@ -43,22 +43,10 @@ impl Codegen {
self.emit(";\n");
},
IR::Fun { name, return_type_hint, args, body } => {
let args_str = args.iter().map(|(name, type_hint)| {
let args = args.iter().map(|(name, type_hint)| {
format!("{} {}", type_hint, name)
}).collect::<Vec<_>>().join(", ");
self.emit(format!(
"{} {}({}) {{",
return_type_hint,
match name.as_str() {
"main" => "main".to_string(),
_ => format!("USER_DEFINED_{}", name),
},
match name.as_str() {
"main" => format!("{}{}{}", "int ARGC, char **ARGV", if args.len() == 0 { "" } else { "," }, args_str.as_str()),
_ => args_str,
}
));
self.emit(format!("{} {}({}) {{", return_type_hint, name, args));
match &**body {
IR::Value { value } => {
self.emit("return ");
@ -69,11 +57,9 @@ impl Codegen {
for (i, node) in body.iter().enumerate() {
if i == body.len() - 1 {
self.emit("return ");
self.gen_ir(node);
self.emit(";");
} else {
self.gen_ir(node);
}
};
self.gen_ir(node);
self.emit(";");
}
},
IR::Binary { op, left, right } => {
@ -89,15 +75,13 @@ impl Codegen {
},
IR::Call { name, args } => {
match name.as_str() {
"write" => {
self.emit("write(1, ");
"puts" => {
self.emit("printf(");
self.gen_ir(&args[0]);
self.emit(", strlen(");
self.gen_ir(&args[0]);
self.emit("));");
self.emit(")");
},
_ => {
self.emit(format!("USER_DEFINED_{}(", name));
self.emit(format!("{}(", name));
for (i, arg) in args.iter().enumerate() {
if i != 0 {
self.emit(", ");

View file

@ -237,7 +237,6 @@ fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone {
let do_block = just(Token::Do)
.ignore_then(
expr.clone()
.or(decl.clone())
.then_ignore(just(Token::Semicolon))
.repeated())
.then_ignore(just(Token::End))

View file

@ -61,7 +61,6 @@ fn main() {
log(0, "Running clang-format...");
let mut clang_format_status = Command::new("clang-format")
.arg("-i")
.arg("-style=Microsoft")
.arg(&out_file_name)
.spawn()
.expect("Failed to run clang-format, make sure you have it installed");