PageRenderTime 33ms CodeModel.GetById 17ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/js/src/jsbuiltins.h

http://github.com/zpao/v8monkey
C++ Header | 653 lines | 414 code | 53 blank | 186 comment | 7 complexity | c600109838e158f78a72858ca82c3b9d MD5 | raw file
  1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2 * vim: set ts=8 sw=4 et tw=99:
  3 *
  4 * ***** BEGIN LICENSE BLOCK *****
  5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  6 *
  7 * The contents of this file are subject to the Mozilla Public License Version
  8 * 1.1 (the "License"); you may not use this file except in compliance with
  9 * the License. You may obtain a copy of the License at
 10 * http://www.mozilla.org/MPL/
 11 *
 12 * Software distributed under the License is distributed on an "AS IS" basis,
 13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 14 * for the specific language governing rights and limitations under the
 15 * License.
 16 *
 17 * The Original Code is Mozilla SpiderMonkey JavaScript 1.9 code, released
 18 * May 28, 2008.
 19 *
 20 * The Initial Developer of the Original Code is
 21 *   Mozilla Corporation.
 22 *
 23 * Contributor(s):
 24 *   Jason Orendorff <jorendorff@mozilla.com>
 25 *
 26 * Alternatively, the contents of this file may be used under the terms of
 27 * either of the GNU General Public License Version 2 or later (the "GPL"),
 28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 29 * in which case the provisions of the GPL or the LGPL are applicable instead
 30 * of those above. If you wish to allow use of your version of this file only
 31 * under the terms of either the GPL or the LGPL, and not to allow others to
 32 * use your version of this file under the terms of the MPL, indicate your
 33 * decision by deleting the provisions above and replace them with the notice
 34 * and other provisions required by the GPL or the LGPL. If you do not delete
 35 * the provisions above, a recipient may use your version of this file under
 36 * the terms of any one of the MPL, the GPL or the LGPL.
 37 *
 38 * ***** END LICENSE BLOCK ***** */
 39
 40#ifndef jsbuiltins_h___
 41#define jsbuiltins_h___
 42
 43#ifdef JS_TRACER
 44
 45// nanojit.h includes windows.h, so undo the obnoxious #defines, if needed
 46#include "nanojit/nanojit.h"
 47#include "jswin.h"
 48#include "jsprvtd.h"
 49
 50enum JSTNErrType { INFALLIBLE, FAIL_STATUS, FAIL_NULL, FAIL_NEG, FAIL_NEITHER };
 51enum { 
 52    JSTN_ERRTYPE_MASK        = 0x07,
 53    JSTN_UNBOX_AFTER         = 0x08,
 54    JSTN_MORE                = 0x10,
 55    JSTN_CONSTRUCTOR         = 0x20,
 56    JSTN_RETURN_NULLABLE_STR = 0x40,
 57    JSTN_RETURN_NULLABLE_OBJ = 0x80
 58};
 59
 60#define JSTN_ERRTYPE(jstn)  ((jstn)->flags & JSTN_ERRTYPE_MASK)
 61
 62/*
 63 * Type describing a type specialization of a js::Native.
 64 *
 65 * |prefix| and |argtypes| declare what arguments should be passed to the
 66 * native function.  |prefix| can contain the following characters:
 67 *
 68 * 'C': a JSContext* argument
 69 * 'T': |this| as a JSObject* argument (bails if |this| is not an object)
 70 * 'S': |this| as a JSString* argument (bails if |this| is not a string)
 71 * 'R': a JSRuntime* argument
 72 * 'P': the pc as a jsbytecode*
 73 * 'D': |this| as a number (jsdouble)
 74 * 'f': the function being called, as a JSObject*
 75 * 'p': the .prototype of the function, as a JSObject*
 76 *
 77 * The corresponding things will get passed as arguments to the builtin in
 78 * reverse order (so TC means JSContext* as the first arg, and the
 79 * JSObject* for |this| as the second arg).
 80 *
 81 * |argtypes| can contain the following characters:
 82 * 'd': a number (double) argument
 83 * 'i': an integer argument
 84 * 's': a JSString* argument
 85 * 'o': a JSObject* argument
 86 * 'r': a JSObject* argument that is of class RegExpClass
 87 * 'f': a JSObject* argument that is of class FunctionClass
 88 * 'v': a value argument: on 32-bit, a Value*, on 64-bit, a jsval
 89 */
 90struct JSSpecializedNative {
 91    const nanojit::CallInfo *builtin;
 92    const char              *prefix;
 93    const char              *argtypes;
 94    uintN                   flags;  /* JSTNErrType | JSTN_UNBOX_AFTER | JSTN_MORE |
 95                                       JSTN_CONSTRUCTOR */
 96};
 97
 98/*
 99 * Type holding extra trace-specific information about a fast native.
100 *
101 * 'specializations' points to a static array of available specializations
102 * terminated by the lack of having the JSTN_MORE flag set.
103 */
104struct JSNativeTraceInfo {
105    js::Native              native;
106    JSSpecializedNative     *specializations;
107};
108
109/* Macros used by JS_DEFINE_CALLINFOn. */
110#ifdef DEBUG
111#define _JS_CI_NAME(op) ,#op
112#else
113#define _JS_CI_NAME(op)
114#endif
115
116#define _JS_I32_ARGTYPE    nanojit::ARGTYPE_I
117#define _JS_I32_RETTYPE    nanojit::ARGTYPE_I
118#define _JS_U64_ARGTYPE    nanojit::ARGTYPE_Q
119#define _JS_U64_RETTYPE    nanojit::ARGTYPE_Q
120#define _JS_F64_ARGTYPE    nanojit::ARGTYPE_D
121#define _JS_F64_RETTYPE    nanojit::ARGTYPE_D
122#define _JS_PTR_ARGTYPE    nanojit::ARGTYPE_P
123#define _JS_PTR_RETTYPE    nanojit::ARGTYPE_P
124
125struct ClosureVarInfo;
126
127/*
128 * Supported types for builtin functions.
129 *
130 * Types with -- for the two string fields are not permitted as argument types
131 * in JS_DEFINE_TRCINFO.
132 *
133 * There are three kinds of traceable-native error handling.
134 *
135 *   - If a traceable native's return type ends with _FAIL, it always runs to
136 *     completion.  It can either succeed or fail with an error or exception;
137 *     on success, it may or may not stay on trace.  There may be side effects
138 *     in any case.  If the call succeeds but bails off trace, we resume in the
139 *     interpreter at the next opcode.
140 *
141 *     _FAIL builtins indicate failure or bailing off trace by setting bits in
142 *     cx->interpState->builtinStatus.
143 *
144 *   - If a traceable native's return type contains _RETRY, it can either
145 *     succeed, fail with a JS exception, or tell the caller to bail off trace
146 *     and retry the call from the interpreter.  The last case happens if the
147 *     builtin discovers that it can't do its job without examining the JS
148 *     stack, reentering the interpreter, accessing properties of the global
149 *     object, etc.
150 *
151 *     The builtin must detect the need to retry before committing any side
152 *     effects.  If a builtin can't do this, it must use a _FAIL return type
153 *     instead of _RETRY.
154 *
155 *     _RETRY builtins indicate failure with a special return value that
156 *     depends on the return type:
157 *
158 *         BOOL_RETRY: JS_NEITHER
159 *         INT32_RETRY: any negative value
160 *         STRING_RETRY: NULL
161 *         OBJECT_RETRY_NULL: NULL
162 *
163 *     _RETRY function calls are faster than _FAIL calls.  Each _RETRY call
164 *     saves two writes to tm->bailExit and a read from state->builtinStatus.
165 *
166 *   - All other traceable natives are infallible (e.g. Date.now, Math.log).
167 *
168 * Special builtins known to the tracer can have their own idiosyncratic
169 * error codes.
170 *
171 * When a traceable native returns a value indicating failure, we fall off
172 * trace.  If an exception is pending, it is thrown; otherwise, we assume the
173 * builtin had no side effects and retry the current bytecode in the
174 * interpreter.
175 *
176 * So a builtin must not return a value indicating failure after causing side
177 * effects (such as reporting an error), without setting an exception pending.
178 * The operation would be retried, despite the first attempt's observable
179 * effects.
180 */
181#define _JS_CTYPE(ctype, size, pch, ach, flags)     (ctype, size, pch, ach, flags)
182
183#define _JS_CTYPE_CONTEXT           _JS_CTYPE(JSContext *,            _JS_PTR,"C", "", INFALLIBLE)
184#define _JS_CTYPE_RUNTIME           _JS_CTYPE(JSRuntime *,            _JS_PTR,"R", "", INFALLIBLE)
185#define _JS_CTYPE_MATHCACHE         _JS_CTYPE(js::MathCache *,        _JS_PTR,"M", "", INFALLIBLE)
186#define _JS_CTYPE_THIS              _JS_CTYPE(JSObject *,             _JS_PTR,"T", "", INFALLIBLE)
187#define _JS_CTYPE_THIS_DOUBLE       _JS_CTYPE(jsdouble,               _JS_F64,"D", "", INFALLIBLE)
188#define _JS_CTYPE_THIS_STRING       _JS_CTYPE(JSString *,             _JS_PTR,"S", "", INFALLIBLE)
189#define _JS_CTYPE_CALLEE            _JS_CTYPE(JSObject *,             _JS_PTR,"f", "", INFALLIBLE)
190#define _JS_CTYPE_CALLEE_PROTOTYPE  _JS_CTYPE(JSObject *,             _JS_PTR,"p", "", INFALLIBLE)
191#define _JS_CTYPE_FUNCTION          _JS_CTYPE(JSFunction *,           _JS_PTR, --, --, INFALLIBLE)
192#define _JS_CTYPE_PC                _JS_CTYPE(jsbytecode *,           _JS_PTR,"P", "", INFALLIBLE)
193#define _JS_CTYPE_VALUEPTR          _JS_CTYPE(js::Value *,            _JS_PTR, --, --, INFALLIBLE)
194#define _JS_CTYPE_CVALUEPTR         _JS_CTYPE(const js::Value *,      _JS_PTR, --, --, INFALLIBLE)
195#define _JS_CTYPE_JSID              _JS_CTYPE(jsid,                   _JS_PTR, --, --, INFALLIBLE)
196#define _JS_CTYPE_JSVAL             _JS_CTYPE(js::Value,              _JS_U64, --, --, INFALLIBLE)
197#define _JS_CTYPE_BOOL              _JS_CTYPE(JSBool,                 _JS_I32, "","i", INFALLIBLE)
198#define _JS_CTYPE_BOOL_RETRY        _JS_CTYPE(JSBool,                 _JS_I32, --, --, FAIL_NEITHER)
199#define _JS_CTYPE_BOOL_FAIL         _JS_CTYPE(JSBool,                 _JS_I32, --, --, FAIL_STATUS)
200#define _JS_CTYPE_BOOLPTR           _JS_CTYPE(JSBool *,               _JS_PTR, --, --, INFALLIBLE)
201#define _JS_CTYPE_INT32             _JS_CTYPE(int32,                  _JS_I32, "","i", INFALLIBLE)
202#define _JS_CTYPE_INT32_RETRY       _JS_CTYPE(int32,                  _JS_I32, --, --, FAIL_NEG)
203#define _JS_CTYPE_INT32_FAIL        _JS_CTYPE(int32,                  _JS_I32, --, --, FAIL_STATUS)
204#define _JS_CTYPE_INT32PTR          _JS_CTYPE(int32 *,                _JS_PTR, --, --, INFALLIBLE)
205#define _JS_CTYPE_UINT32            _JS_CTYPE(uint32,                 _JS_I32, "","i", INFALLIBLE)
206#define _JS_CTYPE_UINT32_RETRY      _JS_CTYPE(uint32,                 _JS_I32, --, --, FAIL_NEG)
207#define _JS_CTYPE_UINT32_FAIL       _JS_CTYPE(uint32,                 _JS_I32, --, --, FAIL_STATUS)
208#define _JS_CTYPE_DOUBLE            _JS_CTYPE(jsdouble,               _JS_F64, "","d", INFALLIBLE)
209#define _JS_CTYPE_DOUBLE_FAIL       _JS_CTYPE(jsdouble,               _JS_F64, --, --, FAIL_STATUS)
210#define _JS_CTYPE_STRING            _JS_CTYPE(JSString *,             _JS_PTR, "","s", INFALLIBLE)
211#define _JS_CTYPE_STRING_RETRY      _JS_CTYPE(JSString *,             _JS_PTR, --, --, FAIL_NULL)
212#define _JS_CTYPE_STRING_FAIL       _JS_CTYPE(JSString *,             _JS_PTR, --, --, FAIL_STATUS)
213#define _JS_CTYPE_STRING_OR_NULL_FAIL _JS_CTYPE(JSString *,           _JS_PTR, --, --, FAIL_STATUS | \
214                                                                              JSTN_RETURN_NULLABLE_STR)
215#define _JS_CTYPE_STRINGPTR         _JS_CTYPE(JSString **,            _JS_PTR, --, --, INFALLIBLE)
216#define _JS_CTYPE_OBJECT            _JS_CTYPE(JSObject *,             _JS_PTR, "","o", INFALLIBLE)
217#define _JS_CTYPE_OBJECT_RETRY      _JS_CTYPE(JSObject *,             _JS_PTR, --, --, FAIL_NULL)
218#define _JS_CTYPE_OBJECT_FAIL       _JS_CTYPE(JSObject *,             _JS_PTR, --, --, FAIL_STATUS)
219#define _JS_CTYPE_OBJECT_OR_NULL_FAIL _JS_CTYPE(JSObject *,           _JS_PTR, --, --, FAIL_STATUS | \
220                                                                              JSTN_RETURN_NULLABLE_OBJ)
221#define _JS_CTYPE_OBJECTPTR         _JS_CTYPE(JSObject **,            _JS_PTR, --, --, INFALLIBLE)
222#define _JS_CTYPE_CONSTRUCTOR_RETRY _JS_CTYPE(JSObject *,             _JS_PTR, --, --, FAIL_NULL | \
223                                                                                  JSTN_CONSTRUCTOR)
224#define _JS_CTYPE_REGEXP            _JS_CTYPE(JSObject *,             _JS_PTR, "","r", INFALLIBLE)
225#define _JS_CTYPE_SHAPE             _JS_CTYPE(js::Shape *,            _JS_PTR, --, --, INFALLIBLE)
226#define _JS_CTYPE_TRACERSTATE       _JS_CTYPE(TracerState *,          _JS_PTR, --, --, INFALLIBLE)
227#define _JS_CTYPE_FRAGMENT          _JS_CTYPE(nanojit::Fragment *,    _JS_PTR, --, --, INFALLIBLE)
228#define _JS_CTYPE_CLASS             _JS_CTYPE(js::Class *,            _JS_PTR, --, --, INFALLIBLE)
229#define _JS_CTYPE_DOUBLEPTR         _JS_CTYPE(double *,               _JS_PTR, --, --, INFALLIBLE)
230#define _JS_CTYPE_CHARPTR           _JS_CTYPE(char *,                 _JS_PTR, --, --, INFALLIBLE)
231#define _JS_CTYPE_CVIPTR            _JS_CTYPE(const ClosureVarInfo *, _JS_PTR, --, --, INFALLIBLE)
232#define _JS_CTYPE_FRAMEINFO         _JS_CTYPE(FrameInfo *,            _JS_PTR, --, --, INFALLIBLE)
233#define _JS_CTYPE_UINTN             _JS_CTYPE(uintN,                  _JS_PTR, --, --, INFALLIBLE)
234 
235/*
236 * The "VALUE" type is used to indicate that a native takes a js::Value
237 * parameter by value. Unfortunately, for technical reasons, we can't simply
238 * have the parameter type be js::Value. Furthermore, the right thing to pass
239 * differs based on word size. Thus, a native that declares a parameter of type
240 * VALUE should have the corresponding argument type be:
241 *  - on 32-bit: const Value*
242 *  - on 64-bit: jsval (which is a uint64)
243 *
244 * To write code that just does the right thing, use the pattern:
245 *  void foo(js::ValueArgType arg) {
246 *    const js::Value &v = js::ValueArgToConstRef(arg);
247 */
248#if JS_BITS_PER_WORD == 32
249# define _JS_CTYPE_VALUE            _JS_CTYPE(js::ValueArgType,       _JS_PTR, "","v", INFALLIBLE)
250#elif JS_BITS_PER_WORD == 64
251# define _JS_CTYPE_VALUE            _JS_CTYPE(js::ValueArgType,       _JS_U64, "","v", INFALLIBLE)
252#endif
253
254namespace js {
255#if JS_BITS_PER_WORD == 32
256typedef const js::Value *ValueArgType;
257
258static JS_ALWAYS_INLINE const js::Value &
259ValueArgToConstRef(const js::Value *arg)
260{
261    return *arg;
262}
263#elif JS_BITS_PER_WORD == 64
264typedef js::Value        ValueArgType;
265
266static JS_ALWAYS_INLINE const Value &
267ValueArgToConstRef(const Value &v)
268{
269    return v;
270}
271#endif
272}  /* namespace js */
273
274#define _JS_EXPAND(tokens)  tokens
275
276#define _JS_CTYPE_TYPE2(t,s,p,a,f)      t
277#define _JS_CTYPE_TYPE(tyname)          _JS_EXPAND(_JS_CTYPE_TYPE2    _JS_CTYPE_##tyname)
278#define _JS_CTYPE_RETTYPE2(t,s,p,a,f)   s##_RETTYPE
279#define _JS_CTYPE_RETTYPE(tyname)       _JS_EXPAND(_JS_CTYPE_RETTYPE2 _JS_CTYPE_##tyname)
280#define _JS_CTYPE_ARGTYPE2(t,s,p,a,f)   s##_ARGTYPE
281#define _JS_CTYPE_ARGTYPE(tyname)       _JS_EXPAND(_JS_CTYPE_ARGTYPE2 _JS_CTYPE_##tyname)
282#define _JS_CTYPE_PCH2(t,s,p,a,f)       p
283#define _JS_CTYPE_PCH(tyname)           _JS_EXPAND(_JS_CTYPE_PCH2     _JS_CTYPE_##tyname)
284#define _JS_CTYPE_ACH2(t,s,p,a,f)       a
285#define _JS_CTYPE_ACH(tyname)           _JS_EXPAND(_JS_CTYPE_ACH2     _JS_CTYPE_##tyname)
286#define _JS_CTYPE_FLAGS2(t,s,p,a,f)     f
287#define _JS_CTYPE_FLAGS(tyname)         _JS_EXPAND(_JS_CTYPE_FLAGS2   _JS_CTYPE_##tyname)
288
289#define _JS_static_TN(t)  static t
290#define _JS_static_CI     static
291#define _JS_extern_TN(t)  extern t
292#define _JS_extern_CI
293#define _JS_FRIEND_TN(t)  extern JS_FRIEND_API(t)
294#define _JS_FRIEND_CI
295#define _JS_TN_LINKAGE(linkage, t)  _JS_##linkage##_TN(t)
296#define _JS_CI_LINKAGE(linkage)     _JS_##linkage##_CI
297
298#define _JS_CALLINFO(name) name##_ci
299
300#if defined(JS_NO_FASTCALL) && defined(NANOJIT_IA32)
301#define _JS_DEFINE_CALLINFO(linkage, name, crtype, cargtypes, argtypes, isPure, storeAccSet)      \
302    _JS_TN_LINKAGE(linkage, crtype) name cargtypes;                                               \
303    _JS_CI_LINKAGE(linkage) const nanojit::CallInfo _JS_CALLINFO(name) =                          \
304        { (intptr_t) &name, argtypes, nanojit::ABI_CDECL, isPure, storeAccSet _JS_CI_NAME(name) };\
305    JS_STATIC_ASSERT_IF(isPure, (storeAccSet) == nanojit::ACCSET_NONE);
306
307#else
308#define _JS_DEFINE_CALLINFO(linkage, name, crtype, cargtypes, argtypes, isPure, storeAccSet)      \
309    _JS_TN_LINKAGE(linkage, crtype) FASTCALL name cargtypes;                                      \
310    _JS_CI_LINKAGE(linkage) const nanojit::CallInfo _JS_CALLINFO(name) =                          \
311        { (uintptr_t) &name, argtypes, nanojit::ABI_FASTCALL, isPure, storeAccSet _JS_CI_NAME(name) }; \
312    JS_STATIC_ASSERT_IF(isPure, (storeAccSet) == nanojit::ACCSET_NONE);
313#endif
314
315/*
316 * This macro is used for builtin functions that can be called from JITted
317 * code.  It declares a C function named <op> and a CallInfo struct named
318 * <op>_ci so the tracer can call it.  The <N> in JS_DEFINE_CALLINFO_<N> is
319 * the number of arguments the builtin takes.  Builtins with no arguments
320 * are not supported.  Using a macro is clunky but ensures that the types
321 * for each C function matches those for the corresponding CallInfo struct;
322 * mismatched types can cause subtle problems.
323 *
324 * The macro arguments are:
325 *
326 * - The linkage for the function and the associated CallInfo global.  It
327 *   can be extern, static, or FRIEND, which specifies JS_FRIEND_API linkage
328 *   for the function.
329 *
330 * - The return type. This identifier must name one of the _JS_TYPEINFO_*
331 *   macros defined in jsbuiltins.h.
332 *
333 * - The builtin name.
334 *
335 * - The parameter types.
336 *
337 * - The isPure flag.  Set to 1 if:
338 *   (a) the function's return value is determined solely by its arguments
339 *       (ie. no hidden state, no implicit inputs used such as global
340 *       variables or the result of an I/O operation); and
341 *   (b) the function causes no observable side-effects (ie. no writes to
342 *       global variables, no I/O output).
343 *   Multiple calls to a pure function can be merged during CSE.
344 *
345 * - The storeAccSet.  This indicates which memory access regions the function
346 *   accesses.  It must be ACCSET_NONE if the function is pure;  use
347 *   ACCSET_STORE_ANY if you're not sure.  Used to determine if each call site
348 *   of the function aliases any loads.
349 */
350#define JS_DEFINE_CALLINFO_1(linkage, rt, op, at0, isPure, storeAccSet)                           \
351    _JS_DEFINE_CALLINFO(linkage, op,                                                              \
352                        _JS_CTYPE_TYPE(rt),                                                       \
353                        (_JS_CTYPE_TYPE(at0)),                                                    \
354                        nanojit::CallInfo::typeSig1(_JS_CTYPE_RETTYPE(rt),                        \
355                                                    _JS_CTYPE_ARGTYPE(at0)),                      \
356                        isPure, storeAccSet)
357#define JS_DEFINE_CALLINFO_2(linkage, rt, op, at0, at1, isPure, storeAccSet)                      \
358    _JS_DEFINE_CALLINFO(linkage, op,                                                              \
359                        _JS_CTYPE_TYPE(rt),                                                       \
360                        (_JS_CTYPE_TYPE(at0),                                                     \
361                         _JS_CTYPE_TYPE(at1)),                                                    \
362                        nanojit::CallInfo::typeSig2(_JS_CTYPE_RETTYPE(rt),                        \
363                                                    _JS_CTYPE_ARGTYPE(at0),                       \
364                                                    _JS_CTYPE_ARGTYPE(at1)),                      \
365                        isPure, storeAccSet)
366#define JS_DEFINE_CALLINFO_3(linkage, rt, op, at0, at1, at2, isPure, storeAccSet)                 \
367    _JS_DEFINE_CALLINFO(linkage, op,                                                              \
368                        _JS_CTYPE_TYPE(rt),                                                       \
369                        (_JS_CTYPE_TYPE(at0),                                                     \
370                         _JS_CTYPE_TYPE(at1),                                                     \
371                         _JS_CTYPE_TYPE(at2)),                                                    \
372                        nanojit::CallInfo::typeSig3(_JS_CTYPE_RETTYPE(rt),                        \
373                                                    _JS_CTYPE_ARGTYPE(at0),                       \
374                                                    _JS_CTYPE_ARGTYPE(at1),                       \
375                                                    _JS_CTYPE_ARGTYPE(at2)),                      \
376                        isPure, storeAccSet)
377#define JS_DEFINE_CALLINFO_4(linkage, rt, op, at0, at1, at2, at3, isPure, storeAccSet)            \
378    _JS_DEFINE_CALLINFO(linkage, op,                                                              \
379                        _JS_CTYPE_TYPE(rt),                                                       \
380                        (_JS_CTYPE_TYPE(at0),                                                     \
381                         _JS_CTYPE_TYPE(at1),                                                     \
382                         _JS_CTYPE_TYPE(at2),                                                     \
383                         _JS_CTYPE_TYPE(at3)),                                                    \
384                        nanojit::CallInfo::typeSig4(_JS_CTYPE_RETTYPE(rt),                        \
385                                                    _JS_CTYPE_ARGTYPE(at0),                       \
386                                                    _JS_CTYPE_ARGTYPE(at1),                       \
387                                                    _JS_CTYPE_ARGTYPE(at2),                       \
388                                                    _JS_CTYPE_ARGTYPE(at3)),                      \
389                        isPure, storeAccSet)
390#define JS_DEFINE_CALLINFO_5(linkage, rt, op, at0, at1, at2, at3, at4, isPure, storeAccSet)       \
391    _JS_DEFINE_CALLINFO(linkage, op,                                                              \
392                        _JS_CTYPE_TYPE(rt),                                                       \
393                        (_JS_CTYPE_TYPE(at0),                                                     \
394                         _JS_CTYPE_TYPE(at1),                                                     \
395                         _JS_CTYPE_TYPE(at2),                                                     \
396                         _JS_CTYPE_TYPE(at3),                                                     \
397                         _JS_CTYPE_TYPE(at4)),                                                    \
398                        nanojit::CallInfo::typeSig5(_JS_CTYPE_RETTYPE(rt),                        \
399                                                    _JS_CTYPE_ARGTYPE(at0),                       \
400                                                    _JS_CTYPE_ARGTYPE(at1),                       \
401                                                    _JS_CTYPE_ARGTYPE(at2),                       \
402                                                    _JS_CTYPE_ARGTYPE(at3),                       \
403                                                    _JS_CTYPE_ARGTYPE(at4)),                      \
404                        isPure, storeAccSet)
405#define JS_DEFINE_CALLINFO_6(linkage, rt, op, at0, at1, at2, at3, at4, at5, isPure, storeAccSet)  \
406    _JS_DEFINE_CALLINFO(linkage, op,                                                              \
407                        _JS_CTYPE_TYPE(rt),                                                       \
408                        (_JS_CTYPE_TYPE(at0),                                                     \
409                         _JS_CTYPE_TYPE(at1),                                                     \
410                         _JS_CTYPE_TYPE(at2),                                                     \
411                         _JS_CTYPE_TYPE(at3),                                                     \
412                         _JS_CTYPE_TYPE(at4),                                                     \
413                         _JS_CTYPE_TYPE(at5)),                                                    \
414                        nanojit::CallInfo::typeSig6(_JS_CTYPE_RETTYPE(rt),                        \
415                                                    _JS_CTYPE_ARGTYPE(at0),                       \
416                                                    _JS_CTYPE_ARGTYPE(at1),                       \
417                                                    _JS_CTYPE_ARGTYPE(at2),                       \
418                                                    _JS_CTYPE_ARGTYPE(at3),                       \
419                                                    _JS_CTYPE_ARGTYPE(at4),                       \
420                                                    _JS_CTYPE_ARGTYPE(at5)),                      \
421                        isPure, storeAccSet)
422#define JS_DEFINE_CALLINFO_7(linkage, rt, op, at0, at1, at2, at3, at4, at5, at6, isPure,          \
423                             storeAccSet)                                                         \
424    _JS_DEFINE_CALLINFO(linkage, op,                                                              \
425                        _JS_CTYPE_TYPE(rt),                                                       \
426                        (_JS_CTYPE_TYPE(at0),                                                     \
427                         _JS_CTYPE_TYPE(at1),                                                     \
428                         _JS_CTYPE_TYPE(at2),                                                     \
429                         _JS_CTYPE_TYPE(at3),                                                     \
430                         _JS_CTYPE_TYPE(at4),                                                     \
431                         _JS_CTYPE_TYPE(at5),                                                     \
432                         _JS_CTYPE_TYPE(at6)),                                                    \
433                        nanojit::CallInfo::typeSig7(_JS_CTYPE_RETTYPE(rt),                        \
434                                                    _JS_CTYPE_ARGTYPE(at0),                       \
435                                                    _JS_CTYPE_ARGTYPE(at1),                       \
436                                                    _JS_CTYPE_ARGTYPE(at2),                       \
437                                                    _JS_CTYPE_ARGTYPE(at3),                       \
438                                                    _JS_CTYPE_ARGTYPE(at4),                       \
439                                                    _JS_CTYPE_ARGTYPE(at5),                       \
440                                                    _JS_CTYPE_ARGTYPE(at6)),                      \
441                        isPure, storeAccSet)
442#define JS_DEFINE_CALLINFO_8(linkage, rt, op, at0, at1, at2, at3, at4, at5, at6, at7, isPure,     \
443                             storeAccSet)                                                         \
444    _JS_DEFINE_CALLINFO(linkage, op,                                                              \
445                        _JS_CTYPE_TYPE(rt),                                                       \
446                        (_JS_CTYPE_TYPE(at0),                                                     \
447                         _JS_CTYPE_TYPE(at1),                                                     \
448                         _JS_CTYPE_TYPE(at2),                                                     \
449                         _JS_CTYPE_TYPE(at3),                                                     \
450                         _JS_CTYPE_TYPE(at4),                                                     \
451                         _JS_CTYPE_TYPE(at5),                                                     \
452                         _JS_CTYPE_TYPE(at6),                                                     \
453                         _JS_CTYPE_TYPE(at7)),                                                    \
454                        nanojit::CallInfo::typeSig8(_JS_CTYPE_RETTYPE(rt),                        \
455                                                    _JS_CTYPE_ARGTYPE(at0),                       \
456                                                    _JS_CTYPE_ARGTYPE(at1),                       \
457                                                    _JS_CTYPE_ARGTYPE(at2),                       \
458                                                    _JS_CTYPE_ARGTYPE(at3),                       \
459                                                    _JS_CTYPE_ARGTYPE(at4),                       \
460                                                    _JS_CTYPE_ARGTYPE(at5),                       \
461                                                    _JS_CTYPE_ARGTYPE(at6),                       \
462                                                    _JS_CTYPE_ARGTYPE(at7)),                      \
463                        isPure, storeAccSet)
464
465#define JS_DECLARE_CALLINFO(name)  extern const nanojit::CallInfo _JS_CALLINFO(name);
466
467#define _JS_TN_INIT_HELPER_n(n, args)  _JS_TN_INIT_HELPER_##n args
468
469#define _JS_TN_INIT_HELPER_1(linkage, rt, op, at0, isPure, storeAccSet)                           \
470    &_JS_CALLINFO(op),                                                                            \
471    _JS_CTYPE_PCH(at0),                                                                           \
472    _JS_CTYPE_ACH(at0),                                                                           \
473    _JS_CTYPE_FLAGS(rt)
474
475#define _JS_TN_INIT_HELPER_2(linkage, rt, op, at0, at1, isPure, storeAccSet)                      \
476    &_JS_CALLINFO(op),                                                                            \
477    _JS_CTYPE_PCH(at1) _JS_CTYPE_PCH(at0),                                                        \
478    _JS_CTYPE_ACH(at1) _JS_CTYPE_ACH(at0),                                                        \
479    _JS_CTYPE_FLAGS(rt)
480
481#define _JS_TN_INIT_HELPER_3(linkage, rt, op, at0, at1, at2, isPure, storeAccSet)                 \
482    &_JS_CALLINFO(op),                                                                            \
483    _JS_CTYPE_PCH(at2) _JS_CTYPE_PCH(at1) _JS_CTYPE_PCH(at0),                                     \
484    _JS_CTYPE_ACH(at2) _JS_CTYPE_ACH(at1) _JS_CTYPE_ACH(at0),                                     \
485    _JS_CTYPE_FLAGS(rt)
486
487#define _JS_TN_INIT_HELPER_4(linkage, rt, op, at0, at1, at2, at3, isPure, storeAccSet)            \
488    &_JS_CALLINFO(op),                                                                            \
489    _JS_CTYPE_PCH(at3) _JS_CTYPE_PCH(at2) _JS_CTYPE_PCH(at1) _JS_CTYPE_PCH(at0),                  \
490    _JS_CTYPE_ACH(at3) _JS_CTYPE_ACH(at2) _JS_CTYPE_ACH(at1) _JS_CTYPE_ACH(at0),                  \
491    _JS_CTYPE_FLAGS(rt)
492
493#define _JS_TN_INIT_HELPER_5(linkage, rt, op, at0, at1, at2, at3, at4, isPure, storeAccSet)       \
494    &_JS_CALLINFO(op),                                                                            \
495    _JS_CTYPE_PCH(at4) _JS_CTYPE_PCH(at3) _JS_CTYPE_PCH(at2) _JS_CTYPE_PCH(at1)                   \
496        _JS_CTYPE_PCH(at0),                                                                       \
497    _JS_CTYPE_ACH(at4) _JS_CTYPE_ACH(at3) _JS_CTYPE_ACH(at2) _JS_CTYPE_ACH(at1)                   \
498        _JS_CTYPE_ACH(at0),                                                                       \
499    _JS_CTYPE_FLAGS(rt)
500
501#define _JS_TN_INIT_HELPER_6(linkage, rt, op, at0, at1, at2, at3, at4, at5, isPure, storeAccSet) \
502    &_JS_CALLINFO(op),                                                                            \
503    _JS_CTYPE_PCH(at5) _JS_CTYPE_PCH(at4) _JS_CTYPE_PCH(at3) _JS_CTYPE_PCH(at2)                   \
504        _JS_CTYPE_PCH(at1) _JS_CTYPE_PCH(at0),                                                    \
505    _JS_CTYPE_ACH(at5) _JS_CTYPE_ACH(at4) _JS_CTYPE_ACH(at3) _JS_CTYPE_ACH(at2)                   \
506        _JS_CTYPE_ACH(at1) _JS_CTYPE_ACH(at0),                                                    \
507    _JS_CTYPE_FLAGS(rt)
508
509#define _JS_TN_INIT_HELPER_7(linkage, rt, op, at0, at1, at2, at3, at4, at5, at6, isPure, storeAccSet) \
510    &_JS_CALLINFO(op),                                                                            \
511    _JS_CTYPE_PCH(at6) _JS_CTYPE_PCH(at5) _JS_CTYPE_PCH(at4) _JS_CTYPE_PCH(at3)                   \
512        _JS_CTYPE_PCH(at2)  _JS_CTYPE_PCH(at1) _JS_CTYPE_PCH(at0),                                \
513    _JS_CTYPE_ACH(at6) _JS_CTYPE_ACH(at5) _JS_CTYPE_ACH(at4) _JS_CTYPE_ACH(at3)                   \
514        _JS_CTYPE_ACH(at2) _JS_CTYPE_ACH(at1) _JS_CTYPE_ACH(at0),                                 \
515    _JS_CTYPE_FLAGS(rt)
516
517#define _JS_TN_INIT_HELPER_8(linkage, rt, op, at0, at1, at2, at3, at4, at5, at6, at7, isPure, storeAccSet) \
518    &_JS_CALLINFO(op),                                                                            \
519    _JS_CTYPE_PCH(at7) _JS_CTYPE_PCH(at6) _JS_CTYPE_PCH(at5) _JS_CTYPE_PCH(at4)                   \
520        _JS_CTYPE_PCH(at3) _JS_CTYPE_PCH(at2)  _JS_CTYPE_PCH(at1) _JS_CTYPE_PCH(at0),             \
521    _JS_CTYPE_ACH(at7) _JS_CTYPE_ACH(at6) _JS_CTYPE_ACH(at5) _JS_CTYPE_ACH(at4)                   \
522        _JS_CTYPE_ACH(at3) _JS_CTYPE_ACH(at2) _JS_CTYPE_ACH(at1) _JS_CTYPE_ACH(at0),              \
523    _JS_CTYPE_FLAGS(rt)
524
525#define JS_DEFINE_TRCINFO_1(name, tn0)                                                            \
526    _JS_DEFINE_CALLINFO_n tn0                                                                     \
527    JSSpecializedNative name##_sns[] = {                                                          \
528        { _JS_TN_INIT_HELPER_n tn0 }                                                              \
529    };                                                                                            \
530    JSNativeTraceInfo name##_trcinfo = { name, name##_sns };
531
532#define JS_DEFINE_TRCINFO_2(name, tn0, tn1)                                                       \
533    _JS_DEFINE_CALLINFO_n tn0                                                                     \
534    _JS_DEFINE_CALLINFO_n tn1                                                                     \
535    JSSpecializedNative name##_sns[] = {                                                          \
536        { _JS_TN_INIT_HELPER_n tn0 | JSTN_MORE },                                                 \
537        { _JS_TN_INIT_HELPER_n tn1 }                                                              \
538    };                                                                                            \
539    JSNativeTraceInfo name##_trcinfo = { name, name##_sns };
540
541#define JS_DEFINE_TRCINFO_3(name, tn0, tn1, tn2)                                                  \
542    _JS_DEFINE_CALLINFO_n tn0                                                                     \
543    _JS_DEFINE_CALLINFO_n tn1                                                                     \
544    _JS_DEFINE_CALLINFO_n tn2                                                                     \
545    JSSpecializedNative name##_sns[] = {                                                          \
546        { _JS_TN_INIT_HELPER_n tn0 | JSTN_MORE },                                                 \
547        { _JS_TN_INIT_HELPER_n tn1 | JSTN_MORE },                                                 \
548        { _JS_TN_INIT_HELPER_n tn2 }                                                              \
549    };                                                                                            \
550    JSNativeTraceInfo name##_trcinfo = { name, name##_sns };
551
552#define JS_DEFINE_TRCINFO_4(name, tn0, tn1, tn2, tn3)                                             \
553    _JS_DEFINE_CALLINFO_n tn0                                                                     \
554    _JS_DEFINE_CALLINFO_n tn1                                                                     \
555    _JS_DEFINE_CALLINFO_n tn2                                                                     \
556    _JS_DEFINE_CALLINFO_n tn3                                                                     \
557    JSSpecializedNative name##_sns[] = {                                                          \
558        { _JS_TN_INIT_HELPER_n tn0 | JSTN_MORE },                                                 \
559        { _JS_TN_INIT_HELPER_n tn1 | JSTN_MORE },                                                 \
560        { _JS_TN_INIT_HELPER_n tn2 | JSTN_MORE },                                                 \
561        { _JS_TN_INIT_HELPER_n tn3 }                                                              \
562    };                                                                                            \
563    JSNativeTraceInfo name##_trcinfo = { name, name##_sns };
564
565#define _JS_DEFINE_CALLINFO_n(n, args)  JS_DEFINE_CALLINFO_##n args
566
567jsdouble FASTCALL
568js_StringToNumber(JSContext* cx, JSString* str, JSBool *ok);
569
570/* Extern version of SetBuiltinError. */
571extern JS_FRIEND_API(void)
572js_SetTraceableNativeFailed(JSContext *cx);
573
574extern jsdouble FASTCALL
575js_dmod(jsdouble a, jsdouble b);
576
577#else
578
579#define JS_DEFINE_CALLINFO_1(linkage, rt, op, at0, isPure, storeAccSet)
580#define JS_DEFINE_CALLINFO_2(linkage, rt, op, at0, at1, isPure, storeAccSet)
581#define JS_DEFINE_CALLINFO_3(linkage, rt, op, at0, at1, at2, isPure, storeAccSet)
582#define JS_DEFINE_CALLINFO_4(linkage, rt, op, at0, at1, at2, at3, isPure, storeAccSet)
583#define JS_DEFINE_CALLINFO_5(linkage, rt, op, at0, at1, at2, at3, at4, isPure, storeAccSet)
584#define JS_DEFINE_CALLINFO_6(linkage, rt, op, at0, at1, at2, at3, at4, at5, isPure, storeAccSet)
585#define JS_DEFINE_CALLINFO_7(linkage, rt, op, at0, at1, at2, at3, at4, at5, at6, isPure, storeAccSet)
586#define JS_DEFINE_CALLINFO_8(linkage, rt, op, at0, at1, at2, at3, at4, at5, at6, at7, isPure, storeAccSet)
587#define JS_DECLARE_CALLINFO(name)
588#define JS_DEFINE_TRCINFO_1(name, tn0)
589#define JS_DEFINE_TRCINFO_2(name, tn0, tn1)
590#define JS_DEFINE_TRCINFO_3(name, tn0, tn1, tn2)
591#define JS_DEFINE_TRCINFO_4(name, tn0, tn1, tn2, tn3)
592
593#endif /* !JS_TRACER */
594
595/* Defined in jsarray.cpp. */
596namespace js {
597JS_DECLARE_CALLINFO(NewDenseEmptyArray)
598JS_DECLARE_CALLINFO(NewDenseAllocatedArray)
599JS_DECLARE_CALLINFO(NewDenseUnallocatedArray)
600JS_DECLARE_CALLINFO(NewDenseAllocatedEmptyArray)
601}
602JS_DECLARE_CALLINFO(js_NewbornArrayPush_tn)
603JS_DECLARE_CALLINFO(js_EnsureDenseArrayCapacity)
604
605/* Defined in jsbuiltins.cpp. */
606JS_DECLARE_CALLINFO(js_UnboxNumberAsDouble)
607JS_DECLARE_CALLINFO(js_UnboxNumberAsInt32)
608JS_DECLARE_CALLINFO(js_dmod)
609JS_DECLARE_CALLINFO(js_imod)
610JS_DECLARE_CALLINFO(js_DoubleToInt32)
611JS_DECLARE_CALLINFO(js_DoubleToUint32)
612JS_DECLARE_CALLINFO(js_StringToNumber)
613JS_DECLARE_CALLINFO(js_StringToInt32)
614JS_DECLARE_CALLINFO(js_AddProperty)
615JS_DECLARE_CALLINFO(js_AddAtomProperty)
616JS_DECLARE_CALLINFO(js_HasNamedProperty)
617JS_DECLARE_CALLINFO(js_HasNamedPropertyInt32)
618JS_DECLARE_CALLINFO(js_TypeOfObject)
619JS_DECLARE_CALLINFO(js_BooleanIntToString)
620JS_DECLARE_CALLINFO(js_NewNullClosure)
621
622/* Defined in jsfun.cpp. */
623JS_DECLARE_CALLINFO(js_AllocFlatClosure)
624JS_DECLARE_CALLINFO(js_PutArgumentsOnTrace)
625JS_DECLARE_CALLINFO(js_PutCallObjectOnTrace)
626JS_DECLARE_CALLINFO(js_SetCallVar)
627JS_DECLARE_CALLINFO(js_SetCallArg)
628JS_DECLARE_CALLINFO(js_CloneFunctionObject)
629JS_DECLARE_CALLINFO(js_CreateCallObjectOnTrace)
630JS_DECLARE_CALLINFO(js_NewArgumentsOnTrace)
631
632/* Defined in jsnum.cpp. */
633JS_DECLARE_CALLINFO(js_NumberToString)
634
635/* Defined in jsobj.cpp. */
636JS_DECLARE_CALLINFO(js_Object_tn)
637JS_DECLARE_CALLINFO(js_CreateThisFromTrace)
638JS_DECLARE_CALLINFO(js_InitializerObject)
639
640/* Defined in vm/RegExpObject.cpp. */
641JS_DECLARE_CALLINFO(js_CloneRegExpObject)
642
643/* Defined in jsstr.cpp. */
644JS_DECLARE_CALLINFO(js_String_tn)
645JS_DECLARE_CALLINFO(js_CompareStringsOnTrace)
646JS_DECLARE_CALLINFO(js_ConcatStrings)
647JS_DECLARE_CALLINFO(js_EqualStringsOnTrace)
648JS_DECLARE_CALLINFO(js_FlattenOnTrace)
649
650/* Defined in jstypedarray.cpp. */
651JS_DECLARE_CALLINFO(js_TypedArray_uint8_clamp_double)
652
653#endif /* jsbuiltins_h___ */