Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Champii committed Jun 2, 2022
2 parents 9dc0729 + 6daa232 commit 5f699c9
Show file tree
Hide file tree
Showing 27 changed files with 542 additions and 376 deletions.
58 changes: 51 additions & 7 deletions .github/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Rock is highly inspired from Livescript and Rust, and will also borrow (pun inte

No to be taken seriously (yet)

# VTable
# Index
- [Features]( #features )
- [Install]( #install )
- [Using released binary]( #using-released-binary )
Expand Down Expand Up @@ -74,14 +74,12 @@ cargo run -- -V

## Quickstart

Lets create a new project folder to compute some factorials
- Lets create a new project folder to compute some factorials

``` sh
mkdir -P factorial/src && cd factorial
mkdir -p factorial/src && cd factorial
```

Add some files like this:

- Create a `factorial/src/main.rk` file:

```haskell
Expand Down Expand Up @@ -135,6 +133,22 @@ Prints
Test
```

The `id` function here is polymorphic by default, as we don't make any constraint on the type that we should take or return.
If we did something like this
`id a = a + a`
We would have constrained `a` to types that implement [`Num`](https://github.com/Champii/Rock/blob/master/std/src/num.rk)

Note that this example would still be valid, as `Int64`, `Float64` and `String` are all implementors of `Num`(*).
The output would be

``` sh
2
4.4
TestTest
```

(*) `String` is nowhere at its place here, and only implements `+` for string concatenation. This should change in the future with more traits like `Add` in rust

### Custom infix operator

``` haskell
Expand All @@ -152,9 +166,14 @@ rock run

Prints `6`

You can create any operator that is made of any combination of one or more of `'+', '-', '/', '*', '|', '<', '>', '=', '!', '$', '@', '&'`

Most of the commonly defined operators like `+`, `<=`, etc are already implemented by the [stdlib](https://github.com/Champii/Rock/tree/master/std) that is automaticaly compiled with every package.
There is a `--nostd` option to allow you to use your own custom implementation.

### Trait definition

This `trait ToString` is redondant with the `trait Show` implemented in the lib, and serves as a demonstration only
This `trait ToString` is redondant with the `trait Show` implemented in the stdlib, and serves as a demonstration only

``` haskell
trait ToString a
Expand All @@ -176,7 +195,7 @@ main =
rock run
```

Prints
Prints

```
33
Expand Down Expand Up @@ -208,6 +227,31 @@ rock run

Prints `MyName`

### Modules and code separation

- `./myproj/src/foo.rk`

```haskell
bar a = a + 1
```

- `./myproj/src/main.rk`

```haskell
mod foo

use foo::bar

main = print bar 1
```

Prints `2`

Note that we could have skiped the
`use foo::bar`
if we wrote
`main = print foo::bar 1`

## REPL

Only supports basic expressions for now.
Expand Down
2 changes: 1 addition & 1 deletion .github/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.1
v0.2.2
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rock"
version = "0.2.1"
version = "0.2.2"
authors = ["champii <contact@champii>"]
edition = "2018"

Expand Down
68 changes: 56 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Rock v0.2.1
# Rock v0.2.2

[![Rust](https://github.com/Champii/Rock/actions/workflows/rust.yml/badge.svg?branch=master)](https://github.com/Champii/Rock/actions/workflows/rust.yml)
[![Rust](https://github.com/Champii/Rock/actions/workflows/rust.yml/badge.svg?branch=-)](https://github.com/Champii/Rock/actions/workflows/rust.yml)

Little language made with Rust and LLVM.

Expand All @@ -9,7 +9,7 @@ Rock is highly inspired from Livescript and Rust, and will also borrow (pun inte

No to be taken seriously (yet)

# VTable
# Index
- [Features]( #features )
- [Install]( #install )
- [Using released binary]( #using-released-binary )
Expand Down Expand Up @@ -45,10 +45,10 @@ You will need `clang` somewhere in your $PATH

Linux x86_64 only

[Rock v0.2.1](https://github.com/Champii/Rock/releases/download/v0.2.1/rock) (Tested on arch, btw)
[Rock v0.2.2](https://github.com/Champii/Rock/releases/download/v0.2.2/rock) (Tested on arch, btw)

``` sh
wget https://github.com/Champii/Rock/releases/download/v0.2.1/rock
wget https://github.com/Champii/Rock/releases/download/v0.2.2/rock
chmod +x rock
./rock -V
```
Expand All @@ -74,14 +74,12 @@ cargo run -- -V

## Quickstart

Lets create a new project folder to compute some factorials
- Lets create a new project folder to compute some factorials

``` sh
mkdir -P factorial/src && cd factorial
mkdir -p factorial/src && cd factorial
```

Add some files like this:

- Create a `factorial/src/main.rk` file:

```haskell
Expand Down Expand Up @@ -135,6 +133,22 @@ Prints
Test
```

The `id` function here is polymorphic by default, as we don't make any constraint on the type that we should take or return.
If we did something like this
`id a = a + a`
We would have constrained `a` to types that implement [`Num`](https://github.com/Champii/Rock/blob/master/std/src/num.rk)

Note that this example would still be valid, as `Int64`, `Float64` and `String` are all implementors of `Num`(*).
The output would be

``` sh
2
4.4
TestTest
```

(*) `String` is nowhere at its place here, and only implements `+` for string concatenation. This should change in the future with more traits like `Add` in rust

### Custom infix operator

``` haskell
Expand All @@ -152,9 +166,14 @@ rock run

Prints `6`

You can create any operator that is made of any combination of one or more of `'+', '-', '/', '*', '|', '<', '>', '=', '!', '$', '@', '&'`

Most of the commonly defined operators like `+`, `<=`, etc are already implemented by the [stdlib](https://github.com/Champii/Rock/tree/master/std) that is automaticaly compiled with every package.
There is a `--nostd` option to allow you to use your own custom implementation.

### Trait definition

This `trait ToString` is redondant with the `trait Show` implemented in the lib, and serves as a demonstration only
This `trait ToString` is redondant with the `trait Show` implemented in the stdlib, and serves as a demonstration only

``` haskell
trait ToString a
Expand All @@ -176,7 +195,7 @@ main =
rock run
```

Prints
Prints

```
33
Expand Down Expand Up @@ -208,6 +227,31 @@ rock run

Prints `MyName`

### Modules and code separation

- `./myproj/src/foo.rk`

```haskell
bar a = a + 1
```

- `./myproj/src/main.rk`

```haskell
mod foo

use foo::bar

main = print bar 1
```

Prints `2`

Note that we could have skiped the
`use foo::bar`
if we wrote
`main = print foo::bar 1`

## REPL

Only supports basic expressions for now.
Expand All @@ -228,7 +272,7 @@ rock --repl
```

``` sh
Rock: v0.2.1
Rock: v0.2.2
----

Type ':?' for help
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn write_header(output_file: &mut File) {
let expected_ret = expected_ret.parse::<i64>().unwrap();
let (ret_code, stdout) = super::test::run(path, input.to_string(), config);
let (ret_code, stdout) = super::helpers::test_utils::run(path, input.to_string(), config);
assert_eq!(expected_ret, ret_code);
assert_eq!(expected_output, stdout);
Expand Down
1 change: 0 additions & 1 deletion src/lib/ast/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[macro_use]
pub mod ast_print;

pub mod return_placement;
pub mod tree;
pub mod visit;

Expand Down
64 changes: 0 additions & 64 deletions src/lib/ast/return_placement.rs

This file was deleted.

6 changes: 5 additions & 1 deletion src/lib/ast/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,15 @@ impl IdentifierPath {
Self {
path: vec![Identifier {
name: "root".to_string(),
node_id: 42, // FIXME: should have a valid node_id ?
node_id: 0, // FIXME: should have a valid node_id ?
}],
}
}

pub fn has_root(&self) -> bool {
self.path.len() > 0 && self.path[0].name == "root"
}

pub fn parent(&self) -> Self {
let mut parent = self.clone();

Expand Down
6 changes: 2 additions & 4 deletions src/lib/ast_lowering/ast_lowering_context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::{BTreeMap, HashMap};

use crate::{
ast::{return_placement::ReturnInserter, tree::*, NodeId},
ast::{tree::*, NodeId},
hir::{self, Arena, FnBodyId, HirId},
infer::Envs,
ty::*,
Expand Down Expand Up @@ -210,9 +210,7 @@ impl AstLoweringContext {
body_id: FnBodyId,
fn_id: HirId,
) -> hir::FnBody {
let body = ReturnInserter { body: fn_body }.run();

let body = self.lower_body(&body);
let body = self.lower_body(&fn_body);

hir::FnBody {
id: body_id,
Expand Down
Loading

0 comments on commit 5f699c9

Please sign in to comment.