Git Product home page Git Product logo

csp's Introduction

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

  • STEP 1: Implement interpreter A which supports F-function operations
  • STEP 2: Implement interpreter B on A which supports the 9 LISP primitives
  • STEP 3: Provide access to some built-in common funtions.

Application framework (not started yet)

  • Provide C code manipulating routines.
  • Framework for writing C programs in LISP. The C preprocessor serves as a translator.

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

  • Interpreter A almost done. Supports CAR CDR CONS APPEND LIST SAFE_CAR SAFE_CDR EQ ATOM QUOTE COND PAIR NULL AND NOT ASSOC EVLIS EVCON

  • Interpreter B (The main eval recursion) Supports atom quote eq car cdr cons lambda cond

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.

csp's People

Contributors

kchanqvq avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.