add extern support

This commit is contained in:
alex-eg
2025-06-13 18:20:51 +03:00
parent 4efa730b21
commit 2295b5ad17
3 changed files with 19 additions and 1 deletions

View File

@@ -17,6 +17,9 @@
(fn bool bar () false) (fn bool bar () false)
(extern fn void puk ((int a) (float b)))
(extern var int i)
(pub fn int main () (pub fn int main ()
(var (* list-int) l (make-list-int)) (var (* list-int) l (make-list-int))
(printf "Size of the list: %zu\n" (length-list-int l)) (printf "Size of the list: %zu\n" (length-list-int l))

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 '("include" (regexp-opt '("extern"
"include"
"fn" "fn"
"pub" "pub"
"struct" "struct"

View File

@@ -27,6 +27,7 @@
(define (atom-to-fmt-c atom) (define (atom-to-fmt-c atom)
(case atom (case atom
((fn) '%fun) ((fn) '%fun)
((prototype) '%prototype)
((var) '%var) ((var) '%var)
((begin) '%begin) ((begin) '%begin)
((pointer) '%pointer) ((pointer) '%pointer)
@@ -89,9 +90,22 @@
(append (walk-generic form (list)) (append (walk-generic form (list))
(cons `(typedef struct ,name ,name) acc)))) (cons `(typedef struct ,name ,name) acc))))
(define (walk-extern form acc)
(case (cadr form)
((fn)
(append
(walk-generic (list 'extern (cons 'prototype (cddr form))) (list))
acc))
((var)
(append
(walk-generic (list 'extern (cdr form)) (list))
acc))
(else (error "Extern what?"))))
(define (walk-sex-tree form acc) (define (walk-sex-tree form acc)
(case (car form) (case (car form)
((fn) (walk-function form #t acc)) ((fn) (walk-function form #t acc))
((extern) (walk-extern form acc))
((pub) (walk-function form #f acc)) ((pub) (walk-function form #f acc))
((struct union) (walk-struct form acc)) ((struct union) (walk-struct form acc))
((unquote) (fold (fn (walk-sex-tree x y)) ((unquote) (fold (fn (walk-sex-tree x y))