Skip to content

Commit

Permalink
Fix links in kaleidoscope
Browse files Browse the repository at this point in the history
  • Loading branch information
k4rtik committed Feb 6, 2024
1 parent e060023 commit 3fbca1e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 58 deletions.
109 changes: 56 additions & 53 deletions examples/kaleidoscope/README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,56 @@
# Kaleidoscope

This example shows how one can implement the [Kaleidoscope programming language](https://llvm.org/docs/tutorial/index.html) using Inkwell.
It implements every feature up to the [7th chapter](https://llvm.org/docs/tutorial/LangImpl07.html).

The [usage](../../README.md#usage) part doesn't fit the example as it shares the same `Cargo.toml` file with the whole project.

To run the example, the LLVM version is required:
```sh
cargo run --example kaleidoscope --features llvm$(llvm-config --version | sed 's/\./-/;s/\.[0-9]*//')
```

When running this command, a prompt will be displayed; for example:

```
?> 1 + 1
=> 2
?> var a = 5, b = 10 in a * b
=> 50
?> def fib(n) if n < 2 then n else fib(n - 1) + fib(n - 2)
?> fib(40)
=> 102334155
?>
```

Additional arguments can be passed to the produced executable:
- `--dc`: **D**isplay **C**ompiler output
- `--dp`: **D**isplay **P**arser output
- `--dl`: **D**isplay **L**exer output

For example, running with all three switches may lead to the following output:
```
?> 1 + 2 * 2
-> Attempting to parse lexed input:
[Number(1), Op('+'), Number(2), Op('*'), Number(2)]
-> Expression parsed:
Binary { op: '+', left: Number(1), right: Binary { op: '*', left: Number(2), right: Number(2) } }
-> Expression compiled to IR:
define double @anonymous() {
entry:
ret double 5.000000e+00
}
=> 5
```

Finally, the prompt can be exited by entering "exit" or "quit".
# Kaleidoscope

This example shows how one can implement the [Kaleidoscope programming language](https://llvm.org/docs/tutorial/index.html) using Inkwell.
It implements every feature up to the [7th chapter](https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl07.html).

The [usage](../../README.md#usage) part doesn't fit the example as it shares the same `Cargo.toml` file with the whole project.

To run the example, the LLVM version is required:

```sh
cargo run --example kaleidoscope --features llvm$(llvm-config --version | sed 's/\./-/;s/\.[0-9]*//')
```

When running this command, a prompt will be displayed; for example:

```
?> 1 + 1
=> 2
?> var a = 5, b = 10 in a * b
=> 50
?> def fib(n) if n < 2 then n else fib(n - 1) + fib(n - 2)
?> fib(40)
=> 102334155
?>
```

Additional arguments can be passed to the produced executable:

- `--dc`: **D**isplay **C**ompiler output
- `--dp`: **D**isplay **P**arser output
- `--dl`: **D**isplay **L**exer output

For example, running with all three switches may lead to the following output:

```
?> 1 + 2 * 2
-> Attempting to parse lexed input:
[Number(1), Op('+'), Number(2), Op('*'), Number(2)]
-> Expression parsed:
Binary { op: '+', left: Number(1), right: Binary { op: '*', left: Number(2), right: Number(2) } }
-> Expression compiled to IR:
define double @anonymous() {
entry:
ret double 5.000000e+00
}
=> 5
```

Finally, the prompt can be exited by entering "exit" or "quit".
13 changes: 8 additions & 5 deletions examples/kaleidoscope/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
//! This is an example of the [Kaleidoscope tutorial](https://llvm.org/docs/tutorial/)
//! made in Rust, using Inkwell.
//! Currently, all features up to the [7th chapter](https://llvm.org/docs/tutorial/LangImpl07.html)
//! Currently, all features up to the
//! [7th chapter](https://llvm.org/docs/tutorial/MyFirstLanguageFrontend/LangImpl07.html)
//! are available.
//! This example is supposed to be ran as a executable, which launches a REPL.
//! The source code is in the following order:
//! - Lexer,
//! - Parser,
//! - Compiler,
//! - Program.
//! - `implementation_typed_pointers.rs`:
//! Lexer,
//! Parser,
//! Compiler.
//! - `main.rs`:
//! Program.
//!
//! Both the `Parser` and the `Compiler` may fail, in which case they would return
//! an error represented by `Result<T, &'static str>`, for easier error reporting.
Expand Down

0 comments on commit 3fbca1e

Please sign in to comment.