Landed sourcepawn-1.2. The big changes:
1) JIT compilation/optimization now occurs per-function, and only when functions are first used. We're now officially a whole-method JIT rather than an AOT compiler (albiet, still a simple JIT). This has two implications: Functions are now much better abstracted internally, and loading a plugin is now much less expensive. If a function contains calls to other functions, THOSE functions are only compiled when they're invoked as well.
2) I've removed debug mode. We always show full backtraces now, as there was a very cheap way to implement this which really cleaned up everything. This is great for a number of reasons -- there's less code, the JIT is better designed, we don't need to relocate debug tables, and best of all we no longer have to tell users to enable debug mode at their own expense.
3 * =============================================================================
4 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _float_included
36 #define _float_included
39 * Converts an integer into a floating point value.
41 * @param value Integer to convert.
42 * @return Floating point value.
44 native Float:float(value);
47 * Multiplies two floats together.
49 * @param oper1 First value.
50 * @param oper2 Second value.
51 * @return oper1*oper2.
53 native Float:FloatMul(Float:oper1, Float:oper2);
56 * Divides the dividend by the divisor.
58 * @param dividend First value.
59 * @param divisor Second value.
60 * @return dividend/divisor.
62 native Float:FloatDiv(Float:dividend, Float:divisor);
65 * Adds two floats together.
67 * @param oper1 First value.
68 * @param oper2 Second value.
69 * @return oper1+oper2.
71 native Float:FloatAdd(Float:oper1, Float:oper2);
74 * Subtracts oper2 from oper1.
76 * @param oper1 First value.
77 * @param oper2 Second value.
78 * @return oper1-oper2.
80 native Float:FloatSub(Float:oper1, Float:oper2);
83 * Returns the decimal part of a float.
85 * @param value Input value.
86 * @return Decimal part.
88 native Float:FloatFraction(Float:value);
91 * Rounds a float to the closest integer to zero.
93 * @param value Input value to be rounded.
94 * @return Rounded value.
96 native RoundToZero(Float:value);
99 * Rounds a float to the next highest integer value.
101 * @param value Input value to be rounded.
102 * @return Rounded value.
104 native RoundToCeil(Float:value);
107 * Rounds a float to the next lowest integer value.
109 * @param value Input value to be rounded.
110 * @return Rounded value.
112 native RoundToFloor(Float:value);
115 * Standard IEEE rounding.
117 * @param value Input value to be rounded.
118 * @return Rounded value.
120 native RoundToNearest(Float:value);
123 * Compares two floats.
125 * @param fOne First value.
126 * @param fTwo Second value.
127 * @return Returns 1 if the first argument is greater than the second argument.
128 * Returns -1 if the first argument is smaller than the second argument.
129 * Returns 0 if both arguments are equal.
131 native FloatCompare(Float:fOne, Float:fTwo);
134 * Returns the square root of the input value, equivalent to floatpower(value, 0.5).
136 * @param value Input value.
137 * @return Square root of the value.
139 native Float:SquareRoot(Float:value);
142 * Returns the value raised to the power of the exponent.
144 * @param value Value to be raised.
145 * @param exponent Value to raise the base.
146 * @return value^exponent.
148 native Float:Pow(Float:value, Float:exponent);
151 * Returns the value of raising the input by e.
153 * @param value Input value.
154 * @return exp(value).
156 native Float:Exponential(Float:value);
159 * Returns the logarithm of any base specified.
161 * @param value Input value.
162 * @param base Logarithm base to use, default is 10.
163 * @return log(value)/log(base).
165 native Float:Logarithm(Float:value, Float:base=10.0);
168 * Returns the sine of the argument.
170 * @param value Input value in radians.
171 * @return sin(value).
173 native Float:Sine(Float:value);
176 * Returns the cosine of the argument.
178 * @param value Input value in radians.
179 * @return cos(value).
181 native Float:Cosine(Float:value);
184 * Returns the tangent of the argument.
186 * @param value Input value in radians.
187 * @return tan(value).
189 native Float:Tangent(Float:value);
192 * Returns an absolute value.
194 * @param value Input value.
195 * @return Absolute value of the input.
197 native Float:FloatAbs(Float:value);
200 * Returns the arctangent of the input value.
202 * @param angle Input value.
203 * @return atan(value) in radians.
205 native Float:ArcTangent(Float:angle);
208 * Returns the arccosine of the input value.
210 * @param angle Input value.
211 * @return acos(value) in radians.
213 native Float:ArcCosine(Float:angle);
216 * Returns the arcsine of the input value.
218 * @param angle Input value.
219 * @return asin(value) in radians.
221 native Float:ArcSine(Float:angle);
224 * Returns the arctangent2 of the input values.
226 * @param x Horizontal value.
227 * @param y Vertical value.
228 * @return atan2(value) in radians.
230 native Float:ArcTangent2(Float:x, Float:y);
233 * Rounds a floating point number using the "round to nearest" algorithm.
235 * @param value Floating point value to round.
236 * @return The value rounded to the nearest integer.
238 stock RoundFloat(Float:value)
240 return RoundToNearest(value);
244 * User defined operators.
247 #pragma rational Float
249 native Float:operator*(Float:oper1, Float:oper2) = FloatMul;
250 native Float:operator/(Float:oper1, Float:oper2) = FloatDiv;
251 native Float:operator+(Float:oper1, Float:oper2) = FloatAdd;
252 native Float:operator-(Float:oper1, Float:oper2) = FloatSub;
254 stock Float:operator++(Float:oper)
259 stock Float:operator--(Float:oper)
264 stock Float:operator-(Float:oper)
266 return oper^Float:((-1)^((-1)/2)); /* IEEE values are sign/magnitude */
269 stock Float:operator*(Float:oper1, oper2)
271 return FloatMul(oper1, float(oper2)); /* "*" is commutative */
274 stock Float:operator/(Float:oper1, oper2)
276 return FloatDiv(oper1, float(oper2));
279 stock Float:operator/(oper1, Float:oper2)
281 return FloatDiv(float(oper1), oper2);
284 stock Float:operator+(Float:oper1, oper2)
286 return FloatAdd(oper1, float(oper2)); /* "+" is commutative */
289 stock Float:operator-(Float:oper1, oper2)
291 return FloatSub(oper1, float(oper2));
294 stock Float:operator-(oper1, Float:oper2)
296 return FloatSub(float(oper1), oper2);
299 stock bool:operator==(Float:oper1, Float:oper2)
301 return FloatCompare(oper1, oper2) == 0;
304 stock bool:operator==(Float:oper1, oper2)
306 return FloatCompare(oper1, float(oper2)) == 0; /* "==" is commutative */
309 stock bool:operator!=(Float:oper1, Float:oper2)
311 return FloatCompare(oper1, oper2) != 0;
314 stock bool:operator!=(Float:oper1, oper2)
316 return FloatCompare(oper1, float(oper2)) != 0; /* "==" is commutative */
319 stock bool:operator>(Float:oper1, Float:oper2)
321 return FloatCompare(oper1, oper2) > 0;
324 stock bool:operator>(Float:oper1, oper2)
326 return FloatCompare(oper1, float(oper2)) > 0;
329 stock bool:operator>(oper1, Float:oper2)
331 return FloatCompare(float(oper1), oper2) > 0;
334 stock bool:operator>=(Float:oper1, Float:oper2)
336 return FloatCompare(oper1, oper2) >= 0;
339 stock bool:operator>=(Float:oper1, oper2)
341 return FloatCompare(oper1, float(oper2)) >= 0;
344 stock bool:operator>=(oper1, Float:oper2)
346 return FloatCompare(float(oper1), oper2) >= 0;
349 stock bool:operator<(Float:oper1, Float:oper2)
351 return FloatCompare(oper1, oper2) < 0;
354 stock bool:operator<(Float:oper1, oper2)
356 return FloatCompare(oper1, float(oper2)) < 0;
359 stock bool:operator<(oper1, Float:oper2)
361 return FloatCompare(float(oper1), oper2) < 0;
364 stock bool:operator<=(Float:oper1, Float:oper2)
366 return FloatCompare(oper1, oper2) <= 0;
369 stock bool:operator<=(Float:oper1, oper2)
371 return FloatCompare(oper1, float(oper2)) <= 0;
374 stock bool:operator<=(oper1, Float:oper2)
376 return FloatCompare(float(oper1), oper2) <= 0;
379 stock bool:operator!(Float:oper)
381 return (_:oper & ((-1)/2)) == 0; /* -1 = all bits to 1; /2 = remove most significant bit (sign)
382 works on both 32bit and 64bit systems; no constant required */
386 * Forbidden operators.
389 forward operator%(Float:oper1, Float:oper2);
390 forward operator%(Float:oper1, oper2);
391 forward operator%(oper1, Float:oper2);
393 #define FLOAT_PI 3.1415926535897932384626433832795
396 * Converts degrees to radians.
398 * @param angle Degrees.
401 stock Float:DegToRad(Float:angle)
403 return (angle*FLOAT_PI)/180;
407 * Converts degrees to radians.
409 * @param angle Radians.
412 stock Float:RadToDeg(Float:angle)
414 return (angle*180)/FLOAT_PI;