This commit is contained in:
2025-05-26 22:42:01 +03:00
commit db124d68c5
4 changed files with 77 additions and 0 deletions

4
Makefile Normal file
View File

@@ -0,0 +1,4 @@
CHICKEN_C = csc
sexc: sexc.scm
$(CHICKEN_C) $< -o $@

30
Readme.org Normal file
View 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
View 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
View 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)