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