Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[b0ce08]: src / c / instance.d Maximize Restore History

Download this file

instance.d    185 lines (159 with data), 4.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
instance.c -- CLOS interface.
*/
/*
Copyright (c) 1990, Giuseppe Attardi.
Copyright (c) 2001, Juan Jose Garcia Ripoll.
ECL is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
See file '../Copyright' for full details.
*/
#include "ecl.h"
cl_object
cl_allocate_instance(cl_object clas, int size)
{
cl_object x = cl_alloc_instance(size);
int i;
CLASS_OF(x) = clas;
for (i = 0; i < size; i++)
x->instance.slots[i] = OBJNULL;
return(x);
}
cl_object
si_allocate_instance(cl_object clas, cl_object size)
{
if (type_of(clas) != t_instance)
FEwrong_type_argument(@'instance', clas);
@(return cl_allocate_instance(clas, fixnnint(size)))
}
/* corr is a list of (newi . oldi) describing which of the new slots
retains a value from an old slot
*/
cl_object
si_change_instance(cl_object x, cl_object clas, cl_object size, cl_object corr)
{
int nslot, i;
cl_object * oldslots;
if (type_of(x) != t_instance)
FEwrong_type_argument(@'instance', x);
if (type_of(clas) != t_instance)
FEwrong_type_argument(@'instance', clas);
nslot = fixnnint(size);
CLASS_OF(x) = clas;
x->instance.length = nslot;
oldslots = x->instance.slots;
x->instance.slots = (cl_object *)cl_alloc_align(sizeof(cl_object)*nslot,sizeof(cl_object));
for (i = 0; i < nslot; i++) {
if (!Null(corr) && fix(CAAR(corr)) == i) {
x->instance.slots[i] = oldslots[fix(CDAR(corr))];
corr = CDR(corr);
}
else
x->instance.slots[i] = OBJNULL;
}
@(return) /* FIXME! Is this what we need? */
}
cl_object
si_instance_class(cl_object x)
{
if (type_of(x) != t_instance)
FEwrong_type_argument(@'instance', x);
@(return CLASS_OF(x))
}
cl_object
si_instance_class_set(cl_object x, cl_object y)
{
if (type_of(x) != t_instance)
FEwrong_type_argument(@'instance', x);
if (type_of(y) != t_instance)
FEwrong_type_argument(@'instance', y);
CLASS_OF(x) = y;
@(return x)
}
cl_object
instance_ref(cl_object x, int i)
{
if (type_of(x) != t_instance)
FEwrong_type_argument(@'instance', x);
if (i >= x->instance.length || i < 0)
FEerror("~S is an illegal slot index1.",1,i);
return(x->instance.slots[i]);
}
cl_object
si_instance_ref(cl_object x, cl_object index)
{
cl_fixnum i;
if (type_of(x) != t_instance)
FEwrong_type_argument(@'instance', x);
if (!FIXNUMP(index) ||
(i = fix(index)) < 0 || i >= x->instance.length)
FEerror("~S is an illegal slot index.", 1, index);
@(return x->instance.slots[i])
}
cl_object
si_instance_ref_safe(cl_object x, cl_object index)
{
cl_fixnum i;
if (type_of(x) != t_instance)
FEwrong_type_argument(@'instance', x);
if (!FIXNUMP(index) ||
(i = fix(index)) < 0 || i >= x->instance.length)
FEerror("~S is an illegal slot index.", 1, index);
x = x->instance.slots[i];
if (x == OBJNULL)
FEerror("Slot index ~S unbound", 1, index);
@(return x->instance.slots[i])
}
cl_object
instance_set(cl_object x, int i, cl_object v)
{
if (type_of(x) != t_instance)
FEwrong_type_argument(@'instance', x);
if (i >= x->instance.length || i < 0)
FEerror("~S is an illegal slot index2.", 1, i);
x->instance.slots[i] = v;
return(v);
}
cl_object
si_instance_set(cl_object x, cl_object index, cl_object value)
{
cl_fixnum i;
if (type_of(x) != t_instance)
FEwrong_type_argument(@'instance', x);
if (!FIXNUMP(index) ||
(i = fix(index)) >= x->instance.length || i < 0)
FEerror("~S is an illegal slot index.", 1, index);
x->instance.slots[i] = value;
@(return value)
}
cl_object
si_instancep(cl_object x)
{
@(return ((type_of(x) == t_instance) ? Ct : Cnil))
}
cl_object
si_unbound()
{
/* Returns an object that cannot be read or written and which
is used to represent an unitialized slot */
@(return OBJNULL)
}
cl_object
si_sl_boundp(cl_object x)
{
@(return ((x == OBJNULL) ? Cnil : Ct))
}
cl_object
si_sl_makunbound(cl_object x, cl_object index)
{
cl_fixnum i;
if (type_of(x) != t_instance)
FEwrong_type_argument(@'instance', x);
if (!FIXNUMP(index) ||
(i = fix(index)) >= x->instance.length || i < 0)
FEerror("~S is an illegal slot index.", 1, index);
x->instance.slots[i] = OBJNULL;
@(return x)
}