1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00
This commit is contained in:
Natapat Samutpong 2022-03-24 11:18:53 +07:00
parent 1697a1d93f
commit e19e468545
3 changed files with 8 additions and 2 deletions

View file

@ -62,11 +62,13 @@ impl Codegen {
"write" => { format!("write({}){}\n" , self.gen_ir(&args[0], false), semicolon!()) }, "write" => { format!("write({}){}\n" , self.gen_ir(&args[0], false), semicolon!()) },
"write_file" => { format!("writeFile({}, {}){}\n", self.gen_ir(&args[0], false), self.gen_ir(&args[1], false), semicolon!()) }, "write_file" => { format!("writeFile({}, {}){}\n", self.gen_ir(&args[0], false), self.gen_ir(&args[1], false), semicolon!()) },
"read" => { format!("read({}){}\n" , self.gen_ir(&args[0], false), semicolon!()) }, "read" => { format!("read({}){}\n" , self.gen_ir(&args[0], false), semicolon!()) },
"read_file" => { format!("readFile({}){}\n" , self.gen_ir(&args[0], false), semicolon!()) } "read_file" => { format!("readFile({}){}\n" , self.gen_ir(&args[0], false), semicolon!()) },
"emit" => { format!("{}", self.gen_ir(&args[0], false).trim_start_matches('"').trim_end_matches('"')) }, "emit" => { format!("{}", self.gen_ir(&args[0], false).trim_start_matches('"').trim_end_matches('"')) },
"get" => { format!("{}[{}]", self.gen_ir(&args[0], false), self.gen_ir(&args[1], false)) }, "get" => { format!("{}[{}]", self.gen_ir(&args[0], false), self.gen_ir(&args[1], false)) },
"len" => { format!("{}.length", self.gen_ir(&args[0], false)) }, "len" => { format!("{}.length", self.gen_ir(&args[0], false)) },
"throw" => { format!("throw new Error({}){}", self.gen_ir(&args[0], false), semicolon!()) },
_ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering _ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering
} }
}, },

View file

@ -1,7 +1,7 @@
use std::ops::Range; use std::ops::Range;
use parser::Expr; use parser::Expr;
const INTRINSICS: [&str; 7] = [ const INTRINSICS: [&str; 8] = [
"write", "write",
"read", "read",
"write_file", "write_file",
@ -9,6 +9,7 @@ const INTRINSICS: [&str; 7] = [
"emit", "emit",
"get", "get",
"len", "len",
"throw",
]; ];
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

3
example/err/throw.hz Normal file
View file

@ -0,0 +1,3 @@
fun main: void = do
@throw("woopsie");
end;