Home

Awesome

C Super Preprocessing

This is the development repo of C Super Preprocessing project.

CSP is a LISP dialect completely implemented using C macro, which provides LISP compile-time meta programming ability on C preprocessors.

The code is full of hacks like logic riddles, to make it easier for users to join in the development of this project I'm writing wiki pages about the implementation details.

Here's the link.

Some of my original studies are marked. Please do not publish or transfer the articles without permission.

Welcome to join me!

(should I use plural pronoun? 23333 I hope I can use 'us' soon)

Plan

Core interpreter

Application framework (not started yet)

Usage

Include the header.

#include "csp.h"

A CSP atom should be enclosed with brackets.

(car) //This is an atom

Then a list is represented as:

((x) (y) (z))//This is a list

You can execute a LISP expression using $zeval.

//$zeval(expression,environment)
$zeval(( (atom) ((quote) (x)) ),())//Expands to (T)
$zeval(( (cons) ((quote)(a)) ((quote) ((a) (b)))),())//Expands to ((a) (a) (b))
$zeval((((lambda)((x))((cons)(x)((quote)((b)))))((quote)(w))),())//Expands to ((w)(b))
$zeval((( (lambda) ((f)) ((f) ((quote) ((b) (c)))))((quote) ( (lambda) ((x)) ((cons) ((quote)(a)) (x))))),())//Expands to ((a)(b)(c))

Note that you have to define some comparing macro for any atom you used. (car) (cdr) (cons) (cond) (eq) (atom) (lambda) (quote) (x) (y) (f) (a) (b) (c) (T) are predefined. To make your atom comparable you need to define the following macro:

#define EQmyatommyatom )EQ_T( //making (myatom) comparable
#define EQqq )EQ_T( //making (q) comparable

Just pass your file to your C compiler preprocessor to see the result. It is also possible to use the header in your C/C++ project to provide LISP meta programming ability.

$ cc -E mycsp.h

Enjoy yourself!

Current Progress

NOTE cond is not short-circuited. There may be better solution.

IT SUPPORTS LAMBDA!

Run the tests

$ cd tests
$ ./test.sh

ack command is required to run the tests.

Note

It is proved that being SAFE is very important for primitive macros being used in CSP. Since there seems to be no way to implement short-circuit condition on C preprocessor, any primitive macro should not cause error or break the bracket balance when accepting illegal list. Otherwise, it will spoil the main eval condition and cause fail of the whole process.