test semen through semen-process alone
Its fn accessors, walk-form and macro-expand were exported to be called on hand-built forms, checking what every compiled function and macro already goes through; sex-fn-public? and sex-fn-body had no other caller.
This commit is contained in:
14
semen.scm
14
semen.scm
@@ -19,11 +19,7 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
(export/rename (process semen-process))
|
(export/rename (process semen-process))
|
||||||
(export closure-env-declaration
|
(export closure-env-declaration)
|
||||||
;; for the tests
|
|
||||||
sex-fn? sex-fn-public? sex-fn-name sex-fn-arglist
|
|
||||||
sex-fn-return-type sex-fn-prototype sex-fn-body
|
|
||||||
walk-form macro-expand)
|
|
||||||
|
|
||||||
;;; for lambda extraction, docstring processing, macro expansion,
|
;;; for lambda extraction, docstring processing, macro expansion,
|
||||||
;;; injection of module headers, i.e. all things that rearrange code
|
;;; injection of module headers, i.e. all things that rearrange code
|
||||||
@@ -1965,9 +1961,6 @@ Returns #f if the form is not a function, returns the form otherwise"
|
|||||||
('extern 'fn . _)) form)
|
('extern 'fn . _)) form)
|
||||||
(else #f)))
|
(else #f)))
|
||||||
|
|
||||||
(define (sex-fn-public? fn-form)
|
|
||||||
(eq? (first fn-form) 'pub))
|
|
||||||
|
|
||||||
(define (sex-fn-name fn-form)
|
(define (sex-fn-name fn-form)
|
||||||
(assert (sex-fn? fn-form)
|
(assert (sex-fn? fn-form)
|
||||||
(fmt #f "Form " fn-form " is not a function"))
|
(fmt #f "Form " fn-form " is not a function"))
|
||||||
@@ -1982,8 +1975,3 @@ Returns #f if the form is not a function, returns the form otherwise"
|
|||||||
(assert (sex-fn? fn-form)
|
(assert (sex-fn? fn-form)
|
||||||
(fmt #f "Form " fn-form " is not a function"))
|
(fmt #f "Form " fn-form " is not a function"))
|
||||||
(fourth (fn-core fn-form)))
|
(fourth (fn-core fn-form)))
|
||||||
|
|
||||||
(define (sex-fn-body fn-form)
|
|
||||||
(assert (sex-fn? fn-form)
|
|
||||||
(fmt #f "Form " fn-form " is not a function"))
|
|
||||||
(drop fn-form (fn-header-length fn-form)))
|
|
||||||
|
|||||||
@@ -1,35 +1,8 @@
|
|||||||
(import srfi-69
|
(import semen
|
||||||
semen
|
|
||||||
types)
|
types)
|
||||||
|
|
||||||
(define print-str-fn
|
|
||||||
'(fn print-str ((s string)) void
|
|
||||||
(printf "%s" s)))
|
|
||||||
|
|
||||||
(define sum-fn
|
|
||||||
'(pub fn sum ((a int) (b int)) float
|
|
||||||
(return (cast (+ a b) float))))
|
|
||||||
|
|
||||||
(test-group "semen"
|
(test-group "semen"
|
||||||
(test-assert (sex-fn? print-str-fn))
|
;;; Macro expansion
|
||||||
(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 '((s string)) (sex-fn-arglist print-str-fn))
|
|
||||||
(test '(fn print-str ((s string)) void) (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 '((a int) (b int)) (sex-fn-arglist sum-fn))
|
|
||||||
(test '(pub fn sum ((a int) (b int)) float) (sex-fn-prototype sum-fn))
|
|
||||||
(test '((return (cast (+ a b) float))) (sex-fn-body sum-fn))
|
|
||||||
|
|
||||||
(test-assert (sex-fn? '(extern fn foo () void)))
|
|
||||||
(test 'foo (sex-fn-name '(extern fn foo () void)))
|
|
||||||
(test #f (sex-fn? '(struct point ((x int)))))
|
|
||||||
|
|
||||||
(let ((sex-code
|
(let ((sex-code
|
||||||
'((defmacro (sum-var name a b c)
|
'((defmacro (sum-var name a b c)
|
||||||
@@ -39,17 +12,6 @@
|
|||||||
|
|
||||||
(test '((var v 6)) (semen-process sex-code)))
|
(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
|
(let ((sex-code-macro
|
||||||
'((defmacro (x10 a)
|
'((defmacro (x10 a)
|
||||||
`(* 10 ,a))
|
`(* 10 ,a))
|
||||||
|
|||||||
Reference in New Issue
Block a user