Skip to content

Commit a095a0c

Browse files
committed
Create AGENTS.md
1 parent 66b0995 commit a095a0c

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed

AGENTS.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# AGENTS.md
2+
3+
This document defines how automated coding assistants (“agents”) should interact with this repository.
4+
5+
## 1. Repository Overview
6+
7+
This repository contains the **WurstScript compiler**. Its main code lives in:
8+
9+
```
10+
de.peeeq.wurstscript/
11+
```
12+
13+
Other directories like `WurstPack` and `HelperScripts` exist but are largely **deprecated** and should not be modified unless explicitly requested.
14+
15+
### Compiler layout
16+
17+
Inside `de.peeeq.wurstscript`:
18+
19+
* **`src/main/antlr/de/peeeq/wurstscript/antlr/`**
20+
Contains the **ANTLR grammars** (`.g4`) for Wurst and Jass.
21+
These produce concrete syntax trees (CSTs).
22+
23+
* **`parserspec/`**
24+
Contains **.parseq grammars** for `abstractsyntaxgen`
25+
([https://github.com/peterzeller/abstractsyntaxgen](https://github.com/peterzeller/abstractsyntaxgen)).
26+
These define the AST structure used by the compiler.
27+
Code is generated via the Gradle task:
28+
29+
```
30+
./gradlew :gen
31+
```
32+
33+
* **`src/main/java/de/peeeq/`**
34+
Main compiler sources:
35+
36+
* Parsing and AST infrastructure
37+
* Type checking
38+
* Intermediate language (**IM**)
39+
* Jass and Lua backends
40+
* Interpreter for executing IM at compile time
41+
(used for specific compile-time evaluations)
42+
43+
### Compilation pipeline (simplified)
44+
45+
1. Parse Wurst/Jass with ANTLR → CST
46+
2. Abstractsyntaxgen → AST
47+
3. Transform AST → IM
48+
4. Optionally: Run IM in the interpreter, Optimize
49+
5. Transform IM → Backend (Jass or Lua)
50+
51+
52+
### Language and tooling
53+
54+
* **Java 25**
55+
* **Gradle (9.2.1)**
56+
* Unit tests define many entry points and expected behaviors.
57+
58+
---
59+
60+
## 2. Agent Expectations
61+
62+
Changes made by agents must follow these principles:
63+
64+
### Compatibility first
65+
66+
* **All existing tests must continue to pass.**
67+
* If behavior changes intentionally, provide **new tests** that define the updated semantics.
68+
69+
### Minimal, well-scoped edits
70+
71+
Agents should:
72+
73+
* Fix concrete bugs with **small, local patches**.
74+
* Add missing null-checks, defensive checks, or diagnostics where appropriate.
75+
* Add tests when resolving issues or implementing requested features.
76+
77+
Agents should avoid:
78+
79+
* Large refactors (renaming packages, structural moves, mass rewrites).
80+
* Modifying deprecated folders unless explicitly instructed.
81+
* Altering public semantics or language rules without tests demonstrating the intended outcome.
82+
83+
### Test-driven
84+
85+
* Any new behavior requires tests showing failure before the change and success after.
86+
* Use existing test style and harnesses.
87+
88+
### Generated code
89+
90+
* Do **not** modify files generated by `:gen`.
91+
* If modifying `.parseq` files or grammars, regenerate via:
92+
93+
```
94+
./gradlew :gen
95+
```
96+
97+
---
98+
99+
## 3. Coding Guidelines
100+
101+
### Follow existing style
102+
103+
Use the conventions already present in the file you edit. Avoid introducing new patterns without reason.
104+
105+
### Compiler structure expectations
106+
107+
* The IM is the central intermediate representation.
108+
* Transformations should keep IM consistent and valid.
109+
* Backends (Jass/Lua) expect well-formed IM; avoid breaking invariants.
110+
* Interpreter should remain deterministic and side-effect free.
111+
112+
### Error handling
113+
114+
* Prefer explicit, descriptive diagnostic messages.
115+
* Avoid silent fallbacks or suppressed exceptions.
116+
* Don’t change the meaning of existing error messages unless required.
117+
118+
### Performance
119+
120+
* Avoid algorithmic regressions in parsing, type checking, or transforms.
121+
* Consider memory impact when manipulating large ASTs or IM graphs.
122+
123+
---
124+
125+
## 4. Allowed vs. Disallowed Changes
126+
127+
### Allowed
128+
129+
* Fix a crash or incorrect behavior in a specific compiler pass.
130+
* Add a regression test that demonstrates a known issue.
131+
* Improve clarity of error messages.
132+
* Add a small new feature when fully specified by the user and backed by tests.
133+
* Update Gradle/JDK usage only if part of a requested task.
134+
135+
### Disallowed
136+
137+
* Unsolicited rewrites of ANTLR grammars.
138+
* Modifying deprecated folders.
139+
* Changing code generation semantics without explicit tests.
140+
* Changing IM behavior without test coverage.
141+
* Introducing new external dependencies unless requested.
142+
143+
---
144+
145+
## 5. How to Run Tests and Code Generation
146+
147+
Inside
148+
149+
```
150+
de.peeeq.wurstscript/
151+
```
152+
153+
run:
154+
155+
### Run all tests
156+
157+
```
158+
./gradlew test
159+
```
160+
161+
### Run a specific test
162+
163+
```
164+
./gradlew test --tests "tests.wurstscript.tests.GenericsWithTypeclassesTests.identity"
165+
```
166+
167+
### Generate AST code via ANTLR & abstractsyntaxgen
168+
169+
```
170+
./gradlew :gen
171+
```
172+
173+
### Build the compiler
174+
175+
```
176+
./gradlew build
177+
```
178+
179+
---
180+
181+
## 6. Summary for Agents
182+
183+
* Keep changes **minimal**, **compatible**, and **tested**.
184+
* The authoritative behavior is defined by the **existing test suite**.
185+
* The compiler architecture relies on CST → AST → IM → Backend; treat each stage carefully.
186+
* Never modify generated files; modify the sources that generate them instead.
187+
* New behavior must be documented through tests.
188+
189+

0 commit comments

Comments
 (0)