-
Windows Demo v0.0.0
04/07/2023 at 18:21 • 0 commentsI just released a demo that lets everyone to try the Argentum programming language on Windows.
Download link: argentum-demo.7z
It contains:
- a command line compiler,
- simple bindings to SDL,
- and a couple of examples.
Short instruction:
- download,
- extract anywhere,
- read the README.md,
- go to the workdir folder, and launch cmd.
- copy and paste these three commands to compile, link and execute the hello world application:
..\bin\agc.exe -src ..\src -start hello_world -o hw.obj ..\bin\lld-link.exe /libpath:..\libs hw.obj ..\libs\ag_runtime.lib hw.exe
Do the same for the SDL demo application:
..\bin\agc.exe -src ..\src -start demo -o demo.obj ..\bin\lld-link.exe /libpath:..\libs demo.obj ..\libs\ag_runtime.lib ..\libs\SDL2.lib ..\libs\SDL2_image.lib demo.exe
Play with `*.ag` files in `src` directory to see how the language works.
All my examples from the the ongoing posts will work with this compiler.
-
Why?
04/03/2023 at 22:28 • 0 commentsWhy do we need one more programming language?
All nowadays programming languages fall in three possible categories on controlling object lifetimes, memory management and maintaining data structures:
- Manual allocations and deallocations (C/C++...)
- Garbage collector (Go, Kotlin, Java, Python, Dart...)
- Semi-automatic ref counting (Swift, Rust, C++ with smart-pointers...)
All these three approaches have something in common. They all allow developers to create a mess out of data structures and then try to assist programmers more or less in handling that mess.
Argentum proposes the opposite approach. It allows programmers to explicitly declare ownership in cross-object references and automate all operations over data structures using these declarations. And these automatically provided operations guarantee that there are no dangling pointers, unsafe memory access or memory leaks.
Let's look at the example:
class Scene { // this field owns Array, which owns its elements. elements = Array(SceneItem); // this field just references an item, but doesn't own it. focused = &SceneItem; } class SceneItem { x = 0; y = 0; scene = &Scene; // `scene` field references its scene, but doesn't own it. } class Label { +SceneItem; // It's inheritance. text = ""; // `style` field shares ownership over an immutable `Style` instance. style = *Style; } // Create new mutable instance of Scene: root = Scene; // Create Style, fill it and freeze it (with *-operator), making it shareable: normal = *Style.font(times).size(40).weight(600); // Create new Label instance and attach it to the scene. root.elements.add( Label.at(10, 20).setText("Hello").setStyle(normal));
This code gives us a hierarchy of objects that are aware of their ownership and lifetimes.
The `Label` exists as long as it is referenced from the `root` scene. Root scene exists as long as it's referenced by the `root` variable. The `normal` Style exists as long as it's referenced by either label or `normal` variable.
We can destroy all these objects by assigning new values to the correspondent variables and array items.
scene.elements.delete(0);
We can copy any object or the whole scene
anotherScene = @scene; // @ - is a deep copy operator
And this copy will preserve all the properties of the original scene:
- Scene and all mutable subitems will be copied and connected accordingly,
- All non-owning pointers:
- that are inner to the copied hierarchy will be copied in a way to preserve the topology graph,
- pointing outside will pointing to the same objects as in the original,
- If some objects hold system resources (files, sockets, fonts...) the special handlers will be called to handle these resources,
- Argentum also maintains the correctness of `parent` pointers.
And this copy operation performed at the cost of actual objects allocation with no overheads both in space and time.
The same is true for other operations: objects removal, freezing, passing between threads. All these operations are performed automatically by `*` and `&` markers on object fields.
Thus, this language is for sure works differently than mentioned above three groups of all existing languages, that's why it needs to be implemented.