add auto typedefs for structs
This commit is contained in:
@@ -73,6 +73,9 @@ Sex offers automatic unkebabification of all symbols, i.e. no more
|
|||||||
ugly ~GL_ARRAY_BUFFER~ s in your code, they may be written in their
|
ugly ~GL_ARRAY_BUFFER~ s in your code, they may be written in their
|
||||||
proper form: ~GL-ARRAY-BUFFER~.
|
proper form: ~GL-ARRAY-BUFFER~.
|
||||||
|
|
||||||
|
** Auto typedef for structs
|
||||||
|
Probably harmless idk.
|
||||||
|
|
||||||
** Use an established environment for development
|
** Use an established environment for development
|
||||||
As Sex is S-expressions, you always have Emacs with paredit as your
|
As Sex is S-expressions, you always have Emacs with paredit as your
|
||||||
best option.
|
best option.
|
||||||
|
|||||||
@@ -3,7 +3,12 @@
|
|||||||
(define (foo)
|
(define (foo)
|
||||||
"Hello from Chicken code!\n")
|
"Hello from Chicken code!\n")
|
||||||
|
|
||||||
|
(struct foo
|
||||||
|
((int a)
|
||||||
|
(float b)))
|
||||||
|
|
||||||
(pub fn int main ((int argc) (char **argv))
|
(pub fn int main ((int argc) (char **argv))
|
||||||
|
(var int a 10)
|
||||||
(puts "Hello from Sex!")
|
(puts "Hello from Sex!")
|
||||||
(var (array char 512) name)
|
(var (array char 512) name)
|
||||||
(puts "What is your name?")
|
(puts "What is your name?")
|
||||||
|
|||||||
48
sexc.scm
48
sexc.scm
@@ -34,39 +34,49 @@
|
|||||||
#f)))
|
#f)))
|
||||||
|
|
||||||
(define (walk-generic form)
|
(define (walk-generic form)
|
||||||
(let loop ((tree (tree-map atom-to-fmt-c form)))
|
(tree-map
|
||||||
(let ((unquote-form (tree-find (tree-finder 'unquote) tree #f)))
|
atom-to-fmt-c
|
||||||
(if unquote-form
|
(let ((ret-form form))
|
||||||
(let ((inv (invert-tree tree)))
|
(let loop ((unquote-form (tree-find (tree-finder 'unquote) form #f)))
|
||||||
(loop (tree-replace inv unquote-form (eval (cadr unquote-form)))))
|
(if unquote-form
|
||||||
tree))))
|
(begin
|
||||||
|
(set! ret-form (tree-replace (invert-tree form)
|
||||||
|
unquote-form
|
||||||
|
(eval (cadr unquote-form))))
|
||||||
|
(loop (tree-find (tree-finder 'unquote)
|
||||||
|
ret-form
|
||||||
|
#f)))
|
||||||
|
ret-form)))))
|
||||||
|
|
||||||
(define (walk-function form static)
|
(define (walk-function form static)
|
||||||
(if static
|
(if static
|
||||||
(list 'static (walk-generic form))
|
(list 'static (walk-generic form))
|
||||||
(walk-generic (cdr form))))
|
(walk-generic (cdr form))))
|
||||||
|
|
||||||
(define (walk-sex-tree form)
|
(define (walk-struct form acc)
|
||||||
(case (car form)
|
(let ((name (unkebabify (cadr form))))
|
||||||
((fn) (walk-function form #t))
|
(cons (walk-generic form)
|
||||||
((pub) (walk-function form #f))
|
(cons `(typedef struct ,name ,name) acc))))
|
||||||
((template) '()) ; TODO
|
|
||||||
((struct) (walk-generic form))
|
|
||||||
(else (walk-generic form))))
|
|
||||||
|
|
||||||
(define (process-form form)
|
(define (walk-sex-tree form acc)
|
||||||
(case (car form)
|
(case (car form)
|
||||||
((define)
|
((fn) (cons (walk-function form #t) acc))
|
||||||
(eval form) '())
|
((pub) (cons (walk-function form #f) acc))
|
||||||
|
((struct) (walk-struct form acc))
|
||||||
|
(else (cons (walk-generic form) acc))))
|
||||||
|
|
||||||
|
(define (process-form form acc)
|
||||||
|
(case (car form)
|
||||||
|
((define) (eval form) acc)
|
||||||
|
((load) (eval form) acc)
|
||||||
(else
|
(else
|
||||||
(walk-sex-tree form))))
|
(walk-sex-tree form acc))))
|
||||||
|
|
||||||
(define (process-raw-forms raw-forms acc)
|
(define (process-raw-forms raw-forms acc)
|
||||||
(if (null? raw-forms) (filter (fn (not (null? x)))
|
(if (null? raw-forms) (filter (fn (not (null? x)))
|
||||||
(reverse acc))
|
(reverse acc))
|
||||||
(process-raw-forms (cdr raw-forms)
|
(process-raw-forms (cdr raw-forms)
|
||||||
(cons (process-form (car raw-forms))
|
(process-form (car raw-forms) acc))))
|
||||||
acc))))
|
|
||||||
|
|
||||||
(define (read-forms acc)
|
(define (read-forms acc)
|
||||||
(let ((r (read)))
|
(let ((r (read)))
|
||||||
|
|||||||
Reference in New Issue
Block a user