Skip to content

Commit eea9320

Browse files
committed
Rename 'struct' -> 'type'
1 parent c75c31a commit eea9320

File tree

10 files changed

+69
-74
lines changed

10 files changed

+69
-74
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ the expressiveness and ease-of-use of scripting languages with Rust's key design
99
- **Rust-Inspired Design**: Familiar syntax and concepts for Rust developers
1010
- **Memory Safety**: Explicit mutability control with `let` and `mut` keywords
1111
- **Static Typing**: Type annotations with inference capabilities for safer scripts
12-
- **Structs and Methods**: Data structures with associated methods via `impl` blocks
12+
- **Types and Methods**: Data structures with associated methods via `impl` blocks
1313
- **Control Flow**: Standard control structures (`if`/`else`, `while` loops)
1414
- **Traits**: Define shared behavior across types with trait definitions
1515

@@ -18,7 +18,7 @@ the expressiveness and ease-of-use of scripting languages with Rust's key design
1818
Tea brings Rust's safety concepts to scripting:
1919

2020
- **Explicit Mutability**: Variables are immutable by default (`let`), mutable when specified (`let mut`)
21-
- **Impl Blocks**: Methods are defined separately from struct definitions using `impl` blocks
21+
- **Impl Blocks**: Methods are defined separately from type definitions using `impl` blocks
2222
- **Type Annotations**: Optional but explicit type annotations with `:` for safer scripts
2323
- **Arrow Syntax**: Function return types specified with `->`
2424
- **Traits**: Rust-style trait system for defining shared behavior
@@ -62,17 +62,17 @@ fn mut increment_counter() -> i32 {
6262
}
6363
```
6464

65-
### Structs
65+
### Types
6666

67-
Define custom data types with `struct`:
67+
Define custom data types with `type`:
6868

6969
```tea
70-
struct Point {
70+
type Point {
7171
x: f32;
7272
y: f32;
7373
}
7474
75-
struct Person {
75+
type Person {
7676
name: string;
7777
age: i32;
7878
}

examples/015_structs.tea

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
// Struct definitions and instantiation
1+
// Type definitions and instantiation
22

3-
// Simple struct with basic fields
4-
struct Point {
3+
// Simple type with basic fields
4+
type Point {
55
x: float;
66
y: float;
77
}
88

9-
// Struct with mixed data types
10-
struct Person {
9+
// Type with mixed data types
10+
type Person {
1111
name: string;
1212
age: int;
1313
height: float;
1414
is_student: int; // Using int for boolean (1 = true, 0 = false)
1515
}
1616

17-
// Struct with integer fields
18-
struct Rectangle {
17+
// Type with integer fields
18+
type Rectangle {
1919
width: int;
2020
height: int;
2121
}
2222

23-
// Empty struct (no fields)
24-
struct Empty {
23+
// Empty type (no fields)
24+
type Empty {
2525
}
2626

27-
// Struct with optional fields
28-
struct User {
27+
// Type with optional fields
28+
type User {
2929
id: int;
3030
username: string;
3131
email: string?; // Optional email
3232
score: float?; // Optional score
3333
}
3434

35-
// Creating struct instances using 'new' keyword
35+
// Creating type instances using 'new' keyword
3636
let origin = new Point { x: 0.0, y: 0.0 };
3737
let my_point = new Point { x: 3.5, y: 7.2 };
3838

39-
// Struct instantiation with all field types
39+
// Type instantiation with all field types
4040
let person1 = new Person {
4141
name: 'Alice',
4242
age: 25,
@@ -51,19 +51,19 @@ let person2 = new Person {
5151
is_student: 0
5252
};
5353

54-
// Struct instantiation with trailing comma (allowed)
54+
// Type instantiation with trailing comma (allowed)
5555
let rect1 = new Rectangle {
5656
width: 10,
5757
height: 20,
5858
};
5959

60-
// Struct instantiation in single line
60+
// Type instantiation in single line
6161
let rect2 = new Rectangle { width: 5, height: 8 };
6262

63-
// Empty struct instantiation
63+
// Empty type instantiation
6464
let empty_instance = new Empty {};
6565

66-
// Struct with optional fields
66+
// Type with optional fields
6767
let user1 = new User {
6868
id: 1,
6969
username: 'alice123',
@@ -78,16 +78,16 @@ let user2 = new User {
7878
score: null // Optional field set to null
7979
};
8080

81-
// Using struct instances in expressions and assignments
81+
// Using type instances in expressions and assignments
8282
let point_a = new Point { x: 1.0, y: 2.0 };
8383
let point_b = new Point { x: 4.0, y: 6.0 };
8484

85-
// Struct instantiation with computed values
85+
// Type instantiation with computed values
8686
let computed_x = 5.0 + 3.0;
8787
let computed_y = 2.0 * 4.0;
8888
let computed_point = new Point { x: computed_x, y: computed_y };
8989

90-
// Struct instantiation in function calls (when we get to functions with struct params)
90+
// Type instantiation in function calls (when we get to functions with type params)
9191
fn create_default_person() -> Person {
9292
return new Person {
9393
name: 'Default',
@@ -99,7 +99,7 @@ fn create_default_person() -> Person {
9999

100100
let default_person = create_default_person();
101101

102-
// Multiple instances of the same struct
102+
// Multiple instances of the same type
103103
let top_left = new Point { x: 0.0, y: 10.0 };
104104
let top_right = new Point { x: 10.0, y: 10.0 };
105105
let bottom_left = new Point { x: 0.0, y: 0.0 };

examples/016_field_access.tea

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
// Struct field access and modification using dot notation
1+
// Type field access and modification using dot notation
22

3-
// Define structs for examples
4-
struct Point {
3+
// Define types for examples
4+
type Point {
55
x: float;
66
y: float;
77
}
88

9-
struct Person {
9+
type Person {
1010
name: string;
1111
age: int;
1212
height: float;
1313
}
1414

15-
struct Counter {
15+
type Counter {
1616
value: int;
1717
max_value: int;
1818
}
1919

20-
// Create struct instances
20+
// Create type instances
2121
let mut point = new Point { x: 5.0, y: 10.0 };
2222
let mut person = new Person { name: 'Alice', age: 25, height: 170.5 };
2323
let mut counter = new Counter { value: 0, max_value: 100 };
2424

25-
// Reading struct fields using dot notation
25+
// Reading type fields using dot notation
2626
let point_x = point.x; // 5.0
2727
let point_y = point.y; // 10.0
2828
let person_name = person.name; // 'Alice'
2929
let person_age = person.age; // 25
3030
let current_count = counter.value; // 0
3131

32-
// Modifying struct fields (requires mutable struct instance)
32+
// Modifying type fields (requires mutable type instance)
3333
point.x = 15.0;
3434
point.y = 20.0;
3535

@@ -60,7 +60,7 @@ while counter.value < counter.max_value {
6060
println('counter.value = ', counter.value);
6161
}
6262

63-
// Copying field values between structs
63+
// Copying field values between types
6464
let mut point2 = new Point { x: 0.0, y: 0.0 };
6565
point2.x = point.x; // Copy x coordinate
6666
point2.y = point.y; // Copy y coordinate

examples/017_struct_methods.tea

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
// Struct methods using impl blocks
2-
// Methods are functions associated with a specific struct type
1+
// Type methods using impl blocks
2+
// Methods are functions associated with a specific type
33

4-
// Define structs
5-
struct Point {
4+
// Define types
5+
type Point {
66
x: f32;
77
y: f32;
88
}
99

10-
struct Rectangle {
10+
type Rectangle {
1111
width: f32;
1212
height: f32;
1313
}
1414

15-
struct Counter {
15+
type Counter {
1616
value: int;
1717
max_value: int;
1818
}
@@ -115,16 +115,16 @@ impl Counter {
115115
}
116116
}
117117

118-
// Using struct methods
118+
// Using type methods
119119
let mut p1 = new Point { x: 1.0, y: 2.0 };
120120
let p2 = new Point { x: 4.0, y: 6.0 };
121121

122-
// Call methods on structs
122+
// Call methods on types
123123
let distance = p1.distance_to(p2); // Calculate distance between points
124124
let x_coord = p1.get_x(); // Get x coordinate
125125
let is_origin = p1.is_at_origin(); // Check if at origin
126126

127-
// Modify struct through methods
127+
// Modify type through methods
128128
p1.move_by(2.0, 3.0); // Move point by (2, 3)
129129

130130
// Rectangle methods

src/tea_expr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ tea_val_t tea_interpret_evaluate_string(const tea_node_t *node)
112112
tea_inst_t *object = rtl_malloc(sizeof(tea_inst_t) + token->size + 1);
113113
if (!object) {
114114
rtl_log_err(
115-
"Memory error: Failed to allocate memory for struct '%s' instance at line %d, column %d",
115+
"Memory error: Failed to allocate memory for type '%s' instance at line %d, column %d",
116116
token->buf, token->line, token->col);
117117
return tea_val_undef();
118118
}

src/tea_fn.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "tea_stmt.h"
55
#include "tea_struct.h"
66

7-
87
#include <stdlib.h>
98
#include <string.h>
109

@@ -259,7 +258,7 @@ tea_val_t tea_eval_fn_call(tea_ctx_t *ctx, tea_scope_t *scp,
259258
tea_find_struct_decl(ctx, variable->val.obj->type);
260259
if (!struct_declaration) {
261260
rtl_log_err(
262-
"Runtime error: Cannot find struct declaration for type '%s' when calling method",
261+
"Runtime error: Cannot find type declaration for type '%s' when calling method",
263262
variable->val.obj->type);
264263
tea_scope_cleanup(ctx, &inner_scope);
265264
return tea_val_undef();
@@ -271,7 +270,6 @@ tea_val_t tea_eval_fn_call(tea_ctx_t *ctx, tea_scope_t *scp,
271270
function_name = field_token->buf;
272271
function = tea_ctx_find_fn(&struct_declaration->fns, function_name);
273272

274-
275273
} else {
276274
const tea_tok_t *token = node->tok;
277275
if (token) {

src/tea_stmt.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "tea_fn.h"
44
#include "tea_struct.h"
55

6-
76
#include <stdlib.h>
87

98
#include <rtl.h>
@@ -87,9 +86,8 @@ bool tea_interpret_let(tea_ctx_t *ctx, tea_scope_t *scp, const tea_node_t *node)
8786
}
8887

8988
static bool tea_check_field_mutability(const tea_scope_t *scp,
90-
const tea_node_t *field_access_node)
89+
const tea_node_t *object_node)
9190
{
92-
tea_node_t *object_node = field_access_node->field_acc.obj;
9391
if (!object_node || !object_node->tok) {
9492
rtl_log_err(
9593
"Internal error: Field access expression missing object component in AST");
@@ -175,7 +173,7 @@ bool tea_interpret_assign(tea_ctx_t *ctx, tea_scope_t *scp,
175173
}
176174

177175
if (lhs->type != TEA_N_IDENT) {
178-
if (!tea_check_field_mutability(scp, lhs)) {
176+
if (!tea_check_field_mutability(scp, lhs->field_acc.obj)) {
179177
return false;
180178
}
181179

0 commit comments

Comments
 (0)