Examples:
LISP/c turns
(header stdio)
(main
(@printf (str "Hello, world!"))
(return 0))
into (after it being cleaned up)
#include <stdio.h>
int main(int argc,char **argv)
{
printf("Hello, world!");
return 0;
}
Macros:
(lisp/c-macro for-m (vars nums &rest body)
(if (or (null vs) (null nums))
`(block ,body nil) ;; "NIL" to get rid of extra {}s
`(for (var ,(car vars) int 0)
(< ,(car vars) ,(car ns))
(++ ,(car vars))
,(apply for-m (cdr vs) (cdr ns) body)))))
Now,
(for-m (i j k l m) (3 3 3 4 5) (@printf (s. "%d %d %d %d %d") i j k l m))
will compile to
for(int i=0;((i)<(3));++(i))
{
for(int j=0;((j)<(3));++(j))
{
for(int k=0;((k)<(3));++(k))
{
for(int l=0;((l)<(4));++(l))
{
for(int m=0;((m)<(5));++(m))
{
printf("%d %d %d %d %d",i,j,k,l,m);
};
};
};
};
}
See homepage for other examples, including C++ and CUDA.
Homepage: GitHub
License: MIT
Topics: convenience library