Skip to content

Commit 52b0826

Browse files
authored
Use features to describe LLVM wrapper instead of branch (#16)
* Use features in LLVM wrapper instead of branch * Fixed using parentheses on just one Binary Expression * Fixed style issue.
1 parent 86abfb4 commit 52b0826

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Make sure you have
2424
2. Cloned this repository (follow the instructions in each chapter)
2525
3. LLVM installed to run and test locally `cargo test --tests`
2626
* Easiest option is LLVM v10.0 ([Debian/Ubuntu](https://apt.llvm.org/) or [macOS](https://formulae.brew.sh/formula/llvm))
27-
* Otherwise, in `Cargo.toml` you'd need to change the `inkwell = { ..., branch = "your-llvm-version" }` with LLVM version on your system (output of `llvm-config --version`)
27+
* Otherwise, in `Cargo.toml` you'd need to change the `inkwell = { ..., features = ["your-llvm-version"] }` with LLVM version on your system (output of `llvm-config --version`)
2828

2929

3030
To build the book locally, navigate to the `book` subdirectory and follow the instructions in [mdbook](https://github.com/rust-lang/mdBook).

Diff for: book/src/01_calculator/basic_llvm.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
### Setup
55

6-
The code is available in [`calculator/examples/llvm/src/main.rs`](https://github.com/ehsanmok/create-your-own-lang-with-rust/blob/master/calculator/examples/llvm/src/main.rs). Because my `llvm-config --version` shows `10.0.0` so I'm using `branch = "llvm=10-0"` in inkwell
6+
The code is available in [`calculator/examples/llvm/src/main.rs`](https://github.com/ehsanmok/create-your-own-lang-with-rust/blob/master/calculator/examples/llvm/src/main.rs). Because my `llvm-config --version` shows `10.0.0` so I'm using `features = ["llvm10-0"]` in inkwell
77

88
```text
9-
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "llvm10-0" }
9+
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm10-0"] }
1010
```
1111

1212
Go to [`calculator/examples/llvm`](https://github.com/ehsanmok/create-your-own-lang-with-rust/blob/master/calculator/examples/llvm/) sub-crate and `cargo run`.

Diff for: calculator/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2018"
88
pest = "2.1"
99
pest_derive = "2.1"
1010
anyhow = "1.0"
11-
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "llvm10-0" } # use branch according to your llvm version
11+
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm10-0"] } # use correct feature according to your llvm version
1212
rustyline = "6.2"
1313
cfg-if = "0.1"
1414

Diff for: calculator/src/compiler/jit.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use inkwell::{
22
builder::Builder, context::Context, execution_engine::JitFunction, types::IntType,
3-
values::IntValue, OptimizationLevel,
3+
values::AnyValue, values::IntValue, OptimizationLevel,
44
};
55

66
use crate::{Compile, Node, Operator, Result};
@@ -94,6 +94,7 @@ mod tests {
9494
assert_eq!(Jit::from_source("2 + (2 - 1)").unwrap(), 3);
9595
assert_eq!(Jit::from_source("(2 + 3) - 1").unwrap(), 4);
9696
assert_eq!(Jit::from_source("1 + ((2 + 3) - (2 + 3))").unwrap(), 1);
97+
assert_eq!(Jit::from_source("(1 + 2)").unwrap(), 3);
9798
// parser fails
9899
// assert_eq!(Jit::from_source("2 + 3 - 1").unwrap(), 4);
99100
}

Diff for: calculator/src/grammar.pest

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Program = _{ SOI ~ Expr ~ EOF }
22

3-
Expr = { UnaryExpr | BinaryExpr }
3+
Expr = { UnaryExpr | BinaryExpr | Term }
44

55
Term = _{Int | "(" ~ Expr ~ ")" }
66

77
UnaryExpr = { Operator ~ Term }
88

9-
BinaryExpr = { Term ~ (Operator ~ Term)* }
9+
BinaryExpr = { Term ~ (Operator ~ Term)+ }
1010

1111
Operator = { "+" | "-" }
1212

0 commit comments

Comments
 (0)