forked from alex-eg/sex
still mess, probably obsolete anyways
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,6 +1,6 @@
|
|||||||
CHICKEN_C = csc
|
CHICKEN_C = csc
|
||||||
|
|
||||||
MODULES = sexc sex-macros sex-modules utils fmt-c
|
MODULES = sexc sex-macros sex-modules sex-types utils fmt-c
|
||||||
OBJ = $(MODULES:%=%.o)
|
OBJ = $(MODULES:%=%.o)
|
||||||
|
|
||||||
sexc: main.o $(OBJ)
|
sexc: main.o $(OBJ)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ to export ~CHICKEN_INSTALL_REPOSITORY~ and ~CHICKEN_REPOSITORY_PATH~
|
|||||||
environment variables. Refer to the documentation for more info:
|
environment variables. Refer to the documentation for more info:
|
||||||
https://wiki.call-cc.org/man/5/Extension%20tools#changing-the-repository-location
|
https://wiki.call-cc.org/man/5/Extension%20tools#changing-the-repository-location
|
||||||
|
|
||||||
~chicken-install fmt getopt-long brev-separate test tree srfi-1 srfi-13~
|
~chicken-install fmt getopt-long brev-separate test tree srfi-1 srfi-13 srfi-69~
|
||||||
|
|
||||||
** Compilation
|
** Compilation
|
||||||
~make~
|
~make~
|
||||||
|
|||||||
8
example/begin.sex
Normal file
8
example/begin.sex
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
(pub fn void other-fn ()
|
||||||
|
(begin (while true (begin 1 2 3 4)))
|
||||||
|
(switch a
|
||||||
|
((1) (begin
|
||||||
|
(var (const char *) str "121232132")
|
||||||
|
(puts "str")))
|
||||||
|
((2) (puts "2"))
|
||||||
|
(default (puts "more"))))
|
||||||
1
example/fn-no-args.sex
Normal file
1
example/fn-no-args.sex
Normal file
@@ -0,0 +1 @@
|
|||||||
|
(pub fn void no-args-fn () ())
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
(include stdio.h)
|
(include stdio.h)
|
||||||
|
|
||||||
(pub fn int main ((int argc) (char **argv))
|
(pub fn int main ((int argc) (char **argv))
|
||||||
(puts "Hello from Sex!")
|
|
||||||
(var (array char 512) name)
|
(var (array char 512) name)
|
||||||
|
(puts "Hello from Sex!")
|
||||||
(puts "What is your name?")
|
(puts "What is your name?")
|
||||||
(scanf "%s" (cast char* &name))
|
(scanf "%s" (cast char* &name))
|
||||||
(printf "Hello, %s!\n" name)
|
(printf "Hello, %s!\n" name)
|
||||||
|
|||||||
25
example/polymorphism.sex
Normal file
25
example/polymorphism.sex
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
(include stdint.h)
|
||||||
|
|
||||||
|
(struct vec2
|
||||||
|
((uint32_t x)
|
||||||
|
(uint32_t y)))
|
||||||
|
|
||||||
|
(trait gui
|
||||||
|
(fn void update ((float dt)))
|
||||||
|
(fn void render ())
|
||||||
|
(fn vec2 get-position ())
|
||||||
|
(fn void add-child ((gui *w))))
|
||||||
|
|
||||||
|
(struct button
|
||||||
|
((vector gui) children)
|
||||||
|
((vec2 pos)))
|
||||||
|
|
||||||
|
(impl gui button
|
||||||
|
(fn void update ((float dt))
|
||||||
|
())
|
||||||
|
(fn void render ()
|
||||||
|
())
|
||||||
|
(fn vec2 get-position ()
|
||||||
|
(return self->pos))
|
||||||
|
(fn void add-child ((gui *w))
|
||||||
|
(push self->children w)))
|
||||||
@@ -35,11 +35,13 @@ All commands in `lisp-mode-shared-map' are inherited by this map.")
|
|||||||
"define"
|
"define"
|
||||||
"defmacro"
|
"defmacro"
|
||||||
"extern"
|
"extern"
|
||||||
|
"impl"
|
||||||
"import"
|
"import"
|
||||||
"include"
|
"include"
|
||||||
"fn"
|
"fn"
|
||||||
"pub"
|
"pub"
|
||||||
"struct"
|
"struct"
|
||||||
|
"trait"
|
||||||
"var"
|
"var"
|
||||||
"union")
|
"union")
|
||||||
'word)
|
'word)
|
||||||
@@ -57,6 +59,7 @@ All commands in `lisp-mode-shared-map' are inherited by this map.")
|
|||||||
"for"
|
"for"
|
||||||
"goto"
|
"goto"
|
||||||
"return"
|
"return"
|
||||||
|
"self"
|
||||||
"switch"
|
"switch"
|
||||||
"var"
|
"var"
|
||||||
"while")
|
"while")
|
||||||
@@ -81,6 +84,8 @@ All commands in `lisp-mode-shared-map' are inherited by this map.")
|
|||||||
(put 'defmacro 'lisp-indent-function 'defun)
|
(put 'defmacro 'lisp-indent-function 'defun)
|
||||||
(put 'struct 'lisp-indent-function 'defun)
|
(put 'struct 'lisp-indent-function 'defun)
|
||||||
(put 'union 'lisp-indent-function 'defun)
|
(put 'union 'lisp-indent-function 'defun)
|
||||||
|
(put 'trait 'lisp-indent-function 'defun)
|
||||||
|
(put 'impl 'lisp-indent-function 'defun)
|
||||||
(put 'var 'lisp-indent-function 0)
|
(put 'var 'lisp-indent-function 0)
|
||||||
(put 'import 'lisp-indent-function 1)
|
(put 'import 'lisp-indent-function 1)
|
||||||
|
|
||||||
|
|||||||
23
sex-types.scm
Normal file
23
sex-types.scm
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
(declare
|
||||||
|
(unit sex-types)
|
||||||
|
(uses fmt-c))
|
||||||
|
|
||||||
|
(import fmt
|
||||||
|
srfi-69)
|
||||||
|
|
||||||
|
(define +all-types+ (make-hash-table))
|
||||||
|
|
||||||
|
(define (normalize-type type)
|
||||||
|
)
|
||||||
|
|
||||||
|
(define (add-pointer type)
|
||||||
|
(list 'pointer type))
|
||||||
|
|
||||||
|
(define (add-const type)
|
||||||
|
(list 'const type))
|
||||||
|
|
||||||
|
(define (get-types-from-arglist arglist)
|
||||||
|
(list))
|
||||||
|
|
||||||
|
(define (to-c-type type)
|
||||||
|
(fmt #f (c-type type)))
|
||||||
17
sexc.scm
17
sexc.scm
@@ -180,24 +180,35 @@
|
|||||||
(eval (cons 'import (cdr form))) acc)
|
(eval (cons 'import (cdr form))) acc)
|
||||||
((import)
|
((import)
|
||||||
(append (process-raw-forms
|
(append (process-raw-forms
|
||||||
|
|
||||||
(import-modules (cdr form)) (list))
|
(import-modules (cdr form)) (list))
|
||||||
acc))
|
acc))
|
||||||
(else
|
(else
|
||||||
(walk-sex-tree form acc))))
|
(walk-sex-tree form acc))))
|
||||||
|
|
||||||
(define (process-raw-forms raw-forms acc)
|
(define (process-raw-forms raw-forms acc)
|
||||||
|
"First processing pass"
|
||||||
(if (null? raw-forms)
|
(if (null? raw-forms)
|
||||||
(reverse acc)
|
(reverse acc)
|
||||||
(process-raw-forms (cdr raw-forms)
|
(process-raw-forms (cdr raw-forms)
|
||||||
(process-form (car raw-forms) acc))))
|
(process-form (car raw-forms) acc))))
|
||||||
|
|
||||||
|
;;; Second pass
|
||||||
|
|
||||||
|
(define (process-sex-forms forms)
|
||||||
|
"Second processing pass.
|
||||||
|
|
||||||
|
In this pass we do form-rearranging manipulations, like docstring extraction."
|
||||||
|
forms)
|
||||||
|
|
||||||
|
;;; Aux functions
|
||||||
|
|
||||||
(define (read-forms acc)
|
(define (read-forms acc)
|
||||||
(let ((r (read)))
|
(let ((r (read)))
|
||||||
(if (eof-object? r) (reverse acc)
|
(if (eof-object? r) (reverse acc)
|
||||||
(read-forms (cons r acc)))))
|
(read-forms (cons r acc)))))
|
||||||
|
|
||||||
(define (emit-c forms)
|
(define (emit-c forms)
|
||||||
|
"Final conversion to C"
|
||||||
(for-each (lambda (form)
|
(for-each (lambda (form)
|
||||||
(fmt #t (c-expr form) nl))
|
(fmt #t (c-expr form) nl))
|
||||||
forms))
|
forms))
|
||||||
@@ -338,7 +349,9 @@
|
|||||||
(if (eq? input 'stdin)
|
(if (eq? input 'stdin)
|
||||||
(read-forms (list))
|
(read-forms (list))
|
||||||
(read-from-file input)))
|
(read-from-file input)))
|
||||||
(sex-forms (process-input input raw-forms)))
|
(sex-forms
|
||||||
|
(process-sex-forms
|
||||||
|
(process-input input raw-forms))))
|
||||||
(if (or (get-arg args 'macro-expand #f)
|
(if (or (get-arg args 'macro-expand #f)
|
||||||
(get-arg args 'preprocess #f))
|
(get-arg args 'preprocess #f))
|
||||||
;; Preprocess or macroexpand
|
;; Preprocess or macroexpand
|
||||||
|
|||||||
Reference in New Issue
Block a user