Skip to content

Commit

Permalink
v0.4.2 (#141)
Browse files Browse the repository at this point in the history
* Bump version

* Update README to show the right version of llvm

* Add the self returning method with `@->`

* Add tests for self returning function

* Add an embryo of documentation with mdbook

* Documentation

* Fix doc about struct

* Doc

* Add \0 as escaped char and generalize escaped char parsing (#125)

* Add \0 as escaped char and generalize escaped char parsing

* Inline parser variable in parse_char method

* Readme

* Readme

* Escaped chars (#132)

* Add \0 as escaped char and generalize escaped char parsing

* Inline parser variable in parse_char method

* Better unescaped handling

* Fix escaped backslack and add tests

* Restored string unescape

* Fixed the `\0` escaped char

* Doc

* Introducing default trait methods (#128)

* Introducing default trait methods

* Allow for empty impl

* Readme

* Add tests

* Allow for default method overriding

* Add tests for default method overriding

* Doc

* Fix dot notation newline (#140)

* Fix dot notation

by restricting newline in dot notation when parsing an argument

* Readme

* Struct fields are no more reordered. (#138)

* Struct fields are no more reordered.

* Removed comment

* Removed some old readme entry

* Submodule parser errors (#137)

* Subparser now fails when error

* Transformed the module declaration error to failure

* Fixed the diagnostic in submodule not showing
  • Loading branch information
Champii authored Jun 26, 2022
1 parent 48adcbc commit 17b44d6
Show file tree
Hide file tree
Showing 42 changed files with 1,149 additions and 163 deletions.
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.4.1"
version = "0.4.2"
authors = ["champii <contact@champii>"]
edition = "2018"

Expand Down
92 changes: 52 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
# Rock v0.4.1
# Rock v0.4.2

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

Native 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](https://livescript.net/), [Haskell](https://www.haskell.org/) and [Rust](https://www.rust-lang.org/)
Aim to follow the enforced safeness of the Rust model with a borrow checker (Soon™) and to achieve high native performances thanks to LLVM.
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)
No to be taken seriously (yet). Rock is still in its early conception phase, and everything can change and/or break at any time.
Feel free to discuss any new feature or change you may like in an issue! We welcome and value every contribution.

## Index

- [Rock v0.4.1](#rock-v0.4.1)
- [Rock v0.4.2](#rock-v0.4.2)
- [Index](#index)
- [Features](#features)
- [Install](#install)
- [Using Released Binary](#using-released-binary)
- [From source](#from-source)
- [With Cargo from Git](#with-cargo-from-git)
- [With Cargo from Git (Recommanded)](#with-cargo-from-git-recommanded)
- [Manual Clone and Build from Git](#manual-clone-and-build-from-git)
- [Using Released Binary](#using-released-binary)
- [Quickstart](#quickstart)
- [Showcases](#showcases)
- [Polymorphic function](#polymorphic-function)
- [Custom infix operator](#custom-infix-operator)
- [Trait Definition](#trait-definition)
- [Trait default method](#trait-default-method)
- [Struct instance and methods]( #struct-instance-and-methods )
- [Show and Print implementation]( #show-and-print-implementation )
- [Modules and Code Separation](#modules-and-code-separation)
Expand All @@ -44,43 +46,45 @@ No to be taken seriously (yet)

## Install

### Using Released Binary

[Rock v0.4.1](https://github.com/Champii/Rock/releases/download/v0.4.1/rock)

``` sh
wget https://github.com/Champii/Rock/releases/download/v0.4.1/rock
chmod +x rock
./rock -V
```

You will need `clang` somewhere in your $PATH

### From source

You will need `llvm-13` and `clang-13` somewhere in your $PATH

#### With Cargo from Git
#### With Cargo from Git (Recommanded)

```sh
cargo install --git https://github.com/Champii/Rock --locked
cargo install --locked --git https://github.com/Champii/Rock --tag v0.4.2
rock -V
```

#### Manual Clone and Build from Git

```sh
git clone https://github.com/Champii/Rock.git rock
cd rock
git clone https://github.com/Champii/Rock.git
cd Rock
cargo run --release -- -V
```

Note: If you clone and build manually, make sure to add `rock/target/release/` to you `$PATH` so you can run it anywhere on your system.
Note: If you clone and build manually, make sure to add `Rock/target/release/` to you `$PATH` so you can run it anywhere on your system.
This method uses the `master` branch of Rock, that is not stable. You can checkout the latest version tag.

Rock has been tested against Rust stable v1.60.0 and nightly

[Adding Rust Nightly](https://github.com/Champii/Rock/wiki/Adding-Rust-Nightly)

### Using Released Binary

[Rock v0.4.2](https://github.com/Champii/Rock/releases/download/v0.4.2/rock)

``` sh
wget https://github.com/Champii/Rock/releases/download/v0.4.2/rock
chmod +x rock
./rock -V
```

This install method is not well tested yet, and might not work for your environment.
It requires a x86_64 architecture and GLIBC 2.34. (Don't try to upgrade your GLIBC if you don't know what you are doing)

---

## Quickstart
Expand Down Expand Up @@ -150,7 +154,8 @@ If we did something like this
`id: x -> x + x`
We would have constrained `x` 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`(*).
Note that this example would still be valid, as `Int64`, `Float64` and `String` are all implementors of `Num`.
`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

The output would be:

Expand All @@ -160,8 +165,6 @@ The output would be:
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 Down Expand Up @@ -208,6 +211,26 @@ $ rock run
42.42
```

### Trait default method

``` haskell
trait ToString a
@tostring: -> @show!

impl ToString Int64
impl ToString Float64

main: ->
(33).tostring!.print!
(42.42).tostring!.print!
```

``` sh
$ rock run
33
42.42
```

### Struct instance and methods

``` haskell
Expand All @@ -223,9 +246,7 @@ impl Player
@getlevel: -> @level

main: ->
# The parenthesis are needed here because of a bug
# with the chained dot notation in the parser
Player::new(1)
Player::new 1
.getlevel!
.print!
```
Expand All @@ -245,11 +266,8 @@ struct Player
impl Show Player
@show: -> @name + "(" + @level.show! + ")"

use std::print::printl

# This will be generic in the futur
# This will be automatic in the future
impl Print Player
@print: -> printl @

main: ->
let player = Player
Expand All @@ -264,12 +282,6 @@ $ rock run
MyName(42)
```

Note that the `printl` method is defined in the stdlib as
```haskell
printl: x -> puts x.show!
```
with `puts` being an external from the `libc`

### Modules and code separation

- `./myproj/src/foo.rk`
Expand Down
1 change: 1 addition & 0 deletions doc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
book
6 changes: 6 additions & 0 deletions doc/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[book]
authors = ["Champii"]
language = "en"
multilingual = false
src = "src"
title = "Rock v0.4.2 language documentation"
11 changes: 11 additions & 0 deletions doc/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Summary

[Introduction](./intro.md)
- [Quick start](./quick_start.md)
- [Language reference](./language_reference.md)
- [Primitives](./primitives.md)
- [Function](./function_decl.md)
- [Function signature](./function_signature.md)
- [Struct](./struct.md)
- [Trait](./trait.md)
- [Self](./self.md)
73 changes: 73 additions & 0 deletions doc/src/function_decl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Function

## Syntax

The function declaration format is:

```haskell
function_name: arg1, arg2, arg3 -> return_value
```

The function call format is:

```haskell
function_name arg1, arg2, arg3
```

But you can add parenthesis

```haskell
function_name(arg1, arg2, arg3)
```

Every Rock package must have a `./src/main.rk` file containing a `main` function

```haskell
main: -> "Hello World!".print!
```

You can call functions with no args with a bang `!` like the `.print!` above or with
explicit parenthesis like `.print()`
But the idiomatic way is to avoid parenthesis as much as possible

```haskell
add: x, y -> x + y
main: -> add 2, 3
```

Rock does not allow for uppercase identifiers, so you should embrace the snake case.
Uppercase names are reserved for custom types like [Struct](./struct.md) or [Trait](./trait.md)

## Polymorphism

Every function in Rock is polymorphic by default, and only infer the types based on the caller and the return value of its body.
Multiple calls with different types will generate each corresponding function, just like the templates in C++ or in Rust, except the generic parameter is always implicit if no constraints have been made.

For example, lets declare the most polymorphic function of all, `id`:

```haskell
id: x -> x
```

This function takes a `x` argument and returns it. Here `x` can be of any type

```haskell
main: ->
id 42
id 6.66
id "Hello"
id my_custom_struct
```

The infered signature of the function is `id: a => a`, with `a` being any type

If we had changed the body of `id` to be:

```haskell
id: x -> x + x
```

the previous main would still work if all of the types implemented the `Num` trait from the stdlib, that provide implementation of `+` for the basic types



41 changes: 41 additions & 0 deletions doc/src/function_signature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Function signature

## Syntax

```haskell
trait MyTrait a
my_func: a => Int64 => String
```

Here, the `my_func` method takes 2 arguments of type `a` (generic) and `Int64`, and returns a `String`

A signature is always formed of at least one type.
The last (or only) type is the return type

Functions can take functions as parameter, and must be representable in a signature:

```haskell
trait MyTrait a
my_func: a => (a => b) => b
```

Here the first argument of the method `my_func` is the `self`, the second is a function that take the generic type `a` taken from the trait definition and returns a type `b`, and the whole method returns a type `b`

An implementation of this trait would be:

```haskell
impl MyTrait Int64
my_func: f -> f @

# A function of type (a => b)
handler: x -> x.show!

main: -> (2).my_func handler .print!
```

This outputs:

```
2
```

53 changes: 53 additions & 0 deletions doc/src/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Introduction

Rock is an experimental native language.

Its main goal is to mix some parts of popular functionnal languages like haskell or livescript with
the rigor of Rust while staying elegant and fast with minimal runtime

Rock is at an early development stage. Don't expect everything to work smoothly. (you have been warned)

```haskell
struct Player
level: Int64
name: String

impl Player
new: x ->
Player
level: x
name: "MyName"

impl Show Player
@show: -> @name + "(" + @level.show! + ")"

use std::print::printl

impl Print Player
@print: -> printl @

main: ->
let player = Player::new 42
player.print!
```

Rock syntax is entierly based on indentation, like Livescript.
Each whitespace count, and tabulations `\t` are prohibited.

The number of whitespace to make one level of indentation is taken from the first indent level.
If your first indentation has two whitespaces, the rest of the file must have the same number of whitespace per level (here two)

We generally use two as a default, but you can use any number you want. Here is the same example with four whitespaces:

```haskell
struct Player
level: Int64
name: String

impl Player
new: x ->
Player
level: x
name: "MyName"
```

2 changes: 2 additions & 0 deletions doc/src/language_reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Language reference

Loading

0 comments on commit 17b44d6

Please sign in to comment.