Skip to content

Commit 8605482

Browse files
Testclaude
andcommitted
feat(lang): implement record field access with dot notation (Task #24)
Added complete support for record/struct field access and record literals: Parser changes: - Added parse_record_literal() for TypeName { field: value } syntax - Added Dot token to Call precedence level - Modified parse_infix() to handle field access (record.field) - Modified parse_prefix() to detect record literals TypeChecker changes: - Changed TypeInfo::Record from HashMap to String (nominal typing) - Added type_defs field to track struct definitions - Added type_from_ast() to convert AST types to TypeInfo - Implemented field access type inference with struct field lookup - Implemented record literal type checking with field validation Interpreter changes: - Added FieldAccess evaluation (looks up field in Record value) - Added RecordLiteral evaluation (builds HashMap from field expressions) Linter changes: - Added linter cases for FieldAccess and RecordLiteral Other: - Updated .tool-versions (rust nightly for better tooling) - Added examples/28_record_fields.woke and examples/29_simple_record.woke - Created STATE.scm with comprehensive project state tracking - Added SPDX headers to all source files (PMPL-1.0-or-later) All examples build and run successfully. Type checking ensures field access safety and record literal correctness at compile time. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 61a6254 commit 8605482

34 files changed

Lines changed: 1103 additions & 479 deletions

benches/vm_bench.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
12
//! WokeLang VM Performance Benchmarks
23
//!
34
//! Benchmarks comparing interpreter vs VM execution.
45
56
use std::time::Instant;
7+
use wokelang::vm::{compile, run_vm};
68
use wokelang::{Interpreter, Lexer, Parser};
7-
use wokelang::vm::{run_vm, compile};
89

910
fn bench_interpreter(source: &str, iterations: u32) -> std::time::Duration {
1011
let start = Instant::now();

examples/28_record_fields.woke

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// Example demonstrating record field access with dot notation
3+
4+
#verbose on;
5+
6+
// Define a Person struct
7+
type Person = {
8+
name: String,
9+
age: Int
10+
};
11+
12+
to main() {
13+
// Create a person using record literal syntax
14+
remember person = Person {
15+
name: "Alice",
16+
age: 30
17+
};
18+
19+
// Access fields using dot notation
20+
print("Name:");
21+
print(person.name);
22+
23+
print("Age:");
24+
remember personAge = person.age;
25+
print(toString(personAge));
26+
27+
give back 0;
28+
}

examples/29_simple_record.woke

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// Simple record test
3+
4+
#verbose on;
5+
6+
type Point = {
7+
x: Int,
8+
y: Int
9+
};
10+
11+
to main() {
12+
remember p = Point {
13+
x: 10,
14+
y: 20
15+
};
16+
17+
print(toString(p.x));
18+
print(toString(p.y));
19+
20+
give back 0;
21+
}

src/ast/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
12
use std::ops::Range;
23

34
/// Source span for error reporting
@@ -284,6 +285,10 @@ pub enum Expr {
284285
Unwrap(Box<Spanned<Expr>>),
285286
/// Lambda/closure: `|x, y| -> expr` or `|x, y| { ... }`
286287
Lambda(LambdaExpr),
288+
/// Field access: `record.field`
289+
FieldAccess(Box<Spanned<Expr>>, String),
290+
/// Record literal: `Person { name: "Alice", age: 30 }`
291+
RecordLiteral(String, Vec<(String, Spanned<Expr>)>),
287292
}
288293

289294
/// Binary operators

src/codegen/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
12
mod wasm;
23

34
pub use wasm::WasmCompiler;

src/ffi/c_api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
12
//! C-compatible API for WokeLang
23
//!
34
//! This module provides extern "C" functions that can be called from Zig, C,

src/ffi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
12
//! Foreign Function Interface for WokeLang
23
//!
34
//! This module provides a C-compatible API that can be used from Zig, C, or any

0 commit comments

Comments
 (0)