The source code for the V programming language is open

translated into the category of open compiler for language V. V is a statically typed compiled-to-machine language focused on simplifying development maintenance and providing very high compilation speeds. Compiler code, libraries and related tools open under the MIT license.

The V syntax is very similar to the Go language, borrowing some constructs from Oberon, Rust, and Swift. The language is simplified as much as possible and, according to the developer, 30 minutes is enough to study the basics documentation. At the same time, the language remains quite powerful and can be used to perform the same tasks as when using other programming languages ​​(for example, libraries are available for 2D / 3D graphics, creating GUI and web applications).

The desire to create a new language was prompted by the desire to combine Go's inherent simplicity of syntax, compilation speed, ease of parallelization of operations, portability and code maintainability with C / C ++ performance, Rust security and generation of machine code at the Zig compilation stage. I also wanted to get a compact and fast compiler that can work without external dependencies, get rid of the global scope (global variables) and provide the ability to "hot" reload the code.

Compared to C++, the new language is significantly simpler, provides faster compilation speed (up to 400 times), practices safe programming techniques, gets rid of problems with undefined behavior, and provides built-in tools for parallelizing operations. Compared to Python, V is faster, simpler, safer, and more maintainable. Compared to Go, there are no global variables in V, there are no nulls, all variable values ​​must always be defined, all objects are immutable by default, only one type of assignment is supported ("a := 0"), a significantly more compact runtime and the size of the resulting executable files, the presence of direct portability from C, the absence of a garbage collector, faster serialization, the ability to interpolate strings ("println('$foo: $bar.baz')").

fnmain() {
areas := ['game', 'web', 'tools', 'science', 'systems', 'GUI', 'mobile'] a := 10
if true {
to := 20
}
for area in areas {
println('Hello, $area developers!')
}
}

Features of the project:

  • A compact and fast compiler that, together with the standard library, takes about 400 KB. High compilation speed is achieved through direct machine code generation and modularity. The compilation speed is approximately 1.2 million lines of code per second on one CPU core (it is noted that during the operation V can use C, then the speed drops to 100 thousand lines per second). Self-assembly of the compiler, which is also written in the V language (there is also a reference version in Go), takes about 0.4 seconds. By the end of the year, work on additional optimizations is expected to be completed, which will reduce the build time of the compiler to 0.15 seconds. According to the tests conducted by the developer, self-assembly of Go requires 512 MB of disk space and runs in a minute and a half, Rust requires 30 GB and 45 minutes, GCC - 8 GB and 50 minutes, Clang - 90 GB and 25 minutes,
    Swift - 70 GB and 90 minutes;

  • Programs are compiled into executable files without external dependencies. The size of the simple http server executable after build is only 65 KB;
  • The performance of compiled applications is at the level of assemblies of C programs;
  • Possibility of seamless interaction with C-code, without additional overhead. C functions can be called from V code and vice versa, V code can be called in any C-compatible languages;
  • Support for translating C/C++ projects into a representation in V language. Clang's parser is used for translation. Not all features of the C standard are supported yet, but the current capabilities of the compiler are already sufficient for Translation into language V of the game DOOM. The translator from C++ is still at the initial stage of development;
  • Built-in support for serialization, without being tied to runtime;
  • Minimization of memory allocation operations;
  • Security: no NULL, global variables, undefined values ​​and variable redefinition. Built-in means to check for out-of-bounds buffer. Support for generic functions (Generic). Objects and structures that are not changed by default;
  • Possibility of "hot" code reloading (reflecting changes in the code on the fly without recompilation);
  • Means for ensuring multithreading. As in Go, a construct like "run foo()" (similar to "go foo()") is used to start a new thread of execution. Support for goroutines and a thread scheduler is planned for the future;
  • Support for operating systems Windows, macOS, Linux, *BSD. By the end of the year, it is planned to add support for Android and iOS;
  • Memory management at compile time (as in Rust), without the use of a garbage collector;
  • The presence of a multi-platform toolkit for graphics output, using GDI + / Cocoa and OpenGL for rendering (planned to support DirectX, Vulkan and Metal APIs). There are tools for working with 3D objects, skeletal animation and camera control;
  • The presence of a library for the formation of graphical interfaces with design elements native to each OS. Windows uses WinAPI/GDI+, macOS uses Cocoa, and Linux uses its own set of widgets. The library is already in use during development Volt β€” client for Slack, Skype, Gmail, Twitter and Facebook;

    It is planned to create a Delphi-like application for interface design, provide a declarative API similar to SwiftUI and React Native, and provide support for creating mobile applications for iOS and Android;

    The source code for the V programming language is open

  • The presence of a built-in web-framework, which is used to create a website, forum and blog of the project developers. Precompilation of HTML templates is supported, without processing them with each request;
  • Cross compilation support. To build the executable for Windows, just run "v -os windows", and for Linux - "v -os linux" (cross-compilation support for macOS is expected later). Cross-compilation also works for graphical applications;
  • Built-in dependency manager, package manager and build toolkit. To build the program, just run "v .", without using make and external utilities. To install additional libraries, it is enough to execute, for example, "v get sqlite";
  • Availability of plug-ins for development in the V language in editors US Code ΠΈ Vim.

Development accepted community with skepticism, since the published code showed that not all the declared features have been implemented yet and a very large amount of work needs to be done to implement all the plans.
In addition, initially in the repository was placed broken code that has build and run problems. It is assumed that the author has not yet reached the stage at which one begins to notice Pareto law, according to which 20% of efforts give 80% of the result, and the remaining 80% of efforts - only 20% of the result.

In the meantime, about 10 posts have been removed from Project V's bug tracker with demonstration low code quality, for example, the use of C-inserts and the use of functions in the library to remove the directory of the rm command through the call os.system("rm -rf $path"). Project author saidthat he just deleted the messages, published troll (at the same time, changes confirming the validity of criticism, remained Π² edit history).

Source: opennet.ru

Add a comment