#Notes for libCello
This is a haphazard doc about things to know before diving into the code, compilation on windows and some c and c-preprocessor stuff.
Type system: http://libcello.org/documentation/hacking
Reading order for the code:
Prelude.h
, Type.h
, Type.c
, Number.h
, Number.c
, etc
Bellow are a list of C / Preprocessor language features used by libCello, things you have to knwo to understand the code.
###Struct initializers
typedef struct MY_TYPE {
boolean flag;
short int value;
double stuff;
} MY_TYPE;
...
void somefunc(void) {
MY_TYPE a;
a = (MY_TYPE) { .flag = true, .value = 123, .stuff = 0.456 };
a = (MY_TYPE) { .value = 234, .stuff = 1.234, .flag = false };
a = (MY_TYPE) { true, 123, 0.456 };
a = (MY_TYPE) { false, 234, 1.234 };
}
more info:
- http://stackoverflow.com/questions/330793/how-to-initialize-a-struct-in-ansi-c
- http://en.wikipedia.org/wiki/Struct_(C_programming_language)
This way you can test preprocessing according to the C99 standard.
gcc -std=c99 -E test.c > test.pre
test.pre will be the preprocessor output.
// single hash turns the token into a string
#define test(X) #X
// test(alpha) ----> "alpha"
more info:
// double hash, concatenates tokens
#define instance(T,C) local C T##C
// instance(Int, New) = { sizeof(IntData), Int_New, Int_Delete };
// ^----------------^ this is the part where the macro gets expanded
// ----> local New NewInt = { sizeof(IntData), Int_New, Int_Delete };
more info:
#define lit(T, ...) (T##Data[]){{T, __VA_ARGS__}}
// lit(Int, 5) --> (IntData[]) {{Int, 5}}
The parameters coming where the "..." is will be placed at __VA_ARGS__
more info:
without make
Prerequesites:
- You will need MingW.
- Make sure gcc is in the path.
Run this .bat file from the root of the libcello repository.
REM libcello how to on windows
REM This is a .bat file you can run it from the base directory of libcello
REM Dependency: mingw32, gcc on the path
mkdir release
mkdir release\Cello
copy include\Cello.h release\
copy include\*.h release\Cello
del release\Cello\Cello.h
cd src
gcc -c -std=c99 *.c -iquote ..\include
ar rcs libcello.a *.o
del *.o
move libcello.a ..\release
cd ..
After this you will find the following files in your release directory:
Cello.h Header file
Cello Directory with all the headers
libcello.a Lib which you will have to pass to gcc when compiling
Now you can write your own file main.c
and compile it using
gcc -std=c99 main.c libcello.a -o main.exe