Skip to content

Commit d049cce

Browse files
committed
chore: Move build-toolchain into the root
Simplifies `make` maintainance calls when all is in the root.
1 parent 2125fdb commit d049cce

9 files changed

+52
-42
lines changed

build/Makefile Makefile

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
.PHONY: .FORCE
2-
ETARENEG=cd ../src && awk -f ../build/etareneg.awk
2+
ETARENEG=awk -f etareneg.awk
33

4-
all:
5-
@echo No target specified. See README.md for details.
4+
help:
5+
@echo "No target specified."
6+
@echo "See README.md build-section for details."
67
@echo ""
7-
@echo " make builtins update src/_builtins.rs from src/"
8-
@echo " make parser update src/compiler/parse.rs from src/compiler/tokay.tok"
9-
@echo " make prelude update src/compiler/prelude.rs from src/prelude.tok"
8+
@echo " make builtins update src/_builtins.rs"
9+
@echo " make parser update src/compiler/parser.rs from src/compiler/tokay.tok"
10+
@echo " make prelude update src/compiler/prelude.rs from src/prelude.tok"
1011
@echo ""
12+
@echo "This is the Tokay source generation toolchain."
13+
@echo "To just build Tokay, simply use 'cargo build'."
14+
15+
all:
16+
make prelude
17+
make parser
18+
make builtins
1119

1220
# builtins --------------------------------------------------------------------
13-
BUILTINS=../src/_builtins.rs
21+
BUILTINS=src/_builtins.rs
1422

1523
builtins: $(BUILTINS)
1624

@@ -25,7 +33,7 @@ reset-builtins:
2533

2634

2735
# parser ----------------------------------------------------------------------
28-
PARSER=../src/compiler/parser.rs
36+
PARSER=src/compiler/parser.rs
2937

3038
parser: $(PARSER)
3139

@@ -39,7 +47,7 @@ reset-parser:
3947
git checkout $(PARSER)
4048

4149
# prelude ----------------------------------------------------------------------
42-
PRELUDE=../src/compiler/prelude.rs
50+
PRELUDE=src/compiler/prelude.rs
4351

4452
prelude: $(PRELUDE)
4553

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,34 @@ Int print($1, "=>", fibonacci($1))
180180
181181
The Tokay homepage [tokay.dev](https://tokay.dev) provides links to a quick start and documentation. The documentation source code is maintained in a [separate repository](https://github.com/tokay-lang/tokay-docs).
182182
183+
## Building
184+
185+
The `Makefile` located in `src/` provides tooling to build Tokay's internal parts.
186+
187+
### `make builtins` - update Tokay's builtin registry from the Rust sources
188+
189+
Generate the file `src/_builtins.rs` using `src/_builtins.tok`.
190+
191+
- `make builtins` updates the content of `src/_builtins.rs` using `src/_builtins.tok` from the Rust sources.
192+
- `make show-builtins` dumps what would be generated by `make builtins`
193+
- `make reset-builtins` resets `src/_builtins.rs` from git, if something went wrong.
194+
195+
### `make parser` - update Tokay's parser from `tokay.tok`
196+
197+
Tokay uses a program written in itself (`src/compiler/tokay.tok`) to generate its own language parser (`src/compiler/parser.rs`) incrementally.
198+
199+
- `make parser` updates the content of `src/compiler/parser.rs` from `src/compiler/tokay.tok`.
200+
- `make show-parser` dumps what would be generated by `make parser`
201+
- `make reset-parser` resets `src/compiler/parser.rs` from git, if something went wrong.
202+
203+
### `make prelude` - update Tokay's prelude from `prelude.tok`
204+
205+
Tokay needs the prelude to provide general language features and defaults.
206+
207+
- `make prelude` updates the content of `src/compiler/prelude.rs` from `src/prelude.tok`.
208+
- `make show-prelude` dumps what would be generated by `make prelude`
209+
- `make reset-prelude` resets `src/compiler/prelude.rs` from git, if something went wrong.
210+
183211
## Debugging
184212
185213
For debugging, there are two methods to use.

build/README.md

-27
This file was deleted.

build/etareneg.awk etareneg.awk

File renamed without changes.

src/_builtins.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use crate::builtin::Builtin;
77

8-
/*GENERATE cargo run -- _builtins.tok -- `find . -name "*.rs"` */
8+
/*GENERATE cargo run -- src/_builtins.tok -- `find src -name "*.rs"` */
99
pub static BUILTINS: [Builtin; 70] = [
1010
Builtin {
1111
name: "Float",

src/_builtins.tok

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ _ 'tokay_' kind => {
1717
#print(offset()["filename"], $kind, $name)
1818

1919
mod = offset()["filename"].split("/")
20+
mod.pop(0) # remove the "src/"
2021
last = mod.len - 1
2122
mod[last] = mod[last].replace(".rs")
2223
if mod[last] == "mod" mod.pop()

src/compiler/parser.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Tokay parser, implemented in Tokay itself.
1+
//! The Tokay parser, implemented in Tokay itself.
22

33
use super::*;
44
use crate::error::Error;
@@ -24,9 +24,9 @@ impl Parser {
2424
// The best way is to test grammar changes with `tokay.tok` intensely before rebuilding the
2525
// parser, to ensure all runs well.
2626

27-
// To update this file, `cd build` and run `make parser` in a shell.
27+
// To update this file, run `make parser` in a shell.
2828

29-
/*GENERATE cargo run -- "`sed 's/ast("main")/ast2rust(ast("main"), level=3)/g' compiler/tokay.tok`" -- compiler/tokay.tok */
29+
/*GENERATE cargo run -- "`sed 's/ast("main")/ast2rust(ast("main"), level=3)/g' src/compiler/tokay.tok`" -- src/compiler/tokay.tok */
3030
value!([
3131
"emit" => "main",
3232
"children" =>

src/compiler/prelude.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl Compiler {
1212
pub(super) fn load_prelude(&mut self) {
1313
// fixme: Make this lazy_static, so its created only once!
1414
let ast =
15-
/*GENERATE cargo run -- "`sed 's/ast("main")/ast2rust(ast("main"), level=3)/g' compiler/tokay.tok`" -- prelude.tok */
15+
/*GENERATE cargo run -- "`sed 's/ast("main")/ast2rust(ast("main"), level=3)/g' src/compiler/tokay.tok`" -- src/prelude.tok */
1616
value!([
1717
"emit" => "main",
1818
"children" =>

src/compiler/tokay.tok

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# This Tokay program expresses Tokay's grammar in itself.
66
# It is used to modify and build Tokays own language parser.
77
#
8-
# See `build/README.md` for details.
8+
# See `README.md` build-section for details.
99
#
1010

1111
#ExpectAndRecover : @<P> msg=void {

0 commit comments

Comments
 (0)