From 650bff6d0e5e4e01b0094e72c9e45b050470816b Mon Sep 17 00:00:00 2001 From: alex-eg Date: Sat, 14 Jun 2025 17:10:09 +0300 Subject: [PATCH] fix pub function prototypes --- example/test-list.sex | 8 +++++++- sexc.scm | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/example/test-list.sex b/example/test-list.sex index e3661b6..c23f322 100644 --- a/example/test-list.sex +++ b/example/test-list.sex @@ -13,7 +13,8 @@ (struct foo ((float a) (int b) - ((const char *) c))) + ((const char *) c) + ((fn bool ((bool val))) not))) ,(list-T '(int)) ,(make-list-T '(int) #f) @@ -38,3 +39,8 @@ ,(list-for-each '((printf "%d " v) l v)) (printf "\n") 0) + +(pub fn segs-renderer* create-renderer ()) +(pub fn void clear-command-buffer ((segs-renderer *r))) +(pub fn void add-render-command ((segs-renderer *r) ((fn void ()) command))) +(pub fn void commit-command-buffer ((segs-renderer *r))) diff --git a/sexc.scm b/sexc.scm index 476142b..7af9a40 100644 --- a/sexc.scm +++ b/sexc.scm @@ -80,10 +80,21 @@ form)) acc))))) +(define (normalize-fn-form form) + ;; (fn ret-type name arglist body) -> normal function + ;; (fn ret-type name arglist) -> prototype + (if (>= (length form) 5) + form + (cons 'prototype (cdr form)))) + (define (walk-function form static acc) (if static - (append (walk-generic (list 'static form) (list)) acc) - (append (walk-generic (cdr form) (list)) acc))) + (append (walk-generic (list 'static (normalize-fn-form form)) + (list)) + acc) + (append (walk-generic (normalize-fn-form (cdr form)) + (list)) + acc))) (define (walk-struct form acc) (let ((name (unkebabify (cadr form)))) @@ -94,11 +105,11 @@ (case (cadr form) ((fn) (append - (walk-generic (list 'extern (cons 'prototype (cddr form))) (list)) + (list (cons 'extern (walk-function form #f (list)))) acc)) ((var) (append - (walk-generic (list 'extern (cdr form)) (list)) + (list (cons 'extern (walk-generic (cdr form) (list)))) acc)) (else (error "Extern what?"))))