2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 PyrObject represents the structure of all SC Objects.
31 /* special gc colors */
33 obj_permanent
= 1, // sent to gc->New as a flag
34 obj_gcmarker
= 2 // gc treadmill marker
61 PyrObjectHdr : object header fields
62 prev, next : pointers in the GC treadmill
63 classptr : pointer to the object's class
64 size : number of slots or indexable elements.
66 obj_format : what kind of data this object holds
67 obj_sizeclass : power of two size class of the object
69 immutable : set if object may not be updated.
70 finalize : set if object requires finalization.
71 marked : used by garbage collector debug sanity check. may be used by primitives but must be cleared before exiting primitive.
72 gc_color : GC color : black, grey, white, free, permanent
73 scratch1 : undefined value. may be used within primitives as a temporary scratch value.
77 struct PyrObjectHdr
*prev
, *next
;
78 struct PyrClass
*classptr
;
81 unsigned char obj_format
;
82 unsigned char obj_sizeclass
;
83 unsigned char obj_flags
;
84 unsigned char gc_color
;
88 int SizeClass() { return obj_sizeclass
; }
90 void SetMark() { obj_flags
|= obj_marked
; }
91 void ClearMark() { obj_flags
&= ~obj_marked
; }
92 bool IsMarked() const { return obj_flags
& obj_marked
; }
93 bool IsPermanent() const { return gc_color
== obj_permanent
; }
94 bool IsImmutable() const { return obj_flags
& obj_immutable
; }
95 bool IsMutable() const { return !IsMutable(); }
98 struct PyrObject
: public PyrObjectHdr
{
102 struct PyrList
: public PyrObjectHdr
107 struct PyrDoubleArray
: public PyrObjectHdr
112 struct PyrFloatArray
: public PyrObjectHdr
117 struct PyrInt32Array
: public PyrObjectHdr
122 struct PyrInt16Array
: public PyrObjectHdr
127 struct PyrInt8Array
: public PyrObjectHdr
132 struct PyrString
: public PyrObjectHdr
137 struct PyrSymbolArray
: public PyrObjectHdr
139 PyrSymbol
* symbols
[1];
142 extern struct PyrClass
*class_object
;
143 extern struct PyrClass
*class_array
;
144 extern struct PyrClass
*class_list
, *class_method
, *class_fundef
, *class_frame
, *class_class
;
145 extern struct PyrClass
*class_symbol
, *class_nil
;
146 extern struct PyrClass
*class_boolean
, *class_true
, *class_false
;
147 extern struct PyrClass
*class_int
, *class_char
, *class_float
, *class_complex
;
148 extern struct PyrClass
*class_rawptr
;
149 extern struct PyrClass
*class_string
;
150 extern struct PyrClass
*class_magnitude
, *class_number
, *class_collection
;
151 extern struct PyrClass
*class_sequenceable_collection
;
152 extern struct PyrClass
*class_arrayed_collection
;
153 extern struct PyrClass
*class_simple_number
;
154 extern struct PyrClass
*class_signal
;
155 extern struct PyrClass
*class_wavetable
;
156 extern struct PyrClass
*class_rawarray
;
157 extern struct PyrClass
*class_int8array
;
158 extern struct PyrClass
*class_int16array
;
159 extern struct PyrClass
*class_int32array
;
160 extern struct PyrClass
*class_symbolarray
;
161 extern struct PyrClass
*class_floatarray
;
162 extern struct PyrClass
*class_doublearray
;
163 extern struct PyrClass
*class_func
, *class_absfunc
;
164 extern struct PyrClass
*class_stream
;
165 extern struct PyrClass
*class_process
;
166 extern struct PyrClass
*class_interpreter
;
167 extern struct PyrClass
*class_thread
;
168 extern struct PyrClass
*class_routine
;
169 extern struct PyrClass
*class_finalizer
;
170 extern struct PyrClass
*class_server_shm_interface
;
172 extern PyrSymbol
*s_none
;
173 extern PyrSymbol
*s_object
;
174 extern PyrSymbol
*s_bag
;
175 extern PyrSymbol
*s_set
;
176 extern PyrSymbol
*s_identityset
;
177 extern PyrSymbol
*s_dictionary
;
178 extern PyrSymbol
*s_identitydictionary
;
179 extern PyrSymbol
*s_linkedlist
;
180 extern PyrSymbol
*s_sortedlist
;
181 extern PyrSymbol
*s_array
;
182 extern PyrSymbol
*s_list
, *s_method
, *s_fundef
, *s_frame
, *s_class
;
183 extern PyrSymbol
*s_symbol
, *s_nil
;
184 extern PyrSymbol
*s_boolean
, *s_true
, *s_false
;
185 extern PyrSymbol
*s_int
, *s_char
, *s_color
, *s_float
, *s_complex
;
186 extern PyrSymbol
*s_rawptr
, *s_objptr
;
187 extern PyrSymbol
*s_string
;
188 extern PyrSymbol
*s_magnitude
, *s_number
, *s_collection
;
189 extern PyrSymbol
*s_ordered_collection
;
190 extern PyrSymbol
*s_sequenceable_collection
;
191 extern PyrSymbol
*s_arrayed_collection
;
192 extern PyrSymbol
*s_simple_number
;
193 extern PyrSymbol
*s_signal
;
194 extern PyrSymbol
*s_wavetable
;
195 extern PyrSymbol
*s_int8array
;
196 extern PyrSymbol
*s_int16array
;
197 extern PyrSymbol
*s_int32array
;
198 extern PyrSymbol
*s_symbolarray
;
199 extern PyrSymbol
*s_floatarray
;
200 extern PyrSymbol
*s_doublearray
;
201 extern PyrSymbol
*s_point
;
202 extern PyrSymbol
*s_rect
;
203 extern PyrSymbol
*s_stream
;
204 extern PyrSymbol
*s_process
;
205 extern PyrSymbol
*s_main
;
206 extern PyrSymbol
*s_thread
;
207 extern PyrSymbol
*s_routine
;
208 extern PyrSymbol
*s_linear
, *s_exponential
, *s_gate
;
209 extern PyrSymbol
*s_env
;
211 extern PyrSymbol
*s_audio
, *s_control
, *s_scalar
;
212 extern PyrSymbol
*s_run
;
213 extern PyrSymbol
*s_next
;
214 extern PyrSymbol
*s_at
;
215 extern PyrSymbol
*s_put
;
216 extern PyrSymbol
*s_series
, *s_copyseries
, *s_putseries
;
217 extern PyrSymbol
*s_value
;
218 extern PyrSymbol
*s_performList
;
219 extern PyrSymbol
*s_superPerformList
;
220 extern PyrSymbol
*s_ugen
, *s_outputproxy
;
221 extern PyrSymbol
*s_new
, *s_ref
;
222 extern PyrSymbol
*s_synth
, *s_spawn
, *s_environment
, *s_event
;
223 extern PyrSymbol
*s_interpreter
;
224 extern PyrSymbol
*s_finalizer
;
225 extern PyrSymbol
*s_awake
;
226 extern PyrSymbol
*s_appclock
;
227 extern PyrSymbol
*s_systemclock
;
228 extern PyrSymbol
*s_server_shm_interface
;
231 extern int gFormatElemSize
[NUMOBJFORMATS
];
232 extern int gFormatElemCapc
[NUMOBJFORMATS
];
233 extern int gFormatElemTag
[NUMOBJFORMATS
];
235 void dumpObject(PyrObject
*obj
);
236 void dumpObjectSlot(PyrSlot
*slot
);
238 bool respondsTo(PyrSlot
*slot
, PyrSymbol
*selector
);
239 bool isSubclassOf(struct PyrClass
*classobj
, struct PyrClass
*testclass
);
241 extern struct PyrClass
* gTagClassTable
[16];
243 inline struct PyrClass
* classOfSlot(PyrSlot
*slot
)
247 if (IsFloat(slot
)) classobj
= class_float
;
248 else if ((tag
= GetTag(slot
) & 0xF) == 1) classobj
= slotRawObject(slot
)->classptr
;
249 else classobj
= gTagClassTable
[tag
];
254 typedef int (*ObjFuncPtr
)(struct VMGlobals
*, struct PyrObject
*);
256 void stringFromPyrString(PyrString
*obj
, char *str
, int maxlength
);
257 void pstringFromPyrString(PyrString
*obj
, unsigned char *str
, int maxlength
);
259 int instVarOffset(const char *classname
, const char *instvarname
);
260 int classVarOffset(const char *classname
, const char *classvarname
, PyrClass
** classobj
);
262 void fillSlots(PyrSlot
* slot
, int size
, PyrSlot
* fillslot
);
263 void nilSlots(PyrSlot
* slot
, int size
);
264 void zeroSlots(PyrSlot
* slot
, int size
);
266 int calcHash(PyrSlot
*a
);
267 int getIndexedFloat(struct PyrObject
*obj
, int index
, float *value
);
268 int getIndexedDouble(struct PyrObject
*obj
, int index
, double *value
);
270 inline int getIndexedVal(struct PyrObject
*obj
, int index
, float *value
)
272 return getIndexedFloat(obj
, index
, value
);
275 inline int getIndexedVal(struct PyrObject
*obj
, int index
, double *value
)
277 return getIndexedDouble(obj
, index
, value
);
280 void getIndexedSlot(struct PyrObject
*obj
, PyrSlot
*a
, int index
);
281 int putIndexedSlot(struct VMGlobals
*g
, struct PyrObject
*obj
, PyrSlot
*c
, int index
);
282 int putIndexedFloat(PyrObject
*obj
, double val
, int index
);
284 inline long ARRAYMAXINDEXSIZE(PyrObjectHdr
* obj
)
286 return (1L << obj
->obj_sizeclass
);
289 inline long MAXINDEXSIZE(PyrObjectHdr
* obj
)
291 return ((1L << obj
->obj_sizeclass
) * gFormatElemCapc
[ obj
->obj_format
]);
294 void InstallFinalizer(VMGlobals
* g
, PyrObject
*inObj
, int slotIndex
, ObjFuncPtr inFunc
);