EDDI Compiler 1.1.3 - Templates

I finished the version 1.1.3 of the EDDI Compiler (eddic).

The main improvement to the language is the support of templates. The syntax is more or less the same as the syntax of C++ templates, but the features are much more limited. In EDDI, you can declare class templates and function templates. Class templates can also includes member function templates.

Here is an example of the use of templates in EDDI:

template<type T>
struct node {
    T value;

    this(T init){
        print("C1|");
        this.value = init;
    }

    T get_value(){
        return this.value;
    }

    template<type U>
    void print_value(U v){
        print(v);
        print("|");
    }
}

template<type T>
void debug(T t){
    print(t);
    print("|");
}

template<type T>
void test(node<T>* node){
    debug<T>(node.value);
    debug<T>(node.get_value());
}

void main(){
    node<int> first_node(100);
    node<float> second_node(13.3);

    test<int>(first_node);
    test<float>(second_node);

    first_node.print_value<float>(1.0);
    second_node.print_value<int>(10);
}

This new feature adds generic programming capabilities to the language.

This version also adds other language improvements. The first one is the support of the ! operator for a bool, to test if a bool is false. This version also includes support for iterating through all the chars of a string with a foreach loop. And finally, the this pointer is now implicit to access member fields of a struct from member functions.

The optimization engine has been greatly improved. The pointers are much better handled and some regression due to new features have been fixed. The Constant Propagation optimization can take default values of struct and arrays into account. Finally, the functions with char parameters can now be inlined.

Finally, the compiler use a new logging system, that can be completely removed at compile-time for release versions.

Future Work

The next version of the EDDI compiler (eddic) will be the version 1.1.4. This version will add support for some basic pointer manipulation. It will also add support for dynamically allocated arrays. Finally, the version will includes several new optimization techniques regarding to loops: Loop Invariant Code Motion, Loop Strength Reduction and perhaps some basic Loop Unrolling.

Download

You can find the EDDI Compiler sources on the Github repository: https://github.com/wichtounet/eddic

The exact version I refer to is the v1.1.3 available in the GitHub tags or directly as the release branch.

Related articles

  • EDDI Compiler 1.1.0 - Member functions
  • EDDI Compiler 1.1.2 – Read command line
  • EDDI Compiler 1.0.1 - Pointers and better struct support
  • EDDI Compiler 0.6.0 : Arrays
  • EDDI Compiler 1.1.4 – Graph Coloring Register Allocation
  • EDDI Compiler 1.0.2 – Better pointer support and Dead-Code Elimination
  • Comments

    Comments powered by Disqus