add chicken-import support to sex

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

View File

@@ -3,7 +3,12 @@
(include stdbool.h) (include stdbool.h)
(include stdio.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 (struct foo
((float a) ((float a)
@@ -16,9 +21,8 @@
,(length-list-T '(int) #f) ,(length-list-T '(int) #f)
,(is-empty-list-T '(int) #f) ,(is-empty-list-T '(int) #f)
(extern fn void puk ((int a) (float b))) (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) (pub fn void baz () true)
(extern var int i) (extern var int i)

View File

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

View File

@@ -111,6 +111,7 @@
(else (error "Pub what?")))) (else (error "Pub what?"))))
(define (walk-sex-tree form acc) (define (walk-sex-tree form acc)
(if (list? form)
(case (car form) (case (car form)
((fn) (walk-function form #t acc)) ((fn) (walk-function form #t acc))
((extern) (walk-extern form acc)) ((extern) (walk-extern form acc))
@@ -120,13 +121,17 @@
acc acc
(eval (cadr form)))) (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) (define (process-form form acc)
(case (car form) (case (car form)
((define) (eval form) acc) ((define) (eval form) acc)
((template) (eval form) acc) ((template) (eval form) acc)
((load) (eval form) acc) ((load) (eval form) acc)
((chicken-import)
(eval (cons 'import (cdr form))) acc)
(else (else
(walk-sex-tree form acc)))) (walk-sex-tree form acc))))