EDDI Compiler 1.1.0 - Member functions

The version 1.1.0 of the EDDI Compiler (eddic) is available. It took much less time to implement that version than I thought.

The main change to the language is the support of member functions. Each structure can now declare some functions. Functions can be called in each structure object. Here is an example of what can be done with that feature in EDDI:

struct Counter {
    int value;

    void increment(){
        this.value = this.value + 1;
    }

    void add(int number){
        this.value = this.value + number;
    }

    void add(int n1, int n2){
        this.value = this.value + n1;
        this.value = this.value + n2;
    }
}

void main(){
    Counter counter;
    counter.increment();
    println(counter.value);

    counter.add(99);
    println(counter.value);

    counter.add(11, 69);
    println(counter.value);
}

The this pointer is available in each member function. The pointer is passed on the stack just like any other parameter.

Another improvement is the support of the ternary operator:

void main(){
    int a = 5 > 2 ? 44 : 66;
    println(a);
}

The inliner has been improved to support inlining member functions and functions with pointer parameters. The parameter allocation in register is only done starting at O1.

The peephole optimizer has also been improved. Some stacks operations optimization are performed and some unnecessary copies of parameter register are removed.

Finally, the assembly generation has been improved to not use stack frames starting at O2. When this optimization is enabled, the local variables are addressed using stack pointers instead of the base pointer that is not used anymore. This optimization reduces the overhead of function calls.

Future work

The next version of the EDDI Compiler will be the version 1.1.1.

Download

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

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

Related articles

  • EDDI Compiler 1.0.3 - Inlining and register allocation
  • EDDI Compiler 1.1.3 - Templates
  • EDDI Compiler 1.0.2 – Better pointer support and Dead-Code Elimination
  • EDDI Compiler 1.0.1 - Pointers and better struct support
  • eddic 1.2.0 - Single inheritance, copy construction
  • EDDI Compiler 1.0 - Structures and Global Optimizations
  • Comments

    Comments powered by Disqus