virgil language

bearophile bearophileHUGS at lycos.com
Sun Feb 17 08:49:01 PST 2008


For a language like D that is still in development stage, it can be positive to take a look at other languages now and then. The "virgil" language is designed for embedded microcontrollers (EM), that's a very different situation from the PC (but D often looks like a superset of C, and C variants are the most used languages for EM, beside assembly, so it's not a totally different situation). EM often have few kbytes of ROM and even only few hundreds of bytes of RAM. So you have to use as little memory as possible (you cross-compile it on a PC, where you have much more resources). Despite such strong limitations, the virgil language is quite more powerful than C, it has strong typing, full OOP, delegates, it has quite advanced ways to reduce memory footprint, it's high-level enough, and it has some interesting sides. This is an interesting quotation from its docs:

http://compilers.cs.ucla.edu/virgil/overview.html
<<
Compile-time Initialization
The most significant feature of Virgil that is not in other mainstream languages is the concept of initialization time. To avoid the need for a large runtime system that dynamically manages heap memory and performs garbage collection, Virgil does not allow applications to allocate memory from the heap at runtime. Instead, the Virgil compiler allows the application to run initialization routines at compilation time, while the program is being compiled. These initialization routines allow the program to pre-allocate and initialize all data structures that it will need at runtime. This computation phase is Turing-complete, which means that the application can perform any computation, including building complex data structures such as trees and hashtables, building numerical approximation tables, allocating resource pools, and generally configuring itself.
When the application's initialization routines terminate, the live fields of the components of the program serve as the roots for computing the reachable heap of the program. Unreachable objects and arrays that are allocated during the initialization phase are discarded. The reachable heap is then compiled directly into the program binary and is immediately available to the program at runtime. The Virgil compiler also optimizes the implementation of the program against this reachable heap and removes dead code with an optimization known as reachable members analysis, which is described in more detail in the publications available.
>>

Another quotation from an article:

<<
the Virgil compiler includes an interpreter for the complete Virgil language. After typechecking is complete, the compiler executes the application’s initialization code with the built-in interpreter. The interpreter allows the application code to perform any Turing-complete computation using the complete Virgil language, including, for example, allocating objects, initializing them, calling methods on them, etc. This phase allows unrestricted allocation; a general-purpose garbage collector ensures that unreachable objects allocated by the application are discarded. When the application’s initialization routines have terminated, the compiler will generate an executable that includes not only the code of the program, but also the data of the entire reachable heap. This initial heap is immediately available to the program at runtime on the device. During execution the program can perform unrestricted computation and can read and write heap fields, but further memory allocation is disallowed and will result in an exception.
>>

Some articles about virgil language:
http://compilers.cs.ucla.edu/virgil/ref/pubs.html

Bye,
bearophile



More information about the Digitalmars-d mailing list