Skip to content

Instantly share code, notes, and snippets.

@klaufir
Created July 18, 2013 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klaufir/6031599 to your computer and use it in GitHub Desktop.
Save klaufir/6031599 to your computer and use it in GitHub Desktop.
libCello notes

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

Some reading

Type system: http://libcello.org/documentation/hacking

Reading order for the code: Prelude.h, Type.h, Type.c, Number.h, Number.c, etc

C and preprocessor

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:

Testing Macros

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.

Macro Stringification

// single hash turns the token into a string

#define test(X) #X
// test(alpha) ----> "alpha"

more info:

Macro Concacatenation

// 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:

Variadic macros

#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:

Compiling libcello on Windows

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment