Explicitly include a boost "windows" folder even on linux
[supercollider.git] / include / lang / PyrObject.h
blob099acfcf50bfe2742871fd9b621e4745f10d763f
1 /*
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.
26 #ifndef _PYROBJECT_H_
27 #define _PYROBJECT_H_
29 #include "PyrSlot.h"
31 /* special gc colors */
32 enum {
33 obj_permanent = 1, // sent to gc->New as a flag
34 obj_gcmarker = 2 // gc treadmill marker
37 /* obj flag fields */
38 enum {
39 obj_inaccessible = 4,
40 obj_immutable = 16,
41 obj_marked = 128
44 /* format types : */
45 enum {
46 obj_notindexed,
47 obj_slot,
48 obj_double,
49 obj_float,
50 obj_int32,
51 obj_int16,
52 obj_int8,
53 obj_char,
54 obj_symbol,
56 NUMOBJFORMATS
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
68 obj_flags :
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.
76 struct PyrObjectHdr {
77 struct PyrObjectHdr *prev, *next;
78 struct PyrClass *classptr;
79 int size;
81 unsigned char obj_format;
82 unsigned char obj_sizeclass;
83 unsigned char obj_flags;
84 unsigned char gc_color;
86 int scratch1;
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 {
97 PyrSlot slots[1];
100 struct PyrList : public PyrObjectHdr
102 PyrSlot array;
105 struct PyrDoubleArray : public PyrObjectHdr
107 double d[1];
110 struct PyrFloatArray : public PyrObjectHdr
112 float f[1];
115 struct PyrInt32Array : public PyrObjectHdr
117 uint32 i[1];
120 struct PyrInt16Array : public PyrObjectHdr
122 uint16 i[1];
125 struct PyrInt8Array : public PyrObjectHdr
127 uint8 b[1];
130 struct PyrString : public PyrObjectHdr
132 char s[1];
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;
168 extern struct PyrClass *class_server_shm_interface;
170 extern PyrSymbol *s_none;
171 extern PyrSymbol *s_object;
172 extern PyrSymbol *s_bag;
173 extern PyrSymbol *s_set;
174 extern PyrSymbol *s_identityset;
175 extern PyrSymbol *s_dictionary;
176 extern PyrSymbol *s_identitydictionary;
177 extern PyrSymbol *s_linkedlist;
178 extern PyrSymbol *s_sortedlist;
179 extern PyrSymbol *s_array;
180 extern PyrSymbol *s_list, *s_method, *s_fundef, *s_frame, *s_class;
181 extern PyrSymbol *s_symbol, *s_nil;
182 extern PyrSymbol *s_boolean, *s_true, *s_false;
183 extern PyrSymbol *s_int, *s_char, *s_color, *s_float, *s_complex;
184 extern PyrSymbol *s_rawptr, *s_objptr;
185 extern PyrSymbol *s_string;
186 extern PyrSymbol *s_magnitude, *s_number, *s_collection;
187 extern PyrSymbol *s_ordered_collection;
188 extern PyrSymbol *s_sequenceable_collection;
189 extern PyrSymbol *s_arrayed_collection;
190 extern PyrSymbol *s_simple_number;
191 extern PyrSymbol *s_signal;
192 extern PyrSymbol *s_wavetable;
193 extern PyrSymbol *s_int8array;
194 extern PyrSymbol *s_int16array;
195 extern PyrSymbol *s_int32array;
196 extern PyrSymbol *s_symbolarray;
197 extern PyrSymbol *s_floatarray;
198 extern PyrSymbol *s_doublearray;
199 extern PyrSymbol *s_point;
200 extern PyrSymbol *s_rect;
201 extern PyrSymbol *s_stream;
202 extern PyrSymbol *s_process;
203 extern PyrSymbol *s_main;
204 extern PyrSymbol *s_thread;
205 extern PyrSymbol *s_routine;
206 extern PyrSymbol *s_linear, *s_exponential, *s_gate;
207 extern PyrSymbol *s_env;
209 extern PyrSymbol *s_audio, *s_control, *s_scalar;
210 extern PyrSymbol *s_run;
211 extern PyrSymbol *s_next;
212 extern PyrSymbol *s_at;
213 extern PyrSymbol *s_put;
214 extern PyrSymbol *s_series, *s_copyseries, *s_putseries;
215 extern PyrSymbol *s_value;
216 extern PyrSymbol *s_performList;
217 extern PyrSymbol *s_superPerformList;
218 extern PyrSymbol *s_ugen, *s_outputproxy;
219 extern PyrSymbol *s_new, *s_ref;
220 extern PyrSymbol *s_synth, *s_spawn, *s_environment, *s_event;
221 extern PyrSymbol *s_interpreter;
222 extern PyrSymbol *s_finalizer;
223 extern PyrSymbol *s_awake;
224 extern PyrSymbol *s_appclock;
225 extern PyrSymbol *s_systemclock;
226 extern PyrSymbol *s_server_shm_interface;
229 extern int gFormatElemSize[NUMOBJFORMATS];
230 extern int gFormatElemCapc[NUMOBJFORMATS];
231 extern int gFormatElemTag[NUMOBJFORMATS];
233 void dumpObject(PyrObject *obj);
234 void dumpObjectSlot(PyrSlot *slot);
236 bool respondsTo(PyrSlot *slot, PyrSymbol *selector);
237 bool isSubclassOf(struct PyrClass *classobj, struct PyrClass *testclass);
239 const int kFloatTagIndex = 11;
240 extern struct PyrClass* gTagClassTable[16];
242 inline struct PyrClass* classOfSlot(PyrSlot *slot)
244 PyrClass *classobj;
245 int tag;
246 if (IsFloat(slot)) classobj = gTagClassTable[kFloatTagIndex];
247 else if ((tag = GetTag(slot) & 0xF) == 1) classobj = slotRawObject(slot)->classptr;
248 else classobj = gTagClassTable[tag];
250 return classobj;
253 typedef int (*ObjFuncPtr)(struct VMGlobals*, struct PyrObject*);
255 void stringFromPyrString(PyrString *obj, char *str, int maxlength);
256 void pstringFromPyrString(PyrString *obj, unsigned char *str, int maxlength);
258 int instVarOffset(const char *classname, const char *instvarname);
259 int classVarOffset(const char *classname, const char *classvarname, PyrClass** classobj);
261 void fillSlots(PyrSlot* slot, int size, PyrSlot* fillslot);
262 void nilSlots(PyrSlot* slot, int size);
263 void zeroSlots(PyrSlot* slot, int size);
265 int calcHash(PyrSlot *a);
266 int getIndexedFloat(struct PyrObject *obj, int index, float *value);
267 int getIndexedDouble(struct PyrObject *obj, int index, double *value);
269 inline int getIndexedVal(struct PyrObject *obj, int index, float *value)
271 return getIndexedFloat(obj, index, value);
274 inline int getIndexedVal(struct PyrObject *obj, int index, double *value)
276 return getIndexedDouble(obj, index, value);
279 void getIndexedSlot(struct PyrObject *obj, PyrSlot *a, int index);
280 int putIndexedSlot(struct VMGlobals *g, struct PyrObject *obj, PyrSlot *c, int index);
281 int putIndexedFloat(PyrObject *obj, double val, int index);
283 inline int ARRAYMAXINDEXSIZE(PyrObjectHdr* obj)
285 return (1L << obj->obj_sizeclass);
288 inline int MAXINDEXSIZE(PyrObjectHdr* obj)
290 return ((1L << obj->obj_sizeclass) * gFormatElemCapc[ obj->obj_format ]);
293 void InstallFinalizer(VMGlobals* g, PyrObject *inObj, int slotIndex, ObjFuncPtr inFunc);
295 /////
297 #endif