From bd71dcc8a79e14289f35346de126c46de7c41618 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Sat, 14 Jun 2025 14:07:00 +0300 Subject: [PATCH] add chicken-import support to sex also fix unquoting to single atom processing wrongly in walk-sex-tree --- example/test-list.sex | 10 +++++++--- sex-mode.el | 3 ++- sexc.scm | 23 ++++++++++++++--------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/example/test-list.sex b/example/test-list.sex index 7a4c69c..e3661b6 100644 --- a/example/test-list.sex +++ b/example/test-list.sex @@ -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) diff --git a/sex-mode.el b/sex-mode.el index 7a54a96..2f3803f 100644 --- a/sex-mode.el +++ b/sex-mode.el @@ -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" diff --git a/sexc.scm b/sexc.scm index 417a992..a735bbd 100644 --- a/sexc.scm +++ b/sexc.scm @@ -111,22 +111,27 @@ (else (error "Pub what?")))) (define (walk-sex-tree form acc) - (case (car form) - ((fn) (walk-function form #t acc)) - ((extern) (walk-extern form acc)) - ((pub) (walk-public form acc)) - ((struct union) (walk-struct form acc)) - ((unquote) (fold (fn (walk-sex-tree x y)) - acc - (eval (cadr form)))) + (if (list? form) + (case (car form) + ((fn) (walk-function form #t acc)) + ((extern) (walk-extern form acc)) + ((pub) (walk-public form acc)) + ((struct union) (walk-struct form acc)) + ((unquote) (fold (fn (walk-sex-tree x y)) + 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))))