37 lines
1.1 KiB
Scheme
37 lines
1.1 KiB
Scheme
;;; Uses the greet module. Build both, then link them:
|
|
;;;
|
|
;;; ./sexc example/greet.sex -c -o greet.o
|
|
;;; ./sexc example/greet-app.sex -o greet-app -- greet.o
|
|
;;;
|
|
;;; `(import greet)' pastes greet's public declarations here: `greet'
|
|
;;; as a prototype and `greet-count' as an extern. Both keep external
|
|
;;; linkage, so they refer to the one definition in greet.o rather than
|
|
;;; to private copies.
|
|
;;;
|
|
;;; Also check that import populates type-database, by means of
|
|
;;; describe-fields macro, which should work on imported type.
|
|
|
|
(include stdio.h)
|
|
|
|
(import greet)
|
|
|
|
(pub fn main () int
|
|
(greet "world")
|
|
(greet "sex")
|
|
(printf "%d greetings\n" greet-count)
|
|
(describe-fields greeting)
|
|
(printf "\n")
|
|
;; ...and through the imported typedef for it
|
|
(describe-fields greeting-t)
|
|
(printf "\n")
|
|
(var m (enum mood) grumpy)
|
|
(printf "mood %d\n" m)
|
|
|
|
(var add-10 (closure ((int)) int) (make-adder 10))
|
|
(printf "closure %d %d" (add-10 5) (apply-twice add-10 1))
|
|
(var base int 100)
|
|
(var here (closure ((int)) int)
|
|
(closure ((x int)) int (base) (return (+ base x))))
|
|
(printf " %d\n" (apply-twice here 1))
|
|
(return 0))
|