Skip to content

Commit 0c740df

Browse files
committed
updates
1 parent 8336056 commit 0c740df

19 files changed

Lines changed: 518 additions & 943 deletions

Cargo.lock

Lines changed: 153 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[package]
22
name = "crawfish"
3-
version = "0.1.0"
3+
version = "0.0.1"
44
edition = "2024"
55

66
[dependencies]
77
ariadne = "0.4"
8+
inkwell = { version = "0.8.0", features = ["llvm20-1"] }

README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,42 @@
77
> [!CAUTION]
88
> The compiler can't compile crawfish programs yet.
99
10-
## Installation (building from source)
10+
## Installation (Building from Source)
1111

12-
### Requirements
12+
### Dependencies
1313

14-
- [Rust Compiler](https://www.rust-lang.org/)
15-
- [LLVM](https://llvm.org/)
14+
- Rust Compiler
15+
- LLVM
1616

1717
### Steps
1818

19-
1. Git clone the repository
19+
1. Install Rust
20+
```sh
21+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
22+
```
23+
24+
2. Install `llvm-config-20` and `libpolly-20-dev`
25+
```sh
26+
wget https://apt.llvm.org/llvm.sh
27+
chmod +x llvm.sh
28+
sudo ./llvm.sh 20
29+
sudo apt install libpolly-20-dev
30+
```
31+
32+
3. Git clone the repository
2033

2134
```sh
2235
git clone https://github.com/simontran7/crawfish.git
2336
```
2437

25-
2. `cd` into the `crawfish/` directory, then build the project with GNU Make
38+
4. `cd` into the `crawfish/` directory, then build the project with GNU Make
2639

2740
```sh
2841
cd crawfish/
29-
make
42+
cargo build --release
3043
```
3144

32-
4. Move the `build/crawfish` compiler binary to a desired location (e.g. in `/Users/<your name>`), then add it to your `PATH` by adding the following line to your `.bashrc` file
45+
5. Move the `target/release/crawfish` binary to a desired location (e.g. in `/Users/<your name>`), then add it to your `PATH` by adding the following line to your `.bashrc` file
3346

3447
```sh
3548
# in your .bashrc
@@ -38,4 +51,18 @@ export PATH=$PATH:<path to the crawfish compiler executable>
3851

3952
## Usage
4053

54+
```
55+
Crawfish compiler
56+
57+
Usage:
58+
crawfish [OPTIONS] <COMMAND> [ARGS...]
59+
60+
Command:
61+
compile <file>.crw compile the current file
62+
63+
Options:
64+
-h, --help print possible commands
65+
-v, --version print compiler version
66+
```
67+
4168
See `docs/tour-of-crawfish.md` for a tour of the language.

docs/ARCHITECTURE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ fn bar() {
158158
fn baz() { ... } // this still parses fine!
159159
```
160160

161-
### Lexer
161+
### Tokenizer
162162

163-
The lexer is hand-written, and conceptually a deterministic finite automaton (DFA) that recognizes a regular language. Lexer generators or regular expressions are convenient, but don't offer as much flexibility as a hand-written lexer. It's also another dependency to maintain.
163+
The tokenizer is hand-written, and conceptually a deterministic finite automaton (DFA) that recognizes a regular language. Lexer generators or regular expressions are convenient, but don't offer as much flexibility as a hand-written tokenizer. It's also another dependency to maintain.
164164

165165
Structurally, the lexer is a simple struct with two fields:
166166
- `source`: a string slice of the user's source code, useful for accurate span tracking and error messages

docs/language-design.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -371,24 +371,6 @@ interface <interface name>[T] {
371371
| Math | `ln()` |
372372
| Math | `pow_e()` |
373373
374-
### Containers and Algorithms
375-
376-
- `ArrayList`: a list backed by a dynamic array
377-
- `SinglyLinkedList`: a list backed by a singly linked list
378-
- `DoublyLinkedList`: a list backed by a doubly linked list
379-
- `ArrayStack`: a stack backed by a dynamic array
380-
- `LinkedStack`: a stack backed by a singly linked list
381-
- `ArrayQueue`: a queue backed by a circular dynamic array
382-
- `LinkedQueue`: a queue backed by a singly linked list
383-
- `MinHeapPriorityQueue`: a priority queue backed by a min binary heap
384-
- `MaxHeapPriorityQueue`: a priority queue backed by a max binary heap
385-
- `HashMap`: a map backed by a hash table
386-
- `HashSet`: a set backed by a hash table
387-
- `RBTreeOrderedMap`: a ordered map backed by a Red-Black Tree
388-
- `RBTreeOrderedSet`: an ordered set backed by a Red-Black Tree
389-
- `sort`: driftsort stable sorting algorithm
390-
- `binary_search`: binary search algorithm
391-
392374
## Imports
393375
394376
```

src/common/interner.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
use std::collections::HashMap;
22

3-
/// Interner Data Structure which interns literals and identifiers.
3+
/// Interner which interns literals and identifiers.
44
pub struct Interner {
5-
// string id -> string literal
5+
// symbols -> string literal
66
strings: Vec<String>,
7-
// string literal -> string id
8-
ids: HashMap<String, Symbol>,
7+
// string literal -> symbols
8+
symbols: HashMap<String, Symbol>,
99
}
1010

1111
impl Interner {
1212
/// Creates and returns an instance of `Interner`.
1313
pub fn new() -> Interner {
1414
Interner {
1515
strings: Vec::new(),
16-
ids: HashMap::new(),
16+
symbols: HashMap::new(),
1717
}
1818
}
1919

2020
/// Interns `string` and returns a string id.
2121
pub fn intern(&mut self, string: &str) -> Symbol {
22-
if let Some(&id) = self.ids.get(string) {
22+
if let Some(&id) = self.symbols.get(string) {
2323
return id;
2424
}
2525
let id = Symbol(self.strings.len() as u32);
2626
self.strings.push(string.to_owned());
27-
self.ids.insert(string.to_owned(), id);
27+
self.symbols.insert(string.to_owned(), id);
2828
id
2929
}
3030

@@ -49,8 +49,8 @@ mod tests {
4949
fn requirement_1() {
5050
let s = "foo";
5151
let mut interner = Interner::new();
52-
let id = interner.intern(s);
53-
assert_eq!(s, interner.resolve(id).unwrap());
52+
let symbol = interner.intern(s);
53+
assert_eq!(s, interner.resolve(symbol).unwrap());
5454
}
5555

5656
// If two strings are equal, then they should have the same id.

src/common/span.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::fmt;
2+
13
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
24
pub struct Span {
35
start: u32,
@@ -23,3 +25,9 @@ impl From<&Span> for std::ops::Range<usize> {
2325
span.start as usize..span.end as usize
2426
}
2527
}
28+
29+
impl fmt::Display for Span {
30+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31+
write!(f, "[{}, {})", self.start, self.end)
32+
}
33+
}

0 commit comments

Comments
 (0)