Saturday, July 10, 2010

Regarding function ambiguity

Yet another ambiguity situation can be seen in PineDL. That being the function type vs. function declaration.

Consider the following (valid) expression:
function() return 0;
The above being a function that takes no arguments and returns 0.

Now, consider this in context:
var foo = function() return 0;;
Note that the double ';' is needed(the first to end the function statement, the other to end the variable declaration).

The 'function' keyword is, however, a type as well.
const mytype = function;
Being a type constant, operations can be applied to function, including calling.
const x = function();

Now, consider this piece of code:
x = function();;
What can this be?
1. Function constant calling, assigning the result to variable x, and finally an empty statement.
2. Function declaration, assigning the function to x.

But which?
Of course, some cases are obviously one of the two:
{var x = function();} //Obviously 1
var x = function(){}; //Obviously 2

But the problem is in edge cases.
There are a few solutions:
1. Demand functions to be declared with {}
2. Prefer one of the cases(problematic)
3. Demand functions to be declared with {}, but allow functions to be declared using the \foo() syntax, and allow those to have no {}. In addition, make sure \ is not a valid type constant.

I haven't decided which yet.

Saturday, July 3, 2010

Getting LLVM to work with MinGW

Today, I have tried to make LLVM to work on Windows with MinGW.
When trying to use LLVM, it is very clear that it isn't a "pure" Windows project. For instance, plain MinGW won't work. While I expected to have to install mingw32-make, I also did have to install MSYS, which I particularly hate.

After downloading the source code, there were a few problems I had to face:
1. Could not rename File exists
c:\MinGW\bin\ranlib.exe: unable to rename 'c:/Users/HP530/Downloads/llvm-2.7/llvm-2.7/llvm-2.7/Release/lib/libLLVMX86CodeGen.a'; reason: File exists
make[3]: *** [/c/Users/HP530/Downloads/llvm-2.7/llvm-2.7/llvm-2.7/Release/lib/libLLVMX86CodeGen.a] Error 1

These ones were annoying. To solve them, I first had to go to the Release/lib folder and see if the indicated file existed. If so, I had to delete it and try again. If not, just running make again would make it work.

2. Figuring out the correct order to use when compiling a sample "hello world!" project. Here is the way I used:
g++ `llvm-config --cxxflags` -o hworld.o -c hworld.cpp
g++ `llvm-config --ldflags` -o hworld.exe hworld.o `llvm-config --libs` -limagehlp -lpsapi


The -lpsapi and -limagehlp wasn't obvious, even when looking at LLVM's documentation. I happened to find those mentioned in some mailing list when googling for the problem.

3. Threading
For this one, stackoverflow helped me. Lots of undefined references to __imp__pthreads functions. To solve it, I had to run ./configure with --disable-threads

Now that I've got this out of the way, I hope I'll finally be able to learn LLVM.

References:
http://stackoverflow.com/questions/2129263/how-to-build-llvm-using-gcc-4-on-windows
http://osdir.com/ml/compilers.llvm.devel/2005-09/msg00067.html
http://llvm.org/docs/CommandGuide/html/llvm-config.html