A programming language idea: no static code, explicit caller context (Kite)
Marconi
soldate at gmail.com
Sat May 2 13:42:11 UTC 2026
```c
import kite.io.file;
type node {
int value;
pointer node next; // manual pointer, can be 0 (null)
}
type file_reader {
string read(string path) {
file f = owner.fs.open(path);
if (f == 0) {
// throws error, does NOT return
// control jumps to owner.on_error(...)
throw "file not found";
}
return f.read_all();
}
}
type list {
node head;
void add(int v) {
node n;
// n is created here
// if it does NOT escape this scope → stack
// if it escapes (like below) → heap via owner.on_heap()
n.value = v;
// n escapes here because it's stored in a field
// compiler promotes it to heap
// owner.on_heap(...) is called internally
n.next = head;
head = n;
}
}
type app {
pointer on_heap(int size) {
// called when an object needs to go to heap
return allocator.alloc(size);
}
void on_error(string e) {
// central error handling
console.write("error: " + e);
}
void main() {
list l;
l.add(10);
l.add(20);
node current = l.head;
// current is a reference (never null)
while (current != 0) { // pointer comparison
console.write(current.value);
current = current.next;
}
// Example of object lifetime:
node temp;
temp.value = 42;
// temp does NOT escape → stays on stack
// automatically destroyed when leaving scope
node leaked;
leaked = l.head;
// leaked references a heap object (because it escaped
earlier)
// heap objects must be freed manually
delete leaked;
// if not deleted → memory leak (by design)
}
}
```
More information about the Digitalmars-d
mailing list