Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
236 lines (140 sloc) 13.3 KB

Aroop, the C code generator designed for writing scalable server

###1. Abstract

One of the main cause of using Aroop code generator is portability while using high level language. In fact the C programming language was popular because of universality and portability. The portability in C was achieved by compiling the universal C code into different non-portable assembly language. And Aroop is one way that portable because it can generate portable C code. Also it can use the existing C libraries by mapping them into api files. Furthermore Aroop uses high level language features and object pools. It is used to develop frameworks to build scalable servers.


Programming language, Compiler, Code generator, High level language, Object oriented language

###2. Summary

Aroop is a subset of Vala programming language. The Aroop compiler is a fork of Vala compiler. And the programming languages are similar as well. Both of the compilers avoid any additional ABI. Both of them has the goal to use the existing C sources. The C programmers have to write a lot of boilerplate code to do simple things. These two compilers give the C programmers a way to write new code in Vala and still be able to integrate it with existing C libraries. The Vala project initially wanted to reduce boilerplate code needed for GObject based C programming. Thus it has GObject in it's core library. Aroop was developed as a compiler profile of Vala language. The idea behind Aroop is scalable server development. The Aroop does not use GObject, it uses Object-Pool-Plus library as replacement. It has memory pools and an optional Red-Black tree available for searching. It has object tokens which is useful to reference objects via numbers. It has string type that reduces memory copy. And it has libraries to do message passing.

###3.1. Language features(syntax)

Duck typing

It reduces the need of mentioning the variable type while declaration. The expression below declares a variable of type Mango in Java.

Mango x = new Mango();

The same thing is done below in Vala.

var x = new Mango();

Clearly it reduces the number of mention of the type.

No header files

In C and C++ it takes time to write header files duplicating much of the code prototype. But this is not needed in Aroop. The same feature is available in Java too. Defining a Class in Vala source files is all it needs for linking.

For external linking Aroop(and Vala) automatically generates prototypes of the classes. They are listed in a file called vapi files.


In some languages writing callback is either complex or needs memory allocation (for example in Java). Here it is easy to do using delegates. And it automatically captures the required variables in the scope(it is not needed to specify them explicitly as in C++). An example of such delegate is shown below.

// count variable declaration
int count = 0;
ar.visit_each((x) => {
	// the count variable is accessed from outer scope
	count = x.calc();
}, Replica_flags.ALL);

The code above generates C structures automatically to capture the local variables. It then passes them as parameter to visit_each() function.

Single lambda access operator

It does not complicate things using both -> and . operators as in C. It uses only . operator. This reduces time to refactor the code.

Nullable and non-nullable variables

It can be suggested if a variable is nullable. Non-nullable variable reduces the need to be checked for being null. It uses ? operator for nullable variables.

var? x = new Mango();

Locally scoped functions and classes

It has ways to hide the blocks of code and structures inside a package. It uses 'internal', 'private' and 'protected' access modifiers for this purpose. This helps to modify them later without worrying about how they are used outside(because they do not live outside) of the package. This helps to write black boxes.

Python like language integration.

Life is short. It is possible to write code in python and compile it with this Vala compiler. This is added by Genie.

Deferred statements

Sometimes we acquire a resource and we need to get them free. In those cases we may defer a free statement to be executed before the function or block exits. This feature is planned to be added in future.

With expression

When we operate on an object we repeatedly need to refer the fields of the objects again and again. We may reduce the retyping of the variable using a with statement. For example, we may reduce the following code.


The same thing is done using with statement below.

with object {
	do1(); do2(); do3();

###3.2. Language features(design patterns)

Plugin based programming

Plugin based programming is a way to develop the features as plugins. It has lots of advantages over the kitchen-sink approach. Aroop is used to write Shotodol, a plugin based server. The idea is to reduce coupling of class inheritance using plugin based development. This also helps to write modular code.



It has namespaces that helps to group code.

Exception handling

This reduces the code size.

###3.4. Language features(memory management)


It has magnificent string type, Xtring. It reduces memory copy. It is possible to mark the string immutable(something like const ). It can be zero terminated on demand. Xtring can be allocated in stack memory as well as in heap. It is possible to manipulate binary data(non-ASCII data) in the form of strings.

Garbage collection

It has reference counted garbage collection system. It does not handle circular reference itself. The reference counting and object structure is just before the start of the object memory, so there is less memory operations.

Memory debugging

It aims to make memory debugging easier. For example there is a memory profiler command in shotodol . It shows which module allocated memory, where and how much. It can also be debugged to see where exactly the referencing and dereferencing occurs.

Serialization and Message passing

It has high-level message passing framework as shotodol.bundle. It serializes the data into memory bags. And it can be sent as message for example to the extension methods. Otherwise it is also possible to write message in database for interprocess communication like in shotodol_db.


It has a chunk of collection data which resides close together to be accessed and handled in less memory operation(caching). It uses memory pools for that. And it uses tree searching and hashing in hash tables and non-sparse arrays. Furthermore it is possible to traverse the elements of the collection based on their flags. These features are not directly available in Vala compiler and GObject library.

###3.5. Language features(Concurrency)

Lock free queue

It is possible to send asynchronous message. There is lock free queue implementation.


It has both preemptive and non-preemptive multitasking.

CompositeFiber is a thread. It is collection of _Fiber_s. And it executes the step() method of registered _Fiber_s one by one. If step() returns nonzero then it is oust from the execution line.

SpinningWheel is a CompositeFiber that integrates the platform thread library. An application may contain only main thread which can perform CompositeFiber without the need of SpinningWheel . Otherwise if it contains multiple threads, it will need SpinningWheel to create them.

###3.6. Language features(Adaptability)

Easy to learn

It has similarity with C,C++,C# and Java. The core idea of object oriented programming and functional programming are same. And syntaxes are very similar. So if someone knows any of those functional and object oriented programming languages then it will be easier for him to learn Vala. In fact vala is very popular in open-source community.

Integrating low-level-code

It is possible to write low level code, such as C/assembly in it. It can be written as library and integrated with vapi files.


It generates code for C, so it can be ported in places where C is available. And C is available in most of the platforms.

It has object introspection developed over C

It is possible to write object-oriented code in C using it's object introspection.

Using the same language to write the compiler

Here the same language is used to write compiler. It makes available the features above for writing the compiler. This may be easier for users to change/modify it. There are plans to reorganize the code using plugin based approach.

###4. Comparison

Aroop is very similar to some object oriented projects.

  • Java and this language both are object oriented language. Both has similarities in syntax. But Java is compiled to bytecode and it needs jni to communicate with native code. On the other hand Aroop is compiled into C sources and it uses vapi to map the C code into vala. Again Aroop does not need VM for execution.
  • Scalla is similar to Aroop because Scalla is high level language and both are source to source compilers.
  • C++ is similar in syntax though they have dissimilarities. C++ needs header files which is absent here. But both of them can use native C code readily.
  • C preprocessor is similar in a sense that it produces C sources.

###5. Compiler

This compiler is a choice of development and extension over the other compilers like gcc and llvm because of the works done already. Aroop is already in use. There is another compiler concept available named Roopantor. That project is created for an ease of development and extension. It has the same philosophy of shotodol. And it is written in Aroop language. The idea behind Roopantor is flexibility. It is ongoing project and it can also be used for experimental purpose to write new language features and test them.

Extending compiler

The extension mechanism is provided by plugin. So it will be easy to add new plugin to add new feature. The Roopantor project structure is ideal for that purpose.

###6. Current status

Currently Aroop compiles shotodol and it is used to develop server applications.

###7. Conclusion

Though Aroop is initially being developed to support the development of scalable servers, it attracts the developers of other applications too.

###8.1. Other related proposals

###8.2. Readings

###8.3. Links

###8.4. Talks

###8.5. Other projects