]> git.jsancho.org Git - gacela.git/blob - src/system.scm
Component definitions support using Guile records
[gacela.git] / src / system.scm
1 ;;; Gacela, a GNU Guile extension for fast games development
2 ;;; Copyright (C) 2013 by Javier Sancho Fernandez <jsf at jsancho dot org>
3 ;;;
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.
8 ;;;
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.
13 ;;;
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/>.
16
17
18 (define-module (gacela system)
19   #:use-module (srfi srfi-9))
20
21
22 ;;; Component definitions
23
24 (define (make-symbol . args)
25   (string->symbol
26    (string-concatenate
27     (map (lambda (a) (if (symbol? a) (symbol->string a) a)) args))))
28
29 (define-macro (define-component name . args)
30   `(begin
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
37        (lambda (record port)
38          (format port "#<[~a]" ',name)
39          ,@(map (lambda (a) `(format port " ~a: ~a" ',a (,(make-symbol name "-" a) record))) args)
40          (format port ">")))
41      ',name))
42
43 (define (get-component-type component)
44   (record-type-name (record-type-descriptor component)))
45
46 (export define-component
47         get-component-type)