1+ # Default recipe to show help
2+ default :
3+ @ just --list
4+
5+ # Build variables
6+ binary := " halcyon"
7+ test_dir := " writing-a-c-compiler-tests"
8+
9+ # Build the project
10+ build :
11+ cabal build
12+
13+ # Build in watch mode - recompiles on file changes
14+ watch :
15+ cabal build --enable-tests --file-watch
16+
17+ # Run compiler on a file with specific stage
18+ run FILE STAGE = " ":
19+ cabal run {{ binary}} -- {{ FILE}} {{ STAGE}}
20+
21+ # Run all tests
22+ test :
23+ cabal test
24+
25+ # Run specific test file or directory
26+ test-file FILE :
27+ cabal test --test-options=" --match '{{ FILE}} '"
28+
29+ # Run compiler test suite
30+ test-compiler :
31+ cd {{ test_dir}} && ./ test_compiler ../ bin/ {{ binary}}
32+
33+ # Run compiler test suite for specific chapter
34+ test-chapter CHAPTER :
35+ cd {{ test_dir}} && ./ test_compiler ../ bin/ {{ binary}} --chapter {{ CHAPTER}}
36+
37+ # Run tests in watch mode
38+ test-watch :
39+ cabal test --enable-tests --file-watch
40+
41+ # Check setup for compiler test suite
42+ check-setup :
43+ cd {{ test_dir}} && ./ test_compiler --check-setup
44+
45+ # Format Haskell source files using ormolu
46+ fmt :
47+ find lib test -name " *.hs" -exec ormolu --mode inplace {} \;
48+
49+ # Check formatting without making changes
50+ fmt-check :
51+ find lib test -name " *.hs" -exec ormolu --mode check {} \;
52+
53+ # Run HLint suggestions
54+ lint :
55+ hlint lib test
56+
57+ # Apply HLint suggestions automatically where possible
58+ lint-apply :
59+ hlint lib test --refactor --refactor-options=" --inplace"
60+
61+ # Update symlink to latest build (if needed)
62+ link :
63+ rm -f bin/ {{ binary}}
64+ ln -s " $(cabal list-bin {{ binary}} )" bin/ {{ binary}}
65+
66+ # Clean build artifacts
67+ clean :
68+ cabal clean
69+ rm -f bin/ {{ binary}}
70+
71+ # Clean and rebuild everything
72+ rebuild : clean build
73+
74+ # Create new test file from template
75+ new-test NAME :
76+ #!/usr/bin/env bash
77+ file=" test/Test/{{ NAME}} .hs"
78+ echo " {-# LANGUAGE OverloadedStrings #-}" > ${file}
79+ echo " module Test.{{ NAME}} ({{ NAME}} Specs) where" >> ${file}
80+ echo " " >> ${file}
81+ echo " import Test.Hspec" >> ${file}
82+ echo " " >> ${file}
83+ echo " {{ NAME}} Specs :: Spec" >> ${file}
84+ echo " {{ NAME}} Specs = describe \" {{ NAME}} \" $ do" >> ${file}
85+ echo " it \" placeholder test\" $ do" >> ${file}
86+ echo " True \` shouldBe\` True" >> ${file}
87+
88+ # Generate documentation
89+ docs :
90+ cabal haddock --enable-documentation
91+
92+ # Run ghci with project modules
93+ repl :
94+ cabal repl
95+
96+ # Initialize a new test C file
97+ new-c-test CHAPTER NAME :
98+ #!/usr/bin/env bash
99+ dir=" {{ test_dir}} /tests/chapter_{{ CHAPTER}} /valid"
100+ file=" ${dir}/{{ NAME}} .c"
101+ mkdir -p ${dir}
102+ echo " int main(void) {" > ${file}
103+ echo " return 0;" >> ${file}
104+ echo " }" >> ${file}
105+
106+ # Show project dependency tree
107+ deps :
108+ cabal-plan deps
109+
110+ # Update cabal index
111+ update :
112+ cabal update
113+
114+ # Build project with profiling
115+ build-profile :
116+ cabal build --enable-profiling
117+
118+ # Count lines of code
119+ loc :
120+ find lib test -name " *.hs" | xargs wc -l
121+
122+ # Check for outdated dependencies
123+ outdated :
124+ cabal outdated
125+
126+ # List all modules in the project
127+ modules :
128+ find lib test -name " *.hs" -exec basename {} .hs \;
129+
130+ # Generate comprehensive project context for AI assistance
131+ context * FILENAME = " ai-context.txt":
132+ #!/ bin/ bash
133+ echo " <documents>" > {{ FILENAME}}
134+
135+ # Project Structure Document
136+ echo " <document index=\" 1\" >" >> {{ FILENAME}}
137+ echo " <source>structure.txt</source>" >> {{ FILENAME}}
138+ echo " <document_content>" >> {{ FILENAME}}
139+ # Add git status and recent history
140+ echo " <git_status>" >> {{ FILENAME}}
141+ git status -s >> {{ FILENAME}}
142+ echo " </git_status>" >> {{ FILENAME}}
143+ echo " <git_history>" >> {{ FILENAME}}
144+ git log --oneline -n 10 >> {{ FILENAME}} # Last 10 commits
145+ echo " </git_history>" >> {{ FILENAME}}
146+ # Add directory tree
147+ echo " <directory_tree>" >> {{ FILENAME}}
148+ eza -T --git-ignore >> {{ FILENAME}}
149+ echo " </directory_tree>" >> {{ FILENAME}}
150+ echo " </document_content>" >> {{ FILENAME}}
151+ echo " </document>" >> {{ FILENAME}}
152+
153+ # Cabal Configuration Document
154+ echo " <document index=\" 3\" >" >> {{ FILENAME}}
155+ echo " <source>project-config.txt</source>" >> {{ FILENAME}}
156+ echo " <document_content>" >> {{ FILENAME}}
157+ cat halcyon.cabal >> {{ FILENAME}}
158+ echo " </document_content>" >> {{ FILENAME}}
159+ echo " </document>" >> {{ FILENAME}}
160+
161+ # Source Files Document
162+ echo " <document index=\" 4\" >" >> {{ FILENAME}}
163+ echo " <source>source-files.txt</source>" >> {{ FILENAME}}
164+ echo " <document_content>" >> {{ FILENAME}}
165+ find . -name " *.hs" -type f \
166+ - not -path " ./dist-newstyle/*" \
167+ - not -path " ./writing-a-c-compiler-tests/*" \
168+ - not -path " ./c-programs/*" \
169+ - exec sh -c ' echo "<file>{}" && echo "<content>" && cat "{}" && echo "</content>"' \; >> {{ FILENAME}}
170+ echo " </document_content>" >> {{ FILENAME}}
171+ echo " </document>" >> {{ FILENAME}}
172+
173+ echo " </documents>" >> {{ FILENAME}}
174+
175+ echo " Project context saved to {{ FILENAME}} "
176+
177+ # Generate module dependency graph in DOT format
178+ deps-graph * FILENAME = " module-deps.dot":
179+ #!/ bin/ bash
180+ if ! command -v dot &> / dev/ null; then \
181+ echo " graphviz not found. Install with: brew install graphviz" ; \
182+ exit 1 ; \
183+ fi
184+ if ! command -v graphmod &> / dev/ null; then \
185+ echo " graphmod not found. Install with: cabal install graphmod" ; \
186+ exit 1 ; \
187+ fi
188+ # Generate module graph excluding external modules
189+ graphmod -i Data.Text,Data.Set,Control.Monad,System.IO \
190+ - -no-cluster \
191+ - q lib/ Halcyon lib/ Halcyon.hs | dot -Tdot -o {{ FILENAME}}
192+ echo " Module dependency graph saved to {{ FILENAME}} "
193+
194+ # Install development tools needed for context generation
195+ setup-context-tools :
196+ cabal install graphmod
197+ # Ensure dot (graphviz) is installed
198+ @ if ! command -v dot &> / dev/ null; then \
199+ echo " Graphviz not installed. Please install:" ; \
200+ echo " brew install graphviz # on macOS" ; \
201+ echo " apt install graphviz # on Ubuntu" ; \
202+ fi
0 commit comments