mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
Compare commits
No commits in common. "cf3dccca2cbcb57bef77b541cb1bae4f4d057d3f" and "f9a88c14c581acc6cd35ed08de1062a37f3666d4" have entirely different histories.
cf3dccca2c
...
f9a88c14c5
93
README.md
93
README.md
|
@ -28,5 +28,98 @@ Steps to build:
|
|||
2) Build executable `cargo build`
|
||||
3) Try running some examples! `path/to/executable compile path/to/file.hz`
|
||||
|
||||
# Syntax
|
||||
> This language is still in development, the syntax can be changed at anytime.
|
||||
|
||||
Hazure is a [free-form](https://en.wikipedia.org/wiki/Free-form_language) syntax style, so the indentation is purely for readability.
|
||||
|
||||
```sml
|
||||
fun main: void = do
|
||||
@write("Hello, World!");
|
||||
end;
|
||||
```
|
||||
|
||||
is the same as
|
||||
|
||||
```sml
|
||||
fun main: void = do @write("Hello, World!"); end;
|
||||
```
|
||||
|
||||
Hazure is also [expression-oriented](https://en.wikipedia.org/wiki/Expression-oriented_programming_language) like OCaml. There are currently 10 expressions:
|
||||
|
||||
1) Comment
|
||||
```
|
||||
-- Comment!
|
||||
-{ Block Comment }-
|
||||
```
|
||||
2) Values / Types
|
||||
```sml
|
||||
1
|
||||
true
|
||||
"string"
|
||||
variable
|
||||
```
|
||||
3) Unary and Binary
|
||||
```sml
|
||||
1 + 2
|
||||
!true
|
||||
```
|
||||
4) Call and Intrinsic. Intrinsic starts with a `@`
|
||||
```sml
|
||||
@write("Hello")
|
||||
foo("bar")
|
||||
```
|
||||
5) Pipeline
|
||||
```sml
|
||||
"Hello, World" |> @write(_)
|
||||
```
|
||||
6) Variable declaration
|
||||
```sml
|
||||
let foo: int = 727;
|
||||
let bar: string = "Hi";
|
||||
let baz: boolean = true;
|
||||
```
|
||||
7) Function declaration
|
||||
```sml
|
||||
fun foo: void = @write("void returns nothing");
|
||||
fun bar (x: int): int = x + 1;
|
||||
fun baz (x: int) (y: int): int = x + y;
|
||||
```
|
||||
8) If conditions
|
||||
```sml
|
||||
let cond: bool = true;
|
||||
if cond then
|
||||
@write("True");
|
||||
else
|
||||
do
|
||||
@write("False");
|
||||
end;
|
||||
end;
|
||||
```
|
||||
9) Case matching
|
||||
```sml
|
||||
case 1 + 1 of
|
||||
| 2 -> @write("Yes");
|
||||
\ @write("How?");
|
||||
end;
|
||||
```
|
||||
10) Do notation. It allows you to have multiple expression because something like right hand side of the function declaration `fun a: int = ...` can only have 1 expression. Do allows you to bypass that.
|
||||
```sml
|
||||
do
|
||||
@write("Hello, World");
|
||||
foo(bar);
|
||||
let baz: int = 6 + 10;
|
||||
end;
|
||||
```
|
||||
|
||||
Hazure isn't a scripting language, so, you will need a main function.
|
||||
|
||||
```sml
|
||||
fun main: void = do
|
||||
@write("Hello, World");
|
||||
@write(34 + 35);
|
||||
end;
|
||||
```
|
||||
|
||||
# License
|
||||
Hazure is licensed under both [MIT license](https://github.com/azur1s/hazure/blob/master/LICENSE-MIT) and [Apache License](https://github.com/azur1s/hazure/blob/master/LICENSE-APACHE)
|
92
SYNTAX.md
92
SYNTAX.md
|
@ -1,92 +0,0 @@
|
|||
# Syntax
|
||||
> This language is still in development, the syntax can be changed at anytime.
|
||||
|
||||
Hazure is a [free-form](https://en.wikipedia.org/wiki/Free-form_language) syntax style, so the indentation is purely for readability.
|
||||
|
||||
```sml
|
||||
fun main: void = do
|
||||
@write("Hello, World!");
|
||||
end;
|
||||
```
|
||||
|
||||
is the same as
|
||||
|
||||
```sml
|
||||
fun main: void = do @write("Hello, World!"); end;
|
||||
```
|
||||
|
||||
Hazure is also [expression-oriented](https://en.wikipedia.org/wiki/Expression-oriented_programming_language) like OCaml. There are currently 10 expressions:
|
||||
|
||||
1) Comment
|
||||
```
|
||||
-- Comment!
|
||||
-{ Block Comment }-
|
||||
```
|
||||
2) Values / Types
|
||||
```sml
|
||||
1
|
||||
true
|
||||
"string"
|
||||
variable
|
||||
```
|
||||
3) Unary and Binary
|
||||
```sml
|
||||
1 + 2
|
||||
!true
|
||||
```
|
||||
4) Call and Intrinsic. Intrinsic starts with a `@`
|
||||
```sml
|
||||
@write("Hello")
|
||||
foo("bar")
|
||||
```
|
||||
5) Pipeline
|
||||
```sml
|
||||
"Hello, World" |> @write(_)
|
||||
```
|
||||
6) Variable declaration
|
||||
```sml
|
||||
let foo: int = 727;
|
||||
let bar: string = "Hi";
|
||||
let baz: boolean = true;
|
||||
```
|
||||
7) Function declaration
|
||||
```sml
|
||||
fun foo: void = @write("void returns nothing");
|
||||
fun bar (x: int): int = x + 1;
|
||||
fun baz (x: int) (y: int): int = x + y;
|
||||
```
|
||||
8) If conditions
|
||||
```sml
|
||||
let cond: bool = true;
|
||||
if cond then
|
||||
@write("True");
|
||||
else
|
||||
do
|
||||
@write("False");
|
||||
end;
|
||||
end;
|
||||
```
|
||||
9) Case matching
|
||||
```sml
|
||||
case 1 + 1 of
|
||||
| 2 -> @write("Yes");
|
||||
\ @write("How?");
|
||||
end;
|
||||
```
|
||||
10) Do notation. It allows you to have multiple expression because something like right hand side of the function declaration `fun a: int = ...` can only have 1 expression. Do allows you to bypass that.
|
||||
```sml
|
||||
do
|
||||
@write("Hello, World");
|
||||
foo(bar);
|
||||
let baz: int = 6 + 10;
|
||||
end;
|
||||
```
|
||||
|
||||
Hazure isn't a scripting language, so, you will need a main function.
|
||||
|
||||
```sml
|
||||
fun main: void = do
|
||||
@write("Hello, World");
|
||||
@write(34 + 35);
|
||||
end;
|
||||
```
|
|
@ -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 { read, write, readFile, writeFile } from \"https://raw.githubusercontent.com/azur1s/hazure/master/runtime/io.ts\"\n");
|
||||
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));
|
||||
|
@ -74,7 +74,7 @@ impl Codegen {
|
|||
.collect::<Vec<_>>().
|
||||
join(", ");
|
||||
format!(
|
||||
"const f_{} = ({}): {} => {};\n",
|
||||
"const f_{} = ({}): {} => {{\n{}\n}};\n",
|
||||
name,
|
||||
args,
|
||||
return_type_hint,
|
||||
|
@ -90,11 +90,10 @@ impl Codegen {
|
|||
},
|
||||
|
||||
IRKind::Do { body } => {
|
||||
let mut out = "{\n".to_string();
|
||||
let mut out = String::new();
|
||||
for expr in body {
|
||||
out.push_str(&self.gen_ir(&expr, true));
|
||||
}
|
||||
out.push_str("}\n");
|
||||
out
|
||||
},
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
fun main: void = do
|
||||
do
|
||||
let foo: string = "Hello";
|
||||
@write(foo);
|
||||
end;
|
||||
@write(foo); -- TODO: This is a runtime error
|
||||
end;
|
|
@ -1,14 +0,0 @@
|
|||
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;
|
|
@ -1,5 +0,0 @@
|
|||
-- Run this file from root path
|
||||
fun main: void = do
|
||||
@read_file("./example/io/read_file.hz")
|
||||
|> @write(_);
|
||||
end;
|
|
@ -1,3 +0,0 @@
|
|||
fun main: void = do
|
||||
@write_file("console.log('Hello, World!')", "hello.js");
|
||||
end;
|
Loading…
Reference in a new issue