1 ;;; Gacela, a GNU Guile extension for fast games development
2 ;;; Copyright (C) 2013 by Javier Sancho Fernandez <jsf at jsancho dot org>
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation, either version 3 of the License, or
7 ;;; (at your option) any later version.
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;; GNU General Public License for more details.
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 (define-module (gacela system)
19 #:use-module (srfi srfi-9))
22 ;;; Component definitions
24 (define (make-symbol . args)
27 (map (lambda (a) (if (symbol? a) (symbol->string a) a)) args))))
29 (define-macro (define-component name . args)
31 (use-modules (srfi srfi-9) (srfi srfi-9 gnu))
32 (define-record-type ,name
33 (,(make-symbol "make-" name) ,@args)
34 ,(make-symbol name "?")
35 ,@(map (lambda (a) (list a (make-symbol name "-" a) (make-symbol "set-" name "-" a "!"))) args))
36 (set-record-type-printer! ,name
38 (format port "#<[~a]" ',name)
39 ,@(map (lambda (a) `(format port " ~a: ~a" ',a (,(make-symbol name "-" a) record))) args)
43 (define (get-component-type component)
44 (record-type-name (record-type-descriptor component)))
46 (export define-component