mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-18 21:29:18 +02:00
Issue #412 - Handle all cond-expand's
This change allows libraries to expand properly when cond-expand contains multiple sub-expressions. Previously it only worked properly if the sub-expressions were begin's.
This commit is contained in:
parent
501b4391bc
commit
f0bf9fc1d4
2 changed files with 49 additions and 14 deletions
|
@ -1,9 +1,24 @@
|
|||
(define-library (example life)
|
||||
(export life)
|
||||
(import (except (scheme base) set!)
|
||||
(scheme write)
|
||||
(example grid))
|
||||
(begin
|
||||
; (scheme write)
|
||||
; (example grid)
|
||||
)
|
||||
(cond-expand
|
||||
(cyclone
|
||||
(import (scheme write))
|
||||
; ))
|
||||
; (cond-expand
|
||||
; (cyclone
|
||||
(import (example grid))
|
||||
))
|
||||
|
||||
;(cond-expand
|
||||
; (cyclone
|
||||
(export life)
|
||||
;))
|
||||
(cond-expand
|
||||
(cyclone
|
||||
(begin
|
||||
(define (life-count grid i j)
|
||||
(define (count i j)
|
||||
(if (ref grid i j) 1 0))
|
||||
|
@ -15,11 +30,18 @@
|
|||
(count (+ i 1) (- j 1))
|
||||
(count (+ i 1) j)
|
||||
(count (+ i 1) (+ j 1))))
|
||||
)
|
||||
(begin
|
||||
(define (life-alive? grid i j)
|
||||
(case (life-count grid i j)
|
||||
((3) #t)
|
||||
((2) (ref grid i j))
|
||||
(else #f)))
|
||||
)
|
||||
|
||||
)
|
||||
)
|
||||
(begin
|
||||
(define (clear-vt100)
|
||||
(display
|
||||
(string
|
||||
|
|
|
@ -240,26 +240,39 @@
|
|||
(lambda (d acc)
|
||||
(cond
|
||||
((tagged-list? 'cond-expand d)
|
||||
(let* ((expr (expander d))
|
||||
(begin? (and (pair? expr)
|
||||
(not (member (car expr)
|
||||
'(import export c-linker-options include-c-header))))))
|
||||
;(write `(DEBUG ,begin? ,(if (pair? expr) (lambda? (car expr)) #f) ,expr))
|
||||
;(newline)
|
||||
;; Can have more than one ce expression, EG:
|
||||
;; (cond-expand
|
||||
;; (cyclone
|
||||
;; (import ...)
|
||||
;; (export ...)
|
||||
;;
|
||||
;; TODO: handle this properly
|
||||
(let* ((expr (expander d)))
|
||||
(cond
|
||||
;; Special case, multiple sub-expressions
|
||||
((and (pair? expr)
|
||||
(lambda? (car expr))
|
||||
(eq? '() (lambda->formals (car expr))))
|
||||
(cons `(begin ,@(lambda->exp (car expr))) acc))
|
||||
(begin?
|
||||
(cons `(begin ,expr) acc))
|
||||
(append
|
||||
(reverse ;; Preserve order
|
||||
(map form-ce-expr (lambda->exp (car expr))))
|
||||
acc))
|
||||
(else
|
||||
(cons expr acc)))))
|
||||
(cons (form-ce-expr expr) acc)))))
|
||||
(else
|
||||
(cons d acc)) ))
|
||||
'()
|
||||
decls)))
|
||||
|
||||
(define (form-ce-expr expr)
|
||||
(cond
|
||||
((and (pair? expr)
|
||||
(not (member (car expr)
|
||||
'(import export c-linker-options include-c-header))))
|
||||
`(begin ,expr))
|
||||
(else
|
||||
expr)))
|
||||
|
||||
(define (lib:atom->string atom)
|
||||
(cond
|
||||
((symbol? atom)
|
||||
|
|
Loading…
Add table
Reference in a new issue