Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 52b0826

Browse files
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

‎README.md

Lines changed: 1 addition & 1 deletion
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).

‎book/src/01_calculator/basic_llvm.md

Lines changed: 2 additions & 2 deletions
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`.

‎calculator/Cargo.toml

Lines changed: 1 addition & 1 deletion
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

‎calculator/src/compiler/jit.rs

Lines changed: 2 additions & 1 deletion
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
}

‎calculator/src/grammar.pest

Lines changed: 2 additions & 2 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /