initial
This commit is contained in:
4
Makefile
Normal file
4
Makefile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
CHICKEN_C = csc
|
||||||
|
|
||||||
|
sexc: sexc.scm
|
||||||
|
$(CHICKEN_C) $< -o $@
|
||||||
30
Readme.org
Normal file
30
Readme.org
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
* The Sex language
|
||||||
|
Sex is a S-expressions language, which transpiles to C.
|
||||||
|
|
||||||
|
* Compilation and usage
|
||||||
|
Sex is written in Chicken Scheme, so first you'll need to get yourself
|
||||||
|
a Chicken.
|
||||||
|
|
||||||
|
** Compilation
|
||||||
|
~make~
|
||||||
|
|
||||||
|
** Usage
|
||||||
|
You'll also need a C compiler, so pick any.
|
||||||
|
#+begin_src
|
||||||
|
cat hello-world.sex | sexc > hello_world.c
|
||||||
|
cc hello_world.c -o hello_world
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
* Features
|
||||||
|
** Full C interoperability
|
||||||
|
Just ~(include "Your/Favourite/Library.h")~ and use it as you would
|
||||||
|
have is C. For hardcore fans of traditional Lisp naming convention,
|
||||||
|
Sex offers automatic unkebabification of all symbols, i.e. no more
|
||||||
|
ugly ~GL_ARRAY_BUFFER~'s in your code, they may be writted in their
|
||||||
|
proper form: ~GL-ARRAY-BUFFER~.
|
||||||
|
|
||||||
|
** Use an established environment for development
|
||||||
|
As Sex is S-expressions, you always have Emacs with paredit as your
|
||||||
|
best option.
|
||||||
|
|
||||||
|
** COMING SOON: Polymorhpism
|
||||||
10
hello-world.sex
Normal file
10
hello-world.sex
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
(include stdio.h)
|
||||||
|
(include unistd.h)
|
||||||
|
|
||||||
|
(fn int main ((int argc) (char **argv))
|
||||||
|
(puts "Hello from Sex!")
|
||||||
|
(var (array char 513) name)
|
||||||
|
(puts "What is your name?")
|
||||||
|
(scanf "%s" &name)
|
||||||
|
(printf "Hello, %s!\n" name)
|
||||||
|
0)
|
||||||
33
sexc.scm
Normal file
33
sexc.scm
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
(import brev-separate fmt fmt-c tree (chicken string))
|
||||||
|
|
||||||
|
(define (unkebabify sym)
|
||||||
|
(string->symbol
|
||||||
|
(string-translate (symbol->string sym) #\- #\_)))
|
||||||
|
|
||||||
|
(define (loop)
|
||||||
|
(let ((r (read)))
|
||||||
|
(unless (eof-object? r)
|
||||||
|
(cond ((eqv? (car r) 'define) (eval r))
|
||||||
|
(#t
|
||||||
|
(fmt #t
|
||||||
|
(c-expr
|
||||||
|
(tree-map
|
||||||
|
(fn
|
||||||
|
(case x
|
||||||
|
((fn) '%fun)
|
||||||
|
((var) '%var)
|
||||||
|
((begin) '%begin)
|
||||||
|
((pointer) '%pointer)
|
||||||
|
((array) '%array)
|
||||||
|
(([]) 'vector-ref)
|
||||||
|
((include) '%include)
|
||||||
|
((cast) '%cast)
|
||||||
|
(else
|
||||||
|
(if (symbol? x)
|
||||||
|
(unkebabify x)
|
||||||
|
x))))
|
||||||
|
r)))
|
||||||
|
(fmt #t "\n")))
|
||||||
|
(loop))))
|
||||||
|
|
||||||
|
(loop)
|
||||||
Reference in New Issue
Block a user