Wednesday, February 07, 2007

type deduction for variables + back end progress

I have an idea for a new feature for variables: automatic type deduction. A new reserved keyword "auto" is used in place of the type for the variable, and the compiler will deduce the type from the type of the initializer expression. The type will always be a pointer or a reference, to avoid unneeded copies of the initializer.
procedure test(x : int, y : const int, z : * int)
var a : auto = x # var a: & int = x
var b : auto = y # var b : & const int = y
var c : auto = z # var c : * int = z
var d : auto = a + b # var d : & int = a + b
end
I am still working on the compiler back end. Progress is very slow, because I don't have much time to work on it. I got most of the LLVM libraries compiled with CMake (LLVM normally uses GNU autotools), and linked with my front end. The front end currently emits a simple hello world program as LLVM assembly code (regardless of what sourcefile you 'compile'). I did not get the LLVM tools compiled yet; for "llc" I am stuck on a link error about some symbols from libtool. I have never used libtool myself so I don't know how it's used in a program. I will have to take another look and if I can't solve it I will have to ask for some help on the CMake mailing list. I wonder why my compiler gets linked with LLVM without errors and why "llc" fails. Other work in this matter is on the front end. There is some functionality that is needed for code generation that is still missing in the front end. For example, I still need to finish constant folding, because this is required for determining the size of array types. After that I can start implementing real code generation.

2 comments:

Anonymous said...

if you are still working on cmake and llvm... check out gcc-xml - they are compiling the whole gcc compiler with cmake.... good luck!
daniel

HyperQuantum said...

I'll have a look at it.
Thanks for your suggestion.