From 8aee7b79747a91613536e72dce72fac53f1224f4 Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Sun, 20 Mar 2022 05:35:29 +0700 Subject: [PATCH] examples --- crates/codegen/src/ts.rs | 2 +- example/{ => io}/emit.hz | 0 example/{hello_world.hz => io/hello.hz} | 0 example/io/read.hz | 14 ++++++++++++++ example/io/read_file.hz | 5 +++++ example/io/write_file.hz | 3 +++ 6 files changed, 23 insertions(+), 1 deletion(-) rename example/{ => io}/emit.hz (100%) rename example/{hello_world.hz => io/hello.hz} (100%) create mode 100644 example/io/read.hz create mode 100644 example/io/read_file.hz create mode 100644 example/io/write_file.hz 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