mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
use module from github
This commit is contained in:
parent
dff9e03ea9
commit
c96ffcc4cd
|
@ -17,6 +17,7 @@ impl Codegen {
|
|||
|
||||
pub fn gen(&mut self, irs: Vec<IR>) {
|
||||
self.emit(format!("// Auto-generated by hazure compiler version {}\n", env!("CARGO_PKG_VERSION")));
|
||||
self.emit("import { write, writeFile } from \"https://raw.githubusercontent.com/azur1s/hazure/master/std/io.ts\"\n");
|
||||
|
||||
for ir in irs {
|
||||
self.emit(&self.gen_ir(&ir.kind, true));
|
||||
|
@ -56,7 +57,8 @@ impl Codegen {
|
|||
|
||||
IRKind::Intrinsic { name, args } => {
|
||||
match name.as_str() {
|
||||
"write" => { format!("console.log({}){}\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!()) },
|
||||
"read" => { todo!() },
|
||||
_ => unreachable!(format!("Unknown intrinsic: {}", name)) // Shoul be handled by lowering
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::ops::Range;
|
||||
use parser::Expr;
|
||||
|
||||
const INTRINSICS: [&str; 2] = [
|
||||
const INTRINSICS: [&str; 3] = [
|
||||
"write",
|
||||
"read",
|
||||
"write_file",
|
||||
];
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
@ -14,7 +14,7 @@ export function write(text: any): void {
|
|||
* @param text The text to write. Can be any type.
|
||||
* @param path The path to the file.
|
||||
*/
|
||||
export function write_file(text: any, path: string): void {
|
||||
export function writeFile(text: any, path: string): void {
|
||||
const bytes: Uint8Array = new TextEncoder().encode(text);
|
||||
Deno.writeFileSync(path, bytes);
|
||||
}
|
Loading…
Reference in a new issue