diff --git a/crates/codegen/src/ts.rs b/crates/codegen/src/ts.rs index bd449ff..8acba21 100644 --- a/crates/codegen/src/ts.rs +++ b/crates/codegen/src/ts.rs @@ -17,7 +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"); + 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)); diff --git a/example/emit.hz b/example/io/emit.hz similarity index 100% rename from example/emit.hz rename to example/io/emit.hz diff --git a/example/hello_world.hz b/example/io/hello.hz similarity index 100% rename from example/hello_world.hz rename to example/io/hello.hz diff --git a/example/io/read.hz b/example/io/read.hz new file mode 100644 index 0000000..90c2af9 --- /dev/null +++ b/example/io/read.hz @@ -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; \ No newline at end of file diff --git a/example/io/read_file.hz b/example/io/read_file.hz new file mode 100644 index 0000000..b7af16c --- /dev/null +++ b/example/io/read_file.hz @@ -0,0 +1,5 @@ +-- Run this file from root path +fun main: void = do + @read_file("./example/io/read_file.hz") + |> @write(_); +end; \ No newline at end of file diff --git a/example/io/write_file.hz b/example/io/write_file.hz new file mode 100644 index 0000000..f205262 --- /dev/null +++ b/example/io/write_file.hz @@ -0,0 +1,3 @@ +fun main: void = do + @write_file("console.log('Hello, World!')", "hello.js"); +end; \ No newline at end of file