supernova: fix for small audio vector sizes
[supercollider.git] / lang / LangPrimSource / PyrCharPrim.cpp
blobf2dc9e12269789596f623646715c6b7c0433805a
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 Primitives for Char.
26 #include <ctype.h>
27 #include "PyrPrimitive.h"
28 #include "VMGlobals.h"
31 int prToLower(struct VMGlobals *g, int numArgsPushed);
32 int prToLower(struct VMGlobals *g, int numArgsPushed)
34 PyrSlot *a;
36 a = g->sp;
38 SetRawChar(a, tolower(slotRawChar(a)));
40 return errNone;
43 int prToUpper(struct VMGlobals *g, int numArgsPushed);
44 int prToUpper(struct VMGlobals *g, int numArgsPushed)
46 PyrSlot *a;
48 a = g->sp;
50 SetRawChar(a, toupper(slotRawChar(a)));
52 return errNone;
55 int prIsAlpha(struct VMGlobals *g, int numArgsPushed);
56 int prIsAlpha(struct VMGlobals *g, int numArgsPushed)
58 PyrSlot *a;
60 a = g->sp;
62 if (isalpha(slotRawChar(a))) { SetTrue(a); }
63 else { SetFalse(a); }
65 return errNone;
68 int prIsAlphaNum(struct VMGlobals *g, int numArgsPushed);
69 int prIsAlphaNum(struct VMGlobals *g, int numArgsPushed)
71 PyrSlot *a;
73 a = g->sp;
75 if (isalnum(slotRawChar(a))) { SetTrue(a); }
76 else { SetFalse(a); }
78 return errNone;
81 int prIsControl(struct VMGlobals *g, int numArgsPushed);
82 int prIsControl(struct VMGlobals *g, int numArgsPushed)
84 PyrSlot *a;
86 a = g->sp;
88 if (iscntrl(slotRawChar(a))) { SetTrue(a); }
89 else { SetFalse(a); }
91 return errNone;
94 int prIsDigit(struct VMGlobals *g, int numArgsPushed);
95 int prIsDigit(struct VMGlobals *g, int numArgsPushed)
97 PyrSlot *a;
99 a = g->sp;
101 if (isdigit(slotRawChar(a))) { SetTrue(a); }
102 else { SetFalse(a); }
104 return errNone;
107 int prIsPrint(struct VMGlobals *g, int numArgsPushed);
108 int prIsPrint(struct VMGlobals *g, int numArgsPushed)
110 PyrSlot *a;
112 a = g->sp;
114 if (isprint(slotRawChar(a))) { SetTrue(a); }
115 else { SetFalse(a); }
117 return errNone;
120 int prIsPunct(struct VMGlobals *g, int numArgsPushed);
121 int prIsPunct(struct VMGlobals *g, int numArgsPushed)
123 PyrSlot *a;
125 a = g->sp;
127 if (ispunct(slotRawChar(a))) { SetTrue(a); }
128 else { SetFalse(a); }
130 return errNone;
133 int prIsSpace(struct VMGlobals *g, int numArgsPushed);
134 int prIsSpace(struct VMGlobals *g, int numArgsPushed)
136 PyrSlot *a;
138 a = g->sp;
140 if (isspace(slotRawChar(a))) { SetTrue(a); }
141 else { SetFalse(a); }
143 return errNone;
146 int prAsciiValue(struct VMGlobals *g, int numArgsPushed);
147 int prAsciiValue(struct VMGlobals *g, int numArgsPushed)
149 PyrSlot *a;
151 a = g->sp;
153 SetTagRaw(a, tagInt);
155 return errNone;
158 int prDigitValue(struct VMGlobals *g, int numArgsPushed);
159 int prDigitValue(struct VMGlobals *g, int numArgsPushed)
161 PyrSlot *a;
162 char c;
164 a = g->sp;
166 c = slotRawChar(a);
167 if (c >= '0' && c <= '9') {
168 SetInt(a, c - '0');
169 } else if (c >= 'a' && c <= 'z') {
170 SetInt(a, c - 'a' + 10);
171 } else if (c >= 'A' && c <= 'Z') {
172 SetInt(a, c - 'A' + 10);
173 } else {
174 return errFailed;
177 return errNone;
181 int prAsAscii(struct VMGlobals *g, int numArgsPushed);
182 int prAsAscii(struct VMGlobals *g, int numArgsPushed)
184 PyrSlot *a;
186 a = g->sp;
187 SetChar(a, slotRawInt(a) & 255);
189 return errNone;
192 int prAsDigit(struct VMGlobals *g, int numArgsPushed);
193 int prAsDigit(struct VMGlobals *g, int numArgsPushed)
195 PyrSlot *a;
196 int c;
198 a = g->sp;
200 c = slotRawInt(a);
201 if (c >= 0 && c <= 9) {
202 SetChar(a, slotRawInt(a) + '0');
203 } else if (c >= 10 && c <= 35) {
204 SetChar(a, slotRawInt(a) + 'A' - 10);
205 } else {
206 return errFailed;
209 return errNone;
212 void initCharPrimitives();
213 void initCharPrimitives()
215 int base, index = 0;
217 base = nextPrimitiveIndex();
219 definePrimitive(base, index++, "_AsciiValue", prAsciiValue, 1, 0);
220 definePrimitive(base, index++, "_DigitValue", prDigitValue, 1, 0);
221 definePrimitive(base, index++, "_AsAscii", prAsAscii, 1, 0);
222 definePrimitive(base, index++, "_AsDigit", prAsDigit, 1, 0);
223 definePrimitive(base, index++, "_ToLower", prToLower, 1, 0);
224 definePrimitive(base, index++, "_ToUpper", prToUpper, 1, 0);
225 definePrimitive(base, index++, "_IsAlpha", prIsAlpha, 1, 0);
226 definePrimitive(base, index++, "_IsAlphaNum", prIsAlphaNum, 1, 0);
227 definePrimitive(base, index++, "_IsPrint", prIsPrint, 1, 0);
228 definePrimitive(base, index++, "_IsPunct", prIsPunct, 1, 0);
229 definePrimitive(base, index++, "_IsControl", prIsControl, 1, 0);
230 definePrimitive(base, index++, "_IsSpace", prIsSpace, 1, 0);
231 definePrimitive(base, index++, "_IsDecDigit", prIsDigit, 1, 0);
237 #if _SC_PLUGINS_
240 #include "SCPlugin.h"
242 // export the function that SC will call to load the plug in.
243 #pragma export on
244 extern "C" { SCPlugIn* loadPlugIn(void); }
245 #pragma export off
248 // define plug in object
249 class APlugIn : public SCPlugIn
251 public:
252 APlugIn();
253 virtual ~APlugIn();
255 virtual void AboutToCompile();
258 APlugIn::APlugIn()
260 // constructor for plug in
263 APlugIn::~APlugIn()
265 // destructor for plug in
268 void APlugIn::AboutToCompile()
270 // this is called each time the class library is compiled.
271 initCharPrimitives();
274 // This function is called when the plug in is loaded into SC.
275 // It returns an instance of APlugIn.
276 SCPlugIn* loadPlugIn()
278 return new APlugIn();
281 #endif