Skip to content

Commit

Permalink
v0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Champii committed Apr 20, 2022
2 parents ffcd530 + 5cef8f3 commit 9dc0729
Show file tree
Hide file tree
Showing 36 changed files with 162 additions and 389 deletions.
22 changes: 0 additions & 22 deletions .github/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,9 @@ mkdir -P factorial/src && cd factorial

Add some files like this:

- Copy all the stdlib files from [std/src/\*.rk](https://github.com/Champii/Rock/blob/master/std/src) into `factorial/src/`

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

```haskell
mod lib

use lib::prelude::(*)

fact a =
if a <= 1
then 1
Expand Down Expand Up @@ -121,10 +115,6 @@ Note that you currently must be at the project root to run the compiler. (i.e. i


``` haskell
mod lib

use lib::prelude::(*)

id a = a

main =
Expand All @@ -148,10 +138,6 @@ Test
### Custom infix operator

``` haskell
mod lib

use lib::prelude::(*)

infix |> 1
|> x f = f x

Expand All @@ -171,10 +157,6 @@ Prints `6`
This `trait ToString` is redondant with the `trait Show` implemented in the lib, and serves as a demonstration only

``` haskell
mod lib

use lib::prelude::(*)

trait ToString a
toString :: a -> String

Expand Down Expand Up @@ -204,10 +186,6 @@ Prints
### Struct instance and Show implementation

``` haskell
mod lib

use lib::prelude::(*)

struct Player
level :: Int64
name :: String
Expand Down
2 changes: 1 addition & 1 deletion .github/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.0
v0.2.1
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.0"
version = "0.2.1"
authors = ["champii <contact@champii>"]
edition = "2018"

Expand Down
30 changes: 4 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Rock v0.2.0
# Rock v0.2.1

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

Expand Down Expand Up @@ -45,10 +45,10 @@ You will need `clang` somewhere in your $PATH

Linux x86_64 only

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

``` sh
wget https://github.com/Champii/Rock/releases/download/v0.2.0/rock
wget https://github.com/Champii/Rock/releases/download/v0.2.1/rock
chmod +x rock
./rock -V
```
Expand Down Expand Up @@ -82,15 +82,9 @@ mkdir -P factorial/src && cd factorial

Add some files like this:

- Copy all the stdlib files from [std/src/\*.rk](https://github.com/Champii/Rock/blob/master/std/src) into `factorial/src/`

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

```haskell
mod lib

use lib::prelude::(*)

fact a =
if a <= 1
then 1
Expand Down Expand Up @@ -121,10 +115,6 @@ Note that you currently must be at the project root to run the compiler. (i.e. i


``` haskell
mod lib

use lib::prelude::(*)

id a = a

main =
Expand All @@ -148,10 +138,6 @@ Test
### Custom infix operator

``` haskell
mod lib

use lib::prelude::(*)

infix |> 1
|> x f = f x

Expand All @@ -171,10 +157,6 @@ Prints `6`
This `trait ToString` is redondant with the `trait Show` implemented in the lib, and serves as a demonstration only

``` haskell
mod lib

use lib::prelude::(*)

trait ToString a
toString :: a -> String

Expand Down Expand Up @@ -204,10 +186,6 @@ Prints
### Struct instance and Show implementation

``` haskell
mod lib

use lib::prelude::(*)

struct Player
level :: Int64
name :: String
Expand Down Expand Up @@ -250,7 +228,7 @@ rock --repl
```

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

Type ':?' for help
Expand Down
7 changes: 7 additions & 0 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ fn main() {
.takes_value(false)
.help("Show the InferContext state before solve (DEPRECATED)"),
)
.arg(
Arg::with_name("nostd")
.long("nostd")
.takes_value(false)
.help("Does not include stdlib"),
)
.arg(
Arg::with_name("output-folder")
.short("o")
Expand All @@ -163,6 +169,7 @@ fn main() {
repl: matches.is_present("repl"),
no_optimize: matches.is_present("no-optimize"),
build_folder: PathBuf::from(matches.value_of("output-folder").unwrap()),
std: !matches.is_present("nostd"),
..Default::default()
};

Expand Down
12 changes: 6 additions & 6 deletions src/lib/ast/ast_print.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::fmt::Debug;

use crate::ast::tree::*;
use crate::ast::visit::*;
use crate::helpers::*;
use crate::ty::*;
use paste::paste;

use crate::{
ast::{tree::*, visit::*},
helpers::*,
ty::*,
};

pub struct AstPrintContext {
indent: usize,
}
Expand Down Expand Up @@ -83,7 +85,6 @@ macro_rules! impl_visitor_trait {

impl_visitor_trait!(
Root
// Mod
TopLevel
StructDecl
Use
Expand All @@ -92,7 +93,6 @@ impl_visitor_trait!(
Impl
FunctionDecl
Identifier
// ArgumentDecl
Body
Statement
For
Expand Down
17 changes: 2 additions & 15 deletions src/lib/ast/return_placement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,20 @@ pub struct ReturnInserter<'a> {
pub body: &'a Body,
}

// TODO: Implement `Visitor` trait for `ReturnInserter`
impl<'a> ReturnInserter<'a> {
pub fn run(&mut self) -> Body {
let mut body = self.body.clone();

self.visit_body(&mut body);

body.clone()
body
}

fn visit_body(&mut self, body: &mut Body) {
// let mut is_assign = None;

if let Some(stmt) = body.stmts.iter_mut().last() {
// if let StatementKind::Assign(ref mut a) = *stmt.kind.clone() {
// is_assign = Some(a.clone());
// }

self.visit_statement(stmt);
}

// if let Some(a) = is_assign {
// body.stmts.push(Statement {
// kind: Box::new(StatementKind::Expression(Box::new(Expression {
// kind: ExpressionKind::Return(Box::new(a.name.as_expression())),
// }))),
// });
// }
}

fn visit_statement(&mut self, stmt: &mut Statement) {
Expand Down
23 changes: 4 additions & 19 deletions src/lib/ast/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,6 @@ pub enum AssignLeftSide {
Dot(Expression),
}

impl AssignLeftSide {
pub fn as_expression(&self) -> Expression {
match self {
AssignLeftSide::Identifier(i) => i.clone(),
AssignLeftSide::Indice(i) => i.clone(),
AssignLeftSide::Dot(d) => d.clone(),
}
}
}

#[derive(Debug, Clone)]
pub struct Assign {
pub name: AssignLeftSide,
Expand Down Expand Up @@ -516,7 +506,8 @@ pub enum Expression {
#[derive(Debug, Clone)]
pub enum UnaryExpr {
PrimaryExpr(PrimaryExpr),
UnaryExpr(Operator, Box<UnaryExpr>),
#[allow(dead_code)]
UnaryExpr(Operator, Box<UnaryExpr>), // Parser for that is not implemented yet
}

impl UnaryExpr {
Expand Down Expand Up @@ -603,14 +594,6 @@ impl PrimaryExpr {
}
}

pub fn new_empty(op: Operand) -> PrimaryExpr {
PrimaryExpr {
op,
node_id: u64::MAX,
secondaries: None,
}
}

pub fn new(node_id: NodeId, op: Operand, secondaries: Vec<SecondaryExpr>) -> PrimaryExpr {
PrimaryExpr {
op,
Expand Down Expand Up @@ -699,6 +682,8 @@ impl SecondaryExpr {
matches!(self, SecondaryExpr::Dot(_))
}

// might be useful
#[allow(dead_code)]
pub fn is_arguments(&self) -> bool {
matches!(self, SecondaryExpr::Arguments(_))
}
Expand Down
5 changes: 0 additions & 5 deletions src/lib/ast/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ generate_visitor_trait!(
StructDecl
Identifier
IdentifierPath
// ArgumentDecl
Body
Statement
For
Expand Down Expand Up @@ -138,10 +137,6 @@ pub fn walk_identifier<'a, V: Visitor<'a>>(visitor: &mut V, identifier: &'a Iden
visitor.visit_name(&identifier.name);
}

/* pub fn walk_argument_decl<'a, V: Visitor<'a>>(visitor: &mut V, argument: &'a ArgumentDecl) {
visitor.visit_name(&argument.name);
} */

pub fn walk_body<'a, V: Visitor<'a>>(visitor: &mut V, body: &'a Body) {
walk_list!(visitor, visit_statement, &body.stmts);
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib/ast_lowering/ast_lowering_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ impl AstLoweringContext {

pub fn lower_struct_decl(&mut self, s: &StructDecl) -> hir::StructDecl {
let hir_t = hir::StructDecl {
// hir_id: self.hir_map.next_hir_id(s.name.node_id),
name: self.lower_identifier(&s.name),
defs: s
.defs
Expand Down Expand Up @@ -327,7 +326,6 @@ impl AstLoweringContext {

pub fn lower_struct_ctor(&mut self, s: &StructCtor) -> hir::Expression {
hir::Expression::new_struct_ctor(hir::StructCtor {
// hir_id: self.hir_map.next_hir_id(s.node_id),
name: self.lower_identifier(&s.name),
defs: s
.defs
Expand Down
4 changes: 0 additions & 4 deletions src/lib/ast_lowering/hir_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ impl HirMap {
pub fn duplicate_hir_mapping(&mut self, hir_id: HirId) -> Option<HirId> {
let node_id = self.get_node_id(&hir_id)?;

/* let mut fake_ident = Identity::new_placeholder();
fake_ident.node_id = node_id; */

let new_id = self.next_hir_id(node_id);

self.add_hir_mapping(new_id.clone(), node_id);
Expand Down
Loading

0 comments on commit 9dc0729

Please sign in to comment.