The Solod project develops a subset of the Go language that is translated into the C language.

The Solod (So) programming language is presented. It provides a subset of the Go language transcompiled into a C11 representation suitable for compilation with the GCC, Clang, and zig cc compilers. A key difference between Solod and Go and Tinygo is its use of manual memory management, which operates without a garbage collector, automatic memory allocation, or reference counting. The transpiler for Solod is written in Go and distributed under the BSD license. It runs on Linux, macOS, and Windows.

The language supports structures, methods, interfaces, slices, functions that return multiple values ​​(e.g., result + error code), generics, and deferred calls (defer). For simplicity, the language does not support channels, coroutines, or closures. Solod development can utilize existing LSP servers, linters, integrated development environments, and code editors that support the Go language, as well as the "go test" toolchain.

Code written in Solod can be integrated with C applications (C can call Solod functions and vice versa) and does not require a runtime. Key areas of application include systems programming, with capabilities similar to C, but with Go-style syntax and type checking. Solod can also be used to port Go libraries for use in C projects. Go packages such as strings, io, bytes, mem, slices, and others have been ported to C. In addition to the set of ported Go libraries, Solod programs can use bindings for the standard C library, libc.

By default, all memory is allocated on the stack, but heap allocation is possible using the Alloc / Free functions of the standard library. Garbage collection and reference counting are not used, but Solod provides features for type checking and crashes when accessing an array out of bounds. Dangling pointer returns and memory misfreeding are not checked. The use of AddressSanitizer (-fsanitize=address) in modern compilers is mentioned as the primary method for detecting memory issues.

In terms of performance, compiled programs written in Solod are generally faster than Go programs. For example, functions from the Byte package perform 1.5 times faster with identical memory consumption. Byte buffer operations are 1.3 times faster for reading and 2-4 times faster for writing. In the Map package, integer key retrieval is 3.4 times faster, but key modification is 1.6 times slower. String key retrieval is on par with Go, but modification is 1.5 times slower. Parsing and formatting integers is 2 times faster, and floating-point parsing is 1.5/1.2 times faster. String functions are 1.3 times faster, and string creation is 2-4 times faster with a 10-20% reduction in memory consumption.

Source: opennet.ru

Add a comment