|
1 | 1 | # Repository Guidelines |
2 | 2 |
|
3 | 3 | ## Project Structure & Module Organization |
4 | | -- Core compiler code lives in `src/main/scala/onion/compiler`; pipeline stages (`Parsing`, `Rewriting`, `Typing`, `TypedGenerating`) now report through `CompilationOutcome` and share diagnostics via `CompilationReporter`. |
5 | | -- Tooling entry points are under `src/main/scala/onion/tools` (`CompilerFrontend`, `ScriptRunner`, `Shell`); JVM interop helpers remain in `src/main/java/onion`. |
6 | | -- The bytecode backend (`AsmCodeGeneration.scala`, `AsmCodeGenerationVisitor.scala`) centralises local-slot management, including captured-variable helpers for closures, so new emitters should reuse those utilities. |
7 | | -- Resources such as localized error messages sit in `src/main/resources`; integration fixtures are in `src/test/run`. |
8 | | -- Tests use ScalaTest (`AnyFunSpec`, `Diagrams`) and live under `src/test/scala/onion/compiler` and `src/test/scala/onion/compiler/tools`. |
| 4 | +- Compiler pipeline and IR live in `src/main/scala/onion/compiler` (`Parsing` → `Rewriting` → `Typing` → `TypedGenerating`), returning `CompilationOutcome` and reporting via `CompilationReporter`. |
| 5 | +- CLI/tools are in `src/main/scala/onion/tools` (`CompilerFrontend`, `ScriptRunner`, `Shell`); Java helpers for JVM interop are in `src/main/java/onion`. |
| 6 | +- Parser grammar is JavaCC: edit `grammar/JJOnionParser.jj` (not generated sources). Generated parser code lands under `target/scala-*/src_managed/main/java/onion/compiler/parser`. |
| 7 | +- Samples are in `run/` (`*.on`), and user-facing docs are in `docs/` (MkDocs config: `mkdocs.yml`). |
| 8 | +- Tests are ScalaTest and live in `src/test/scala`; script-style fixtures live in `src/test/run`. |
9 | 9 |
|
10 | 10 | ## Build, Test, and Development Commands |
11 | | -- `sbt compile` – compile both Scala and Java sources with the Scala 3 toolchain. |
12 | | -- `sbt test` – execute the ScalaTest suite, including the new failure-handling spec for `Shell`. |
13 | | -- `sbt run` – launch `onion.tools.CompilerFrontend` with interactive flags. |
14 | | -- `sbt runScript -- <file.on> [args…]` – run scripts through `ScriptRunner`. |
15 | | -- `sbt "runMain onion.tools.CompilerFrontend -d target/run-samples run/*.on"` – compile all `run/` samples into `target/run-samples`. |
| 11 | +- `sbt compile` – build the compiler; also regenerates the JavaCC parser if `grammar/JJOnionParser.jj` is newer. |
| 12 | +- `sbt test` – run the full ScalaTest suite. |
| 13 | +- `sbt "testOnly onion.compiler.tools.FunctionTypeSpec"` – run a focused spec while iterating. |
| 14 | +- `sbt run` – run `onion.tools.CompilerFrontend` (main entrypoint). |
| 15 | +- `sbt runScript -- run/Hello.on [args…]` – compile+run a script via `ScriptRunner`. |
| 16 | +- `sbt dist` – build a distributable zip under `target/dist` (includes `bin/`, `run/`, and `onion.jar`). |
16 | 17 |
|
17 | 18 | ## Coding Style & Naming Conventions |
18 | | -- Scala sources use two-space indentation, braced blocks, and `camelCase` for methods/values, `PascalCase` for classes/objects. |
19 | | -- Prefer `given`/`using` idioms and sum types (`CompilationOutcome`) over `null`; rely on `scala.util.Using` for resource safety. |
20 | | -- Java helpers mirror functional interfaces (`Function0`…`Function10`); keep them minimal and annotate with `@FunctionalInterface` when extending. |
21 | | -- Localized strings come from `Message`/`Systems`; avoid hard-coded literals outside resource bundles. |
| 19 | +- Use 2-space indentation and the existing braced style; keep names `camelCase` (methods/vals) and `PascalCase` (types). |
| 20 | +- Prefer Scala 3 idioms (`given`/`using`, enums/ADTs) and avoid `null`; use `scala.util.Using` for resource safety. |
| 21 | +- Keep codegen changes localized to the ASM backend (`AsmCodeGeneration*.scala`) and reuse the local-slot/capture utilities there. |
| 22 | +- Lint/refactor tooling is available via sbt-scalafix: use `sbt scalafix` when rules are configured for the change. |
22 | 23 |
|
23 | 24 | ## Testing Guidelines |
24 | | -- Place new behavioural tests alongside existing specs under `src/test/scala/onion/compiler/tools`; follow the `<Feature>Spec` naming pattern. |
25 | | -- Capture failure scenarios with the structured reporter (`CompilationReporter`) and silence `System.err` within specs when asserting failures. |
26 | | -- Aim to cover both happy path (`Shell.Success`) and failure path (`Shell.Failure`) for new pipeline features. |
| 25 | +- Add/extend specs under `src/test/scala` using the existing `*Spec` naming pattern. |
| 26 | +- For end-to-end behavior, prefer running `Shell`/`ScriptRunner` against small programs in `src/test/run` or `run/`. |
| 27 | +- When changing parsing/typing/codegen, include at least one positive case and one failure case (assert via `CompilationOutcome.Failure` diagnostics). |
27 | 28 |
|
28 | 29 | ## Commit & Pull Request Guidelines |
29 | | -- Match the existing `git log` style: `<Area>: <action>` (e.g., `Typing: extract …`), one topic per commit. |
30 | | -- In the body, explain the intent and note how you verified it (e.g., `sbt test`), linking issues when relevant. |
31 | | -- Prepare PRs with a short checklist: scope summary, tests executed (`sbt test`), any follow-up tasks, and screenshots/logs only when UX changes are involved. |
| 30 | +- Follow existing commit subjects: `<Area>: <action>` (examples: `Parser: …`, `Typing: …`, `Docs: …`), one topic per commit. |
| 31 | +- Include a short “how verified” note in the commit body (e.g., `sbt test`, or the specific `testOnly` you ran). |
| 32 | +- PRs should summarize behavior changes, link issues/design notes when relevant, and mention updated docs/samples if syntax changes are involved. |
0 commit comments