diff --git a/crates/codegen/src/ts.rs b/crates/codegen/src/ts.rs index 4a2e1ff..bdee1d0 100644 --- a/crates/codegen/src/ts.rs +++ b/crates/codegen/src/ts.rs @@ -17,6 +17,7 @@ impl Codegen { pub fn gen(&mut self, irs: Vec) { 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 } diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index da98155..ca2cecd 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -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)] diff --git a/std/io.ts b/std/io.ts index ec80b0a..4553e25 100644 --- a/std/io.ts +++ b/std/io.ts @@ -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); } \ No newline at end of file