add chicken-import support to sex

also fix unquoting to single atom processing wrongly in walk-sex-tree
This commit is contained in:
alex-eg
2025-06-14 14:07:00 +03:00
parent 750d8f8256
commit 8b1ade4f24
3 changed files with 23 additions and 13 deletions

View File

@@ -3,7 +3,12 @@
(include stdbool.h)
(include stdio.h)
(load "list.seh")
(chicken-import srfi-1 brev-separate) ; list routines, e.g. fold
(chicken-load "list.seh")
(define (imports-test a b c)
(fold + 0 (list 1 2 3 a b c)))
(struct foo
((float a)
@@ -16,9 +21,8 @@
,(length-list-T '(int) #f)
,(is-empty-list-T '(int) #f)
(extern fn void puk ((int a) (float b)))
(fn bool bar () false)
(fn int bar () ,(imports-test 10 20 30))
(pub fn void baz () true)
(extern var int i)

View File

@@ -28,7 +28,8 @@ All commands in `lisp-mode-shared-map' are inherited by this map.")
(list
;; Declarations
(list (concat "("
(regexp-opt '("extern"
(regexp-opt '("chicken-import"
"extern"
"include"
"fn"
"pub"

View File

@@ -111,6 +111,7 @@
(else (error "Pub what?"))))
(define (walk-sex-tree form acc)
(if (list? form)
(case (car form)
((fn) (walk-function form #t acc))
((extern) (walk-extern form acc))
@@ -120,13 +121,17 @@
acc
(eval (cadr form))))
(else (append (walk-generic form (list)) acc))))
(else (append (walk-generic form (list)) acc)))
;; only for unquote support
(list (list (atom-to-fmt-c form)))))
(define (process-form form acc)
(case (car form)
((define) (eval form) acc)
((template) (eval form) acc)
((load) (eval form) acc)
((chicken-import)
(eval (cons 'import (cdr form))) acc)
(else
(walk-sex-tree form acc))))