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() { return ((obj_flags
& obj_marked
) != 0); } // BG2004-10-09 : the previous version did execute some hidden code in int -> bool conversion
93 bool IsPermanent() { return gc_color
== obj_permanent
; }
96 struct PyrObject
: public PyrObjectHdr
{
100 struct PyrList
: public PyrObjectHdr
105 struct PyrDoubleArray
: public PyrObjectHdr
110 struct PyrFloatArray
: public PyrObjectHdr
115 struct PyrInt32Array
: public PyrObjectHdr
120 struct PyrInt16Array
: public PyrObjectHdr
125 struct PyrInt8Array
: public PyrObjectHdr
130 struct PyrString
: public PyrObjectHdr
135 struct PyrSymbolArray
: public PyrObjectHdr
137 PyrSymbol
* symbols
[1];
140 extern struct PyrClass
*class_object
;
141 extern struct PyrClass
*class_array
;
142 extern struct PyrClass
*class_list
, *class_method
, *class_fundef
, *class_frame
, *class_class
;
143 extern struct PyrClass
*class_symbol
, *class_nil
;
144 extern struct PyrClass
*class_boolean
, *class_true
, *class_false
;
145 extern struct PyrClass
*class_int
, *class_char
, *class_float
, *class_complex
;
146 extern struct PyrClass
*class_rawptr
;
147 extern struct PyrClass
*class_string
;
148 extern struct PyrClass
*class_magnitude
, *class_number
, *class_collection
;
149 extern struct PyrClass
*class_sequenceable_collection
;
150 extern struct PyrClass
*class_arrayed_collection
;
151 extern struct PyrClass
*class_simple_number
;
152 extern struct PyrClass
*class_signal
;
153 extern struct PyrClass
*class_wavetable
;
154 extern struct PyrClass
*class_rawarray
;
155 extern struct PyrClass
*class_int8array
;
156 extern struct PyrClass
*class_int16array
;
157 extern struct PyrClass
*class_int32array
;
158 extern struct PyrClass
*class_symbolarray
;
159 extern struct PyrClass
*class_floatarray
;
160 extern struct PyrClass
*class_doublearray
;
161 extern struct PyrClass
*class_func
, *class_absfunc
;
162 extern struct PyrClass
*class_stream
;
163 extern struct PyrClass
*class_process
;
164 extern struct PyrClass
*class_interpreter
;
165 extern struct PyrClass
*class_thread
;
166 extern struct PyrClass
*class_routine
;
167 extern struct PyrClass
*class_finalizer
;
169 extern PyrSymbol
*s_none
;
170 extern PyrSymbol
*s_object
;
171 extern PyrSymbol
*s_bag
;
172 extern PyrSymbol
*s_set
;
173 extern PyrSymbol
*s_identityset
;
174 extern PyrSymbol
*s_dictionary
;
175 extern PyrSymbol
*s_identitydictionary
;
176 extern PyrSymbol
*s_linkedlist
;
177 extern PyrSymbol
*s_sortedlist
;
178 extern PyrSymbol
*s_array
;
179 extern PyrSymbol
*s_list
, *s_method
, *s_fundef
, *s_frame
, *s_class
;
180 extern PyrSymbol
*s_symbol
, *s_nil
;
181 extern PyrSymbol
*s_boolean
, *s_true
, *s_false
;
182 extern PyrSymbol
*s_int
, *s_char
, *s_color
, *s_float
, *s_complex
;
183 extern PyrSymbol
*s_rawptr
, *s_objptr
;
184 extern PyrSymbol
*s_string
;
185 extern PyrSymbol
*s_magnitude
, *s_number
, *s_collection
;
186 extern PyrSymbol
*s_ordered_collection
;
187 extern PyrSymbol
*s_sequenceable_collection
;
188 extern PyrSymbol
*s_arrayed_collection
;
189 extern PyrSymbol
*s_simple_number
;
190 extern PyrSymbol
*s_signal
;
191 extern PyrSymbol
*s_wavetable
;
192 extern PyrSymbol
*s_int8array
;
193 extern PyrSymbol
*s_int16array
;
194 extern PyrSymbol
*s_int32array
;
195 extern PyrSymbol
*s_symbolarray
;
196 extern PyrSymbol
*s_floatarray
;
197 extern PyrSymbol
*s_doublearray
;
198 extern PyrSymbol
*s_point
;
199 extern PyrSymbol
*s_rect
;
200 extern PyrSymbol
*s_stream
;
201 extern PyrSymbol
*s_process
;
202 extern PyrSymbol
*s_main
;
203 extern PyrSymbol
*s_thread
;
204 extern PyrSymbol
*s_routine
;
205 extern PyrSymbol
*s_linear
, *s_exponential
, *s_gate
;
206 extern PyrSymbol
*s_env
;
208 extern PyrSymbol
*s_audio
, *s_control
, *s_scalar
;
209 extern PyrSymbol
*s_run
;
210 extern PyrSymbol
*s_next
;
211 extern PyrSymbol
*s_at
;
212 extern PyrSymbol
*s_put
;
213 extern PyrSymbol
*s_series
, *s_copyseries
, *s_putseries
;
214 extern PyrSymbol
*s_value
;
215 extern PyrSymbol
*s_performList
;
216 extern PyrSymbol
*s_superPerformList
;
217 extern PyrSymbol
*s_ugen
, *s_outputproxy
;
218 extern PyrSymbol
*s_new
, *s_ref
;
219 extern PyrSymbol
*s_synth
, *s_spawn
, *s_environment
, *s_event
;
220 extern PyrSymbol
*s_interpreter
;
221 extern PyrSymbol
*s_finalizer
;
222 extern PyrSymbol
*s_awake
;
223 extern PyrSymbol
*s_appclock
;
224 extern PyrSymbol
*s_systemclock
;
227 extern int gFormatElemSize
[NUMOBJFORMATS
];
228 extern int gFormatElemCapc
[NUMOBJFORMATS
];
229 extern int gFormatElemTag
[NUMOBJFORMATS
];
231 void dumpObject(PyrObject
*obj
);
232 void dumpObjectSlot(PyrSlot
*slot
);
234 bool respondsTo(PyrSlot
*slot
, PyrSymbol
*selector
);
235 bool isSubclassOf(struct PyrClass
*classobj
, struct PyrClass
*testclass
);
237 const int kFloatTagIndex
= 11;
238 extern struct PyrClass
* gTagClassTable
[16];
240 inline struct PyrClass
* classOfSlot(PyrSlot
*slot
)
244 if (IsFloat(slot
)) classobj
= gTagClassTable
[kFloatTagIndex
];
245 else if ((tag
= GetTag(slot
) & 0xF) == 1) classobj
= slotRawObject(slot
)->classptr
;
246 else classobj
= gTagClassTable
[tag
];
251 typedef int (*ObjFuncPtr
)(struct VMGlobals
*, struct PyrObject
*);
253 void stringFromPyrString(PyrString
*obj
, char *str
, int maxlength
);
254 void pstringFromPyrString(PyrString
*obj
, unsigned char *str
, int maxlength
);
256 int instVarOffset(const char *classname
, const char *instvarname
);
257 int classVarOffset(const char *classname
, const char *classvarname
, PyrClass
** classobj
);
259 void fillSlots(PyrSlot
* slot
, int size
, PyrSlot
* fillslot
);
260 void nilSlots(PyrSlot
* slot
, int size
);
261 void zeroSlots(PyrSlot
* slot
, int size
);
263 int calcHash(PyrSlot
*a
);
264 int getIndexedFloat(struct PyrObject
*obj
, int index
, float *value
);
265 int getIndexedDouble(struct PyrObject
*obj
, int index
, double *value
);
267 inline int getIndexedVal(struct PyrObject
*obj
, int index
, float *value
)
269 return getIndexedFloat(obj
, index
, value
);
272 inline int getIndexedVal(struct PyrObject
*obj
, int index
, double *value
)
274 return getIndexedDouble(obj
, index
, value
);
277 void getIndexedSlot(struct PyrObject
*obj
, PyrSlot
*a
, int index
);
278 int putIndexedSlot(struct VMGlobals
*g
, struct PyrObject
*obj
, PyrSlot
*c
, int index
);
279 int putIndexedFloat(PyrObject
*obj
, double val
, int index
);
281 inline int ARRAYMAXINDEXSIZE(PyrObjectHdr
* obj
)
283 return (1L << obj
->obj_sizeclass
);
286 inline int MAXINDEXSIZE(PyrObjectHdr
* obj
)
288 return ((1L << obj
->obj_sizeclass
) * gFormatElemCapc
[ obj
->obj_format
]);
291 void InstallFinalizer(VMGlobals
* g
, PyrObject
*inObj
, int slotIndex
, ObjFuncPtr inFunc
);