;;; 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) ;; the bare record name, then the method both ways round (var v vec2 #(vec2 : 3 4)) (printf "vec2 %d %d\n" (.manhattan v) (vec2/manhattan (& v))) ;; only the handle crossed: (. t n) here is an incomplete type (var t (* tally) (tally/make)) (.bump t) (.bump t) (printf "tally %d\n" (.count t)) (.drop t) ;; neither cell nor ledger is visible here, only declared (var b board (make-board)) (printf "board %d\n" (board-total (& b))) (printf "ledger %d\n" (ledger-total (greet-ledger))) (var c colour (colour/rgb 1 2 3)) (match c ((rgb (r g b)) (printf "colour %d%d%d\n" r g b)) ((none ()) (printf "colour none\n"))) (return 0))