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 executingPath
;
119 PyrSlot oldExecutingPath
;
123 #define EVALSTACKDEPTH 512
129 #ifdef PYR_SLOTS_GENERIC
130 long padding
; // used for the tag in the generic pyrslot implementation
132 unsigned short unused1
;
133 unsigned short specialIndex
;
134 unsigned short methType
;
135 unsigned short frameSize
;
137 #ifdef PYR_SLOTS_GENERIC
138 long padding2
; // used for the tag in generic pyrslot implementation, second slot
141 unsigned char unused2
;
142 unsigned char numargs
;
143 unsigned char varargs
;
144 unsigned char numvars
;
145 unsigned char numtemps
;
146 unsigned char needsHeapContext
;
147 unsigned char popSize
;
148 unsigned char posargs
;
152 #define METHRAW(obj) ((PyrMethodRaw*)&(((PyrBlock*)obj)->rawData1))
154 struct PyrBlock
: public PyrObjectHdr
159 PyrSlot code
; // byte codes, nil if inlined
160 PyrSlot selectors
; // method selectors, class names, closures table
161 PyrSlot constants
; // floating point constants table (to alleviate the literal table problem)
162 PyrSlot prototypeFrame
; // prototype of an activation frame
163 PyrSlot contextDef
; // ***defining block context
164 PyrSlot argNames
; // ***arguments to block
165 PyrSlot varNames
; // ***variables in block
166 PyrSlot sourceCode
; // source code if it is a closed function.
169 struct PyrMethod
: public PyrBlock
173 PyrSlot primitiveName
;
197 struct PyrClosure
: public PyrObjectHdr
204 struct PyrInterpreter
: public PyrObjectHdr
207 PyrSlot cmdLine
, context
;
208 PyrSlot a
, b
, c
, d
, e
, f
, g
, h
, i
, j
;
209 PyrSlot k
, l
, m
, n
, o
, p
, q
, r
, s
, t
;
210 PyrSlot u
, v
, w
, x
, y
, z
;
211 PyrSlot codeDump
, preProcessor
;
233 extern PyrSlot gSpecialValues
[svNumSpecialValues
];
235 extern PyrMethod
*gNullMethod
; // used to fill row table
237 PyrObject
* instantiateObject(class PyrGC
*gc
, PyrClass
* classobj
, int size
,
238 bool fill
, bool collect
);
240 PyrObject
* newPyrObject(class PyrGC
*gc
, size_t inNumBytes
, int inFlags
, int inFormat
, bool inCollect
);
241 PyrString
* newPyrString(class PyrGC
*gc
, const char *s
, int flags
, bool collect
);
242 PyrString
* newPyrStringN(class PyrGC
*gc
, int size
, int flags
, bool collect
);
243 PyrObject
* newPyrArray(class PyrGC
*gc
, int size
, int flags
, bool collect
);
244 PyrSymbolArray
* newPyrSymbolArray(class PyrGC
*gc
, int size
, int flags
, bool collect
);
245 PyrInt8Array
* newPyrInt8Array(class PyrGC
*gc
, int size
, int flags
, bool collect
);
246 PyrInt32Array
* newPyrInt32Array(class PyrGC
*gc
, int size
, int flags
, bool collect
);
247 PyrDoubleArray
* newPyrDoubleArray(class PyrGC
*gc
, int size
, int flags
, bool collect
);
249 PyrObject
* copyObject(class PyrGC
*gc
, PyrObject
*inobj
, bool collect
);
250 PyrObject
* copyObjectRange(class PyrGC
*gc
, PyrObject
*inobj
, int start
, int end
, bool collect
);