forked from alex-eg/sex
Also rename macros to sex-macros, module-system to sex-modules for clarity, uniformity, and to avoid name clashes with Chicken's units/modules named "macros" and "modules"
58 lines
1.6 KiB
Scheme
58 lines
1.6 KiB
Scheme
(import srfi-69
|
|
semen)
|
|
|
|
(define print-str-fn
|
|
'(fn void print-str ((string s))
|
|
(printf "%s" s)))
|
|
|
|
(define sum-fn
|
|
'(pub fn float sum ((int a) (int b))
|
|
(return (cast float (+ a b)))))
|
|
|
|
(test-group "semen"
|
|
(test-assert (sex-fn? print-str-fn))
|
|
(test #f (sex-fn-public? print-str-fn))
|
|
(test 'void (sex-fn-return-type print-str-fn))
|
|
(test 'print-str (sex-fn-name print-str-fn))
|
|
(test '((string s)) (sex-fn-arglist print-str-fn))
|
|
(test '(fn void print-str ((string s))) (sex-fn-prototype print-str-fn))
|
|
(test '((printf "%s" s)) (sex-fn-body print-str-fn))
|
|
|
|
(test-assert (sex-fn? sum-fn))
|
|
(test #t (sex-fn-public? sum-fn))
|
|
(test 'float (sex-fn-return-type sum-fn))
|
|
(test 'sum (sex-fn-name sum-fn))
|
|
(test '((int a) (int b)) (sex-fn-arglist sum-fn))
|
|
(test '(pub fn float sum ((int a) (int b))) (sex-fn-prototype sum-fn))
|
|
(test '((return (cast float (+ a b)))) (sex-fn-body sum-fn))
|
|
|
|
(let ((sex-code
|
|
'((defmacro (sum-var name a b c)
|
|
`(var ,name ,(+ a b c)))
|
|
|
|
(sum-var v 1 2 3))))
|
|
|
|
(test '((var v 6)) (semen-process sex-code)))
|
|
|
|
;;; Macro expansion
|
|
|
|
(define (form-identity form env)
|
|
form)
|
|
|
|
(test 'a (walk-form 'a form-identity (make-hash-table)))
|
|
(test '(a b c) (walk-form '(a b c) form-identity (make-hash-table)))
|
|
|
|
(test 'a (macro-expand 'a))
|
|
(test '(a b c) (macro-expand '(a b c)))
|
|
|
|
(let ((sex-code-macro
|
|
'((defmacro (x10 a)
|
|
`(* 10 ,a))
|
|
|
|
(fn void foo ((int a) (int b))
|
|
(return (+ a (x10 b)))))))
|
|
|
|
(test '((fn void foo ((int a) (int b))
|
|
(return (+ a (* 10 b)))))
|
|
(semen-process sex-code-macro))))
|