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 This file contains the definitions of the core objects that implement the class system.
29 #include "PyrObject.h"
30 #include "VMGlobals.h"
32 #define classClassNumInstVars 19
34 enum { classIsIntrinsic
= 1, classHasIndexableInstances
= 2 };
36 struct PyrClass
: public PyrObjectHdr
45 PyrSlot classVarNames
;
46 PyrSlot iprototype
; // instance prototype
47 PyrSlot cprototype
; // class var prototype
50 PyrSlot constValues
; // const values
52 PyrSlot instanceFormat
;
53 PyrSlot instanceFlags
;
56 PyrSlot maxSubclassIndex
; // used by isKindOf
59 PyrSlot classVarIndex
;
64 inline bool isKindOf(PyrObjectHdr
*obj
, struct PyrClass
*testclass
)
66 int objClassIndex
= slotRawInt(&obj
->classptr
->classIndex
);
67 return objClassIndex
>= slotRawInt(&testclass
->classIndex
) && objClassIndex
<= slotRawInt(&testclass
->maxSubclassIndex
);
70 inline bool isKindOfSlot(PyrSlot
*slot
, struct PyrClass
*testclass
)
72 return IsObj(slot
) && isKindOf(slotRawObject(slot
), testclass
);
82 struct PyrFrame
: public PyrObjectHdr
94 struct PyrProcess
: public PyrObjectHdr
99 PyrSlot curThread
, mainThread
;
100 PyrSlot sysSchedulerQueue
;
101 PyrSlot nowExecutingPath
;
105 enum { tInit
, tStart
, tReady
, tRunning
, tSleeping
, tSuspended
, tDone
};
107 struct PyrThread
: public PyrObjectHdr
109 PyrSlot state
, func
, stack
, method
, block
, frame
, ip
, sp
;
110 PyrSlot numpop
, receiver
, numArgsPushed
;
111 PyrSlot parent
, terminalValue
;
112 PyrSlot primitiveError
;
113 PyrSlot primitiveIndex
;
115 PyrSlot beats
, seconds
, clock
, nextBeat
, endBeat
, endValue
;
117 PyrSlot exceptionHandler
;
118 PyrSlot threadPlayer
;
119 PyrSlot executingPath
;
120 PyrSlot oldExecutingPath
;
124 #define EVALSTACKDEPTH 512
130 #ifdef PYR_SLOTS_GENERIC
131 long padding
; // used for the tag in the generic pyrslot implementation
133 unsigned short unused1
;
134 unsigned short specialIndex
;
135 unsigned short methType
;
136 unsigned short frameSize
;
138 #ifdef PYR_SLOTS_GENERIC
139 long padding2
; // used for the tag in generic pyrslot implementation, second slot
142 unsigned char unused2
;
143 unsigned char numargs
;
144 unsigned char varargs
;
145 unsigned char numvars
;
146 unsigned char numtemps
;
147 unsigned char needsHeapContext
;
148 unsigned char popSize
;
149 unsigned char posargs
;
153 #define METHRAW(obj) ((PyrMethodRaw*)&(((PyrBlock*)obj)->rawData1))
155 struct PyrBlock
: public PyrObjectHdr
160 PyrSlot code
; // byte codes, nil if inlined
161 PyrSlot selectors
; // method selectors, class names, closures table
162 PyrSlot constants
; // floating point constants table (to alleviate the literal table problem)
163 PyrSlot prototypeFrame
; // prototype of an activation frame
164 PyrSlot contextDef
; // ***defining block context
165 PyrSlot argNames
; // ***arguments to block
166 PyrSlot varNames
; // ***variables in block
167 PyrSlot sourceCode
; // source code if it is a closed function.
170 struct PyrMethod
: public PyrBlock
174 PyrSlot primitiveName
;
198 struct PyrClosure
: public PyrObjectHdr
205 struct PyrInterpreter
: public PyrObjectHdr
208 PyrSlot cmdLine
, context
;
209 PyrSlot a
, b
, c
, d
, e
, f
, g
, h
, i
, j
;
210 PyrSlot k
, l
, m
, n
, o
, p
, q
, r
, s
, t
;
211 PyrSlot u
, v
, w
, x
, y
, z
;
212 PyrSlot codeDump
, preProcessor
;
234 extern PyrSlot gSpecialValues
[svNumSpecialValues
];
236 extern PyrMethod
*gNullMethod
; // used to fill row table
238 PyrObject
* instantiateObject(class PyrGC
*gc
, PyrClass
* classobj
, int size
,
239 bool fill
, bool collect
);
241 PyrObject
* newPyrObject(class PyrGC
*gc
, size_t inNumBytes
, int inFlags
, int inFormat
, bool inCollect
);
242 PyrString
* newPyrString(class PyrGC
*gc
, const char *s
, int flags
, bool collect
);
243 PyrString
* newPyrStringN(class PyrGC
*gc
, int size
, int flags
, bool collect
);
244 PyrObject
* newPyrArray(class PyrGC
*gc
, int size
, int flags
, bool collect
);
245 PyrSymbolArray
* newPyrSymbolArray(class PyrGC
*gc
, int size
, int flags
, bool collect
);
246 PyrInt8Array
* newPyrInt8Array(class PyrGC
*gc
, int size
, int flags
, bool collect
);
247 PyrInt32Array
* newPyrInt32Array(class PyrGC
*gc
, int size
, int flags
, bool collect
);
248 PyrDoubleArray
* newPyrDoubleArray(class PyrGC
*gc
, int size
, int flags
, bool collect
);
250 PyrObject
* copyObject(class PyrGC
*gc
, PyrObject
*inobj
, bool collect
);
251 PyrObject
* copyObjectRange(class PyrGC
*gc
, PyrObject
*inobj
, int start
, int end
, bool collect
);