Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Champii committed Jun 8, 2022
2 parents 01f4236 + e7d4979 commit d575bdf
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 54 deletions.
32 changes: 15 additions & 17 deletions .github/templates/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# Rock {version}
# Rock v0.2.4-develop

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

Little language made with Rust and LLVM.

Aim to follow the enforced safeness of the Rust model with a borrow checker (Soon™) and achieve high native performances thanks to LLVM.
Rock is highly inspired from Livescript and Rust, and will also borrow (pun intended) some features from Crystal, from functional languages like Haskell, and even from Rust itself.
Rock is highly inspired from [Livescript](https://livescript.net/), [Haskell](https://www.haskell.org/) and [Rust](https://www.rust-lang.org/)

No to be taken seriously (yet)


## Index

- [Rock {version}](#rock-{version})
- [Rock v0.2.4-develop](#rock-v0.2.4-develop)
- [Index](#index)
- [Features](#features)
- [Install](#install)
Expand Down Expand Up @@ -58,10 +57,10 @@ You will need `clang` somewhere in your $PATH

Linux x86_64 only

[Rock {version}](https://github.com/Champii/Rock/releases/download/{version}/rock) (Tested on arch, btw)
[Rock v0.2.4-develop](https://github.com/Champii/Rock/releases/download/v0.2.4-develop/rock) (Tested on arch, btw)

``` sh
wget https://github.com/Champii/Rock/releases/download/{version}/rock
wget https://github.com/Champii/Rock/releases/download/v0.2.4-develop/rock
chmod +x rock
./rock -V
```
Expand Down Expand Up @@ -107,7 +106,7 @@ fact a =
then 1
else a * fact (a - 1)

main = fact(4).print!
main = fact 4 .print!
```

Assuming that you built Rock and put its binary in your PATH:
Expand All @@ -129,9 +128,9 @@ Note that you currently must be at the project root to run the compiler. (i.e. i
id a = a

main =
id(1).print!
id(2.2).print!
id("Test").print!
id 1 .print!
id 2.2 .print!
id "Test" .print!
```

Prints
Expand Down Expand Up @@ -221,8 +220,7 @@ impl Player
@getlevel = @level

main =
let player = Player::new 1
player.getlevel!.print!
Player::new 1 .getlevel!.print!
```

``` sh
Expand Down Expand Up @@ -253,7 +251,7 @@ main =

``` sh
$ rock run
MyName
MyName(42)
```

Note that the `printl` method is defined in the stdlib as
Expand All @@ -277,7 +275,7 @@ mod foo

use foo::bar

main = bar(1).print!
main = bar 1 .print!
```

```sh
Expand All @@ -288,7 +286,7 @@ $ rock run
Note that we could have skiped the
`use foo::bar`
if we wrote
`main = foo::bar(1).print!`
`main = foo::bar 1 .print!`

## REPL

Expand All @@ -310,7 +308,7 @@ rock --repl
```

``` sh
Rock: {version}
Rock: v0.2.4-develop
----

Type ':?' for help
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

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

38 changes: 18 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
Little language made with Rust and LLVM.

Aim to follow the enforced safeness of the Rust model with a borrow checker (Soon™) and achieve high native performances thanks to LLVM.
Rock is highly inspired from Livescript and Rust, and will also borrow (pun intended) some features from Crystal, from functional languages like Haskell, and even from Rust itself.
Rock is highly inspired from [Livescript](https://livescript.net/), [Haskell](https://www.haskell.org/) and [Rust](https://www.rust-lang.org/)

No to be taken seriously (yet)


## Index

- [Rock v0.2.4-develop](#rock-v0.2.4-develop)
Expand Down Expand Up @@ -107,7 +106,7 @@ fact a =
then 1
else a * fact (a - 1)

main = fact(4).print()
main = fact 4 .print!
```

Assuming that you built Rock and put its binary in your PATH:
Expand All @@ -129,9 +128,9 @@ Note that you currently must be at the project root to run the compiler. (i.e. i
id a = a

main =
id(1).print()
id(2.2).print()
id("Test").print()
id 1 .print!
id 2.2 .print!
id "Test" .print!
```

Prints
Expand Down Expand Up @@ -168,7 +167,7 @@ infix |> 1

f a = a + 2

main = (4 |> f).print()
main = (4 |> f).print!
```

``` sh
Expand All @@ -190,14 +189,14 @@ trait ToString a
tostring :: a -> String

impl ToString Int64
@tostring = @show()
@tostring = @show!

impl ToString Float64
@tostring = @show()
@tostring = @show!

main =
(33).tostring().print()
(42.42).tostring().print()
(33).tostring!.print!
(42.42).tostring!.print!
```

``` sh
Expand All @@ -221,8 +220,7 @@ impl Player
@getlevel = @level

main =
let player = Player::new 1
player.getlevel().print()
Player::new 1 .getlevel!.print!
```

``` sh
Expand All @@ -238,27 +236,27 @@ struct Player
name :: String

impl Show Player
@show = @name + "(" + @level.show() + ")"
@show = @name + "(" + @level.show! + ")"

impl Print Player
@print = printl self.show()
@print = printl @show!

main =
let player = Player
level: 42
name: "MyName"

player.print()
player.print!
```

``` sh
$ rock run
MyName
MyName(42)
```

Note that the `printl` method is defined in the stdlib as
```haskell
printl a = c_puts a.show()
printl a = c_puts a.show!
```
with `c_puts` being the `libc` `puts`

Expand All @@ -277,7 +275,7 @@ mod foo

use foo::bar

main = bar(1).print()
main = bar 1 .print!
```

```sh
Expand All @@ -288,7 +286,7 @@ $ rock run
Note that we could have skiped the
`use foo::bar`
if we wrote
`main = foo::bar(1).print()`
`main = foo::bar 1 .print!`

## REPL

Expand Down
1 change: 1 addition & 0 deletions src/lib/ast_lowering/ast_lowering_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl AstLoweringContext {
.clone();

let type_sig = type_sig.apply_forall_types(&r#trait.types, &i.types);

type_sig
} else {
f.signature.clone()
Expand Down
24 changes: 19 additions & 5 deletions src/lib/infer/monomorphize/monomorphizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ impl<'a> Monomorphizer<'a> {
}
}

// The collect here is needed as we NEED the generated_fn_hir_id.insert() side effect
// and the for version would be too messy
#[allow(clippy::needless_collect)]
let fresh_top_levels_flat = self
.get_fn_envs_pairs()
.into_iter()
Expand Down Expand Up @@ -287,15 +284,32 @@ impl<'a, 'b> VisitorMut<'a> for Monomorphizer<'b> {
.get(&self.resolve(&old_fc_op).unwrap())
.unwrap()
{
HirNode::FunctionDecl(_) => {
HirNode::FunctionDecl(f) => {
if let Some(generated_fn) = self.generated_fn_hir_id.get(&(
self.resolve_rec(&old_fc_op).unwrap(),
fc.to_func_type(&self.root.node_types),
)) {
self.new_resolutions
.insert(fc.op.get_hir_id(), generated_fn.clone());
} else {
panic!("BUG: Cannot find function from signature");
// This is a dirty duplicate of the `Prototype` branch below
if let Some(f) = self.root.get_trait_method(
(*f.name).clone(),
&fc.to_func_type(&self.root.node_types),
) {
if let Some(trans_res) = self.trans_resolutions.get(&f.hir_id) {
self.new_resolutions.insert(fc.op.get_hir_id(), trans_res);
} else {
panic!(
"NO TRANS RES FOR TRAIT {:#?} {:#?} {:#?}",
self.trans_resolutions,
fc.op.get_hir_id(),
f.hir_id,
);
}
} else {
}
// panic!("BUG: Cannot find function from signature");
}

self.trans_resolutions.remove(&old_fc_op);
Expand Down
1 change: 1 addition & 0 deletions src/lib/resolver/resolve_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl<'a> Visitor<'a> for ResolveCtx<'a> {

self.pop_scope();
}

fn visit_impl(&mut self, impl_: &'a Impl) {
self.push_scope();
self.import_struct_scope(Identifier::new(impl_.name.get_name(), 0));
Expand Down
3 changes: 1 addition & 2 deletions src/lib/testcases/basic/trait_monomorph/main.rk
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ impl Toto Int64
impl Toto Bool
@toto = "true"

# print a = a.toto()
print a = Toto::toto a
print a = a.toto()

main =
print true
Expand Down
3 changes: 1 addition & 2 deletions std/src/print.rk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::num::(*)
printl a = c_puts a.show!

trait Print a
print :: a -> a
print :: a -> Int64

# Here we would need generic impl
impl Print Bool
Expand All @@ -23,5 +23,4 @@ impl Print Float64
impl Print String
@print = printl @


use Print::(*)

0 comments on commit d575bdf

Please sign in to comment.