Skip to content

Commit 9f679ce

Browse files
committed
docs: update code examples and reference documentation for clarity and new features
Revise the code examples section to reflect changes in memory management and unsafe operations, including new examples for type aliases and destructors. Update the reference documentation to include type aliases in the design principles and lexical structure sections, enhancing clarity and usability. Remove the obsolete primitive types documentation and adjust related references accordingly.
1 parent 711a7ee commit 9f679ce

File tree

9 files changed

+780
-66
lines changed

9 files changed

+780
-66
lines changed

docs/reference/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ This page contains the Ovum language reference.
1919

2020
## Type system
2121

22-
* [Primitive types](./primitive_types.md)
2322
* [Object model](./object_model.md)
2423
* [Nullable types](./nullable.md)
2524

docs/reference/code_examples.md

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fun DemoControlFlow(): Void {
182182
}
183183
```
184184

185-
## 9) Memory Management and Unsafe Operations
185+
## 9) Unsafe Operations
186186

187187
```ovum
188188
fun DemoUnsafeOperations(): Void {
@@ -209,7 +209,74 @@ fun DemoUnsafeOperations(): Void {
209209
}
210210
```
211211

212-
## 10) Complete Program Example
212+
## 10) Type Aliases
213+
214+
```ovum
215+
// Define type aliases for better readability
216+
typealias UserId = Int
217+
typealias UserName = String
218+
typealias UserList = ObjectArray
219+
220+
class User {
221+
public val Id: UserId
222+
public val Name: UserName
223+
224+
public fun User(id: UserId, name: UserName): User {
225+
this.Id = id
226+
this.Name = name
227+
return this
228+
}
229+
}
230+
231+
fun ProcessUsers(users: UserList): Void {
232+
for (i in 0..users.Length()) {
233+
val user: User = (users[i] as User)!!
234+
sys::Print("User " + user.Id.ToString() + ": " + user.Name)
235+
}
236+
}
237+
```
238+
239+
240+
## 11) Memory Management and Destructors
241+
242+
```ovum
243+
class DatabaseConnection {
244+
private val ConnectionId: Int
245+
private val IsConnected: Bool
246+
247+
public fun DatabaseConnection(id: Int): DatabaseConnection {
248+
this.ConnectionId = id
249+
this.IsConnected = true
250+
// Establish database connection
251+
return this
252+
}
253+
254+
public fun Query(sql: String): String {
255+
if (!IsConnected) return "Not connected"
256+
// Execute query
257+
return "Query result"
258+
}
259+
260+
// Destructor called automatically by GC
261+
public destructor(): Void {
262+
if (IsConnected) {
263+
// Close database connection
264+
sys::Print("Closing connection " + ConnectionId.ToString())
265+
}
266+
}
267+
}
268+
269+
fun DemoMemoryManagement(): Void {
270+
val db: DatabaseConnection = DatabaseConnection(1)
271+
val result: String = db.Query("SELECT * FROM users")
272+
sys::Print("Query result: " + result)
273+
274+
// db will be garbage collected automatically
275+
// destructor will be called by GC
276+
}
277+
```
278+
279+
## 12) Complete Program Example
213280

214281
```ovum
215282
// Complete Ovum program demonstrating key features
@@ -254,4 +321,4 @@ fun Main(args: StringArray): Int {
254321
255322
return 0
256323
}
257-
```
324+
```

docs/reference/design.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Ovum's core design principles center around:
2828
* **Access modifiers are mandatory** for all fields and methods in classes (`public`/`private`).
2929
* **Fields use `val` (immutable) or `var` (mutable)**.
3030
* **Namespaces** with `::` resolution (e.g., `sys::Print`).
31+
* **Functional objects** (`call` member) for functional programming.
32+
* **Type aliases** (`typealias` keyword) for better readability.
3133
* **Built-in operators**; **no user-defined operators**.
3234
* **Preprocessor**: `#import`, `#define`, `#ifdef`, `#ifndef`, `#else`, `#undef`.
3335
* **Managed runtime**: VM with **JIT** and **GC**; **no manual memory management**.

docs/reference/lexical_structure.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Names for variables, functions, classes, etc., consist of letters, digits, and u
1010

1111
## Keywords
1212

13-
Ovum reserves certain words like `fun`, `class`, `interface`, `var`, `override`, `pure`, `if`, `else`, `for`, `while`, `return`, `unsafe`, `val`, `static`, `public`, `private`, `implements`, `as`, `is`, `null`, `true`, `false`, etc. These cannot be used as identifiers.
13+
Ovum reserves certain words like `fun`, `class`, `interface`, `var`, `override`, `pure`, `if`, `else`, `for`, `while`, `return`, `unsafe`, `val`, `static`, `public`, `private`, `implements`, `as`, `is`, `null`, `true`, `false`, `typealias`, `destructor`, `call`, etc. These cannot be used as identifiers.
1414

1515
## Literals
1616

@@ -54,7 +54,7 @@ Conditional ::= "#ifdef" Identifier { GlobalDef | Import | Conditional }
5454
| "#ifndef" Identifier { GlobalDef | Import | Conditional }
5555
[ "#else" { GlobalDef | Import | Conditional } ] "#endif" ;
5656
57-
GlobalDef ::= FunctionDecl | ClassDecl | InterfaceDecl | GlobalVarDecl ;
57+
GlobalDef ::= FunctionDecl | ClassDecl | InterfaceDecl | GlobalVarDecl | TypeAliasDecl ;
5858
5959
FunctionDecl ::= [ "pure" ] "fun" Identifier "(" [ ParamList ] ")" [ ":" Type ] Block ;
6060
ParamList ::= Parameter { "," Parameter } ;
@@ -83,6 +83,8 @@ InterfaceCall ::= "call" "(" [ ParamList ] ")" [ ":" Type ] ";" ; // public &
8383
8484
GlobalVarDecl ::= [ "var" ] Identifier ":" Type "=" Expression ";" ;
8585
86+
TypeAliasDecl ::= "typealias" Identifier "=" Type ";" ;
87+
8688
Type ::= NullableType | NonNullType ;
8789
NullableType ::= NonNullType "?" ;
8890
NonNullType ::= PrimitiveType

0 commit comments

Comments
 (0)