From db124d68c56b01e716a8dbd8f8222122990154ba Mon Sep 17 00:00:00 2001 From: alex-eg Date: Mon, 26 May 2025 22:42:01 +0300 Subject: [PATCH] initial --- Makefile | 4 ++++ Readme.org | 30 ++++++++++++++++++++++++++++++ hello-world.sex | 10 ++++++++++ sexc.scm | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 Makefile create mode 100644 Readme.org create mode 100644 hello-world.sex create mode 100644 sexc.scm diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1722901 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +CHICKEN_C = csc + +sexc: sexc.scm + $(CHICKEN_C) $< -o $@ diff --git a/Readme.org b/Readme.org new file mode 100644 index 0000000..9f0b854 --- /dev/null +++ b/Readme.org @@ -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 diff --git a/hello-world.sex b/hello-world.sex new file mode 100644 index 0000000..23cd6ad --- /dev/null +++ b/hello-world.sex @@ -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) diff --git a/sexc.scm b/sexc.scm new file mode 100644 index 0000000..16262cc --- /dev/null +++ b/sexc.scm @@ -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)