forked from alex-eg/sex
add support for begin in Sex
begin-wrapped blocks are now creating lexical scopes
This commit is contained in:
@@ -38,9 +38,10 @@
|
|||||||
|
|
||||||
(pub defmacro (list-for-each list-type list-var elt-type elt-var what-do)
|
(pub defmacro (list-for-each list-type list-var elt-type elt-var what-do)
|
||||||
(let ((list-var-2 (cat list-var '-2)))
|
(let ((list-var-2 (cat list-var '-2)))
|
||||||
`((var (pointer ,list-type) ,list-var-2 ,list-var)
|
`((begin
|
||||||
(var ,elt-type ,elt-var (-> ,list-var-2 value))
|
(var (pointer ,list-type) ,list-var-2 ,list-var)
|
||||||
(while (!= (-> ,list-var-2 next) NULL)
|
(var ,elt-type ,elt-var (-> ,list-var-2 value))
|
||||||
,what-do
|
(while (!= (-> ,list-var-2 next) NULL)
|
||||||
(= ,list-var-2 (-> ,list-var-2 next))
|
,what-do
|
||||||
(= ,elt-var (-> ,list-var-2 value))))))
|
(= ,list-var-2 (-> ,list-var-2 next))
|
||||||
|
(= ,elt-var (-> ,list-var-2 value)))))))
|
||||||
|
|||||||
@@ -218,6 +218,7 @@
|
|||||||
((apply cpp-if/aux (substring/shared (symbol->string (car x)) 1)
|
((apply cpp-if/aux (substring/shared (symbol->string (car x)) 1)
|
||||||
(cdr x)) st))
|
(cdr x)) st))
|
||||||
((%endif) ((apply cpp-endif (cdr x)) st))
|
((%endif) ((apply cpp-endif (cdr x)) st))
|
||||||
|
((%block-begin) ((apply c-braced-block #f (cdr x)) st))
|
||||||
((%block) ((apply c-braced-block (cdr x)) st))
|
((%block) ((apply c-braced-block (cdr x)) st))
|
||||||
((%comment) ((apply c-comment (cdr x)) st))
|
((%comment) ((apply c-comment (cdr x)) st))
|
||||||
((:) ((apply c-label (cdr x)) st))
|
((:) ((apply c-label (cdr x)) st))
|
||||||
@@ -521,7 +522,7 @@
|
|||||||
|
|
||||||
(define (c-braced-block/aux offset header . body)
|
(define (c-braced-block/aux offset header . body)
|
||||||
(lambda (st)
|
(lambda (st)
|
||||||
((cat header (c-open-brace st) (c-indent st offset)
|
((cat (if header header "") (c-open-brace st) (c-indent st offset)
|
||||||
(apply c-begin body) fl
|
(apply c-begin body) fl
|
||||||
(c-current-indent-string st offset) (c-close-brace st))
|
(c-current-indent-string st offset) (c-close-brace st))
|
||||||
st)))
|
st)))
|
||||||
|
|||||||
2
sexc.scm
2
sexc.scm
@@ -36,7 +36,7 @@
|
|||||||
((fn) '%fun)
|
((fn) '%fun)
|
||||||
((prototype) '%prototype)
|
((prototype) '%prototype)
|
||||||
((var) '%var)
|
((var) '%var)
|
||||||
((begin) '%begin)
|
((begin) '%block-begin)
|
||||||
((define) '%define)
|
((define) '%define)
|
||||||
((pointer) '%pointer)
|
((pointer) '%pointer)
|
||||||
((array) '%array)
|
((array) '%array)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
(test '%fun (atom-to-fmt-c 'fn))
|
(test '%fun (atom-to-fmt-c 'fn))
|
||||||
(test '%prototype (atom-to-fmt-c 'prototype))
|
(test '%prototype (atom-to-fmt-c 'prototype))
|
||||||
(test '%var (atom-to-fmt-c 'var))
|
(test '%var (atom-to-fmt-c 'var))
|
||||||
(test '%begin (atom-to-fmt-c 'begin))
|
(test '%block-begin (atom-to-fmt-c 'begin))
|
||||||
(test '%define (atom-to-fmt-c 'define))
|
(test '%define (atom-to-fmt-c 'define))
|
||||||
(test '%pointer (atom-to-fmt-c 'pointer))
|
(test '%pointer (atom-to-fmt-c 'pointer))
|
||||||
(test '%array (atom-to-fmt-c 'array))
|
(test '%array (atom-to-fmt-c 'array))
|
||||||
|
|||||||
Reference in New Issue
Block a user