EDDI 0.4.1 : Loops and better assembly generation

I just released the 0.4.1 version of the EDDI compiler.

This version introduce two kind of loops :

  • the while loop
  • the for loop, in its general form with three expressions

Moreover, you can now use parenth in mathematical expressions.

That's it for the new features, but the compiler has been greatly improved. Now the scope of variables is managed, so you can have twice the same variables as long as they are not visible at the same time.

For the assembly, there have been many improvements. The variables are not stored in a more efficient way, the concatenation of strings has been improved to take less space and other little changes have been made. The Lexer has been rewritten using a Scanner to manage the source file directly so that the error do now give the line and the column of the error source. The Parser and the Compiler itself have had some refactorings, but nothing really big.

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

The exact version I refer to is the v0.4.1 available in the github tags.

The next version will certainly see more loops versions, some assembly refinements and perhaps first kind of function calls. I will also try to escalate the Token information in order to have better reporting when there are semantic errors. I will also some refactorings in the parse node to have a better integration of the Condition and the StringPool.

EDDI 0.4 : Native compilation and swap operator

The version 0.4 of EDDI is released.

There is only one new feature, the swap operator () to swap two variables together, but the biggest news is that now EDDI is not anymore an interpreted language, but is a compiled language.

In fact, I rewritten the compiler in order to output Linux assembly code. For now the code is only 32 bits, but I plan to support 64 as well. I made that change in order to not having to write a virtual machine and in order to learn assembly as well. The current outputted assembly code is not really optimized and there will certainly be a lot of changes. Indeed, in order to simplify the switch to native compiler, I continued using stack operations, so that the numeric computations have a lot have a lot of stack operations in it. Moreover, I'm far from being a professional in assembly, so that, they can beginner's errors in the generated code.

I use as to compile the assembly and then gcc to link. I will try to not depend on gcc, but it seems to be difficult if I want to use malloc (used for the string concatenation).

You can download the sources and find some information on the GitHub repository : https://github.com/wichtounet/eddic/ (check the tag v0.4 if you want the exact version I refer in this post).

Do not hesitate to send me your comments about the C++ code, the design or the outputted assembly.

The first version will see loops integrated, certainly some assembly optimizations and some code refactorings I planned.

How to profile your applications using the Linux perf tools

When an application encounters some performance issues, we have to find the code that causes the problem to optimize only what really matters.

To find the code we have to optimize, the profilers are really useful. In this post, we'll use the Linux perf tools to profile a simple C++ application.

The perf tools are integrated in the Linux kernel since the 2.6 version. The perf tools are based on the perf events subsystem. The perf profiler uses hardware counters to profile the application. The result of this profiler are really precise and because it is not doing instrumentation of the code, it is really fast.

Read more…

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

Book Review : Accelerated C++

Because I started a project in C++ and had not a lot of knowledges about this language, I bought some books and just finished the first : Accelerated C++, written by Andrew Koenig and Barbara E. Moo

This book, as its name indicates, will not tell you anything about C++. It will teach you everything you need to know when starting developing applications in C++. As the authors said :

you need to know everything in this book - even tough this book doesn't tell you everything you need to know

This book is a really good book for people wanting to learn C++ quickly having knowledge in another language. It's not a good book if it's you first programming language, it will not tell you how to write a if/else statement.

This book takes a practical approach. For every notion you'll learn in the book, you practice it using some examples, improved chapter after chapter. Each chapter is also finished with a set of exercises that you can solve if you want to practice directly. In every chapter, you'll learn how to use the standard library utilities to makes coding easier, it's a really good point.

You'll start working with strings in a simple example project, then improve the project using the STL containers and algorithms. The sequential and the associative containers are studied. After using the generic functions from the STL, you'll write your own generic functions using templates. Once you got the basis, the authors teach you how to define your own types. You will then learn how to manage memory, More than defining types, you also will be able to write abstract types and use inheritance to solve problems. The authors will also show you a way to manage memory (almost) automatically using handles (smart pointers). And finally, you will revisit the first example improving it by using everything you learned so far.

To conclude, I have to say that this book is really a good one and I recommend it for every developer that want to switch from another language to C++

No more ads on the site !

Hi,

As you have perhaps noticed, there is no more Google Adsense on the site. I removed them for several reasons :

  • They were not really visually good
  • They slowed down the site by a factor of two
  • That gave a bad image of the site
  • This is not the main goal of the website to make money
  • They didn't made enough money to counter the previous disadvantages

So you will now have a faster and a bit nicer website to look at :)

The only page that contains ads on the site is the search because of the use of Google Custom Search that includes Google Ads, but this is not my ads. I will perhaps consider to add another search system in the future.

I hope this will make the site more enjoyable

P.S. Is there is still a page with ads that I have forgotten to update, just let a comment with the URL of the page and I will remove the ads

EDDI 0.2.1 : Integer operations and optimizations

I've introduced a new feature in EDDI. You can now make computations on integers and string concatenations.

So you can now write this kind of thing with EDDI :

int i = 4 + 2 * 2;
int j = i + 5 % 6 / 3 * 4;
Print(i + 2);
Print(j % i);

Adding computations has not been very difficult. The difficult thing has been to find a way to mange operators priorities. For now, I'm not really satisfied with the result, but it works. I will try to think of another way to make that in the future.

I've also introduced the first compile-time optimizations. When a computation is known to be constant a compile time, the computation is directly replaced with its result.

The next step will be to introduce branches and loops.

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.2.1

EDDI 0.2 : Integers and variables

I just pushed the last commits of Eddi 0.2.

This new version allows the use of integers. You can declare int variables and pass int values or variables to the Print operation.

I've also refactored the compiled to use a kind of parse tree and several phases. But now, I'm not really satisfied with the design. The classes are too strongly coupled and the parse tree is too specific I think, too many assumptions are made during the semantical analysis. But now, I don't know how to improve that. I also think that the design and the operations will not support some more advanced adds later, I don't know... Don't hesitate if you have any idea or comment on the design :)

I've also made some changes to the Lexer in order to improve the performances, but nothing spectacular.

You can now compile this kind of code with Eddi :

int a = 1;
string b = "asdf";
Print(1);
Print("Test");
Print(a);
Print(b);
b = "new b";
Prinb(b);

The next changes will be to add operations on int and perhaps also the concat on two stirngs. I will see. I will also try to improve the design of the compiler if I found some ideas.

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.2

How to install a specific version of GCC on Ubuntu 11.04 (natty)

Sometimes you need to install a specific version of gcc for some reasons, for example when you need to have the same compiler version as the one used by your team.

In that, the package manager doesn't help because not every version of gcc is packaged in every version of Ubuntu. So you must install it by hand and it can take a little time and there is some things that has to be done in order to work.

I'm talking here of Ubuntu 11.04 (natty), because this is the version I installed Ubuntu on. This procedure will certainly work but you could have a problem with some dependencies that are installed in natty and not in your version or in the contrary have a dependency already installed.

So this article will detail every step to install a specific version of gcc

Read more…

EDDI 0.1.1 : Variables

The version 0.1.1 of EDDI is now available.

This new version introduce the feature to put variable on the code. You can now write things like that :

a = "Variable a";
b = "Variable b";
Print(a);
Print(b);

And you can also reassign value to a variable and assign the value of a variable to another :

a = b;
b = "New variable b";

Nothing extraordinary, but it's a start. The variable name are compiled into integers and a table of variable has been made on the virtual machine.

The last step will be to introduce a new type : the integers. But for this integration, I'm not exactly sure on how to do that. I will certainly create a string pool and put only references to the strings on the stack, but it's not clearly defined. Don't hesitate if you have any comment :)

The project is 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.1.1.