Close

Argentum got const objects and shared pointers

A project log for Argentum programming language

It automatically prevents all memory leaks. It doesn't use GC, so no pauses. It's compiled to machine code. It's crazy safe and fast.

andrey-kalmatskiyAndrey Kalmatskiy 04/27/2023 at 17:180 Comments

Anrgentum objects can be turned immutable with prefix freeze operator "*". 

class Point {
   x = 0;
   y = 0;
   set(x int, y int) this { this.x := x; this.y := y; }
}
p = *Point.set(10, 42);
// now point p is immutable
p.x += 1; // compilation error, `p` is *Point, and cannot be modified.

Immutable objects are shared across object hierarchies and threads.

There can be declared a methods, specifically callable to immutable objects and methods that cam be called on any objects - regardless their mutable status:

class Node {
   name = "";
   chilren = Array;
   -isLeaf() bool { children.size() == 0 } 
}
// method `isLeaf` can be called on any Node - frozen or not

Frozen pointers can reference one object from different other objects. They represent the "aggregation" relationships in terms of UML. With adding of this mechanism Argentum now supports all UML object relations:

Details are here: http://aglang.org/.....shared-pointers-to-immutable-objects

Discussions