• Stars
    star
    247
  • Rank 164,117 (Top 4 %)
  • Language
    C
  • License
    The Unlicense
  • Created over 10 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Anonymous functions in C

Synposis

LambdaPP is a preprocessor for giving you anonymous functions in C.

Examples

// for an example the table consists of a string keyed (room) of occupants
// stored in a linked list.
hashtable_t *table;
hashtable_foreach(table,
    lambda void(list_t *list) {
        list_foreach(list,
            lambda void(const char *occupant) {
                printf(">> %s\n", occupant);
            }
        );
    }
);

Closures are not supported by this system. It's important to note these are not nested functions or blocks, for information on these please see the following links.

Nested functions

Blocks

This is a source translation that produces global functions and replaces instances of the lambda with the literal.

How it works

Given a lambda, a static function is created. The scope which implements the lambda is replaced with a reference to the static function by taking it's address.

Example

(lambda void(void) { printf("Hello world"); })();

Would be translated to

static void lambda_0(void);
(&lambda_0)();
static void lambda_0(void) { printf("Hello world"); }

To better see how it works, here's the original example expanded:

hashtable_t *table;
static void lambda_0(list_t *list);
hashtable_foreach(table, &lambda_0);
static void lambda_1(const char *occupant);
static void lambda_0(list_t *list) {
    list_foreach(list, &lambda_1);
}
static void lambda_1(const char *occupant) {
    printf(">> %s\n", occupant);
}

Diagnostics

LambdaPP inserts #file and #line directives into the source code such that compiler diagnostics will still work.

More Repositories

1

incbin

Include binary files in C/C++
C
946
star
2

moreram

Get more system memory
C
804
star
3

breaking_the_physical_limits_of_fonts

Breaking the physical limits of fonts
JavaScript
319
star
4

glsl-parser

A GLSL parser
C++
251
star
5

gmqcc

An Improved Quake C Compiler
C++
159
star
6

normals_revisited

revisiting a known normal transformation in computer graphics
149
star
7

codin

Odin to C compiler
C
141
star
8

fpinspect

Inspect floating point computations
C
135
star
9

cvec

No bullshit vector library for C
C
78
star
10

neothyne

Engine and game
C++
77
star
11

libintrusive

Intrusive data structures for C
C
55
star
12

NVFC

OpenSource tool for monitoring, configuring and overclocking NVIDIA GPUs
C
44
star
13

scope_stack_alloc

A scoped stack allocator
C++
36
star
14

deshade

dump and replace shaders of any OpenGL or Vulkan application
C++
29
star
15

gml

Dynamically typed, higher-order, semi-functional, interpreted and embeddable programming language
C
28
star
16

0xABAD1DEA

Static global objects with constructors and destructors made useful in C++
C++
27
star
17

fibers

The fiber sourcebook
HTML
21
star
18

smbf

Static model binary format
C++
19
star
19

gmrtdxt

Realtime DXT compressor and optimizer
C++
19
star
20

fpot

Fast Point Overlap Test
C
17
star
21

dep_sort

Generic topological sorting for sorting a list of dependencies in C++17
C++
13
star
22

wfstd

Standard library I developed while working for Wayforward
C
11
star
23

vector_benchmark

Benchmarking a trivial replacement for std::vector
C++
11
star
24

alice

A barebones kernel for i386
C
10
star
25

bbgl

OpenGL Rendering as a seperate process (Black Box)
C
10
star
26

redroid

The ultimate IRC bot
C
9
star
27

lua-vec

highly efficent, caching, copy-on-write lua vector math library
Lua
7
star
28

printer-display

Use your printer as a display
C
7
star
29

odin_review

A review of the Odin programming language
HTML
6
star
30

pastes

Just a place where I store my pastes
C
6
star
31

discord-rogue

A tiny rogue like for Discord on nodejs
JavaScript
6
star
32

pds2tc

Public domain S2TC implementation
C
5
star
33

aau

Almost Always Unsigned
HTML
5
star
34

Kaizen

a small, embeddable continous integration framework for small projects
C
4
star
35

libpartial

Partially applied functions for C
C
4
star
36

xcpumemperf

Benchmark to determine cross CPU memory performance for UNIX/POSIX systems
C
3
star
37

zbar-lite

Stripped down light weight version of the zbar library
C
3
star
38

aoc

advent of code 2018 solutions https://adventofcode.com/
C++
3
star
39

glsl-compiler

GLSL compiler targeting a simple SSA IR
3
star
40

smm_video_scraper

Scrape level codes from SMM videos
Python
3
star
41

nra

patch games for nes mini and snes mini to use retroarch cores automatically
C
2
star
42

windows_explicide_runtime_imports

Explicit runtime imports for Windows
C
1
star
43

CV

CV, resume of @graphitemaster
1
star