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-20 05:35:29 +07:00
parent f9a88c14c5
commit 8aee7b7974
6 changed files with 23 additions and 1 deletions

View file

@ -17,7 +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");
self.emit("import { read, write, readFile, writeFile } from \"https://raw.githubusercontent.com/azur1s/hazure/master/runtime/io.ts\"\n");
for ir in irs {
self.emit(&self.gen_ir(&ir.kind, true));

14
example/io/read.hz Normal file
View file

@ -0,0 +1,14 @@
fun say_hi (name: string): void = do
@write("Hi ");
@write(name);
@write("!");
end;
fun main: void = do
let input: string = @read("Enter your name:");
case input of
| "" -> @write("I don't know your name :(");
\ say_hi(input);
end;
end;

5
example/io/read_file.hz Normal file
View file

@ -0,0 +1,5 @@
-- Run this file from root path
fun main: void = do
@read_file("./example/io/read_file.hz")
|> @write(_);
end;

3
example/io/write_file.hz Normal file
View file

@ -0,0 +1,3 @@
fun main: void = do
@write_file("console.log('Hello, World!')", "hello.js");
end;