Introduced programming language Solod (So), providing a subset of the Go language that transpiles into a representation in C (C11) suitable for building with GCC, Clang, and zig cc compilers. The key difference between Solod and Go is the use of manual memory management, operating without a garbage collector, automatic memory allocation, and reference counting. The transpiler for Solod is written in Go and is distributed is licensed under BSD. It supports operation on Linux, macOS, and Windows.
The language supports structures, methods, interfaces, slices, multiple return values from functions (for example, result + error code), generics and deferred calls (defer). For the sake of simplicity, the language does not support channels, coroutines, or closures. When developing with Solod, existing LSP servers, linters, integrated development environments, and code editors that support Go can be used, as well as the 'go test' toolchain.
Code written in Solod can integrate with applications in C (C can call functions in Solod and vice versa) and does not require attaching a runtime. Key areas of application include system programming with capabilities close to C but with Go-style syntax and type-checking support. Solod can also be used to port Go libraries for use in C projects. Ported Go packages to C include:
- strings
- io (antonz.org)
- bytes
- mem
- slices
and etc. Besides set of ported Go libraries can be used in programs written in Solod wrapper over the standard C library libc.
By default, all memory is allocated on the stack, but memory can be allocated on the heap through the functions Alloc / Free of the standard library. Garbage collection and reference counting are not used, but Solod provides capabilities for type checking and crashing upon accessing out of bounds arrays. However, checks for dangling pointer returns and unfreed memory are not performed. The primary method for identifying memory issues is the use of AddressSanitizer -fsanitize=address in modern compilers.
In terms of performance, compiled programs written in Solod generally is faster outperform Go programs:
- The performance of functions from the Byte package is 1.5 times faster with the same memory consumption;
- Working with byte buffers is 1.3 times faster for reading and 2-4 times faster for writing;
- In the Map package, selection by integer key is 3.4 times faster, but modifying keys is 1.6 times slower;
- Selection by string keys is on par with the Go language, but modification is 1.5 times slower;
- Parsing and formatting integers is 2 times faster, while floating-point numbers are 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: linux.org.ru
