Fix metadata usage
[sxemacs] / src / category.c
1 /*** category.c -- categorial view on objects, this is NOT OO
2  *
3  * Copyright (C) 2008 Sebastian Freundt
4  *
5  * Author:  Sebastian Freundt <hroptatyr@sxemacs.org>
6  *
7  * This file is part of SXEmacs.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of the author nor the names of any contributors
21  *    may be used to endorse or promote products derived from this
22  *    software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  ***/
37
38 #include "config.h"
39 #include "lisp.h"
40 #include "category.h"
41 #include "lrecord.h"
42
43 struct cat_morphism_s __morphisms[lrecord_type_last_built_in_type];
44 cat_morphism_t morphisms = __morphisms;
45
46 #if 0
47 void*const*
48 cat_morphisms(const void *obj)
49 {
50 /* returns a pointer to the array of implementations or
51  * NULL if there are none */
52         if (((const struct lrecord_header*)obj)->morphisms & cat_mk_lc) {
53                 return &((const struct __cat_morphism_lcrec_s*)obj)->foo;
54         } else {
55                 return &((const struct __cat_morphism_lrec_s*)obj)->foo;
56         }
57 }
58
59 void*
60 cat_morphism(const void *obj, cat_morphism_kind_t kind)
61 {
62         unsigned int flags = ((const struct lrecord_header*)obj)->morphisms;
63
64         if (!__bit_set_p(flags, kind)) {
65                 int type = ((const struct lrecord_header*)obj)->type;
66                 switch (kind) {
67                 case cat_mk_seq:
68                         GC_CRITICAL("here %x %x\n", flags, kind);
69                         return morphisms[type].seq_impl;
70                 case cat_mk_set:
71                         return morphisms[type].set_impl;
72                 case cat_mk_aseq:
73                         return morphisms[type].aseq_impl;
74                 case cat_mk_aset:
75                         return morphisms[type].aset_impl;
76                 default:
77                         return NULL;
78                 }
79         } else {
80                 void *const*mph = cat_morphisms(obj);
81                 return mph[__nbits_right_of(flags, kind)-(flags&1)];
82         }
83 }
84 #endif
85
86 /* category.c ends here */