Skip to content

Commit fa8691c

Browse files
committed
Add AGENTS.md
1 parent 2fcdff0 commit fa8691c

2 files changed

Lines changed: 146 additions & 5 deletions

File tree

AGENTS.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# AGENTS.md
2+
3+
High-signal context for working in this repository.
4+
5+
## Build
6+
7+
```bash
8+
make # Build compiler (requires LLVM 14-21, C++17)
9+
make test # Build and run unit tests
10+
make clean # Remove obj/ directory
11+
make cleanStd # Remove cached std/*.o and std/*.ll files
12+
```
13+
14+
**LLVM version**: Auto-detects in order: 18 → 17 → 16 → 15 → default. Override with `LLVM_VERSION=18`.
15+
16+
**Variables**: `FLAGS` (default: `-O3`), `COMPILER`, `LLVM_STATIC=1` for static linking.
17+
18+
## Tests
19+
20+
Unit tests use a custom macro framework in `tests/unit/test.hpp`:
21+
```cpp
22+
TEST("name") EXPECT_TRUE(condition);
23+
TEST("name") EXPECT_EQ(a, b);
24+
TEST("name") EXPECT_NE(a, b);
25+
TEST("name") EXPECT_NOT_NULL(ptr);
26+
```
27+
28+
Test executables: `./tests/test_nodes`, `./tests/test_parser`
29+
30+
**Writing new tests**: Must define `std::string exePath = "./";` before calling parser functions.
31+
32+
## Running Rave Programs
33+
34+
```bash
35+
./rave source.rave -o output # Basic compilation
36+
./rave source.rave -o output -Ofast --recompileStd # Max performance
37+
./rave source.rave -o output.exe -t i686-win32 # Cross-compile for Windows
38+
```
39+
40+
## Key Conventions
41+
42+
- **Import syntax**: `import <std/io>` (angle brackets, not quotes)
43+
- **Prelude**: `std/prelude` and `std/memory` auto-import unless `--noPrelude`
44+
- **Stdlib cache**: Standard library compiles to `std/<module>.<platform>.o`. Use `--recompileStd` after changing optimization flags or stdlib code.
45+
- **Cross-compilation**: Set compiler in `options.json` (e.g., `"compiler": "i686-w64-mingw32-gcc-win32"`) and pass `-t <target>`.
46+
- **Return syntax**: `return` is a variable, not a keyword. Use `return = value` to set the return value. For immediate return, use `@return(value)` or `@return()` to return without changing the return value.
47+
48+
## Types
49+
50+
**Basic types**: `bool`, `char`/`uchar` (8-bit), `short`/`ushort` (16-bit), `int`/`uint` (32-bit), `long`/`ulong` (64-bit), `cent`/`ucent` (128-bit), `half` (16-bit float), `bhalf` (bfloat16), `float` (32-bit), `double` (64-bit), `real` (128-bit float), `isize`/`usize` (pointer-sized), `alias` (variables only).
51+
52+
**Pointers**: `char*`, `bool**`, etc. **Arrays**: `int[10]`, `char*[512]`. **Function pointers**: `void()`, `int(int, int)`.
53+
54+
**SIMD vectors**: `short8`, `int4`, `int8`, `float2`, `float4`, `float8`, `double2`, `double4`, `mask16`, `mask32`.
55+
56+
**Type aliases**: `type intptr = int*;`
57+
58+
## Builtins (Compile-Time)
59+
60+
**Type introspection**: `@sizeOf(type)`, `@baseType(type)`, `@typeToString(type)`, `@isNumeric(type)`, `@isStructure(type)`, `@isPointer(type)`, `@isVector(type)`, `@isArray(type)`, `@isFloat(type)`, `@isUnsigned(type)`.
61+
62+
**Value limits**: `@minOf(type)`, `@maxOf(type)`.
63+
64+
**Diagnostics**: `@error(msg)`, `@warning(msg)`, `@echo(msg)`. **String**: `@contains(str1, str2)`.
65+
66+
**Compile-time args** (functions with `(ctargs)`): `@getCurrArg(type)`, `@getArg(n, type)`, `@getCurrArgType()`, `@getArgType(n)`, `@skipArg()`, `@argsLength()`, `@foreachArgs()`.
67+
68+
**Function introspection**: `@hasMethod(type, name)`, `@hasDestructor(type)`, `@getLinkName(func)`, `@callWithArgs(func, args)`, `@callWithBeforeArgs(func, args)`.
69+
70+
**Other**: `@alloca(n)`, `@compileAndLink(files)`, `@addLibrary(name)`, `@aliasExists(name)`, `@return(value)`, `@fmodf(val, div)`, `@atomicTAS(ptr, val)`, `@atomicClear(ptr)`, `@ctlz(val, isZeroPoison)`, `@cttz(val, isZeroPoison)`.
71+
72+
## Control Flow
73+
74+
**Conditionals**: `if (cond) { } else { }`, `if likely(cond)`, `if unlikely(cond)`.
75+
76+
**Loops**: `while (cond) { }`, `for (init; cond; step) { }`, `for (;;)`, `foreach (elem; arr) { }`, `foreach (elem; data; length) { }`. Control: `break`, `continue`.
77+
78+
**Switch**: `switch (val) { case(expr) { } default { } }` - no break/continue needed.
79+
80+
**Defer**: `defer { }` (runs at block end), `fdefer { }` (runs at function return).
81+
82+
**Cast**: `cast(type)expr` (conversion), `bitcast(type)expr` (reinterpret bits).
83+
84+
## Operators
85+
86+
**Arithmetic**: `+`, `-`, `*`, `/`, `%`, `+=`, `-=`, `*=`, `/=`.
87+
88+
**Comparison**: `==`, `!=`, `<`, `>`, `<=`, `>=`, `&&`, `||`.
89+
90+
**Bitwise**: `&` (AND), `|` (OR), `!!` (XOR), `<.` (left shift), `>.` (right shift).
91+
92+
**Membership**: `in`, `!in` - check element presence in array or overloaded structure.
93+
94+
**Address-of**: `&var` - get pointer to variable/function/member.
95+
96+
## Declarations
97+
98+
**Functions**: `int sum(int a, int b) => a + b;`. Parentheses optional if no args. Overloading supported.
99+
100+
**Variables**: `int a = 0;`, `char* b = "hello";`. Function pointers: `int(int) f = func;`.
101+
102+
**Structs**: Have constructors (`Type this { }`), destructors (`void ~this { }`), methods, operator overloading (`operator=(Type* ptr, args)`).
103+
104+
**Namespaces**: `namespace Name { }`. Access via `Name::member`.
105+
106+
**Aliases**: `alias name = value;` - compile-time constant substitution.
107+
108+
## Declaration Parameters
109+
110+
`(C)` - no mangling. `(linkname: "name")` - custom linker name. `(vararg)` - variadic. `(volatile)` - external modification. `(fastcc)`/`(coldcc)` - calling conventions. `(cdecl64)` - 64-bit cdecl. `(nochecks)` - disable runtime checks. `(private)` - not importable. `(noOptimize)` - skip optimization. `(inline)` - force inlining. `(align: n)` - alignment. `(arrayable)` - array literal support. `(noOperators)` - disable operator overloading. `(data: "field")`/`(length: "field")` - foreach support. `(ctargs)` - compile-time arguments.
111+
112+
## Platform Constants
113+
114+
**Platform**: `__RAVE_PLATFORM` (X86, X86_64, ARM, AARCH64, etc.), `__RAVE_OS` (LINUX, WINDOWS, MACOS, FREEBSD).
115+
116+
**Endianness**: `__RAVE_LITTLE_ENDIAN`, `__RAVE_BIG_ENDIAN`.
117+
118+
**x86 features**: `__RAVE_SSE`, `__RAVE_SSE2`, `__RAVE_SSE3`, `__RAVE_SSSE3`, `__RAVE_SSE4_1`, `__RAVE_SSE4_2`, `__RAVE_AVX`, `__RAVE_AVX2`, `__RAVE_AVX512`, `__RAVE_FMA`, `__RAVE_POPCNT`.
119+
120+
**ARM features**: `__RAVE_ASIMD`, `__RAVE_SVE`, `__RAVE_SVE2`.
121+
122+
**Compile settings**: `__RAVE_OPTIMIZATION_LEVEL`, `__RAVE_RUNTIME_CHECKS`.
123+
124+
**Usage**: `@if (__RAVE_PLATFORM == "X86_64") { ... }`.
125+
126+
## Architecture
127+
128+
```
129+
src/
130+
├── main.cpp # CLI, arg parsing
131+
├── compiler.cpp # Orchestration, linking
132+
├── llvm.cpp # LLVM IR generation
133+
├── lexer/ # Tokenization
134+
└── parser/ # AST, type checking
135+
└── nodes/ # 47 AST node types (Node*.cpp)
136+
```
137+
138+
Pipeline: Lexer → Parser (AST + type check) → LLVM IR → Object files → Link
139+
140+
## CI
141+
142+
GitHub Actions runs `make` on push/PR to main. No additional lint/test steps in CI.
143+
144+
## References
145+
146+
- `specifications/` - Language specification documents

specifications/grammar/declarations/structures.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,4 @@ struct C {
6464
int two;
6565
(noCopy) int three;
6666
}
67-
68-
struct D : C {
69-
// is copying elements and all methods from one structure to another.
70-
// to not copy some method or variable, you can use noCopy flag
71-
}
7267
```

0 commit comments

Comments
 (0)