EDDI 0.3 - Branches and conditions if, else if, else

I just pushed a new version of EDDI on the Git repository : EDDI 0.3

This new version adds a new big features : Branches and condition. You can now use else / else if / else statements in EDDI code. So that a code like that will be executed :

if(3 > 2){
    Print("That's true. ");
}

if(2 < 1){
    Print("Try again");
} else {
    Print("Good job");
}

if(2 > 3){
    Print("Not correct...");
} else if(6 > 3){ 
    Print("Right");
}

and will give an output like this one :

That's true. 
Good job
Right

Now, there is no optimization made on the branches or the condition. I'm planning to make optimization when the condition doesn't depend on a variable so that I can automatically chose the good branch to execute.

To implement that branches, I use a common system with jumps and labels. The labels are special bytecode instructions read by the virtual machine and indicating the address of the next instruction. The condition are putting a 1 or a 0 on the stack and the JUMP_IF_NOT bytecode jump if there is a zero on the stack.

For the next feature of the language, I plan to add a for loop. But I'm currently thinking of stopping the development of the virtual machine and output directly assembly code instead of bytecode. Because I want to concentrate on the compiler and I don't care about portability in this particular case. Moreover, this will force me to learn deeply assembly code and enable me to make more optimization. But nothing is sure at this moment.

The sources are available on Github :

  • The compiler, eddic : https://github.com/wichtounet/eddic/
  • The virtual machine, eddivm : https://github.com/wichtounet/eddivm/
  • A commons library used by the two projects : https://github.com/wichtounet/eddi-commons/

If you want to see the exact version reffered to in this subject, you can select the tag v0.3

Related articles

  • EDDI : A new programming language project
  • EDDI 0.1.1 : Variables
  • EDDI 0.2.1 : Integer operations and optimizations
  • EDDI 0.2 : Integers and variables
  • EDDI Compiler 1.1.3 - Templates
  • EDDI 0.4 : Native compilation and swap operator
  • Comments

    Comments powered by Disqus