Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / include / lang / PyrKernel.h
blob24e8937badd46f4d860913ba7ecf3d73d16ef38a
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 This file contains the definitions of the core objects that implement the class system.
26 #ifndef _PYRKERNEL_H_
27 #define _PYRKERNEL_H_
29 #include "PyrObject.h"
30 #include "VMGlobals.h"
32 #define classClassNumInstVars 19
34 enum { classIsIntrinsic = 1, classHasIndexableInstances = 2 };
36 struct PyrClass : public PyrObjectHdr
38 PyrSlot name;
39 PyrSlot nextclass;
40 PyrSlot superclass;
41 PyrSlot subclasses;
42 PyrSlot methods;
44 PyrSlot instVarNames;
45 PyrSlot classVarNames;
46 PyrSlot iprototype; // instance prototype
47 PyrSlot cprototype; // class var prototype
49 PyrSlot constNames;
50 PyrSlot constValues; // const values
52 PyrSlot instanceFormat;
53 PyrSlot instanceFlags;
54 PyrSlot classIndex;
55 PyrSlot classFlags;
56 PyrSlot maxSubclassIndex; // used by isKindOf
57 PyrSlot filenameSym;
58 PyrSlot charPos;
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);
76 operations on class:
77 numInstVars()
78 numClassVars()
82 struct PyrFrame : public PyrObjectHdr
84 PyrSlot method;
85 PyrSlot caller;
86 PyrSlot context;
87 PyrSlot homeContext;
88 PyrSlot ip;
89 PyrSlot vars[1];
92 #define FRAMESIZE 5
94 struct PyrProcess : public PyrObjectHdr
97 PyrSlot classVars;
98 PyrSlot interpreter;
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;
114 PyrSlot randData;
115 PyrSlot beats, seconds, clock, nextBeat, endBeat, endValue;
116 PyrSlot environment;
117 PyrSlot exceptionHandler;
118 PyrSlot threadPlayer;
119 PyrSlot executingPath;
120 PyrSlot oldExecutingPath;
121 PyrSlot stackSize;
124 #define EVALSTACKDEPTH 512
128 struct PyrMethodRaw
130 #ifdef PYR_SLOTS_GENERIC
131 long padding; // used for the tag in the generic pyrslot implementation
132 #endif
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
140 #endif
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
158 PyrSlot rawData1;
159 PyrSlot rawData2;
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
172 PyrSlot ownerclass;
173 PyrSlot name;
174 PyrSlot primitiveName;
175 PyrSlot filenameSym;
176 PyrSlot charPos;
177 //PyrSlot byteMeter;
178 //PyrSlot callMeter;
181 enum {
182 methNormal = 0,
183 methReturnSelf,
184 methReturnLiteral,
185 methReturnArg,
186 methReturnInstVar,
187 methAssignInstVar,
188 methReturnClassVar,
189 methAssignClassVar,
190 methRedirect,
191 methRedirectSuper,
192 methForwardInstVar,
193 methForwardClassVar,
194 methPrimitive,
195 methBlock
198 struct PyrClosure : public PyrObjectHdr
201 PyrSlot block;
202 PyrSlot context;
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;
215 /* special values */
216 enum {
217 svNil,
218 svFalse,
219 svTrue,
220 svNegOne,
221 svZero,
222 svOne,
223 svTwo,
224 svFHalf,
225 svFNegOne,
226 svFZero,
227 svFOne,
228 svFTwo,
229 svInf,
231 svNumSpecialValues
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);
253 #endif