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 qux (lhs: int rhs: int) -> int = lhs + rhs;
fun main () -> int = do fun main () -> int = do
let msg: string = "Hello, World!"; puts("Hello, World");
write(msg);
0; 0;
end; end;

View file

@ -8,7 +8,7 @@ pub struct Codegen {
} }
const HEADER_INCLUDES: [&str; 3] = [ const HEADER_INCLUDES: [&str; 3] = [
"<unistd.h>", "<stdio.h>",
"<string.h>", "<string.h>",
"<hycron/stdbool.h>", "<hycron/stdbool.h>",
]; ];
@ -43,22 +43,10 @@ impl Codegen {
self.emit(";\n"); self.emit(";\n");
}, },
IR::Fun { name, return_type_hint, args, body } => { 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) format!("{} {}", type_hint, name)
}).collect::<Vec<_>>().join(", "); }).collect::<Vec<_>>().join(", ");
self.emit(format!( self.emit(format!("{} {}({}) {{", return_type_hint, name, args));
"{} {}({}) {{",
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,
}
));
match &**body { match &**body {
IR::Value { value } => { IR::Value { value } => {
self.emit("return "); self.emit("return ");
@ -69,11 +57,9 @@ impl Codegen {
for (i, node) in body.iter().enumerate() { for (i, node) in body.iter().enumerate() {
if i == body.len() - 1 { if i == body.len() - 1 {
self.emit("return "); self.emit("return ");
};
self.gen_ir(node); self.gen_ir(node);
self.emit(";"); self.emit(";");
} else {
self.gen_ir(node);
}
} }
}, },
IR::Binary { op, left, right } => { IR::Binary { op, left, right } => {
@ -89,15 +75,13 @@ impl Codegen {
}, },
IR::Call { name, args } => { IR::Call { name, args } => {
match name.as_str() { match name.as_str() {
"write" => { "puts" => {
self.emit("write(1, "); self.emit("printf(");
self.gen_ir(&args[0]); self.gen_ir(&args[0]);
self.emit(", strlen("); self.emit(")");
self.gen_ir(&args[0]);
self.emit("));");
}, },
_ => { _ => {
self.emit(format!("USER_DEFINED_{}(", name)); self.emit(format!("{}(", name));
for (i, arg) in args.iter().enumerate() { for (i, arg) in args.iter().enumerate() {
if i != 0 { if i != 0 {
self.emit(", "); 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) let do_block = just(Token::Do)
.ignore_then( .ignore_then(
expr.clone() expr.clone()
.or(decl.clone())
.then_ignore(just(Token::Semicolon)) .then_ignore(just(Token::Semicolon))
.repeated()) .repeated())
.then_ignore(just(Token::End)) .then_ignore(just(Token::End))

View file

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