Skip to content

Commit b89b9f8

Browse files
antonsyndclaude
andcommitted
docs: update README files with accurate codebase state
Fix stale/inaccurate information across 10 README files: - Root: fill in Quick Example, fix .NET version, fix broken doc links, update project structure - src/: rewrite compiler/core directory trees with actual file counts - CLI: fix net9.0→net10.0, add --incremental option, fix invalid code - CodeGen: add 3 missing partial files, complete type mapping table - Validation: add 7 missing validators with Order values - Services: add 5 missing files - Project: document 7 partial files, add incremental compilation section - TestFixtures: document .warning and .expected.cs test types - Instructions: fix TypeChecker (5→8) and RoslynEmitter (8→11) counts - Model: update incremental compilation from "future" to "implemented" Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8846c2c commit b89b9f8

File tree

10 files changed

+157
-52
lines changed

10 files changed

+157
-52
lines changed

.github/instructions/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ Lexer → Parser → Semantic → Validation → CodeGen → Tests
4343

4444
1. **Lexer** (`Lexer/`) — Add `TokenType` and recognition
4545
2. **Parser** (`Parser/Ast/`) — Add AST record, parsing rule (6 partial files)
46-
3. **Semantic** (`Semantic/`) — Add type checking in `TypeChecker*.cs` (5 partial files)
46+
3. **Semantic** (`Semantic/`) — Add type checking in `TypeChecker*.cs` (8 partial files)
4747
4. **Validation** (`Semantic/Validation/`) — Add validator if needed (pluggable pipeline)
48-
5. **CodeGen** (`CodeGen/RoslynEmitter*.cs`) — Emit via `SyntaxFactory` (8 partial files)
48+
5. **CodeGen** (`CodeGen/RoslynEmitter*.cs`) — Emit via `SyntaxFactory` (11 partial files)
4949
6. **Tests** — Unit tests per component + `.spy`/`.expected` file-based tests
5050

5151
## Key Directories

README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,24 @@ Sharpy combines Python's elegant syntax with .NET's type safety and performance.
99

1010
### Key Features
1111

12-
🐍 **Pythonic Syntax** · ⚡ **Static Typing** · 🔗 **.NET Interop** · 🎯 **Null Safety** (`?.`, `??`) · 📦 **Zero Runtime Overhead**
12+
**Pythonic Syntax** | **Static Typing** | **.NET Interop** | **Null Safety** (`?.`, `??`) | **Zero Runtime Overhead**
1313

1414
## Quick Example
1515

16-
TODO
16+
```python
17+
# hello.spy
18+
def greet(name: str) -> str:
19+
return f"Hello, {name}!"
20+
21+
def main():
22+
message = greet("World")
23+
print(message)
24+
```
25+
26+
```bash
27+
$ dotnet run --project src/Sharpy.Cli -- run hello.spy
28+
Hello, World!
29+
```
1730

1831
## Language Highlights
1932

@@ -56,7 +69,7 @@ def use_dotnet() -> None:
5669

5770
### Prerequisites
5871

59-
- .NET 9.0 or .NET 10.0 SDK ([Download](https://dotnet.microsoft.com/download))
72+
- .NET 10.0 SDK ([Download](https://dotnet.microsoft.com/download))
6073

6174
### Build & Test
6275

@@ -90,10 +103,7 @@ def main():
90103

91104
## Documentation
92105

93-
- [Language Reference](docs/specs/language_reference.md) — Complete language specification
94-
- [Type System](docs/specs/type_system.md) — Type system details
95-
- [Manual](docs/manual/) — Variables, functions, types, control flow, errors
96-
- [Feature Support](docs/status/feature_support.md) — Implementation status
106+
- [Language Specification](docs/language_specification/) — Complete language reference
97107

98108
## Design Philosophy
99109

@@ -111,13 +121,13 @@ Check our [issues](https://github.com/antonsynd/sharpy/issues) to get started.
111121
```
112122
sharpy/
113123
├── src/
114-
│ ├── Sharpy.Core/ # Standard library
124+
│ ├── Sharpy.Core/ # Standard library (runtime)
115125
│ ├── Sharpy.Compiler/ # Compiler (lexer, parser, semantic, codegen)
116-
│ ├── Sharpy.Cli/ # CLI tool
126+
│ ├── Sharpy.Cli/ # CLI tool (sharpyc)
117127
│ └── *.Tests/ # Test projects
118-
├── docs/ # Documentation
119-
├── snippets/ # Example programs
120-
└── lsp/sharpy/ # VS Code extension
128+
├── docs/language_specification/ # Language specification
129+
├── build_tools/ # Build automation and dogfooding tools
130+
└── snippets/ # Example programs
121131
```
122132

123133
## License

src/README.md

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,44 @@ Sharpy.Compiler/
1717
│ │ ├── Node.cs # Base AST node types
1818
│ │ ├── Statement.cs # Statement nodes
1919
│ │ ├── Expression.cs # Expression nodes
20-
│ │ └── Types.cs # Type annotations
21-
│ └── Parser.cs # Recursive descent parser
20+
│ │ ├── Types.cs # Type annotations
21+
│ │ ├── Pattern.cs # Pattern matching nodes
22+
│ │ └── ... # Visitors, validators, future nodes
23+
│ ├── Parser.cs # Recursive descent parser (6 partial files)
24+
│ └── Parser.*.cs # .Definitions, .Expressions, .Primaries, .Statements, .Types
2225
├── Diagnostics/ # Unified error handling
2326
│ ├── DiagnosticBag.cs # Structured diagnostic collection
2427
│ └── DiagnosticCodes.cs # SPY error code catalog
2528
├── Semantic/ # Semantic analysis
2629
│ ├── Symbol.cs # Symbol definitions
2730
│ ├── Scope.cs # Scope management
2831
│ ├── SymbolTable.cs # Symbol table
29-
│ └── BuiltinRegistry.cs # Builtin types/functions registry
30-
└── CodeGen/ # Code generation
31-
├── RoslynEmitter.cs # Generates C# using Roslyn
32-
├── NameMangler.cs # Name conversion (snake_case → PascalCase)
33-
└── CodeGenContext.cs # Code generation state
32+
│ ├── BuiltinRegistry.cs # Builtin types/functions registry
33+
│ ├── TypeChecker.cs # Type checking (8 partial files)
34+
│ ├── TypeChecker.*.cs # .Definitions, .Expressions, .Expressions.Access,
35+
│ │ # .Expressions.Literals, .Expressions.Operators,
36+
│ │ # .Statements, .Utilities
37+
│ └── Validation/ # Pluggable validation pipeline (16 validators)
38+
├── CodeGen/ # Code generation
39+
│ ├── RoslynEmitter.cs # Generates C# using Roslyn (11 partial files)
40+
│ ├── RoslynEmitter.*.cs # .Expressions, .Expressions.Access, .Expressions.Literals,
41+
│ │ # .Expressions.Operators, .Statements, .TypeDeclarations,
42+
│ │ # .ClassMembers, .CompilationUnit, .ModuleClass, .Operators
43+
│ ├── TypeMapper.cs # Maps Sharpy types to C# types
44+
│ ├── NameMangler.cs # Name conversion (snake_case → PascalCase)
45+
│ ├── CodeGenContext.cs # Code generation state
46+
│ └── CodeValidator.cs # Validates generated code compiles
47+
├── Project/ # Multi-file project compilation
48+
│ ├── ProjectCompiler.cs # Orchestrates compilation (7 partial files)
49+
│ ├── SpyProject.cs # Project file parsing
50+
│ ├── DependencyGraph.cs # Build ordering
51+
│ └── IncrementalCompilationCache.cs # Incremental compilation
52+
├── Services/ # Centralized compiler services layer
53+
├── Discovery/ # CLR type discovery
54+
├── Model/ # Core data model (CompilationUnit, ProjectModel)
55+
├── Analysis/ # Control flow graph infrastructure
56+
├── Shared/ # Constants, keyword escaping, type names
57+
└── Text/ # Source text, spans, locations
3458
```
3559

3660
### Sharpy.Core
@@ -39,15 +63,24 @@ The runtime library that compiled Sharpy code depends on.
3963
```
4064
Sharpy.Core/
4165
├── Builtins/ # Always-available types and functions
42-
│ └── Exports.cs # Global functions (print, len, etc.)
66+
│ ├── Builtins.cs # Builtin function dispatch (partial class)
67+
│ └── Exceptions.cs # Builtin exception types
4368
├── Partial.List/ # List[T] implementation (partial class pattern)
4469
├── Partial.Set/ # Set[T] implementation
45-
├── Partial.*/ # Other type implementations split by interface
70+
├── Partial.Complex/ # Complex number implementation
71+
├── Partial.Iterator/ # Iterator base implementation
72+
├── Partial.ListIterator/ # List iterator
73+
├── Partial.ListReverseIterator/ # Reverse list iterator
74+
├── Partial.SetIterator/ # Set iterator
4675
├── Collections/ # Collection interfaces
4776
├── Dict.cs # dict[K,V] implementation
4877
├── Range.cs # range() builtin
4978
├── Enumerate.cs # enumerate() builtin
50-
└── *.cs # Other builtins (Zip, Map, Filter, etc.)
79+
├── Print.cs # print() builtin
80+
├── Len.cs # len() builtin
81+
├── ISized.cs # Protocol interface for len()
82+
├── IBoolConvertible.cs # Protocol interface for bool()
83+
└── *.cs # Other builtins (Zip, Map, Filter, Sorted, etc.)
5184
```
5285

5386
## Key Design Decisions
@@ -63,7 +96,7 @@ var methods = listType.GetMethods(); // Get all Sharpy list methods
6396

6497
### 2. Roslyn Code Generation
6598
Uses Microsoft.CodeAnalysis (Roslyn) to:
66-
- Generate C# syntax trees
99+
- Generate C# syntax trees via `SyntaxFactory` (no string templating)
67100
- Emit optimized IL directly
68101
- Produce PDB debug symbols
69102
- Leverage existing .NET optimizations

src/Sharpy.Cli/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ sharpyc emit csharp <input.spy> # Generated C# code
4040
### Project Options
4141

4242
- `-c, --configuration <Debug|Release>` - Build configuration (default: Debug)
43+
- `--incremental` - Enable incremental compilation (skip unchanged files)
4344
- `--clean` - Delete bin/ and obj/ directories before building
4445
- `--emit-cs-to <dir>` - Save generated C# code to directory
4546

@@ -123,12 +124,12 @@ Create a `.spyproj` file to define your multi-file Sharpy project:
123124
```
124125
bin/
125126
Debug/
126-
net9.0/
127+
net10.0/
127128
MyApp.exe
128129
MyApp.dll
129130
MyApp.pdb
130131
Release/
131-
net9.0/
132+
net10.0/
132133
MyApp.exe
133134
MyApp.dll
134135
```
@@ -178,8 +179,8 @@ def greet(name: str) -> None:
178179
message: str = f"Hello, {name}!"
179180
print(message)
180181

181-
x = 42
182-
greet("World")
182+
def main():
183+
greet("World")
183184
```
184185

185186
Run the compiler:

src/Sharpy.Compiler.Tests/Integration/TestFixtures/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ errors/
4343
└── undefined_var.error # Contains: "undefined_var" (substring to match)
4444
```
4545

46+
### Warning Tests (compilation should succeed with expected warnings)
47+
48+
1. Create a `.spy` file with Sharpy code that produces warnings
49+
2. Create a matching `.expected` file with the expected stdout output
50+
3. Create a matching `.warning` file:
51+
- Empty `.warning` file means expect **no** warnings
52+
- Non-empty lines are expected substrings that must appear in warnings
53+
54+
Example:
55+
```
56+
warnings/
57+
├── unused_var.spy # Code that triggers a warning
58+
├── unused_var.expected # Expected stdout output
59+
└── unused_var.warning # Contains: "unused variable" (substring to match)
60+
```
61+
62+
### C# Snapshot Tests (verify generated C# output)
63+
64+
1. Create a `.spy` file and a matching `.expected.cs` file with the expected generated C#
65+
2. The expected C# is Roslyn-normalized
66+
3. To regenerate snapshots: `UPDATE_SNAPSHOTS=true dotnet test --filter "FullyQualifiedName~FileBasedIntegrationTests"`
67+
68+
Used selectively for representative fixtures to detect codegen changes that don't affect runtime output.
69+
4670
### Skipping Tests
4771

4872
To temporarily skip a test that is pending a fix:

src/Sharpy.Compiler/CodeGen/README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ This directory contains the Roslyn-based C# code generator.
44

55
## Key Files
66

7-
- `RoslynEmitter.cs` - Main emitter, orchestrates code generation
8-
- `RoslynEmitter.*.cs` - Partial classes for different AST node types:
7+
- `RoslynEmitter.cs` - Main emitter, orchestrates code generation and name resolution
8+
- `RoslynEmitter.*.cs` - Partial classes for different AST node types (11 files total):
99
- `.Expressions.cs` - Expression generation
10+
- `.Expressions.Access.cs` - Member access, indexing, slicing
11+
- `.Expressions.Literals.cs` - Literal expressions (numbers, strings, collections)
12+
- `.Expressions.Operators.cs` - Binary/unary operator expressions
1013
- `.Statements.cs` - Statement generation
1114
- `.TypeDeclarations.cs` - Class/struct/interface/enum generation
1215
- `.ClassMembers.cs` - Methods, properties, constructors
1316
- `.ModuleClass.cs` - Module class generation (named after source file)
1417
- `.CompilationUnit.cs` - Top-level compilation unit
15-
- `.Operators.cs` - Binary/unary operators
18+
- `.Operators.cs` - Operator method emission
1619
- `CodeGenContext.cs` - Shared context for emission
1720
- `TypeMapper.cs` - Maps Sharpy types to C# types
1821
- `NameMangler.cs` - Converts snake_case to PascalCase, dunder methods
@@ -136,13 +139,16 @@ Local variables still require tracking during emission for redeclaration handlin
136139

137140
`TypeMapper` handles the translation from Sharpy types to C# types:
138141

139-
- `list[T]``global::Sharpy.List<T>`
140-
- `dict[K, V]``global::Sharpy.Dict<K, V>`
141-
- `str``string`
142142
- `int``int`
143143
- `long``long`
144144
- `float``double`
145+
- `double``double`
146+
- `float32``float`
147+
- `str``string`
145148
- `bool``bool`
149+
- `list[T]``global::Sharpy.List<T>`
150+
- `dict[K, V]``global::Sharpy.Dict<K, V>`
151+
- `set[T]``global::Sharpy.Set<T>`
146152
- `None``void`
147153

148154
## Name Mangling

src/Sharpy.Compiler/Model/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ var errors = unit.Diagnostics.GetAll();
5555
2. **Thread-safety**: DiagnosticBag is thread-safe for future parallel
5656
compilation support.
5757

58-
3. **Incremental compilation ready**: Content hashing and dependency
59-
tracking support future incremental compilation.
58+
3. **Incremental compilation**: Content hashing and dependency
59+
tracking enable incremental compilation (skip unchanged files).
6060

6161
4. **LSP ready**: Token storage and source spans enable future IDE
6262
integration.

src/Sharpy.Compiler/Project/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ This directory contains components for multi-file project compilation.
44

55
## Key Files
66

7-
- `ProjectCompiler.cs` - Orchestrates multi-file compilation pipeline
7+
- `ProjectCompiler.cs` - Orchestrates multi-file compilation pipeline (7 partial files):
8+
- `.cs` (main), `.Initialization.cs`, `.Parsing.cs`, `.Phases.cs`, `.CodeGen.cs`, `.IncrementalCache.cs`, `.Utilities.cs`
89
- `SpyProject.cs` - Project configuration and file discovery
910
- `DependencyGraph.cs` - Immutable dependency graph for build ordering
1011
- `DependencyGraphBuilder.cs` - Thread-safe builder for dependency graph
12+
- `IncrementalCompilationCache.cs` - File hash and symbol caching for incremental builds
1113

1214
## ProjectCompiler
1315

@@ -68,6 +70,16 @@ Handles project file parsing and source file discovery:
6870
- Resolves package dependencies
6971
- Configures compilation options
7072

73+
## Incremental Compilation
74+
75+
Enable with `--incremental` to skip unchanged files:
76+
77+
1. **First build**: All files compiled, symbols and C# cached to `obj/{Config}/.sharpy-symbols`
78+
2. **Subsequent builds**: Files skipped if content hash matches and dependencies unchanged
79+
3. **Transitive deps**: If file A imports B and B changes, A is recompiled
80+
81+
Cache is auto-invalidated on compiler version or schema version changes.
82+
7183
## Design Notes
7284

7385
- `DependencyGraph` is immutable for thread safety

src/Sharpy.Compiler/Semantic/Validation/README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,23 @@ of semantic rules.
1616
- `SemanticContext.cs` - Shared context passed to validators
1717
- `AstTraversalContext.cs` - Tracks traversal state
1818

19-
### Validators
20-
21-
- `ModuleLevelValidator.cs` - Entry point rules, module-level type annotations
22-
- `DecoratorValidator.cs` - Decorator usage validation
23-
- `SignatureValidator.cs` - Function/method signature checks (dunders, protocols)
24-
- `DefaultParameterValidator.cs` - Default parameter constraints
25-
- `ControlFlowValidator.cs` - CFG-based control flow analysis
26-
- `AccessValidator.cs` - Member access validation
27-
- `ProtocolValidator.cs` - Protocol method validation (__len__, __iter__, etc.)
28-
- `OperatorValidator.cs` - Binary/unary operator type checking
19+
### Validators (ordered by execution priority)
20+
21+
- `ModuleLevelValidator.cs` (Order 50) - Entry point rules, module-level type annotations
22+
- `NamingConventionValidator.cs` (Order 55) - Naming convention checks
23+
- `DecoratorValidator.cs` (Order 60) - Decorator usage validation
24+
- `SignatureValidator.cs` (Order 150) - Dunder method signatures, protocol conformance
25+
- `EqualityContractValidator.cs` (Order 160) - Equality contract checks (__eq__/__hash__)
26+
- `InterfaceConflictValidator.cs` (Order 170) - Interface conflict detection
27+
- `DefaultParameterValidator.cs` (Order 250) - Default parameter constraints
28+
- `ControlFlowValidator.cs` (Order 400) - CFG-based control flow analysis
29+
- `PropertyValidator.cs` (Order 410) - Property validation
30+
- `UnusedVariableValidator.cs` (Order 420) - Unused variable warnings
31+
- `UnusedImportValidator.cs` (Order 430) - Unused import warnings
32+
- `AccessValidator.cs` (Order 450) - Private/protected member access validation
33+
- `DunderInvocationValidator.cs` (Order 460) - Direct dunder call warnings
34+
- `ProtocolValidator.cs` (Order 500) - Protocol method validation (__len__, __iter__, etc.)
35+
- `OperatorValidator.cs` (Order 500) - Unsupported operator type checking
2936

3037
## Architecture
3138

@@ -53,7 +60,7 @@ operate as a self-contained AST analysis.
5360

5461
### TypeChecker (type-inference-coupled)
5562

56-
These validations live in `TypeChecker` because they are tightly coupled to the
63+
These validations live in `TypeChecker` (8 partial files) because they are tightly coupled to the
5764
type inference walk and depend on in-progress type resolution state:
5865

5966
- **Type mismatches** — assignment/return type compatibility (SPY0220, SPY0221)

src/Sharpy.Compiler/Services/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,29 @@ The services layer provides common operations used throughout compilation:
1919

2020
## Files
2121

22+
### Core
23+
- `CompilerServices.cs` - Main service container
24+
- `CompilerServicesBuilder.cs` - Builder for constructing services
25+
- `CompilerServicesConfiguration.cs` - Immutable configuration
26+
27+
### Interfaces
2228
- `ITypeResolver.cs` - Type resolution service interface
2329
- `ISymbolLookup.cs` - Symbol lookup service interface
2430
- `IClrTypeMapper.cs` - CLR type mapping service interface
2531
- `IDiagnosticReporter.cs` - Diagnostic reporting service interface
32+
- `IDependencyQuery.cs` - Dependency graph query interface
33+
- `IImportQuery.cs` - Import resolution query interface
34+
- `ISemanticQuery.cs` - Semantic information query interface
35+
36+
### Adapters
2637
- `TypeResolverAdapter.cs` - Adapter wrapping existing TypeResolver
2738
- `SymbolLookupAdapter.cs` - Adapter wrapping existing SymbolTable
2839
- `ClrTypeMapperAdapter.cs` - Adapter for CLR type mapping
40+
- `ImportQueryAdapter.cs` - Adapter for import queries
2941
- `DiagnosticReporter.cs` - Implementation of diagnostic reporting
30-
- `CompilerServicesConfiguration.cs` - Immutable configuration
31-
- `CompilerServices.cs` - Main service container
32-
- `CompilerServicesBuilder.cs` - Builder for constructing services
42+
43+
### Utilities
44+
- `AstPositionService.cs` - AST position lookup utilities
3345

3446
## Usage
3547

0 commit comments

Comments
 (0)