mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
examples
This commit is contained in:
parent
f9a88c14c5
commit
8aee7b7974
|
@ -17,7 +17,7 @@ impl Codegen {
|
||||||
|
|
||||||
pub fn gen(&mut self, irs: Vec<IR>) {
|
pub fn gen(&mut self, irs: Vec<IR>) {
|
||||||
self.emit(format!("// Auto-generated by hazure compiler version {}\n", env!("CARGO_PKG_VERSION")));
|
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 {
|
for ir in irs {
|
||||||
self.emit(&self.gen_ir(&ir.kind, true));
|
self.emit(&self.gen_ir(&ir.kind, true));
|
||||||
|
|
14
example/io/read.hz
Normal file
14
example/io/read.hz
Normal 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
5
example/io/read_file.hz
Normal 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
3
example/io/write_file.hz
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fun main: void = do
|
||||||
|
@write_file("console.log('Hello, World!')", "hello.js");
|
||||||
|
end;
|
Loading…
Reference in a new issue