duk_config.h 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131
  1. /*
  2. * duk_config.h configuration header generated by genconfig.py.
  3. *
  4. * Git commit: external
  5. * Git describe: external
  6. * Git branch: external
  7. *
  8. * Supported platforms:
  9. * - Mac OSX, iPhone, Darwin
  10. * - Orbis
  11. * - OpenBSD
  12. * - Generic BSD
  13. * - Atari ST TOS
  14. * - AmigaOS
  15. * - Windows
  16. * - Flashplayer (Crossbridge)
  17. * - QNX
  18. * - TI-Nspire
  19. * - Emscripten
  20. * - Linux
  21. * - Solaris
  22. * - Generic POSIX
  23. * - Cygwin
  24. * - Generic UNIX
  25. * - Generic fallback
  26. *
  27. * Supported architectures:
  28. * - x86
  29. * - x64
  30. * - x32
  31. * - ARM 32-bit
  32. * - ARM 64-bit
  33. * - MIPS 32-bit
  34. * - MIPS 64-bit
  35. * - PowerPC 32-bit
  36. * - PowerPC 64-bit
  37. * - SPARC 32-bit
  38. * - SPARC 64-bit
  39. * - SuperH
  40. * - Motorola 68k
  41. * - Emscripten
  42. * - Generic
  43. *
  44. * Supported compilers:
  45. * - Clang
  46. * - GCC
  47. * - MSVC
  48. * - Emscripten
  49. * - TinyC
  50. * - VBCC
  51. * - Bruce's C compiler
  52. * - Generic
  53. *
  54. */
  55. #if !defined(DUK_CONFIG_H_INCLUDED)
  56. #define DUK_CONFIG_H_INCLUDED
  57. /*
  58. * Intermediate helper defines
  59. */
  60. /* DLL build detection */
  61. /* not configured for DLL build */
  62. #undef DUK_F_DLL_BUILD
  63. /* Apple OSX, iOS */
  64. #if defined(__APPLE__)
  65. #define DUK_F_APPLE
  66. #endif
  67. /* FreeBSD */
  68. #if defined(__FreeBSD__) || defined(__FreeBSD)
  69. #define DUK_F_FREEBSD
  70. #endif
  71. /* Orbis (PS4) variant */
  72. #if defined(DUK_F_FREEBSD) && defined(__ORBIS__)
  73. #define DUK_F_ORBIS
  74. #endif
  75. /* OpenBSD */
  76. #if defined(__OpenBSD__) || defined(__OpenBSD)
  77. #define DUK_F_OPENBSD
  78. #endif
  79. /* NetBSD */
  80. #if defined(__NetBSD__) || defined(__NetBSD)
  81. #define DUK_F_NETBSD
  82. #endif
  83. /* BSD variant */
  84. #if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
  85. defined(__bsdi__) || defined(__DragonFly__)
  86. #define DUK_F_BSD
  87. #endif
  88. /* Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC
  89. * apparently, so to use with VBCC user must define __TOS__ manually.
  90. */
  91. #if defined(__TOS__)
  92. #define DUK_F_TOS
  93. #endif
  94. /* Motorola 68K. Not defined by VBCC, so user must define one of these
  95. * manually when using VBCC.
  96. */
  97. #if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
  98. #define DUK_F_M68K
  99. #endif
  100. /* AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
  101. * define 'AMIGA' manually when using VBCC.
  102. */
  103. #if defined(AMIGA) || defined(__amigaos__)
  104. #define DUK_F_AMIGAOS
  105. #endif
  106. /* PowerPC */
  107. #if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__)
  108. #define DUK_F_PPC
  109. #if defined(__PPC64__) || defined(__LP64__) || defined(_LP64)
  110. #define DUK_F_PPC64
  111. #else
  112. #define DUK_F_PPC32
  113. #endif
  114. #endif
  115. /* Windows, both 32-bit and 64-bit */
  116. #if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \
  117. defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
  118. #define DUK_F_WINDOWS
  119. #if defined(_WIN64) || defined(WIN64)
  120. #define DUK_F_WIN64
  121. #else
  122. #define DUK_F_WIN32
  123. #endif
  124. #endif
  125. /* Flash player (e.g. Crossbridge) */
  126. #if defined(__FLASHPLAYER__)
  127. #define DUK_F_FLASHPLAYER
  128. #endif
  129. /* QNX */
  130. #if defined(__QNX__)
  131. #define DUK_F_QNX
  132. #endif
  133. /* TI-Nspire (using Ndless) */
  134. #if defined(_TINSPIRE)
  135. #define DUK_F_TINSPIRE
  136. #endif
  137. /* Emscripten (provided explicitly by user), improve if possible */
  138. #if defined(EMSCRIPTEN)
  139. #define DUK_F_EMSCRIPTEN
  140. #endif
  141. /* BCC (Bruce's C compiler): this is a "torture target" for compilation */
  142. #if defined(__BCC__) || defined(__BCC_VERSION__)
  143. #define DUK_F_BCC
  144. #endif
  145. /* Linux */
  146. #if defined(__linux) || defined(__linux__) || defined(linux)
  147. #define DUK_F_LINUX
  148. #endif
  149. /* illumos / Solaris */
  150. #if defined(__sun) && defined(__SVR4)
  151. #define DUK_F_SUN
  152. #endif
  153. /* POSIX */
  154. #if defined(__posix)
  155. #define DUK_F_POSIX
  156. #endif
  157. /* Cygwin */
  158. #if defined(__CYGWIN__)
  159. #define DUK_F_CYGWIN
  160. #endif
  161. /* Generic Unix (includes Cygwin) */
  162. #if defined(__unix) || defined(__unix__) || defined(unix) || \
  163. defined(DUK_F_LINUX) || defined(DUK_F_BSD)
  164. #define DUK_F_UNIX
  165. #endif
  166. /* stdint.h not available */
  167. #if defined(DUK_F_WINDOWS) && defined(_MSC_VER)
  168. #if (_MSC_VER < 1700)
  169. /* VS2012+ has stdint.h, < VS2012 does not (but it's available for download). */
  170. #define DUK_F_NO_STDINT_H
  171. #endif
  172. #endif
  173. #if !defined(DUK_F_NO_STDINT_H) && (defined(DUK_F_TOS) || defined(DUK_F_BCC))
  174. #define DUK_F_NO_STDINT_H
  175. #endif
  176. /* C++ */
  177. #undef DUK_F_CPP
  178. #if defined(__cplusplus)
  179. #define DUK_F_CPP
  180. #endif
  181. /* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
  182. * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
  183. * https://sites.google.com/site/x32abi/
  184. */
  185. #if defined(__amd64__) || defined(__amd64) || \
  186. defined(__x86_64__) || defined(__x86_64) || \
  187. defined(_M_X64) || defined(_M_AMD64)
  188. #if defined(__ILP32__) || defined(_ILP32)
  189. #define DUK_F_X32
  190. #else
  191. #define DUK_F_X64
  192. #endif
  193. #elif defined(i386) || defined(__i386) || defined(__i386__) || \
  194. defined(__i486__) || defined(__i586__) || defined(__i686__) || \
  195. defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \
  196. defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
  197. #if defined(__LP64__) || defined(_LP64)
  198. /* This should not really happen, but would indicate x64. */
  199. #define DUK_F_X64
  200. #else
  201. #define DUK_F_X86
  202. #endif
  203. #endif
  204. /* ARM */
  205. #if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM) || defined(__aarch64__)
  206. #define DUK_F_ARM
  207. #if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__)
  208. #define DUK_F_ARM64
  209. #else
  210. #define DUK_F_ARM32
  211. #endif
  212. #endif
  213. /* MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
  214. #if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \
  215. defined(_R3000) || defined(_R4000) || defined(_R5900) || \
  216. defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \
  217. defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \
  218. defined(__mips) || defined(__MIPS__)
  219. #define DUK_F_MIPS
  220. #if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \
  221. defined(__mips64__) || defined(__mips_n64)
  222. #define DUK_F_MIPS64
  223. #else
  224. #define DUK_F_MIPS32
  225. #endif
  226. #endif
  227. /* SPARC */
  228. #if defined(sparc) || defined(__sparc) || defined(__sparc__)
  229. #define DUK_F_SPARC
  230. #if defined(__LP64__) || defined(_LP64)
  231. #define DUK_F_SPARC64
  232. #else
  233. #define DUK_F_SPARC32
  234. #endif
  235. #endif
  236. /* SuperH */
  237. #if defined(__sh__) || \
  238. defined(__sh1__) || defined(__SH1__) || \
  239. defined(__sh2__) || defined(__SH2__) || \
  240. defined(__sh3__) || defined(__SH3__) || \
  241. defined(__sh4__) || defined(__SH4__) || \
  242. defined(__sh5__) || defined(__SH5__)
  243. #define DUK_F_SUPERH
  244. #endif
  245. /* Clang */
  246. #if defined(__clang__)
  247. #define DUK_F_CLANG
  248. #endif
  249. /* C99 or above */
  250. #undef DUK_F_C99
  251. #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  252. #define DUK_F_C99
  253. #endif
  254. /* C++11 or above */
  255. #undef DUK_F_CPP11
  256. #if defined(__cplusplus) && (__cplusplus >= 201103L)
  257. #define DUK_F_CPP11
  258. #endif
  259. /* GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang. */
  260. #if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG)
  261. #define DUK_F_GCC
  262. #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
  263. /* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
  264. #define DUK_F_GCC_VERSION (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
  265. #else
  266. #error cannot figure out gcc version
  267. #endif
  268. #endif
  269. /* MinGW. Also GCC flags (DUK_F_GCC) are enabled now. */
  270. #if defined(__MINGW32__) || defined(__MINGW64__)
  271. #define DUK_F_MINGW
  272. #endif
  273. /* MSVC */
  274. #if defined(_MSC_VER)
  275. /* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
  276. * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
  277. * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
  278. */
  279. #define DUK_F_MSVC
  280. #if defined(_MSC_FULL_VER)
  281. #if (_MSC_FULL_VER > 100000000)
  282. #define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
  283. #else
  284. #define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
  285. #endif
  286. #endif
  287. #endif /* _MSC_VER */
  288. /* TinyC */
  289. #if defined(__TINYC__)
  290. /* http://bellard.org/tcc/tcc-doc.html#SEC9 */
  291. #define DUK_F_TINYC
  292. #endif
  293. /* VBCC */
  294. #if defined(__VBCC__)
  295. #define DUK_F_VBCC
  296. #endif
  297. /*
  298. * Platform autodetection
  299. */
  300. /* Workaround for older C++ compilers before including <inttypes.h>,
  301. * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
  302. */
  303. #if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
  304. #define __STDC_LIMIT_MACROS
  305. #endif
  306. #if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
  307. #define __STDC_CONSTANT_MACROS
  308. #endif
  309. #if defined(DUK_F_APPLE)
  310. /* --- Mac OSX, iPhone, Darwin --- */
  311. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  312. #define DUK_USE_DATE_TZO_GMTIME_R
  313. #define DUK_USE_DATE_PRS_STRPTIME
  314. #define DUK_USE_DATE_FMT_STRFTIME
  315. #include <TargetConditionals.h>
  316. #include <architecture/byte_order.h>
  317. #include <sys/param.h>
  318. #include <sys/time.h>
  319. #include <time.h>
  320. /* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
  321. #if TARGET_IPHONE_SIMULATOR
  322. #define DUK_USE_OS_STRING "iphone-sim"
  323. #elif TARGET_OS_IPHONE
  324. #define DUK_USE_OS_STRING "iphone"
  325. #elif TARGET_OS_MAC
  326. #define DUK_USE_OS_STRING "osx"
  327. #else
  328. #define DUK_USE_OS_STRING "osx-unknown"
  329. #endif
  330. /* Use _setjmp() on Apple by default, see GH-55. */
  331. #define DUK_JMPBUF_TYPE jmp_buf
  332. #define DUK_SETJMP(jb) _setjmp((jb))
  333. #define DUK_LONGJMP(jb) _longjmp((jb), 1)
  334. #elif defined(DUK_F_ORBIS)
  335. /* --- Orbis --- */
  336. /* Orbis = PS4 */
  337. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  338. #define DUK_USE_DATE_TZO_GMTIME_S
  339. /* no parsing (not an error) */
  340. #define DUK_USE_DATE_FMT_STRFTIME
  341. #include <sys/types.h>
  342. #include <machine/endian.h>
  343. #include <sys/param.h>
  344. #include <sys/time.h>
  345. #include <time.h>
  346. #define DUK_USE_OS_STRING "orbis"
  347. #elif defined(DUK_F_OPENBSD)
  348. /* --- OpenBSD --- */
  349. /* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
  350. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  351. #define DUK_USE_DATE_TZO_GMTIME_R
  352. #define DUK_USE_DATE_PRS_STRPTIME
  353. #define DUK_USE_DATE_FMT_STRFTIME
  354. #include <sys/types.h>
  355. #include <sys/endian.h>
  356. #include <sys/param.h>
  357. #include <sys/time.h>
  358. #include <time.h>
  359. #define DUK_USE_OS_STRING "openbsd"
  360. #elif defined(DUK_F_BSD)
  361. /* --- Generic BSD --- */
  362. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  363. #define DUK_USE_DATE_TZO_GMTIME_R
  364. #define DUK_USE_DATE_PRS_STRPTIME
  365. #define DUK_USE_DATE_FMT_STRFTIME
  366. #include <sys/types.h>
  367. #include <sys/endian.h>
  368. #include <sys/param.h>
  369. #include <sys/time.h>
  370. #include <time.h>
  371. #define DUK_USE_OS_STRING "bsd"
  372. #elif defined(DUK_F_TOS)
  373. /* --- Atari ST TOS --- */
  374. #define DUK_USE_DATE_NOW_TIME
  375. #define DUK_USE_DATE_TZO_GMTIME
  376. /* no parsing (not an error) */
  377. #define DUK_USE_DATE_FMT_STRFTIME
  378. #include <time.h>
  379. #define DUK_USE_OS_STRING "tos"
  380. /* TOS on M68K is always big endian. */
  381. #if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K)
  382. #define DUK_USE_BYTEORDER 3
  383. #endif
  384. #elif defined(DUK_F_AMIGAOS)
  385. /* --- AmigaOS --- */
  386. #if defined(DUK_F_M68K)
  387. /* AmigaOS on M68k */
  388. #define DUK_USE_DATE_NOW_TIME
  389. #define DUK_USE_DATE_TZO_GMTIME
  390. /* no parsing (not an error) */
  391. #define DUK_USE_DATE_FMT_STRFTIME
  392. #include <time.h>
  393. #elif defined(DUK_F_PPC)
  394. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  395. #define DUK_USE_DATE_TZO_GMTIME_R
  396. #define DUK_USE_DATE_PRS_STRPTIME
  397. #define DUK_USE_DATE_FMT_STRFTIME
  398. #include <time.h>
  399. #if !defined(UINTPTR_MAX)
  400. #define UINTPTR_MAX UINT_MAX
  401. #endif
  402. #else
  403. #error AmigaOS but not M68K/PPC, not supported now
  404. #endif
  405. #define DUK_USE_OS_STRING "amigaos"
  406. /* AmigaOS on M68K or PPC is always big endian. */
  407. #if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC))
  408. #define DUK_USE_BYTEORDER 3
  409. #endif
  410. #elif defined(DUK_F_WINDOWS)
  411. /* --- Windows --- */
  412. /* Initial fix: disable secure CRT related warnings when compiling Duktape
  413. * itself (must be defined before including Windows headers). Don't define
  414. * for user code including duktape.h.
  415. */
  416. #if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
  417. #define _CRT_SECURE_NO_WARNINGS
  418. #endif
  419. /* Windows 32-bit and 64-bit are currently the same. */
  420. /* MSVC does not have sys/param.h */
  421. #define DUK_USE_DATE_NOW_WINDOWS
  422. #define DUK_USE_DATE_TZO_WINDOWS
  423. /* Note: PRS and FMT are intentionally left undefined for now. This means
  424. * there is no platform specific date parsing/formatting but there is still
  425. * the ISO 8601 standard format.
  426. */
  427. #if defined(DUK_COMPILING_DUKTAPE)
  428. /* Only include when compiling Duktape to avoid polluting application build
  429. * with a lot of unnecessary defines.
  430. */
  431. #include <windows.h>
  432. #endif
  433. #define DUK_USE_OS_STRING "windows"
  434. /* On Windows, assume we're little endian. Even Itanium which has a
  435. * configurable endianness runs little endian in Windows.
  436. */
  437. #if !defined(DUK_USE_BYTEORDER)
  438. #define DUK_USE_BYTEORDER 1
  439. #endif
  440. #elif defined(DUK_F_FLASHPLAYER)
  441. /* --- Flashplayer (Crossbridge) --- */
  442. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  443. #define DUK_USE_DATE_TZO_GMTIME_R
  444. #define DUK_USE_DATE_PRS_STRPTIME
  445. #define DUK_USE_DATE_FMT_STRFTIME
  446. #include <endian.h>
  447. #include <sys/param.h>
  448. #include <sys/time.h>
  449. #include <time.h>
  450. #define DUK_USE_OS_STRING "flashplayer"
  451. #if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER)
  452. #define DUK_USE_BYTEORDER 1
  453. #endif
  454. #elif defined(DUK_F_QNX)
  455. /* --- QNX --- */
  456. #if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
  457. /* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
  458. #define _XOPEN_SOURCE 600
  459. #define _POSIX_C_SOURCE 200112L
  460. #endif
  461. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  462. #define DUK_USE_DATE_TZO_GMTIME_R
  463. #define DUK_USE_DATE_PRS_STRPTIME
  464. #define DUK_USE_DATE_FMT_STRFTIME
  465. #include <sys/types.h>
  466. #include <sys/param.h>
  467. #include <sys/time.h>
  468. #include <time.h>
  469. #define DUK_USE_OS_STRING "qnx"
  470. #elif defined(DUK_F_TINSPIRE)
  471. /* --- TI-Nspire --- */
  472. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  473. #define DUK_USE_DATE_TZO_GMTIME_R
  474. #define DUK_USE_DATE_PRS_STRPTIME
  475. #define DUK_USE_DATE_FMT_STRFTIME
  476. #include <sys/types.h>
  477. #include <sys/param.h>
  478. #include <sys/time.h>
  479. #include <time.h>
  480. #define DUK_USE_OS_STRING "tinspire"
  481. #elif defined(DUK_F_EMSCRIPTEN)
  482. /* --- Emscripten --- */
  483. #if defined(DUK_COMPILING_DUKTAPE)
  484. #if !defined(_POSIX_C_SOURCE)
  485. #define _POSIX_C_SOURCE 200809L
  486. #endif
  487. #if !defined(_GNU_SOURCE)
  488. #define _GNU_SOURCE /* e.g. getdate_r */
  489. #endif
  490. #if !defined(_XOPEN_SOURCE)
  491. #define _XOPEN_SOURCE /* e.g. strptime */
  492. #endif
  493. #endif /* DUK_COMPILING_DUKTAPE */
  494. #include <sys/types.h>
  495. #if defined(DUK_F_BCC)
  496. /* no endian.h */
  497. #else
  498. #include <endian.h>
  499. #endif /* DUK_F_BCC */
  500. #include <sys/param.h>
  501. #include <sys/time.h>
  502. #include <time.h>
  503. #include <stdint.h>
  504. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  505. #define DUK_USE_DATE_TZO_GMTIME_R
  506. #define DUK_USE_DATE_PRS_STRPTIME
  507. #define DUK_USE_DATE_FMT_STRFTIME
  508. #define DUK_USE_OS_STRING "emscripten"
  509. #elif defined(DUK_F_LINUX)
  510. /* --- Linux --- */
  511. #if defined(DUK_COMPILING_DUKTAPE)
  512. #if !defined(_POSIX_C_SOURCE)
  513. #define _POSIX_C_SOURCE 200809L
  514. #endif
  515. #if !defined(_GNU_SOURCE)
  516. #define _GNU_SOURCE /* e.g. getdate_r */
  517. #endif
  518. #if !defined(_XOPEN_SOURCE)
  519. #define _XOPEN_SOURCE /* e.g. strptime */
  520. #endif
  521. #endif /* DUK_COMPILING_DUKTAPE */
  522. #include <sys/types.h>
  523. #if defined(DUK_F_BCC)
  524. /* no endian.h or stdint.h */
  525. #else
  526. #include <endian.h>
  527. #include <stdint.h>
  528. #endif /* DUK_F_BCC */
  529. #include <sys/param.h>
  530. #include <sys/time.h>
  531. #include <time.h>
  532. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  533. #define DUK_USE_DATE_TZO_GMTIME_R
  534. #define DUK_USE_DATE_PRS_STRPTIME
  535. #define DUK_USE_DATE_FMT_STRFTIME
  536. #define DUK_USE_OS_STRING "linux"
  537. #elif defined(DUK_F_SUN)
  538. /* --- Solaris --- */
  539. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  540. #define DUK_USE_DATE_TZO_GMTIME_R
  541. #define DUK_USE_DATE_PRS_STRPTIME
  542. #define DUK_USE_DATE_FMT_STRFTIME
  543. #include <sys/types.h>
  544. #include <ast/endian.h>
  545. #include <sys/param.h>
  546. #include <sys/time.h>
  547. #include <time.h>
  548. #define DUK_USE_OS_STRING "solaris"
  549. #elif defined(DUK_F_POSIX)
  550. /* --- Generic POSIX --- */
  551. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  552. #define DUK_USE_DATE_TZO_GMTIME_R
  553. #define DUK_USE_DATE_PRS_STRPTIME
  554. #define DUK_USE_DATE_FMT_STRFTIME
  555. #include <sys/types.h>
  556. #include <endian.h>
  557. #include <sys/param.h>
  558. #include <sys/time.h>
  559. #include <time.h>
  560. #define DUK_USE_OS_STRING "posix"
  561. #elif defined(DUK_F_CYGWIN)
  562. /* --- Cygwin --- */
  563. /* don't use strptime() for now */
  564. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  565. #define DUK_USE_DATE_TZO_GMTIME_R
  566. #define DUK_USE_DATE_FMT_STRFTIME
  567. #include <sys/types.h>
  568. #include <endian.h>
  569. #include <sys/param.h>
  570. #include <sys/time.h>
  571. #include <time.h>
  572. #define DUK_JMPBUF_TYPE jmp_buf
  573. #define DUK_SETJMP(jb) _setjmp((jb))
  574. #define DUK_LONGJMP(jb) _longjmp((jb), 1)
  575. #define DUK_USE_OS_STRING "windows"
  576. #elif defined(DUK_F_UNIX)
  577. /* --- Generic UNIX --- */
  578. #define DUK_USE_DATE_NOW_GETTIMEOFDAY
  579. #define DUK_USE_DATE_TZO_GMTIME_R
  580. #define DUK_USE_DATE_PRS_STRPTIME
  581. #define DUK_USE_DATE_FMT_STRFTIME
  582. #include <time.h>
  583. #include <sys/time.h>
  584. #define DUK_USE_OS_STRING "unknown"
  585. #else
  586. /* --- Generic fallback --- */
  587. /* The most portable current time provider is time(), but it only has a
  588. * one second resolution.
  589. */
  590. #define DUK_USE_DATE_NOW_TIME
  591. /* The most portable way to figure out local time offset is gmtime(),
  592. * but it's not thread safe so use with caution.
  593. */
  594. #define DUK_USE_DATE_TZO_GMTIME
  595. /* Avoid custom date parsing and formatting for portability. */
  596. #undef DUK_USE_DATE_PRS_STRPTIME
  597. #undef DUK_USE_DATE_FMT_STRFTIME
  598. /* Rely on C89 headers only; time.h must be here. */
  599. #include <time.h>
  600. #define DUK_USE_OS_STRING "unknown"
  601. #endif /* autodetect platform */
  602. /* Shared includes: C89 */
  603. #include <stdio.h>
  604. #include <stdlib.h>
  605. #include <string.h>
  606. #include <stdarg.h> /* varargs */
  607. #include <setjmp.h>
  608. #include <stddef.h> /* e.g. ptrdiff_t */
  609. #include <math.h>
  610. #include <limits.h>
  611. /* date.h is omitted, and included per platform */
  612. /* Shared includes: stdint.h is C99 */
  613. #if defined(DUK_F_NO_STDINT_H)
  614. /* stdint.h not available */
  615. #else
  616. /* Technically C99 (C++11) but found in many systems. On some systems
  617. * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
  618. * including stdint.h (see above).
  619. */
  620. #include <stdint.h>
  621. #endif
  622. #if defined(DUK_F_CPP)
  623. #include <exception> /* std::exception */
  624. #endif
  625. /*
  626. * Architecture autodetection
  627. */
  628. #if defined(DUK_F_X86)
  629. /* --- x86 --- */
  630. #define DUK_USE_ARCH_STRING "x86"
  631. #if !defined(DUK_USE_BYTEORDER)
  632. #define DUK_USE_BYTEORDER 1
  633. #endif
  634. /* XXX: This is technically not guaranteed because it's possible to configure
  635. * an x86 to require aligned accesses with Alignment Check (AC) flag.
  636. */
  637. #if !defined(DUK_USE_ALIGN_BY)
  638. #define DUK_USE_ALIGN_BY 1
  639. #endif
  640. #define DUK_USE_PACKED_TVAL
  641. #define DUK_F_PACKED_TVAL_PROVIDED
  642. #elif defined(DUK_F_X64)
  643. /* --- x64 --- */
  644. #define DUK_USE_ARCH_STRING "x64"
  645. #if !defined(DUK_USE_BYTEORDER)
  646. #define DUK_USE_BYTEORDER 1
  647. #endif
  648. /* XXX: This is technically not guaranteed because it's possible to configure
  649. * an x86 to require aligned accesses with Alignment Check (AC) flag.
  650. */
  651. #if !defined(DUK_USE_ALIGN_BY)
  652. #define DUK_USE_ALIGN_BY 1
  653. #endif
  654. #undef DUK_USE_PACKED_TVAL
  655. #define DUK_F_PACKED_TVAL_PROVIDED
  656. #elif defined(DUK_F_X32)
  657. /* --- x32 --- */
  658. #define DUK_USE_ARCH_STRING "x32"
  659. #if !defined(DUK_USE_BYTEORDER)
  660. #define DUK_USE_BYTEORDER 1
  661. #endif
  662. /* XXX: This is technically not guaranteed because it's possible to configure
  663. * an x86 to require aligned accesses with Alignment Check (AC) flag.
  664. */
  665. #if !defined(DUK_USE_ALIGN_BY)
  666. #define DUK_USE_ALIGN_BY 1
  667. #endif
  668. #define DUK_USE_PACKED_TVAL
  669. #define DUK_F_PACKED_TVAL_PROVIDED
  670. #elif defined(DUK_F_ARM32)
  671. /* --- ARM 32-bit --- */
  672. #define DUK_USE_ARCH_STRING "arm32"
  673. /* Byte order varies, so rely on autodetect. */
  674. #if !defined(DUK_USE_ALIGN_BY)
  675. #define DUK_USE_ALIGN_BY 4
  676. #endif
  677. #define DUK_USE_PACKED_TVAL
  678. #define DUK_F_PACKED_TVAL_PROVIDED
  679. #elif defined(DUK_F_ARM64)
  680. /* --- ARM 64-bit --- */
  681. #define DUK_USE_ARCH_STRING "arm64"
  682. /* Byte order varies, so rely on autodetect. */
  683. #if !defined(DUK_USE_ALIGN_BY)
  684. #define DUK_USE_ALIGN_BY 8
  685. #endif
  686. #undef DUK_USE_PACKED_TVAL
  687. #define DUK_F_PACKED_TVAL_PROVIDED
  688. #elif defined(DUK_F_MIPS32)
  689. /* --- MIPS 32-bit --- */
  690. #define DUK_USE_ARCH_STRING "mips32"
  691. /* MIPS byte order varies so rely on autodetection. */
  692. /* Based on 'make checkalign' there are no alignment requirements on
  693. * Linux MIPS except for doubles, which need align by 4. Alignment
  694. * requirements vary based on target though.
  695. */
  696. #if !defined(DUK_USE_ALIGN_BY)
  697. #define DUK_USE_ALIGN_BY 4
  698. #endif
  699. #define DUK_USE_PACKED_TVAL
  700. #define DUK_F_PACKED_TVAL_PROVIDED
  701. #elif defined(DUK_F_MIPS64)
  702. /* --- MIPS 64-bit --- */
  703. #define DUK_USE_ARCH_STRING "mips64"
  704. /* MIPS byte order varies so rely on autodetection. */
  705. /* Good default is a bit arbitrary because alignment requirements
  706. * depend on target. See https://github.com/svaarala/duktape/issues/102.
  707. */
  708. #if !defined(DUK_USE_ALIGN_BY)
  709. #define DUK_USE_ALIGN_BY 8
  710. #endif
  711. #undef DUK_USE_PACKED_TVAL
  712. #define DUK_F_PACKED_TVAL_PROVIDED
  713. #elif defined(DUK_F_PPC32)
  714. /* --- PowerPC 32-bit --- */
  715. #define DUK_USE_ARCH_STRING "ppc32"
  716. #if !defined(DUK_USE_BYTEORDER)
  717. #define DUK_USE_BYTEORDER 3
  718. #endif
  719. #if !defined(DUK_USE_ALIGN_BY)
  720. #define DUK_USE_ALIGN_BY 8
  721. #endif
  722. #define DUK_USE_PACKED_TVAL
  723. #define DUK_F_PACKED_TVAL_PROVIDED
  724. #elif defined(DUK_F_PPC64)
  725. /* --- PowerPC 64-bit --- */
  726. #define DUK_USE_ARCH_STRING "ppc64"
  727. #if !defined(DUK_USE_BYTEORDER)
  728. #define DUK_USE_BYTEORDER 3
  729. #endif
  730. #if !defined(DUK_USE_ALIGN_BY)
  731. #define DUK_USE_ALIGN_BY 8
  732. #endif
  733. #undef DUK_USE_PACKED_TVAL
  734. #define DUK_F_PACKED_TVAL_PROVIDED
  735. #elif defined(DUK_F_SPARC32)
  736. /* --- SPARC 32-bit --- */
  737. #define DUK_USE_ARCH_STRING "sparc32"
  738. /* SPARC byte order varies so rely on autodetection. */
  739. #if !defined(DUK_USE_ALIGN_BY)
  740. #define DUK_USE_ALIGN_BY 8
  741. #endif
  742. #define DUK_USE_PACKED_TVAL
  743. #define DUK_F_PACKED_TVAL_PROVIDED
  744. #elif defined(DUK_F_SPARC64)
  745. /* --- SPARC 64-bit --- */
  746. #define DUK_USE_ARCH_STRING "sparc64"
  747. /* SPARC byte order varies so rely on autodetection. */
  748. #if !defined(DUK_USE_ALIGN_BY)
  749. #define DUK_USE_ALIGN_BY 8
  750. #endif
  751. #undef DUK_USE_PACKED_TVAL
  752. #define DUK_F_PACKED_TVAL_PROVIDED
  753. #elif defined(DUK_F_SUPERH)
  754. /* --- SuperH --- */
  755. #define DUK_USE_ARCH_STRING "sh"
  756. /* Byte order varies, rely on autodetection. */
  757. /* Based on 'make checkalign' there are no alignment requirements on
  758. * Linux SH4, but align by 4 is probably a good basic default.
  759. */
  760. #if !defined(DUK_USE_ALIGN_BY)
  761. #define DUK_USE_ALIGN_BY 4
  762. #endif
  763. #define DUK_USE_PACKED_TVAL
  764. #define DUK_F_PACKED_TVAL_PROVIDED
  765. #elif defined(DUK_F_M68K)
  766. /* --- Motorola 68k --- */
  767. #define DUK_USE_ARCH_STRING "m68k"
  768. #if !defined(DUK_USE_BYTEORDER)
  769. #define DUK_USE_BYTEORDER 3
  770. #endif
  771. #if !defined(DUK_USE_ALIGN_BY)
  772. #define DUK_USE_ALIGN_BY 8
  773. #endif
  774. #define DUK_USE_PACKED_TVAL
  775. #define DUK_F_PACKED_TVAL_PROVIDED
  776. #elif defined(DUK_F_EMSCRIPTEN)
  777. /* --- Emscripten --- */
  778. #define DUK_USE_ARCH_STRING "emscripten"
  779. #if !defined(DUK_USE_BYTEORDER)
  780. #define DUK_USE_BYTEORDER 1
  781. #endif
  782. #if !defined(DUK_USE_ALIGN_BY)
  783. #define DUK_USE_ALIGN_BY 8
  784. #endif
  785. #undef DUK_USE_PACKED_TVAL
  786. #define DUK_F_PACKED_TVAL_PROVIDED
  787. #else
  788. /* --- Generic --- */
  789. /* These are necessary wild guesses. */
  790. #define DUK_USE_ARCH_STRING "generic"
  791. /* Rely on autodetection for byte order, alignment, and packed tval. */
  792. #endif /* autodetect architecture */
  793. /*
  794. * Compiler autodetection
  795. */
  796. #if defined(DUK_F_CLANG)
  797. /* --- Clang --- */
  798. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  799. /* C99 / C++11 and above: rely on va_copy() which is required. */
  800. #define DUK_VA_COPY(dest,src) va_copy(dest,src)
  801. #else
  802. /* Clang: assume we have __va_copy() in non-C99 mode. */
  803. #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
  804. #endif
  805. #define DUK_NORETURN(decl) decl __attribute__((noreturn))
  806. #if defined(__clang__) && defined(__has_builtin)
  807. #if __has_builtin(__builtin_unreachable)
  808. #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
  809. #endif
  810. #endif
  811. #define DUK_USE_BRANCH_HINTS
  812. #define DUK_LIKELY(x) __builtin_expect((x), 1)
  813. #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
  814. #if defined(__clang__) && defined(__has_builtin)
  815. #if __has_builtin(__builtin_unpredictable)
  816. #define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x))
  817. #endif
  818. #endif
  819. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  820. #define DUK_NOINLINE __attribute__((noinline))
  821. #define DUK_INLINE inline
  822. #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
  823. #endif
  824. #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
  825. /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
  826. * compiling Duktape or the application.
  827. */
  828. #if defined(DUK_COMPILING_DUKTAPE)
  829. #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
  830. #define DUK_EXTERNAL __declspec(dllexport)
  831. #else
  832. #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
  833. #define DUK_EXTERNAL should_not_happen
  834. #endif
  835. #if defined(DUK_SINGLE_FILE)
  836. #define DUK_INTERNAL_DECL static
  837. #define DUK_INTERNAL static
  838. #else
  839. #define DUK_INTERNAL_DECL extern
  840. #define DUK_INTERNAL /*empty*/
  841. #endif
  842. #define DUK_LOCAL_DECL static
  843. #define DUK_LOCAL static
  844. #else
  845. #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
  846. #define DUK_EXTERNAL __attribute__ ((visibility("default")))
  847. #if defined(DUK_SINGLE_FILE)
  848. #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
  849. /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
  850. * Clang. Based on documentation it should suffice to have the attribute
  851. * in the declaration only, but in practice some warnings are generated unless
  852. * the attribute is also applied to the definition.
  853. */
  854. #define DUK_INTERNAL_DECL static __attribute__ ((unused))
  855. #define DUK_INTERNAL static __attribute__ ((unused))
  856. #else
  857. #define DUK_INTERNAL_DECL static
  858. #define DUK_INTERNAL static
  859. #endif
  860. #else
  861. #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
  862. #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
  863. #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
  864. #else
  865. #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
  866. #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
  867. #endif
  868. #endif
  869. #define DUK_LOCAL_DECL static
  870. #define DUK_LOCAL static
  871. #endif
  872. #if defined(DUK_F_CPP)
  873. #define DUK_USE_COMPILER_STRING "clang"
  874. #else
  875. #define DUK_USE_COMPILER_STRING "clang"
  876. #endif
  877. #undef DUK_USE_VARIADIC_MACROS
  878. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  879. #define DUK_USE_VARIADIC_MACROS
  880. #endif
  881. #define DUK_USE_UNION_INITIALIZERS
  882. #undef DUK_USE_FLEX_C99
  883. #undef DUK_USE_FLEX_ZEROSIZE
  884. #undef DUK_USE_FLEX_ONESIZE
  885. #if defined(DUK_F_C99)
  886. #define DUK_USE_FLEX_C99
  887. #else
  888. #define DUK_USE_FLEX_ZEROSIZE
  889. #endif
  890. #undef DUK_USE_GCC_PRAGMAS
  891. #define DUK_USE_PACK_CLANG_ATTR
  892. #elif defined(DUK_F_GCC)
  893. /* --- GCC --- */
  894. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  895. /* C99 / C++11 and above: rely on va_copy() which is required. */
  896. #define DUK_VA_COPY(dest,src) va_copy(dest,src)
  897. #else
  898. /* GCC: assume we have __va_copy() in non-C99 mode. */
  899. #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
  900. #endif
  901. #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L)
  902. /* since gcc-2.5 */
  903. #define DUK_NORETURN(decl) decl __attribute__((noreturn))
  904. #endif
  905. #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
  906. /* since gcc-4.5 */
  907. #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
  908. #endif
  909. #define DUK_USE_BRANCH_HINTS
  910. #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
  911. /* GCC: test not very accurate; enable only in relatively recent builds
  912. * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
  913. */
  914. #define DUK_LIKELY(x) __builtin_expect((x), 1)
  915. #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
  916. #endif
  917. /* XXX: equivalent of clang __builtin_unpredictable? */
  918. #if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
  919. defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101)
  920. #define DUK_NOINLINE __attribute__((noinline))
  921. #define DUK_INLINE inline
  922. #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
  923. #endif
  924. #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
  925. /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
  926. * compiling Duktape or the application.
  927. */
  928. #if defined(DUK_COMPILING_DUKTAPE)
  929. #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
  930. #define DUK_EXTERNAL __declspec(dllexport)
  931. #else
  932. #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
  933. #define DUK_EXTERNAL should_not_happen
  934. #endif
  935. #if defined(DUK_SINGLE_FILE)
  936. #define DUK_INTERNAL_DECL static
  937. #define DUK_INTERNAL static
  938. #else
  939. #define DUK_INTERNAL_DECL extern
  940. #define DUK_INTERNAL /*empty*/
  941. #endif
  942. #define DUK_LOCAL_DECL static
  943. #define DUK_LOCAL static
  944. #elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000)
  945. #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
  946. #define DUK_EXTERNAL __attribute__ ((visibility("default")))
  947. #if defined(DUK_SINGLE_FILE)
  948. #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
  949. /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
  950. * Clang. Based on documentation it should suffice to have the attribute
  951. * in the declaration only, but in practice some warnings are generated unless
  952. * the attribute is also applied to the definition.
  953. */
  954. #define DUK_INTERNAL_DECL static __attribute__ ((unused))
  955. #define DUK_INTERNAL static __attribute__ ((unused))
  956. #else
  957. #define DUK_INTERNAL_DECL static
  958. #define DUK_INTERNAL static
  959. #endif
  960. #else
  961. #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
  962. #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
  963. #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
  964. #else
  965. #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
  966. #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
  967. #endif
  968. #endif
  969. #define DUK_LOCAL_DECL static
  970. #define DUK_LOCAL static
  971. #endif
  972. #if defined(DUK_F_MINGW)
  973. #if defined(DUK_F_CPP)
  974. #define DUK_USE_COMPILER_STRING "mingw++"
  975. #else
  976. #define DUK_USE_COMPILER_STRING "mingw"
  977. #endif
  978. #else
  979. #if defined(DUK_F_CPP)
  980. #define DUK_USE_COMPILER_STRING "g++"
  981. #else
  982. #define DUK_USE_COMPILER_STRING "gcc"
  983. #endif
  984. #endif
  985. #undef DUK_USE_VARIADIC_MACROS
  986. #if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
  987. #define DUK_USE_VARIADIC_MACROS
  988. #endif
  989. #define DUK_USE_UNION_INITIALIZERS
  990. #undef DUK_USE_FLEX_C99
  991. #undef DUK_USE_FLEX_ZEROSIZE
  992. #undef DUK_USE_FLEX_ONESIZE
  993. #if defined(DUK_F_C99)
  994. #define DUK_USE_FLEX_C99
  995. #else
  996. #define DUK_USE_FLEX_ZEROSIZE
  997. #endif
  998. #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600)
  999. #define DUK_USE_GCC_PRAGMAS
  1000. #else
  1001. #undef DUK_USE_GCC_PRAGMAS
  1002. #endif
  1003. #define DUK_USE_PACK_GCC_ATTR
  1004. #elif defined(DUK_F_MSVC)
  1005. /* --- MSVC --- */
  1006. /* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
  1007. #define DUK_NORETURN(decl) __declspec(noreturn) decl
  1008. /* XXX: DUK_UNREACHABLE for msvc? */
  1009. #undef DUK_USE_BRANCH_HINTS
  1010. /* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
  1011. /* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
  1012. #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
  1013. /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
  1014. * compiling Duktape or the application.
  1015. */
  1016. #if defined(DUK_COMPILING_DUKTAPE)
  1017. #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
  1018. #define DUK_EXTERNAL __declspec(dllexport)
  1019. #else
  1020. #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
  1021. #define DUK_EXTERNAL should_not_happen
  1022. #endif
  1023. #if defined(DUK_SINGLE_FILE)
  1024. #define DUK_INTERNAL_DECL static
  1025. #define DUK_INTERNAL static
  1026. #else
  1027. #define DUK_INTERNAL_DECL extern
  1028. #define DUK_INTERNAL /*empty*/
  1029. #endif
  1030. #define DUK_LOCAL_DECL static
  1031. #define DUK_LOCAL static
  1032. #endif
  1033. #if defined(DUK_F_CPP)
  1034. #define DUK_USE_COMPILER_STRING "msvc++"
  1035. #else
  1036. #define DUK_USE_COMPILER_STRING "msvc"
  1037. #endif
  1038. #undef DUK_USE_VARIADIC_MACROS
  1039. #if defined(DUK_F_C99)
  1040. #define DUK_USE_VARIADIC_MACROS
  1041. #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
  1042. /* VS2005+ should have variadic macros even when they're not C99. */
  1043. #define DUK_USE_VARIADIC_MACROS
  1044. #endif
  1045. #undef DUK_USE_UNION_INITIALIZERS
  1046. #if defined(_MSC_VER) && (_MSC_VER >= 1800)
  1047. /* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
  1048. * https://connect.microsoft.com/VisualStudio/feedback/details/805981
  1049. * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
  1050. * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
  1051. * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
  1052. */
  1053. #define DUK_USE_UNION_INITIALIZERS
  1054. #endif
  1055. #undef DUK_USE_FLEX_C99
  1056. #undef DUK_USE_FLEX_ZEROSIZE
  1057. #undef DUK_USE_FLEX_ONESIZE
  1058. #if defined(DUK_F_C99)
  1059. #define DUK_USE_FLEX_C99
  1060. #else
  1061. #define DUK_USE_FLEX_ZEROSIZE
  1062. #endif
  1063. #undef DUK_USE_GCC_PRAGMAS
  1064. #define DUK_USE_PACK_MSVC_PRAGMA
  1065. /* These have been tested from VS2008 onwards; may work in older VS versions
  1066. * too but not enabled by default.
  1067. */
  1068. #if defined(_MSC_VER) && (_MSC_VER >= 1500)
  1069. #define DUK_NOINLINE __declspec(noinline)
  1070. #define DUK_INLINE __inline
  1071. #define DUK_ALWAYS_INLINE __forceinline
  1072. #endif
  1073. #if defined(_MSC_VER) && (_MSC_VER >= 1900)
  1074. #define DUK_SNPRINTF snprintf
  1075. #define DUK_VSNPRINTF vsnprintf
  1076. #else
  1077. /* (v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
  1078. * NOT NUL terminate on truncation, but Duktape code never assumes that.
  1079. * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
  1080. */
  1081. #define DUK_SNPRINTF _snprintf
  1082. #define DUK_VSNPRINTF _vsnprintf
  1083. #endif
  1084. /* Avoid warning when doing DUK_UNREF(some_function). */
  1085. #define DUK_UNREF(x) do { __pragma(warning(suppress:4100 4101 4550 4551)) (x); } while (0)
  1086. #elif defined(DUK_F_EMSCRIPTEN)
  1087. /* --- Emscripten --- */
  1088. #define DUK_NORETURN(decl) decl __attribute__((noreturn))
  1089. #if defined(__clang__) && defined(__has_builtin)
  1090. #if __has_builtin(__builtin_unreachable)
  1091. #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
  1092. #endif
  1093. #endif
  1094. #define DUK_USE_BRANCH_HINTS
  1095. #define DUK_LIKELY(x) __builtin_expect((x), 1)
  1096. #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
  1097. #if defined(__clang__) && defined(__has_builtin)
  1098. #if __has_builtin(__builtin_unpredictable)
  1099. #define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x))
  1100. #endif
  1101. #endif
  1102. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  1103. #define DUK_NOINLINE __attribute__((noinline))
  1104. #define DUK_INLINE inline
  1105. #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
  1106. #endif
  1107. #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
  1108. #define DUK_EXTERNAL __attribute__ ((visibility("default")))
  1109. #if defined(DUK_SINGLE_FILE)
  1110. #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
  1111. /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
  1112. * Clang. Based on documentation it should suffice to have the attribute
  1113. * in the declaration only, but in practice some warnings are generated unless
  1114. * the attribute is also applied to the definition.
  1115. */
  1116. #define DUK_INTERNAL_DECL static __attribute__ ((unused))
  1117. #define DUK_INTERNAL static __attribute__ ((unused))
  1118. #else
  1119. #define DUK_INTERNAL_DECL static
  1120. #define DUK_INTERNAL static
  1121. #endif
  1122. #else
  1123. #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
  1124. #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
  1125. #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
  1126. #else
  1127. #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
  1128. #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
  1129. #endif
  1130. #endif
  1131. #define DUK_LOCAL_DECL static
  1132. #define DUK_LOCAL static
  1133. #define DUK_USE_COMPILER_STRING "emscripten"
  1134. #undef DUK_USE_VARIADIC_MACROS
  1135. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  1136. #define DUK_USE_VARIADIC_MACROS
  1137. #endif
  1138. #define DUK_USE_UNION_INITIALIZERS
  1139. #undef DUK_USE_FLEX_C99
  1140. #undef DUK_USE_FLEX_ZEROSIZE
  1141. #undef DUK_USE_FLEX_ONESIZE
  1142. #if defined(DUK_F_C99)
  1143. #define DUK_USE_FLEX_C99
  1144. #else
  1145. #define DUK_USE_FLEX_ZEROSIZE
  1146. #endif
  1147. #undef DUK_USE_GCC_PRAGMAS
  1148. #define DUK_USE_PACK_CLANG_ATTR
  1149. #elif defined(DUK_F_TINYC)
  1150. /* --- TinyC --- */
  1151. #undef DUK_USE_BRANCH_HINTS
  1152. #if defined(DUK_F_CPP)
  1153. #define DUK_USE_COMPILER_STRING "tinyc++"
  1154. #else
  1155. #define DUK_USE_COMPILER_STRING "tinyc"
  1156. #endif
  1157. /* http://bellard.org/tcc/tcc-doc.html#SEC7 */
  1158. #define DUK_USE_VARIADIC_MACROS
  1159. #define DUK_USE_UNION_INITIALIZERS
  1160. /* Most portable, wastes space */
  1161. #define DUK_USE_FLEX_ONESIZE
  1162. /* Most portable, potentially wastes space */
  1163. #define DUK_USE_PACK_DUMMY_MEMBER
  1164. #elif defined(DUK_F_VBCC)
  1165. /* --- VBCC --- */
  1166. #undef DUK_USE_BRANCH_HINTS
  1167. #if defined(DUK_F_CPP)
  1168. #define DUK_USE_COMPILER_STRING "vbcc-c++"
  1169. #else
  1170. #define DUK_USE_COMPILER_STRING "vbcc"
  1171. #endif
  1172. #undef DUK_USE_VARIADIC_MACROS
  1173. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  1174. #define DUK_USE_VARIADIC_MACROS
  1175. #endif
  1176. /* VBCC supports C99 so check only for C99 for union initializer support.
  1177. * Designated union initializers would possibly work even without a C99 check.
  1178. */
  1179. #undef DUK_USE_UNION_INITIALIZERS
  1180. #if defined(DUK_F_C99)
  1181. #define DUK_USE_UNION_INITIALIZERS
  1182. #endif
  1183. #define DUK_USE_FLEX_ZEROSIZE
  1184. #define DUK_USE_PACK_DUMMY_MEMBER
  1185. #elif defined(DUK_F_BCC)
  1186. /* --- Bruce's C compiler --- */
  1187. #undef DUK_USE_BRANCH_HINTS
  1188. #if defined(DUK_F_CPP)
  1189. #define DUK_USE_COMPILER_STRING "bcc++"
  1190. #else
  1191. #define DUK_USE_COMPILER_STRING "bcc"
  1192. #endif
  1193. /* Most portable */
  1194. #undef DUK_USE_VARIADIC_MACROS
  1195. /* Most portable, wastes space */
  1196. #undef DUK_USE_UNION_INITIALIZERS
  1197. /* Most portable, wastes space */
  1198. #define DUK_USE_FLEX_ONESIZE
  1199. /* Most portable, potentially wastes space */
  1200. #define DUK_USE_PACK_DUMMY_MEMBER
  1201. /* BCC, assume we're on x86. */
  1202. #if !defined(DUK_USE_BYTEORDER)
  1203. #define DUK_USE_BYTEORDER 1
  1204. #endif
  1205. #else
  1206. /* --- Generic --- */
  1207. #undef DUK_USE_BRANCH_HINTS
  1208. #if defined(DUK_F_CPP)
  1209. #define DUK_USE_COMPILER_STRING "generic-c++"
  1210. #else
  1211. #define DUK_USE_COMPILER_STRING "generic"
  1212. #endif
  1213. #undef DUK_USE_VARIADIC_MACROS
  1214. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  1215. #define DUK_USE_VARIADIC_MACROS
  1216. #endif
  1217. /* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
  1218. #undef DUK_USE_UNION_INITIALIZERS
  1219. #if defined(DUK_F_C99)
  1220. #define DUK_USE_UNION_INITIALIZERS
  1221. #endif
  1222. /* Most portable, wastes space */
  1223. #define DUK_USE_FLEX_ONESIZE
  1224. /* Most portable, potentially wastes space */
  1225. #define DUK_USE_PACK_DUMMY_MEMBER
  1226. #endif /* autodetect compiler */
  1227. /* uclibc */
  1228. #if defined(__UCLIBC__)
  1229. #define DUK_F_UCLIBC
  1230. #endif
  1231. /*
  1232. * Wrapper typedefs and constants for integer types, also sanity check types.
  1233. *
  1234. * C99 typedefs are quite good but not always available, and we want to avoid
  1235. * forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
  1236. * all C99 typedefs and Duktape code should only use these typedefs. Type
  1237. * detection when C99 is not supported is best effort and may end up detecting
  1238. * some types incorrectly.
  1239. *
  1240. * Pointer sizes are a portability problem: pointers to different types may
  1241. * have a different size and function pointers are very difficult to manage
  1242. * portably.
  1243. *
  1244. * http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
  1245. *
  1246. * Note: there's an interesting corner case when trying to define minimum
  1247. * signed integer value constants which leads to the current workaround of
  1248. * defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
  1249. * for a longer discussion.
  1250. *
  1251. * Note: avoid typecasts and computations in macro integer constants as they
  1252. * can then no longer be used in macro relational expressions (such as
  1253. * #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
  1254. * being able to compare DUK_SIZE_MAX against a limit.
  1255. */
  1256. /* XXX: add feature options to force basic types from outside? */
  1257. #if !defined(INT_MAX)
  1258. #error INT_MAX not defined
  1259. #endif
  1260. /* Check that architecture is two's complement, standard C allows e.g.
  1261. * INT_MIN to be -2**31+1 (instead of -2**31).
  1262. */
  1263. #if defined(INT_MAX) && defined(INT_MIN)
  1264. #if INT_MAX != -(INT_MIN + 1)
  1265. #error platform does not seem complement of two
  1266. #endif
  1267. #else
  1268. #error cannot check complement of two
  1269. #endif
  1270. /* Pointer size determination based on __WORDSIZE or architecture when
  1271. * that's not available.
  1272. */
  1273. #if defined(DUK_F_X86) || defined(DUK_F_X32) || \
  1274. defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \
  1275. defined(DUK_F_BCC) || defined(__ANDROID__) || \
  1276. (defined(__WORDSIZE) && (__WORDSIZE == 32))
  1277. #define DUK_F_32BIT_PTRS
  1278. #elif defined(DUK_F_X64) || \
  1279. (defined(__WORDSIZE) && (__WORDSIZE == 64))
  1280. #define DUK_F_64BIT_PTRS
  1281. #else
  1282. /* not sure, not needed with C99 anyway */
  1283. #endif
  1284. /* Intermediate define for 'have inttypes.h' */
  1285. #undef DUK_F_HAVE_INTTYPES
  1286. #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  1287. !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
  1288. /* vbcc + AmigaOS has C99 but no inttypes.h */
  1289. #define DUK_F_HAVE_INTTYPES
  1290. #elif defined(__cplusplus) && (__cplusplus >= 201103L)
  1291. /* C++11 apparently ratified stdint.h */
  1292. #define DUK_F_HAVE_INTTYPES
  1293. #endif
  1294. /* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
  1295. * through automatic detection.
  1296. */
  1297. #if defined(DUK_F_HAVE_INTTYPES)
  1298. /* C99 or compatible */
  1299. #define DUK_F_HAVE_64BIT
  1300. #include <inttypes.h>
  1301. typedef uint8_t duk_uint8_t;
  1302. typedef int8_t duk_int8_t;
  1303. typedef uint16_t duk_uint16_t;
  1304. typedef int16_t duk_int16_t;
  1305. typedef uint32_t duk_uint32_t;
  1306. typedef int32_t duk_int32_t;
  1307. typedef uint64_t duk_uint64_t;
  1308. typedef int64_t duk_int64_t;
  1309. typedef uint_least8_t duk_uint_least8_t;
  1310. typedef int_least8_t duk_int_least8_t;
  1311. typedef uint_least16_t duk_uint_least16_t;
  1312. typedef int_least16_t duk_int_least16_t;
  1313. typedef uint_least32_t duk_uint_least32_t;
  1314. typedef int_least32_t duk_int_least32_t;
  1315. typedef uint_least64_t duk_uint_least64_t;
  1316. typedef int_least64_t duk_int_least64_t;
  1317. typedef uint_fast8_t duk_uint_fast8_t;
  1318. typedef int_fast8_t duk_int_fast8_t;
  1319. typedef uint_fast16_t duk_uint_fast16_t;
  1320. typedef int_fast16_t duk_int_fast16_t;
  1321. typedef uint_fast32_t duk_uint_fast32_t;
  1322. typedef int_fast32_t duk_int_fast32_t;
  1323. typedef uint_fast64_t duk_uint_fast64_t;
  1324. typedef int_fast64_t duk_int_fast64_t;
  1325. typedef uintptr_t duk_uintptr_t;
  1326. typedef intptr_t duk_intptr_t;
  1327. typedef uintmax_t duk_uintmax_t;
  1328. typedef intmax_t duk_intmax_t;
  1329. #define DUK_UINT8_MIN 0
  1330. #define DUK_UINT8_MAX UINT8_MAX
  1331. #define DUK_INT8_MIN INT8_MIN
  1332. #define DUK_INT8_MAX INT8_MAX
  1333. #define DUK_UINT_LEAST8_MIN 0
  1334. #define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX
  1335. #define DUK_INT_LEAST8_MIN INT_LEAST8_MIN
  1336. #define DUK_INT_LEAST8_MAX INT_LEAST8_MAX
  1337. #define DUK_UINT_FAST8_MIN 0
  1338. #define DUK_UINT_FAST8_MAX UINT_FAST8_MAX
  1339. #define DUK_INT_FAST8_MIN INT_FAST8_MIN
  1340. #define DUK_INT_FAST8_MAX INT_FAST8_MAX
  1341. #define DUK_UINT16_MIN 0
  1342. #define DUK_UINT16_MAX UINT16_MAX
  1343. #define DUK_INT16_MIN INT16_MIN
  1344. #define DUK_INT16_MAX INT16_MAX
  1345. #define DUK_UINT_LEAST16_MIN 0
  1346. #define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX
  1347. #define DUK_INT_LEAST16_MIN INT_LEAST16_MIN
  1348. #define DUK_INT_LEAST16_MAX INT_LEAST16_MAX
  1349. #define DUK_UINT_FAST16_MIN 0
  1350. #define DUK_UINT_FAST16_MAX UINT_FAST16_MAX
  1351. #define DUK_INT_FAST16_MIN INT_FAST16_MIN
  1352. #define DUK_INT_FAST16_MAX INT_FAST16_MAX
  1353. #define DUK_UINT32_MIN 0
  1354. #define DUK_UINT32_MAX UINT32_MAX
  1355. #define DUK_INT32_MIN INT32_MIN
  1356. #define DUK_INT32_MAX INT32_MAX
  1357. #define DUK_UINT_LEAST32_MIN 0
  1358. #define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX
  1359. #define DUK_INT_LEAST32_MIN INT_LEAST32_MIN
  1360. #define DUK_INT_LEAST32_MAX INT_LEAST32_MAX
  1361. #define DUK_UINT_FAST32_MIN 0
  1362. #define DUK_UINT_FAST32_MAX UINT_FAST32_MAX
  1363. #define DUK_INT_FAST32_MIN INT_FAST32_MIN
  1364. #define DUK_INT_FAST32_MAX INT_FAST32_MAX
  1365. #define DUK_UINT64_MIN 0
  1366. #define DUK_UINT64_MAX UINT64_MAX
  1367. #define DUK_INT64_MIN INT64_MIN
  1368. #define DUK_INT64_MAX INT64_MAX
  1369. #define DUK_UINT_LEAST64_MIN 0
  1370. #define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX
  1371. #define DUK_INT_LEAST64_MIN INT_LEAST64_MIN
  1372. #define DUK_INT_LEAST64_MAX INT_LEAST64_MAX
  1373. #define DUK_UINT_FAST64_MIN 0
  1374. #define DUK_UINT_FAST64_MAX UINT_FAST64_MAX
  1375. #define DUK_INT_FAST64_MIN INT_FAST64_MIN
  1376. #define DUK_INT_FAST64_MAX INT_FAST64_MAX
  1377. #define DUK_UINTPTR_MIN 0
  1378. #define DUK_UINTPTR_MAX UINTPTR_MAX
  1379. #define DUK_INTPTR_MIN INTPTR_MIN
  1380. #define DUK_INTPTR_MAX INTPTR_MAX
  1381. #define DUK_UINTMAX_MIN 0
  1382. #define DUK_UINTMAX_MAX UINTMAX_MAX
  1383. #define DUK_INTMAX_MIN INTMAX_MIN
  1384. #define DUK_INTMAX_MAX INTMAX_MAX
  1385. #define DUK_SIZE_MIN 0
  1386. #define DUK_SIZE_MAX SIZE_MAX
  1387. #undef DUK_SIZE_MAX_COMPUTED
  1388. #else /* C99 types */
  1389. /* When C99 types are not available, we use heuristic detection to get
  1390. * the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
  1391. * types are then assumed to be exactly the same for now: these could
  1392. * be improved per platform but C99 types are very often now available.
  1393. * 64-bit types are not available on all platforms; this is OK at least
  1394. * on 32-bit platforms.
  1395. *
  1396. * This detection code is necessarily a bit hacky and can provide typedefs
  1397. * and defines that won't work correctly on some exotic platform.
  1398. */
  1399. #if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
  1400. (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
  1401. typedef unsigned char duk_uint8_t;
  1402. typedef signed char duk_int8_t;
  1403. #else
  1404. #error cannot detect 8-bit type
  1405. #endif
  1406. #if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
  1407. typedef unsigned short duk_uint16_t;
  1408. typedef signed short duk_int16_t;
  1409. #elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
  1410. /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
  1411. typedef unsigned int duk_uint16_t;
  1412. typedef signed int duk_int16_t;
  1413. #else
  1414. #error cannot detect 16-bit type
  1415. #endif
  1416. #if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
  1417. typedef unsigned int duk_uint32_t;
  1418. typedef signed int duk_int32_t;
  1419. #elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
  1420. /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
  1421. typedef unsigned long duk_uint32_t;
  1422. typedef signed long duk_int32_t;
  1423. #else
  1424. #error cannot detect 32-bit type
  1425. #endif
  1426. /* 64-bit type detection is a bit tricky.
  1427. *
  1428. * ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
  1429. * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
  1430. * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
  1431. *
  1432. * ULL / LL constants are rejected / warned about by some compilers, even if
  1433. * the compiler has a 64-bit type and the compiler/system headers provide an
  1434. * unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
  1435. * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
  1436. * bits but can't be sure it is exactly 64 bits. Self tests will catch such
  1437. * cases.
  1438. */
  1439. #undef DUK_F_HAVE_64BIT
  1440. #if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
  1441. #if (ULONG_MAX > 4294967295UL)
  1442. #define DUK_F_HAVE_64BIT
  1443. typedef unsigned long duk_uint64_t;
  1444. typedef signed long duk_int64_t;
  1445. #endif
  1446. #endif
  1447. #if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
  1448. #if (ULLONG_MAX > 4294967295UL)
  1449. #define DUK_F_HAVE_64BIT
  1450. typedef unsigned long long duk_uint64_t;
  1451. typedef signed long long duk_int64_t;
  1452. #endif
  1453. #endif
  1454. #if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
  1455. #if (__ULONG_LONG_MAX__ > 4294967295UL)
  1456. #define DUK_F_HAVE_64BIT
  1457. typedef unsigned long long duk_uint64_t;
  1458. typedef signed long long duk_int64_t;
  1459. #endif
  1460. #endif
  1461. #if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
  1462. #if (__LONG_LONG_MAX__ > 2147483647L)
  1463. #define DUK_F_HAVE_64BIT
  1464. typedef unsigned long long duk_uint64_t;
  1465. typedef signed long long duk_int64_t;
  1466. #endif
  1467. #endif
  1468. #if !defined(DUK_F_HAVE_64BIT) && \
  1469. (defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
  1470. /* Both MinGW and MSVC have a 64-bit type. */
  1471. #define DUK_F_HAVE_64BIT
  1472. typedef unsigned long duk_uint64_t;
  1473. typedef signed long duk_int64_t;
  1474. #endif
  1475. #if !defined(DUK_F_HAVE_64BIT)
  1476. /* cannot detect 64-bit type, not always needed so don't error */
  1477. #endif
  1478. typedef duk_uint8_t duk_uint_least8_t;
  1479. typedef duk_int8_t duk_int_least8_t;
  1480. typedef duk_uint16_t duk_uint_least16_t;
  1481. typedef duk_int16_t duk_int_least16_t;
  1482. typedef duk_uint32_t duk_uint_least32_t;
  1483. typedef duk_int32_t duk_int_least32_t;
  1484. typedef duk_uint8_t duk_uint_fast8_t;
  1485. typedef duk_int8_t duk_int_fast8_t;
  1486. typedef duk_uint16_t duk_uint_fast16_t;
  1487. typedef duk_int16_t duk_int_fast16_t;
  1488. typedef duk_uint32_t duk_uint_fast32_t;
  1489. typedef duk_int32_t duk_int_fast32_t;
  1490. #if defined(DUK_F_HAVE_64BIT)
  1491. typedef duk_uint64_t duk_uint_least64_t;
  1492. typedef duk_int64_t duk_int_least64_t;
  1493. typedef duk_uint64_t duk_uint_fast64_t;
  1494. typedef duk_int64_t duk_int_fast64_t;
  1495. #endif
  1496. #if defined(DUK_F_HAVE_64BIT)
  1497. typedef duk_uint64_t duk_uintmax_t;
  1498. typedef duk_int64_t duk_intmax_t;
  1499. #else
  1500. typedef duk_uint32_t duk_uintmax_t;
  1501. typedef duk_int32_t duk_intmax_t;
  1502. #endif
  1503. /* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
  1504. * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
  1505. * -not- portable. See code-issues.txt for a detailed discussion.
  1506. */
  1507. #define DUK_UINT8_MIN 0UL
  1508. #define DUK_UINT8_MAX 0xffUL
  1509. #define DUK_INT8_MIN (-0x80L)
  1510. #define DUK_INT8_MAX 0x7fL
  1511. #define DUK_UINT_LEAST8_MIN 0UL
  1512. #define DUK_UINT_LEAST8_MAX 0xffUL
  1513. #define DUK_INT_LEAST8_MIN (-0x80L)
  1514. #define DUK_INT_LEAST8_MAX 0x7fL
  1515. #define DUK_UINT_FAST8_MIN 0UL
  1516. #define DUK_UINT_FAST8_MAX 0xffUL
  1517. #define DUK_INT_FAST8_MIN (-0x80L)
  1518. #define DUK_INT_FAST8_MAX 0x7fL
  1519. #define DUK_UINT16_MIN 0UL
  1520. #define DUK_UINT16_MAX 0xffffUL
  1521. #define DUK_INT16_MIN (-0x7fffL - 1L)
  1522. #define DUK_INT16_MAX 0x7fffL
  1523. #define DUK_UINT_LEAST16_MIN 0UL
  1524. #define DUK_UINT_LEAST16_MAX 0xffffUL
  1525. #define DUK_INT_LEAST16_MIN (-0x7fffL - 1L)
  1526. #define DUK_INT_LEAST16_MAX 0x7fffL
  1527. #define DUK_UINT_FAST16_MIN 0UL
  1528. #define DUK_UINT_FAST16_MAX 0xffffUL
  1529. #define DUK_INT_FAST16_MIN (-0x7fffL - 1L)
  1530. #define DUK_INT_FAST16_MAX 0x7fffL
  1531. #define DUK_UINT32_MIN 0UL
  1532. #define DUK_UINT32_MAX 0xffffffffUL
  1533. #define DUK_INT32_MIN (-0x7fffffffL - 1L)
  1534. #define DUK_INT32_MAX 0x7fffffffL
  1535. #define DUK_UINT_LEAST32_MIN 0UL
  1536. #define DUK_UINT_LEAST32_MAX 0xffffffffUL
  1537. #define DUK_INT_LEAST32_MIN (-0x7fffffffL - 1L)
  1538. #define DUK_INT_LEAST32_MAX 0x7fffffffL
  1539. #define DUK_UINT_FAST32_MIN 0UL
  1540. #define DUK_UINT_FAST32_MAX 0xffffffffUL
  1541. #define DUK_INT_FAST32_MIN (-0x7fffffffL - 1L)
  1542. #define DUK_INT_FAST32_MAX 0x7fffffffL
  1543. /* 64-bit constants. Since LL / ULL constants are not always available,
  1544. * use computed values. These values can't be used in preprocessor
  1545. * comparisons; flag them as such.
  1546. */
  1547. #if defined(DUK_F_HAVE_64BIT)
  1548. #define DUK_UINT64_MIN ((duk_uint64_t) 0)
  1549. #define DUK_UINT64_MAX ((duk_uint64_t) -1)
  1550. #define DUK_INT64_MIN ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
  1551. #define DUK_INT64_MAX ((duk_int64_t) (DUK_UINT64_MAX >> 1))
  1552. #define DUK_UINT_LEAST64_MIN DUK_UINT64_MIN
  1553. #define DUK_UINT_LEAST64_MAX DUK_UINT64_MAX
  1554. #define DUK_INT_LEAST64_MIN DUK_INT64_MIN
  1555. #define DUK_INT_LEAST64_MAX DUK_INT64_MAX
  1556. #define DUK_UINT_FAST64_MIN DUK_UINT64_MIN
  1557. #define DUK_UINT_FAST64_MAX DUK_UINT64_MAX
  1558. #define DUK_INT_FAST64_MIN DUK_INT64_MIN
  1559. #define DUK_INT_FAST64_MAX DUK_INT64_MAX
  1560. #define DUK_UINT64_MIN_COMPUTED
  1561. #define DUK_UINT64_MAX_COMPUTED
  1562. #define DUK_INT64_MIN_COMPUTED
  1563. #define DUK_INT64_MAX_COMPUTED
  1564. #define DUK_UINT_LEAST64_MIN_COMPUTED
  1565. #define DUK_UINT_LEAST64_MAX_COMPUTED
  1566. #define DUK_INT_LEAST64_MIN_COMPUTED
  1567. #define DUK_INT_LEAST64_MAX_COMPUTED
  1568. #define DUK_UINT_FAST64_MIN_COMPUTED
  1569. #define DUK_UINT_FAST64_MAX_COMPUTED
  1570. #define DUK_INT_FAST64_MIN_COMPUTED
  1571. #define DUK_INT_FAST64_MAX_COMPUTED
  1572. #endif
  1573. #if defined(DUK_F_HAVE_64BIT)
  1574. #define DUK_UINTMAX_MIN DUK_UINT64_MIN
  1575. #define DUK_UINTMAX_MAX DUK_UINT64_MAX
  1576. #define DUK_INTMAX_MIN DUK_INT64_MIN
  1577. #define DUK_INTMAX_MAX DUK_INT64_MAX
  1578. #define DUK_UINTMAX_MIN_COMPUTED
  1579. #define DUK_UINTMAX_MAX_COMPUTED
  1580. #define DUK_INTMAX_MIN_COMPUTED
  1581. #define DUK_INTMAX_MAX_COMPUTED
  1582. #else
  1583. #define DUK_UINTMAX_MIN 0UL
  1584. #define DUK_UINTMAX_MAX 0xffffffffUL
  1585. #define DUK_INTMAX_MIN (-0x7fffffffL - 1L)
  1586. #define DUK_INTMAX_MAX 0x7fffffffL
  1587. #endif
  1588. /* This detection is not very reliable. */
  1589. #if defined(DUK_F_32BIT_PTRS)
  1590. typedef duk_int32_t duk_intptr_t;
  1591. typedef duk_uint32_t duk_uintptr_t;
  1592. #define DUK_UINTPTR_MIN DUK_UINT32_MIN
  1593. #define DUK_UINTPTR_MAX DUK_UINT32_MAX
  1594. #define DUK_INTPTR_MIN DUK_INT32_MIN
  1595. #define DUK_INTPTR_MAX DUK_INT32_MAX
  1596. #elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
  1597. typedef duk_int64_t duk_intptr_t;
  1598. typedef duk_uint64_t duk_uintptr_t;
  1599. #define DUK_UINTPTR_MIN DUK_UINT64_MIN
  1600. #define DUK_UINTPTR_MAX DUK_UINT64_MAX
  1601. #define DUK_INTPTR_MIN DUK_INT64_MIN
  1602. #define DUK_INTPTR_MAX DUK_INT64_MAX
  1603. #define DUK_UINTPTR_MIN_COMPUTED
  1604. #define DUK_UINTPTR_MAX_COMPUTED
  1605. #define DUK_INTPTR_MIN_COMPUTED
  1606. #define DUK_INTPTR_MAX_COMPUTED
  1607. #else
  1608. #error cannot determine intptr type
  1609. #endif
  1610. /* SIZE_MAX may be missing so use an approximate value for it. */
  1611. #undef DUK_SIZE_MAX_COMPUTED
  1612. #if !defined(SIZE_MAX)
  1613. #define DUK_SIZE_MAX_COMPUTED
  1614. #define SIZE_MAX ((size_t) (-1))
  1615. #endif
  1616. #define DUK_SIZE_MIN 0
  1617. #define DUK_SIZE_MAX SIZE_MAX
  1618. #endif /* C99 types */
  1619. /* A few types are assumed to always exist. */
  1620. typedef size_t duk_size_t;
  1621. typedef ptrdiff_t duk_ptrdiff_t;
  1622. /* The best type for an "all around int" in Duktape internals is "at least
  1623. * 32 bit signed integer" which is most convenient. Same for unsigned type.
  1624. * Prefer 'int' when large enough, as it is almost always a convenient type.
  1625. */
  1626. #if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
  1627. typedef int duk_int_t;
  1628. typedef unsigned int duk_uint_t;
  1629. #define DUK_INT_MIN INT_MIN
  1630. #define DUK_INT_MAX INT_MAX
  1631. #define DUK_UINT_MIN 0
  1632. #define DUK_UINT_MAX UINT_MAX
  1633. #else
  1634. typedef duk_int_fast32_t duk_int_t;
  1635. typedef duk_uint_fast32_t duk_uint_t;
  1636. #define DUK_INT_MIN DUK_INT_FAST32_MIN
  1637. #define DUK_INT_MAX DUK_INT_FAST32_MAX
  1638. #define DUK_UINT_MIN DUK_UINT_FAST32_MIN
  1639. #define DUK_UINT_MAX DUK_UINT_FAST32_MAX
  1640. #endif
  1641. /* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
  1642. * distinction matters for the CPU. These types are used mainly in the
  1643. * executor where it might really matter.
  1644. */
  1645. typedef duk_int_fast32_t duk_int_fast_t;
  1646. typedef duk_uint_fast32_t duk_uint_fast_t;
  1647. #define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN
  1648. #define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX
  1649. #define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN
  1650. #define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX
  1651. /* Small integers (16 bits or more) can fall back to the 'int' type, but
  1652. * have a typedef so they are marked "small" explicitly.
  1653. */
  1654. typedef int duk_small_int_t;
  1655. typedef unsigned int duk_small_uint_t;
  1656. #define DUK_SMALL_INT_MIN INT_MIN
  1657. #define DUK_SMALL_INT_MAX INT_MAX
  1658. #define DUK_SMALL_UINT_MIN 0
  1659. #define DUK_SMALL_UINT_MAX UINT_MAX
  1660. /* Fast variants of small integers, again for really fast paths like the
  1661. * executor.
  1662. */
  1663. typedef duk_int_fast16_t duk_small_int_fast_t;
  1664. typedef duk_uint_fast16_t duk_small_uint_fast_t;
  1665. #define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN
  1666. #define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX
  1667. #define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN
  1668. #define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX
  1669. /* Boolean values are represented with the platform 'int'. */
  1670. typedef duk_small_int_t duk_bool_t;
  1671. #define DUK_BOOL_MIN DUK_SMALL_INT_MIN
  1672. #define DUK_BOOL_MAX DUK_SMALL_INT_MAX
  1673. /* Index values must have at least 32-bit signed range. */
  1674. typedef duk_int_t duk_idx_t;
  1675. #define DUK_IDX_MIN DUK_INT_MIN
  1676. #define DUK_IDX_MAX DUK_INT_MAX
  1677. /* Unsigned index variant. */
  1678. typedef duk_uint_t duk_uidx_t;
  1679. #define DUK_UIDX_MIN DUK_UINT_MIN
  1680. #define DUK_UIDX_MAX DUK_UINT_MAX
  1681. /* Array index values, could be exact 32 bits.
  1682. * Currently no need for signed duk_arridx_t.
  1683. */
  1684. typedef duk_uint_t duk_uarridx_t;
  1685. #define DUK_UARRIDX_MIN DUK_UINT_MIN
  1686. #define DUK_UARRIDX_MAX DUK_UINT_MAX
  1687. /* Duktape/C function return value, platform int is enough for now to
  1688. * represent 0, 1, or negative error code. Must be compatible with
  1689. * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
  1690. */
  1691. typedef duk_small_int_t duk_ret_t;
  1692. #define DUK_RET_MIN DUK_SMALL_INT_MIN
  1693. #define DUK_RET_MAX DUK_SMALL_INT_MAX
  1694. /* Error codes are represented with platform int. High bits are used
  1695. * for flags and such, so 32 bits are needed.
  1696. */
  1697. typedef duk_int_t duk_errcode_t;
  1698. #define DUK_ERRCODE_MIN DUK_INT_MIN
  1699. #define DUK_ERRCODE_MAX DUK_INT_MAX
  1700. /* Codepoint type. Must be 32 bits or more because it is used also for
  1701. * internal codepoints. The type is signed because negative codepoints
  1702. * are used as internal markers (e.g. to mark EOF or missing argument).
  1703. * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
  1704. * ensure duk_uint32_t casts back and forth nicely. Almost everything
  1705. * else uses the signed one.
  1706. */
  1707. typedef duk_int_t duk_codepoint_t;
  1708. typedef duk_uint_t duk_ucodepoint_t;
  1709. #define DUK_CODEPOINT_MIN DUK_INT_MIN
  1710. #define DUK_CODEPOINT_MAX DUK_INT_MAX
  1711. #define DUK_UCODEPOINT_MIN DUK_UINT_MIN
  1712. #define DUK_UCODEPOINT_MAX DUK_UINT_MAX
  1713. /* IEEE float/double typedef. */
  1714. typedef float duk_float_t;
  1715. typedef double duk_double_t;
  1716. /* We're generally assuming that we're working on a platform with a 32-bit
  1717. * address space. If DUK_SIZE_MAX is a typecast value (which is necessary
  1718. * if SIZE_MAX is missing), the check must be avoided because the
  1719. * preprocessor can't do a comparison.
  1720. */
  1721. #if !defined(DUK_SIZE_MAX)
  1722. #error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
  1723. #elif !defined(DUK_SIZE_MAX_COMPUTED)
  1724. #if DUK_SIZE_MAX < 0xffffffffUL
  1725. /* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
  1726. * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
  1727. * However, it doesn't seem useful to error out compilation if this is the
  1728. * case.
  1729. */
  1730. #endif
  1731. #endif
  1732. /* Type for public API calls. */
  1733. typedef struct duk_hthread duk_context;
  1734. /* Check whether we should use 64-bit integers or not.
  1735. *
  1736. * Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
  1737. * unless they are known to be unreliable. For instance, 64-bit types are
  1738. * available on VBCC but seem to misbehave.
  1739. */
  1740. #if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
  1741. #define DUK_USE_64BIT_OPS
  1742. #else
  1743. #undef DUK_USE_64BIT_OPS
  1744. #endif
  1745. /*
  1746. * Fill-ins for platform, architecture, and compiler
  1747. */
  1748. /* An abort()-like primitive is needed by the default fatal error handler. */
  1749. #if !defined(DUK_ABORT)
  1750. #define DUK_ABORT abort
  1751. #endif
  1752. #if !defined(DUK_SETJMP)
  1753. #define DUK_JMPBUF_TYPE jmp_buf
  1754. #define DUK_SETJMP(jb) setjmp((jb))
  1755. #define DUK_LONGJMP(jb) longjmp((jb), 1)
  1756. #endif
  1757. #if 0
  1758. /* sigsetjmp() alternative */
  1759. #define DUK_JMPBUF_TYPE sigjmp_buf
  1760. #define DUK_SETJMP(jb) sigsetjmp((jb))
  1761. #define DUK_LONGJMP(jb) siglongjmp((jb), 1)
  1762. #endif
  1763. /* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
  1764. * (which is unfortunately named). May sometimes need replacement, e.g.
  1765. * some compilers don't handle zero length or NULL correctly in realloc().
  1766. */
  1767. #if !defined(DUK_ANSI_MALLOC)
  1768. #define DUK_ANSI_MALLOC malloc
  1769. #endif
  1770. #if !defined(DUK_ANSI_REALLOC)
  1771. #define DUK_ANSI_REALLOC realloc
  1772. #endif
  1773. #if !defined(DUK_ANSI_CALLOC)
  1774. #define DUK_ANSI_CALLOC calloc
  1775. #endif
  1776. #if !defined(DUK_ANSI_FREE)
  1777. #define DUK_ANSI_FREE free
  1778. #endif
  1779. /* ANSI C (various versions) and some implementations require that the
  1780. * pointer arguments to memset(), memcpy(), and memmove() be valid values
  1781. * even when byte size is 0 (even a NULL pointer is considered invalid in
  1782. * this context). Zero-size operations as such are allowed, as long as their
  1783. * pointer arguments point to a valid memory area. The DUK_MEMSET(),
  1784. * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
  1785. * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
  1786. * allowed. If these are not fulfilled, a macro wrapper is needed.
  1787. *
  1788. * http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
  1789. * http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
  1790. *
  1791. * Not sure what's the required behavior when a pointer points just past the
  1792. * end of a buffer, which often happens in practice (e.g. zero size memmoves).
  1793. * For example, if allocation size is 3, the following pointer would not
  1794. * technically point to a valid memory byte:
  1795. *
  1796. * <-- alloc -->
  1797. * | 0 | 1 | 2 | .....
  1798. * ^-- p=3, points after last valid byte (2)
  1799. */
  1800. #if !defined(DUK_MEMCPY)
  1801. #if defined(DUK_F_UCLIBC)
  1802. /* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
  1803. * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
  1804. */
  1805. #define DUK_MEMCPY memmove
  1806. #else
  1807. #define DUK_MEMCPY memcpy
  1808. #endif
  1809. #endif
  1810. #if !defined(DUK_MEMMOVE)
  1811. #define DUK_MEMMOVE memmove
  1812. #endif
  1813. #if !defined(DUK_MEMCMP)
  1814. #define DUK_MEMCMP memcmp
  1815. #endif
  1816. #if !defined(DUK_MEMSET)
  1817. #define DUK_MEMSET memset
  1818. #endif
  1819. #if !defined(DUK_STRLEN)
  1820. #define DUK_STRLEN strlen
  1821. #endif
  1822. #if !defined(DUK_STRCMP)
  1823. #define DUK_STRCMP strcmp
  1824. #endif
  1825. #if !defined(DUK_STRNCMP)
  1826. #define DUK_STRNCMP strncmp
  1827. #endif
  1828. #if !defined(DUK_SPRINTF)
  1829. #define DUK_SPRINTF sprintf
  1830. #endif
  1831. #if !defined(DUK_SNPRINTF)
  1832. /* snprintf() is technically not part of C89 but usually available. */
  1833. #define DUK_SNPRINTF snprintf
  1834. #endif
  1835. #if !defined(DUK_VSPRINTF)
  1836. #define DUK_VSPRINTF vsprintf
  1837. #endif
  1838. #if !defined(DUK_VSNPRINTF)
  1839. /* vsnprintf() is technically not part of C89 but usually available. */
  1840. #define DUK_VSNPRINTF vsnprintf
  1841. #endif
  1842. #if !defined(DUK_SSCANF)
  1843. #define DUK_SSCANF sscanf
  1844. #endif
  1845. #if !defined(DUK_VSSCANF)
  1846. #define DUK_VSSCANF vsscanf
  1847. #endif
  1848. #if !defined(DUK_MEMZERO)
  1849. #define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
  1850. #endif
  1851. #if !defined(DUK_DOUBLE_INFINITY)
  1852. #undef DUK_USE_COMPUTED_INFINITY
  1853. #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
  1854. /* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
  1855. #define DUK_DOUBLE_INFINITY (__builtin_inf())
  1856. #elif defined(INFINITY)
  1857. #define DUK_DOUBLE_INFINITY ((double) INFINITY)
  1858. #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
  1859. #define DUK_DOUBLE_INFINITY (1.0 / 0.0)
  1860. #else
  1861. /* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
  1862. * Use a computed infinity (initialized when a heap is created at the
  1863. * latest).
  1864. */
  1865. #define DUK_USE_COMPUTED_INFINITY
  1866. #define DUK_DOUBLE_INFINITY duk_computed_infinity
  1867. #endif
  1868. #endif
  1869. #if !defined(DUK_DOUBLE_NAN)
  1870. #undef DUK_USE_COMPUTED_NAN
  1871. #if defined(NAN)
  1872. #define DUK_DOUBLE_NAN NAN
  1873. #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
  1874. #define DUK_DOUBLE_NAN (0.0 / 0.0)
  1875. #else
  1876. /* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
  1877. * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
  1878. * Use a computed NaN (initialized when a heap is created at the
  1879. * latest).
  1880. */
  1881. #define DUK_USE_COMPUTED_NAN
  1882. #define DUK_DOUBLE_NAN duk_computed_nan
  1883. #endif
  1884. #endif
  1885. /* Many platforms are missing fpclassify() and friends, so use replacements
  1886. * if necessary. The replacement constants (FP_NAN etc) can be anything but
  1887. * match Linux constants now.
  1888. */
  1889. #undef DUK_USE_REPL_FPCLASSIFY
  1890. #undef DUK_USE_REPL_SIGNBIT
  1891. #undef DUK_USE_REPL_ISFINITE
  1892. #undef DUK_USE_REPL_ISNAN
  1893. #undef DUK_USE_REPL_ISINF
  1894. /* Complex condition broken into separate parts. */
  1895. #undef DUK_F_USE_REPL_ALL
  1896. #if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
  1897. defined(FP_SUBNORMAL) && defined(FP_NORMAL))
  1898. /* Missing some obvious constants. */
  1899. #define DUK_F_USE_REPL_ALL
  1900. #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
  1901. /* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
  1902. #define DUK_F_USE_REPL_ALL
  1903. #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K)
  1904. /* AmigaOS + M68K seems to have math issues even when using GCC cross
  1905. * compilation. Use replacements for all AmigaOS versions on M68K
  1906. * regardless of compiler.
  1907. */
  1908. #define DUK_F_USE_REPL_ALL
  1909. #elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
  1910. /* Placeholder fix for (detection is wider than necessary):
  1911. * http://llvm.org/bugs/show_bug.cgi?id=17788
  1912. */
  1913. #define DUK_F_USE_REPL_ALL
  1914. #elif defined(DUK_F_UCLIBC)
  1915. /* At least some uclibc versions have broken floating point math. For
  1916. * example, fpclassify() can incorrectly classify certain NaN formats.
  1917. * To be safe, use replacements.
  1918. */
  1919. #define DUK_F_USE_REPL_ALL
  1920. #endif
  1921. #if defined(DUK_F_USE_REPL_ALL)
  1922. #define DUK_USE_REPL_FPCLASSIFY
  1923. #define DUK_USE_REPL_SIGNBIT
  1924. #define DUK_USE_REPL_ISFINITE
  1925. #define DUK_USE_REPL_ISNAN
  1926. #define DUK_USE_REPL_ISINF
  1927. #define DUK_FPCLASSIFY duk_repl_fpclassify
  1928. #define DUK_SIGNBIT duk_repl_signbit
  1929. #define DUK_ISFINITE duk_repl_isfinite
  1930. #define DUK_ISNAN duk_repl_isnan
  1931. #define DUK_ISINF duk_repl_isinf
  1932. #define DUK_FP_NAN 0
  1933. #define DUK_FP_INFINITE 1
  1934. #define DUK_FP_ZERO 2
  1935. #define DUK_FP_SUBNORMAL 3
  1936. #define DUK_FP_NORMAL 4
  1937. #else
  1938. #define DUK_FPCLASSIFY fpclassify
  1939. #define DUK_SIGNBIT signbit
  1940. #define DUK_ISFINITE isfinite
  1941. #define DUK_ISNAN isnan
  1942. #define DUK_ISINF isinf
  1943. #define DUK_FP_NAN FP_NAN
  1944. #define DUK_FP_INFINITE FP_INFINITE
  1945. #define DUK_FP_ZERO FP_ZERO
  1946. #define DUK_FP_SUBNORMAL FP_SUBNORMAL
  1947. #define DUK_FP_NORMAL FP_NORMAL
  1948. #endif
  1949. #if defined(DUK_F_USE_REPL_ALL)
  1950. #undef DUK_F_USE_REPL_ALL
  1951. #endif
  1952. /* These functions don't currently need replacement but are wrapped for
  1953. * completeness. Because these are used as function pointers, they need
  1954. * to be defined as concrete C functions (not macros).
  1955. */
  1956. #if !defined(DUK_FABS)
  1957. #define DUK_FABS fabs
  1958. #endif
  1959. #if !defined(DUK_FLOOR)
  1960. #define DUK_FLOOR floor
  1961. #endif
  1962. #if !defined(DUK_CEIL)
  1963. #define DUK_CEIL ceil
  1964. #endif
  1965. #if !defined(DUK_FMOD)
  1966. #define DUK_FMOD fmod
  1967. #endif
  1968. #if !defined(DUK_POW)
  1969. #define DUK_POW pow
  1970. #endif
  1971. #if !defined(DUK_ACOS)
  1972. #define DUK_ACOS acos
  1973. #endif
  1974. #if !defined(DUK_ASIN)
  1975. #define DUK_ASIN asin
  1976. #endif
  1977. #if !defined(DUK_ATAN)
  1978. #define DUK_ATAN atan
  1979. #endif
  1980. #if !defined(DUK_ATAN2)
  1981. #define DUK_ATAN2 atan2
  1982. #endif
  1983. #if !defined(DUK_SIN)
  1984. #define DUK_SIN sin
  1985. #endif
  1986. #if !defined(DUK_COS)
  1987. #define DUK_COS cos
  1988. #endif
  1989. #if !defined(DUK_TAN)
  1990. #define DUK_TAN tan
  1991. #endif
  1992. #if !defined(DUK_EXP)
  1993. #define DUK_EXP exp
  1994. #endif
  1995. #if !defined(DUK_LOG)
  1996. #define DUK_LOG log
  1997. #endif
  1998. #if !defined(DUK_SQRT)
  1999. #define DUK_SQRT sqrt
  2000. #endif
  2001. /* The functions below exist only in C99/C++11 or later and need a workaround
  2002. * for platforms that don't include them. MSVC isn't detected as C99, but
  2003. * these functions also exist in MSVC 2013 and later so include a clause for
  2004. * that too.
  2005. */
  2006. #if defined(DUK_F_C99) || defined(DUK_F_CPP11) || (defined(_MSC_VER) && (_MSC_VER >= 1800))
  2007. #if !defined(DUK_CBRT)
  2008. #define DUK_CBRT cbrt
  2009. #endif
  2010. #if !defined(DUK_LOG2)
  2011. #define DUK_LOG2 log2
  2012. #endif
  2013. #if !defined(DUK_LOG10)
  2014. #define DUK_LOG10 log10
  2015. #endif
  2016. #if !defined(DUK_TRUNC)
  2017. #define DUK_TRUNC trunc
  2018. #endif
  2019. #endif /* DUK_F_C99 */
  2020. /* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
  2021. * see test-bug-netbsd-math-pow.js. MinGW has similar (but different)
  2022. * issues, see test-bug-mingw-math-issues.js. Enable pow() workarounds
  2023. * for these targets.
  2024. */
  2025. #undef DUK_USE_POW_WORKAROUNDS
  2026. #if defined(DUK_F_NETBSD) || defined(DUK_F_MINGW)
  2027. #define DUK_USE_POW_WORKAROUNDS
  2028. #endif
  2029. /* Similar workarounds for atan2() semantics issues. MinGW issues are
  2030. * documented in test-bug-mingw-math-issues.js.
  2031. */
  2032. #undef DUK_USE_ATAN2_WORKAROUNDS
  2033. #if defined(DUK_F_MINGW)
  2034. #define DUK_USE_ATAN2_WORKAROUNDS
  2035. #endif
  2036. /* Rely as little as possible on compiler behavior for NaN comparison,
  2037. * signed zero handling, etc. Currently never activated but may be needed
  2038. * for broken compilers.
  2039. */
  2040. #undef DUK_USE_PARANOID_MATH
  2041. /* There was a curious bug where test-bi-date-canceling.js would fail e.g.
  2042. * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
  2043. * using doubles would be optimized which then broke some corner case tests.
  2044. * The problem goes away by adding 'volatile' to the datetime computations.
  2045. * Not sure what the actual triggering conditions are, but using this on
  2046. * non-C99 systems solves the known issues and has relatively little cost
  2047. * on other platforms.
  2048. */
  2049. #undef DUK_USE_PARANOID_DATE_COMPUTATION
  2050. #if !defined(DUK_F_C99)
  2051. #define DUK_USE_PARANOID_DATE_COMPUTATION
  2052. #endif
  2053. /*
  2054. * Byte order and double memory layout detection
  2055. *
  2056. * Endianness detection is a major portability hassle because the macros
  2057. * and headers are not standardized. There's even variance across UNIX
  2058. * platforms. Even with "standard" headers, details like underscore count
  2059. * varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
  2060. * (Crossbridge has a single underscore, for instance).
  2061. *
  2062. * The checks below are structured with this in mind: several approaches are
  2063. * used, and at the end we check if any of them worked. This allows generic
  2064. * approaches to be tried first, and platform/compiler specific hacks tried
  2065. * last. As a last resort, the user can force a specific endianness, as it's
  2066. * not likely that automatic detection will work on the most exotic platforms.
  2067. *
  2068. * Duktape supports little and big endian machines. There's also support
  2069. * for a hybrid used by some ARM machines where integers are little endian
  2070. * but IEEE double values use a mixed order (12345678 -> 43218765). This
  2071. * byte order for doubles is referred to as "mixed endian".
  2072. */
  2073. /* GCC and Clang provide endianness defines as built-in predefines, with
  2074. * leading and trailing double underscores (e.g. __BYTE_ORDER__). See
  2075. * output of "make gccpredefs" and "make clangpredefs". Clang doesn't
  2076. * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
  2077. * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
  2078. */
  2079. #if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
  2080. #if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
  2081. #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
  2082. #define DUK_USE_BYTEORDER 1
  2083. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
  2084. #define DUK_USE_BYTEORDER 2
  2085. #elif !defined(__FLOAT_WORD_ORDER__)
  2086. /* Float word order not known, assume not a hybrid. */
  2087. #define DUK_USE_BYTEORDER 1
  2088. #else
  2089. /* Byte order is little endian but cannot determine IEEE double word order. */
  2090. #endif /* float word order */
  2091. #elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
  2092. #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
  2093. #define DUK_USE_BYTEORDER 3
  2094. #elif !defined(__FLOAT_WORD_ORDER__)
  2095. /* Float word order not known, assume not a hybrid. */
  2096. #define DUK_USE_BYTEORDER 3
  2097. #else
  2098. /* Byte order is big endian but cannot determine IEEE double word order. */
  2099. #endif /* float word order */
  2100. #else
  2101. /* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
  2102. * integer ordering and is not relevant.
  2103. */
  2104. #endif /* integer byte order */
  2105. #endif /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
  2106. /* More or less standard endianness predefines provided by header files.
  2107. * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
  2108. * will be big endian, see: http://lists.mysql.com/internals/443.
  2109. * On some platforms some defines may be present with an empty value which
  2110. * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
  2111. */
  2112. #if !defined(DUK_USE_BYTEORDER)
  2113. #if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
  2114. defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
  2115. defined(__LITTLE_ENDIAN__)
  2116. #if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
  2117. defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
  2118. #define DUK_USE_BYTEORDER 1
  2119. #elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
  2120. defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
  2121. #define DUK_USE_BYTEORDER 2
  2122. #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
  2123. /* Float word order not known, assume not a hybrid. */
  2124. #define DUK_USE_BYTEORDER 1
  2125. #else
  2126. /* Byte order is little endian but cannot determine IEEE double word order. */
  2127. #endif /* float word order */
  2128. #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
  2129. defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
  2130. defined(__BIG_ENDIAN__)
  2131. #if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
  2132. defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
  2133. #define DUK_USE_BYTEORDER 3
  2134. #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
  2135. /* Float word order not known, assume not a hybrid. */
  2136. #define DUK_USE_BYTEORDER 3
  2137. #else
  2138. /* Byte order is big endian but cannot determine IEEE double word order. */
  2139. #endif /* float word order */
  2140. #else
  2141. /* Cannot determine byte order. */
  2142. #endif /* integer byte order */
  2143. #endif /* !defined(DUK_USE_BYTEORDER) */
  2144. /* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
  2145. * $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
  2146. * 67:#define __LITTLEENDIAN__ 1
  2147. * $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
  2148. * 81:#define __BIGENDIAN__ 1
  2149. * $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
  2150. * 70:#define __LITTLEENDIAN__ 1
  2151. */
  2152. #if !defined(DUK_USE_BYTEORDER)
  2153. #if defined(__LITTLEENDIAN__)
  2154. #define DUK_USE_BYTEORDER 1
  2155. #elif defined(__BIGENDIAN__)
  2156. #define DUK_USE_BYTEORDER 3
  2157. #endif
  2158. #endif
  2159. /*
  2160. * Alignment requirement and support for unaligned accesses
  2161. *
  2162. * Assume unaligned accesses are not supported unless specifically allowed
  2163. * in the target platform. Some platforms may support unaligned accesses
  2164. * but alignment to 4 or 8 may still be desirable.
  2165. */
  2166. /* If not provided, use safe default for alignment. */
  2167. #if !defined(DUK_USE_ALIGN_BY)
  2168. #define DUK_USE_ALIGN_BY 8
  2169. #endif
  2170. /* Compiler specific hackery needed to force struct size to match aligment,
  2171. * see e.g. duk_hbuffer.h.
  2172. *
  2173. * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
  2174. * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
  2175. */
  2176. #if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \
  2177. defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER))
  2178. #define DUK_USE_PACK_DUMMY_MEMBER
  2179. #endif
  2180. #if !defined(DUK_VA_COPY)
  2181. /* We need va_copy() which is defined in C99 / C++11, so an awkward
  2182. * replacement is needed for pre-C99 / pre-C++11 environments. This
  2183. * will quite likely need portability hacks for some non-C99
  2184. * environments.
  2185. */
  2186. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  2187. /* C99 / C++11 and above: rely on va_copy() which is required.
  2188. * Omit parenthesis on macro right side on purpose to minimize differences
  2189. * to direct use.
  2190. */
  2191. #define DUK_VA_COPY(dest,src) va_copy(dest,src)
  2192. #else
  2193. /* Pre-C99: va_list type is implementation dependent. This replacement
  2194. * assumes it is a plain value so that a simple assignment will work.
  2195. * This is not the case on all platforms (it may be a single-array element,
  2196. * for instance).
  2197. */
  2198. #define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
  2199. #endif
  2200. #endif
  2201. #if !defined(DUK_MACRO_STRINGIFY)
  2202. /* Macro hackery to convert e.g. __LINE__ to a string without formatting,
  2203. * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
  2204. */
  2205. #define DUK_MACRO_STRINGIFY_HELPER(x) #x
  2206. #define DUK_MACRO_STRINGIFY(x) DUK_MACRO_STRINGIFY_HELPER(x)
  2207. #endif
  2208. #if !defined(DUK_CAUSE_SEGFAULT)
  2209. /* This can be used for testing; valgrind will then indicate the C call stack
  2210. * leading to the call site.
  2211. */
  2212. #define DUK_CAUSE_SEGFAULT() do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
  2213. #endif
  2214. #if !defined(DUK_UNREF)
  2215. /* Macro for suppressing warnings for potentially unreferenced variables.
  2216. * The variables can be actually unreferenced or unreferenced in some
  2217. * specific cases only; for instance, if a variable is only debug printed,
  2218. * it is unreferenced when debug printing is disabled.
  2219. */
  2220. #define DUK_UNREF(x) do { (void) (x); } while (0)
  2221. #endif
  2222. #if !defined(DUK_NORETURN)
  2223. #define DUK_NORETURN(decl) decl
  2224. #endif
  2225. #if !defined(DUK_UNREACHABLE)
  2226. /* Don't know how to declare unreachable point, so don't do it; this
  2227. * may cause some spurious compilation warnings (e.g. "variable used
  2228. * uninitialized").
  2229. */
  2230. #define DUK_UNREACHABLE() do { } while (0)
  2231. #endif
  2232. #if !defined(DUK_LOSE_CONST)
  2233. /* Convert any input pointer into a "void *", losing a const qualifier.
  2234. * This is not fully portable because casting through duk_uintptr_t may
  2235. * not work on all architectures (e.g. those with long, segmented pointers).
  2236. */
  2237. #define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
  2238. #endif
  2239. #if !defined(DUK_LIKELY)
  2240. #define DUK_LIKELY(x) (x)
  2241. #endif
  2242. #if !defined(DUK_UNLIKELY)
  2243. #define DUK_UNLIKELY(x) (x)
  2244. #endif
  2245. #if !defined(DUK_UNPREDICTABLE)
  2246. #define DUK_UNPREDICTABLE(x) (x)
  2247. #endif
  2248. #if !defined(DUK_NOINLINE)
  2249. #define DUK_NOINLINE /*nop*/
  2250. #endif
  2251. #if !defined(DUK_INLINE)
  2252. #define DUK_INLINE /*nop*/
  2253. #endif
  2254. #if !defined(DUK_ALWAYS_INLINE)
  2255. #define DUK_ALWAYS_INLINE /*nop*/
  2256. #endif
  2257. #if !defined(DUK_EXTERNAL_DECL)
  2258. #define DUK_EXTERNAL_DECL extern
  2259. #endif
  2260. #if !defined(DUK_EXTERNAL)
  2261. #define DUK_EXTERNAL /*empty*/
  2262. #endif
  2263. #if !defined(DUK_INTERNAL_DECL)
  2264. #if defined(DUK_SINGLE_FILE)
  2265. #define DUK_INTERNAL_DECL static
  2266. #else
  2267. #define DUK_INTERNAL_DECL extern
  2268. #endif
  2269. #endif
  2270. #if !defined(DUK_INTERNAL)
  2271. #if defined(DUK_SINGLE_FILE)
  2272. #define DUK_INTERNAL static
  2273. #else
  2274. #define DUK_INTERNAL /*empty*/
  2275. #endif
  2276. #endif
  2277. #if !defined(DUK_LOCAL_DECL)
  2278. #define DUK_LOCAL_DECL static
  2279. #endif
  2280. #if !defined(DUK_LOCAL)
  2281. #define DUK_LOCAL static
  2282. #endif
  2283. #if !defined(DUK_FILE_MACRO)
  2284. #define DUK_FILE_MACRO __FILE__
  2285. #endif
  2286. #if !defined(DUK_LINE_MACRO)
  2287. #define DUK_LINE_MACRO __LINE__
  2288. #endif
  2289. #if !defined(DUK_FUNC_MACRO)
  2290. #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
  2291. #define DUK_FUNC_MACRO __func__
  2292. #elif defined(__FUNCTION__)
  2293. #define DUK_FUNC_MACRO __FUNCTION__
  2294. #else
  2295. #define DUK_FUNC_MACRO "unknown"
  2296. #endif
  2297. #endif
  2298. #if !defined(DUK_BSWAP32)
  2299. #define DUK_BSWAP32(x) \
  2300. ((((duk_uint32_t) (x)) >> 24) | \
  2301. ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
  2302. ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
  2303. (((duk_uint32_t) (x)) << 24))
  2304. #endif
  2305. #if !defined(DUK_BSWAP16)
  2306. #define DUK_BSWAP16(x) \
  2307. ((duk_uint16_t) (x) >> 8) | \
  2308. ((duk_uint16_t) (x) << 8)
  2309. #endif
  2310. /* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
  2311. /* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
  2312. #if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
  2313. #if defined(DUK_F_C99)
  2314. #define DUK_USE_FLEX_C99
  2315. #else
  2316. #define DUK_USE_FLEX_ZEROSIZE /* Not standard but common enough */
  2317. #endif
  2318. #endif
  2319. #if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
  2320. defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
  2321. #define DUK_USE_PACK_DUMMY_MEMBER
  2322. #endif
  2323. #if 0 /* not defined by default */
  2324. #undef DUK_USE_GCC_PRAGMAS
  2325. #endif
  2326. /* Workaround for GH-323: avoid inlining control when compiling from
  2327. * multiple sources, as it causes compiler portability trouble.
  2328. */
  2329. #if !defined(DUK_SINGLE_FILE)
  2330. #undef DUK_NOINLINE
  2331. #undef DUK_INLINE
  2332. #undef DUK_ALWAYS_INLINE
  2333. #define DUK_NOINLINE /*nop*/
  2334. #define DUK_INLINE /*nop*/
  2335. #define DUK_ALWAYS_INLINE /*nop*/
  2336. #endif
  2337. /*
  2338. * Check whether or not a packed duk_tval representation is possible.
  2339. * What's basically required is that pointers are 32-bit values
  2340. * (sizeof(void *) == 4). Best effort check, not always accurate.
  2341. * If guess goes wrong, crashes may result; self tests also verify
  2342. * the guess.
  2343. */
  2344. /* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
  2345. #if !defined(DUK_F_PACKED_TVAL_PROVIDED)
  2346. #undef DUK_F_PACKED_TVAL_POSSIBLE
  2347. /* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
  2348. #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX)
  2349. #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
  2350. #define DUK_F_PACKED_TVAL_POSSIBLE
  2351. #endif
  2352. #endif
  2353. /* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
  2354. #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
  2355. #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
  2356. #define DUK_F_PACKED_TVAL_POSSIBLE
  2357. #endif
  2358. #endif
  2359. /* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
  2360. #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
  2361. #if (DUK_SIZE_MAX <= 0xffffffffUL)
  2362. #define DUK_F_PACKED_TVAL_POSSIBLE
  2363. #endif
  2364. #endif
  2365. #undef DUK_USE_PACKED_TVAL
  2366. #if defined(DUK_F_PACKED_TVAL_POSSIBLE)
  2367. #define DUK_USE_PACKED_TVAL
  2368. #endif
  2369. #undef DUK_F_PACKED_TVAL_POSSIBLE
  2370. #endif /* DUK_F_PACKED_TVAL_PROVIDED */
  2371. /* Object property allocation layout has implications for memory and code
  2372. * footprint and generated code size/speed. The best layout also depends
  2373. * on whether the platform has alignment requirements or benefits from
  2374. * having mostly aligned accesses.
  2375. */
  2376. #undef DUK_USE_HOBJECT_LAYOUT_1
  2377. #undef DUK_USE_HOBJECT_LAYOUT_2
  2378. #undef DUK_USE_HOBJECT_LAYOUT_3
  2379. #if (DUK_USE_ALIGN_BY == 1)
  2380. /* On platforms without any alignment issues, layout 1 is preferable
  2381. * because it compiles to slightly less code and provides direct access
  2382. * to property keys.
  2383. */
  2384. #define DUK_USE_HOBJECT_LAYOUT_1
  2385. #else
  2386. /* On other platforms use layout 2, which requires some padding but
  2387. * is a bit more natural than layout 3 in ordering the entries. Layout
  2388. * 3 is currently not used.
  2389. */
  2390. #define DUK_USE_HOBJECT_LAYOUT_2
  2391. #endif
  2392. /* GCC/clang inaccurate math would break compliance and probably duk_tval,
  2393. * so refuse to compile. Relax this if -ffast-math is tested to work.
  2394. */
  2395. #if defined(__FAST_MATH__)
  2396. #error __FAST_MATH__ defined, refusing to compile
  2397. #endif
  2398. /*
  2399. * Forced options
  2400. */
  2401. #define DUK_USE_ARRAY_FASTPATH
  2402. #define DUK_USE_ARRAY_PROP_FASTPATH
  2403. #define DUK_USE_BASE64_FASTPATH
  2404. #define DUK_USE_DEBUGGER_DUMPHEAP
  2405. #define DUK_USE_DEBUGGER_INSPECT
  2406. #define DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
  2407. #define DUK_USE_DEBUGGER_SUPPORT
  2408. #define DUK_USE_DEBUGGER_THROW_NOTIFY
  2409. #undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
  2410. #define DUK_USE_FASTINT
  2411. #define DUK_USE_FAST_REFCOUNT_DEFAULT
  2412. #define DUK_USE_HEX_FASTPATH
  2413. #define DUK_USE_IDCHAR_FASTPATH
  2414. #define DUK_USE_INTERRUPT_COUNTER
  2415. #define DUK_USE_JSON_DECNUMBER_FASTPATH
  2416. #define DUK_USE_JSON_DECSTRING_FASTPATH
  2417. #define DUK_USE_JSON_EATWHITE_FASTPATH
  2418. #define DUK_USE_JSON_QUOTESTRING_FASTPATH
  2419. #define DUK_USE_JSON_STRINGIFY_FASTPATH
  2420. #undef DUK_USE_PACKED_TVAL
  2421. #undef DUK_USE_PREFER_SIZE
  2422. #define DUK_USE_REFERENCE_COUNTING
  2423. #define DUK_USE_REGEXP_CANON_WORKAROUND
  2424. #undef DUK_USE_STRHASH_DENSE
  2425. #define DUK_USE_STRHASH_SKIP_SHIFT 5
  2426. #define DUK_USE_VALSTACK_UNSAFE
  2427. #undef DUK_USE_VOLUNTARY_GC
  2428. /*
  2429. * Autogenerated defaults
  2430. */
  2431. #define DUK_USE_ARRAY_BUILTIN
  2432. #undef DUK_USE_ASSERTIONS
  2433. #define DUK_USE_AUGMENT_ERROR_CREATE
  2434. #define DUK_USE_AUGMENT_ERROR_THROW
  2435. #define DUK_USE_AVOID_PLATFORM_FUNCPTRS
  2436. #define DUK_USE_BOOLEAN_BUILTIN
  2437. #define DUK_USE_BUFFEROBJECT_SUPPORT
  2438. #undef DUK_USE_BUFLEN16
  2439. #define DUK_USE_BYTECODE_DUMP_SUPPORT
  2440. #define DUK_USE_COMMONJS_MODULES
  2441. #define DUK_USE_COMPILER_RECLIMIT 2500
  2442. #define DUK_USE_COROUTINE_SUPPORT
  2443. #undef DUK_USE_CPP_EXCEPTIONS
  2444. #undef DUK_USE_DATAPTR16
  2445. #undef DUK_USE_DATAPTR_DEC16
  2446. #undef DUK_USE_DATAPTR_ENC16
  2447. #define DUK_USE_DATE_BUILTIN
  2448. #undef DUK_USE_DATE_FORMAT_STRING
  2449. #undef DUK_USE_DATE_GET_LOCAL_TZOFFSET
  2450. #undef DUK_USE_DATE_GET_NOW
  2451. #undef DUK_USE_DATE_PARSE_STRING
  2452. #undef DUK_USE_DATE_PRS_GETDATE
  2453. #undef DUK_USE_DEBUG
  2454. #define DUK_USE_DEBUG_BUFSIZE 65536L
  2455. #define DUK_USE_DEBUG_LEVEL 0
  2456. #undef DUK_USE_DEBUG_WRITE
  2457. #define DUK_USE_DOUBLE_LINKED_HEAP
  2458. #define DUK_USE_DUKTAPE_BUILTIN
  2459. #define DUK_USE_ENCODING_BUILTINS
  2460. #define DUK_USE_ERRCREATE
  2461. #define DUK_USE_ERRTHROW
  2462. #define DUK_USE_ES6
  2463. #define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
  2464. #define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
  2465. #define DUK_USE_ES6_PROXY
  2466. #define DUK_USE_ES6_REGEXP_SYNTAX
  2467. #define DUK_USE_ES6_UNICODE_ESCAPE
  2468. #define DUK_USE_ES7_EXP_OPERATOR
  2469. #define DUK_USE_ESBC_LIMITS
  2470. #define DUK_USE_ESBC_MAX_BYTES 2147418112L
  2471. #define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L
  2472. #undef DUK_USE_EXEC_FUN_LOCAL
  2473. #undef DUK_USE_EXEC_INDIRECT_BOUND_CHECK
  2474. #undef DUK_USE_EXEC_PREFER_SIZE
  2475. #define DUK_USE_EXEC_REGCONST_OPTIMIZE
  2476. #undef DUK_USE_EXEC_TIMEOUT_CHECK
  2477. #undef DUK_USE_EXPLICIT_NULL_INIT
  2478. #undef DUK_USE_EXTSTR_FREE
  2479. #undef DUK_USE_EXTSTR_INTERN_CHECK
  2480. #undef DUK_USE_FATAL_HANDLER
  2481. #define DUK_USE_FINALIZER_SUPPORT
  2482. #undef DUK_USE_FUNCPTR16
  2483. #undef DUK_USE_FUNCPTR_DEC16
  2484. #undef DUK_USE_FUNCPTR_ENC16
  2485. #define DUK_USE_FUNCTION_BUILTIN
  2486. #define DUK_USE_FUNC_FILENAME_PROPERTY
  2487. #define DUK_USE_FUNC_NAME_PROPERTY
  2488. #undef DUK_USE_GC_TORTURE
  2489. #undef DUK_USE_GET_RANDOM_DOUBLE
  2490. #define DUK_USE_GLOBAL_BUILTIN
  2491. #undef DUK_USE_HEAPPTR16
  2492. #undef DUK_USE_HEAPPTR_DEC16
  2493. #undef DUK_USE_HEAPPTR_ENC16
  2494. #define DUK_USE_HOBJECT_HASH_PART
  2495. #define DUK_USE_HSTRING_ARRIDX
  2496. #define DUK_USE_HSTRING_CLEN
  2497. #undef DUK_USE_HSTRING_EXTDATA
  2498. #undef DUK_USE_INTERRUPT_DEBUG_FIXUP
  2499. #define DUK_USE_JC
  2500. #define DUK_USE_JSON_BUILTIN
  2501. #define DUK_USE_JSON_DEC_RECLIMIT 1000
  2502. #define DUK_USE_JSON_ENC_RECLIMIT 1000
  2503. #define DUK_USE_JSON_SUPPORT
  2504. #define DUK_USE_JX
  2505. #define DUK_USE_LEXER_SLIDING_WINDOW
  2506. #undef DUK_USE_LIGHTFUNC_BUILTINS
  2507. #undef DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
  2508. #define DUK_USE_MARK_AND_SWEEP_RECLIMIT 256
  2509. #define DUK_USE_MATH_BUILTIN
  2510. #define DUK_USE_MS_STRINGTABLE_RESIZE
  2511. #define DUK_USE_NATIVE_CALL_RECLIMIT 1000
  2512. #define DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
  2513. #define DUK_USE_NONSTD_ARRAY_MAP_TRAILER
  2514. #define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
  2515. #undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
  2516. #undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
  2517. #define DUK_USE_NONSTD_FUNC_STMT
  2518. #define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
  2519. #define DUK_USE_NONSTD_JSON_ESC_U2028_U2029
  2520. #define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
  2521. #define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
  2522. #define DUK_USE_NUMBER_BUILTIN
  2523. #define DUK_USE_OBJECT_BUILTIN
  2524. #undef DUK_USE_OBJSIZES16
  2525. #undef DUK_USE_PARANOID_ERRORS
  2526. #define DUK_USE_PC2LINE
  2527. #define DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
  2528. #undef DUK_USE_REFCOUNT16
  2529. #define DUK_USE_REFLECT_BUILTIN
  2530. #undef DUK_USE_REFZERO_FINALIZER_TORTURE
  2531. #define DUK_USE_REGEXP_COMPILER_RECLIMIT 10000
  2532. #define DUK_USE_REGEXP_EXECUTOR_RECLIMIT 10000
  2533. #define DUK_USE_REGEXP_SUPPORT
  2534. #undef DUK_USE_ROM_GLOBAL_CLONE
  2535. #undef DUK_USE_ROM_GLOBAL_INHERIT
  2536. #undef DUK_USE_ROM_OBJECTS
  2537. #define DUK_USE_ROM_PTRCOMP_FIRST 63488L
  2538. #undef DUK_USE_ROM_STRINGS
  2539. #define DUK_USE_SECTION_B
  2540. #undef DUK_USE_SELF_TESTS
  2541. #undef DUK_USE_SHUFFLE_TORTURE
  2542. #define DUK_USE_SOURCE_NONBMP
  2543. #undef DUK_USE_STRHASH16
  2544. #define DUK_USE_STRICT_DECL
  2545. #undef DUK_USE_STRICT_UTF8_SOURCE
  2546. #define DUK_USE_STRING_BUILTIN
  2547. #undef DUK_USE_STRLEN16
  2548. #undef DUK_USE_STRTAB_CHAIN
  2549. #undef DUK_USE_STRTAB_CHAIN_SIZE
  2550. #define DUK_USE_STRTAB_PROBE
  2551. #undef DUK_USE_SYMBOL_BUILTIN
  2552. #define DUK_USE_TAILCALL
  2553. #define DUK_USE_TARGET_INFO "unknown"
  2554. #define DUK_USE_TRACEBACKS
  2555. #define DUK_USE_TRACEBACK_DEPTH 10
  2556. #define DUK_USE_USER_DECLARE() /* no user declarations */
  2557. #define DUK_USE_VERBOSE_ERRORS
  2558. #define DUK_USE_VERBOSE_EXECUTOR_ERRORS
  2559. #define DUK_USE_ZERO_BUFFER_DATA
  2560. /*
  2561. * You may add overriding #define/#undef directives below for
  2562. * customization. You of course cannot un-#include or un-typedef
  2563. * anything; these require direct changes above.
  2564. */
  2565. /* __OVERRIDE_DEFINES__ */
  2566. /*
  2567. * Date provider selection
  2568. *
  2569. * User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
  2570. * rely on an external provider. If this is not done, revert to previous
  2571. * behavior and use Unix/Windows built-in provider.
  2572. */
  2573. #if defined(DUK_COMPILING_DUKTAPE)
  2574. #if defined(DUK_USE_DATE_GET_NOW)
  2575. /* External provider already defined. */
  2576. #elif defined(DUK_USE_DATE_NOW_GETTIMEOFDAY)
  2577. #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday((ctx))
  2578. #elif defined(DUK_USE_DATE_NOW_TIME)
  2579. #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time((ctx))
  2580. #elif defined(DUK_USE_DATE_NOW_WINDOWS)
  2581. #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows((ctx))
  2582. #else
  2583. #error no provider for DUK_USE_DATE_GET_NOW()
  2584. #endif
  2585. #if defined(DUK_USE_DATE_GET_LOCAL_TZOFFSET)
  2586. /* External provider already defined. */
  2587. #elif defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME)
  2588. #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_gmtime((d))
  2589. #elif defined(DUK_USE_DATE_TZO_WINDOWS)
  2590. #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows((d))
  2591. #else
  2592. #error no provider for DUK_USE_DATE_GET_LOCAL_TZOFFSET()
  2593. #endif
  2594. #if defined(DUK_USE_DATE_PARSE_STRING)
  2595. /* External provider already defined. */
  2596. #elif defined(DUK_USE_DATE_PRS_STRPTIME)
  2597. #define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_strptime((ctx), (str))
  2598. #elif defined(DUK_USE_DATE_PRS_GETDATE)
  2599. #define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_getdate((ctx), (str))
  2600. #else
  2601. /* No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only. */
  2602. #endif
  2603. #if defined(DUK_USE_DATE_FORMAT_STRING)
  2604. /* External provider already defined. */
  2605. #elif defined(DUK_USE_DATE_FMT_STRFTIME)
  2606. #define DUK_USE_DATE_FORMAT_STRING(ctx,parts,tzoffset,flags) \
  2607. duk_bi_date_format_parts_strftime((ctx), (parts), (tzoffset), (flags))
  2608. #else
  2609. /* No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only. */
  2610. #endif
  2611. #endif /* DUK_COMPILING_DUKTAPE */
  2612. /*
  2613. * Checks for config option consistency (DUK_USE_xxx)
  2614. */
  2615. #if defined(DUK_USE_32BIT_PTRS)
  2616. #error unsupported config option used (option has been removed): DUK_USE_32BIT_PTRS
  2617. #endif
  2618. #if defined(DUK_USE_ALIGN_4)
  2619. #error unsupported config option used (option has been removed): DUK_USE_ALIGN_4
  2620. #endif
  2621. #if defined(DUK_USE_ALIGN_8)
  2622. #error unsupported config option used (option has been removed): DUK_USE_ALIGN_8
  2623. #endif
  2624. #if defined(DUK_USE_BROWSER_LIKE)
  2625. #error unsupported config option used (option has been removed): DUK_USE_BROWSER_LIKE
  2626. #endif
  2627. #if defined(DUK_USE_BUILTIN_INITJS)
  2628. #error unsupported config option used (option has been removed): DUK_USE_BUILTIN_INITJS
  2629. #endif
  2630. #if defined(DUK_USE_BYTEORDER_FORCED)
  2631. #error unsupported config option used (option has been removed): DUK_USE_BYTEORDER_FORCED
  2632. #endif
  2633. #if defined(DUK_USE_DATAPTR_DEC16) && !defined(DUK_USE_DATAPTR16)
  2634. #error config option DUK_USE_DATAPTR_DEC16 requires option DUK_USE_DATAPTR16 (which is missing)
  2635. #endif
  2636. #if defined(DUK_USE_DATAPTR_ENC16) && !defined(DUK_USE_DATAPTR16)
  2637. #error config option DUK_USE_DATAPTR_ENC16 requires option DUK_USE_DATAPTR16 (which is missing)
  2638. #endif
  2639. #if defined(DUK_USE_DDDPRINT)
  2640. #error unsupported config option used (option has been removed): DUK_USE_DDDPRINT
  2641. #endif
  2642. #if defined(DUK_USE_DDPRINT)
  2643. #error unsupported config option used (option has been removed): DUK_USE_DDPRINT
  2644. #endif
  2645. #if defined(DUK_USE_DEBUGGER_FWD_LOGGING)
  2646. #error unsupported config option used (option has been removed): DUK_USE_DEBUGGER_FWD_LOGGING
  2647. #endif
  2648. #if defined(DUK_USE_DEBUGGER_FWD_PRINTALERT)
  2649. #error unsupported config option used (option has been removed): DUK_USE_DEBUGGER_FWD_PRINTALERT
  2650. #endif
  2651. #if defined(DUK_USE_DEBUGGER_SUPPORT) && !defined(DUK_USE_INTERRUPT_COUNTER)
  2652. #error config option DUK_USE_DEBUGGER_SUPPORT requires option DUK_USE_INTERRUPT_COUNTER (which is missing)
  2653. #endif
  2654. #if defined(DUK_USE_DEEP_C_STACK)
  2655. #error unsupported config option used (option has been removed): DUK_USE_DEEP_C_STACK
  2656. #endif
  2657. #if defined(DUK_USE_DOUBLE_BE)
  2658. #error unsupported config option used (option has been removed): DUK_USE_DOUBLE_BE
  2659. #endif
  2660. #if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_LE)
  2661. #error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_LE (which is also defined)
  2662. #endif
  2663. #if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_ME)
  2664. #error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_ME (which is also defined)
  2665. #endif
  2666. #if defined(DUK_USE_DOUBLE_LE)
  2667. #error unsupported config option used (option has been removed): DUK_USE_DOUBLE_LE
  2668. #endif
  2669. #if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_BE)
  2670. #error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_BE (which is also defined)
  2671. #endif
  2672. #if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_ME)
  2673. #error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_ME (which is also defined)
  2674. #endif
  2675. #if defined(DUK_USE_DOUBLE_ME)
  2676. #error unsupported config option used (option has been removed): DUK_USE_DOUBLE_ME
  2677. #endif
  2678. #if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_LE)
  2679. #error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_LE (which is also defined)
  2680. #endif
  2681. #if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_BE)
  2682. #error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_BE (which is also defined)
  2683. #endif
  2684. #if defined(DUK_USE_DPRINT)
  2685. #error unsupported config option used (option has been removed): DUK_USE_DPRINT
  2686. #endif
  2687. #if defined(DUK_USE_DPRINT) && !defined(DUK_USE_DEBUG)
  2688. #error config option DUK_USE_DPRINT requires option DUK_USE_DEBUG (which is missing)
  2689. #endif
  2690. #if defined(DUK_USE_DPRINT_COLORS)
  2691. #error unsupported config option used (option has been removed): DUK_USE_DPRINT_COLORS
  2692. #endif
  2693. #if defined(DUK_USE_DPRINT_RDTSC)
  2694. #error unsupported config option used (option has been removed): DUK_USE_DPRINT_RDTSC
  2695. #endif
  2696. #if defined(DUK_USE_ES6_REGEXP_BRACES)
  2697. #error unsupported config option used (option has been removed): DUK_USE_ES6_REGEXP_BRACES
  2698. #endif
  2699. #if defined(DUK_USE_ESBC_MAX_BYTES) && !defined(DUK_USE_ESBC_LIMITS)
  2700. #error config option DUK_USE_ESBC_MAX_BYTES requires option DUK_USE_ESBC_LIMITS (which is missing)
  2701. #endif
  2702. #if defined(DUK_USE_ESBC_MAX_LINENUMBER) && !defined(DUK_USE_ESBC_LIMITS)
  2703. #error config option DUK_USE_ESBC_MAX_LINENUMBER requires option DUK_USE_ESBC_LIMITS (which is missing)
  2704. #endif
  2705. #if defined(DUK_USE_EXEC_TIMEOUT_CHECK) && !defined(DUK_USE_INTERRUPT_COUNTER)
  2706. #error config option DUK_USE_EXEC_TIMEOUT_CHECK requires option DUK_USE_INTERRUPT_COUNTER (which is missing)
  2707. #endif
  2708. #if defined(DUK_USE_EXTSTR_FREE) && !defined(DUK_USE_HSTRING_EXTDATA)
  2709. #error config option DUK_USE_EXTSTR_FREE requires option DUK_USE_HSTRING_EXTDATA (which is missing)
  2710. #endif
  2711. #if defined(DUK_USE_EXTSTR_INTERN_CHECK) && !defined(DUK_USE_HSTRING_EXTDATA)
  2712. #error config option DUK_USE_EXTSTR_INTERN_CHECK requires option DUK_USE_HSTRING_EXTDATA (which is missing)
  2713. #endif
  2714. #if defined(DUK_USE_FASTINT) && !defined(DUK_USE_64BIT_OPS)
  2715. #error config option DUK_USE_FASTINT requires option DUK_USE_64BIT_OPS (which is missing)
  2716. #endif
  2717. #if defined(DUK_USE_FILE_IO)
  2718. #error unsupported config option used (option has been removed): DUK_USE_FILE_IO
  2719. #endif
  2720. #if defined(DUK_USE_FULL_TVAL)
  2721. #error unsupported config option used (option has been removed): DUK_USE_FULL_TVAL
  2722. #endif
  2723. #if defined(DUK_USE_FUNCPTR_DEC16) && !defined(DUK_USE_FUNCPTR16)
  2724. #error config option DUK_USE_FUNCPTR_DEC16 requires option DUK_USE_FUNCPTR16 (which is missing)
  2725. #endif
  2726. #if defined(DUK_USE_FUNCPTR_ENC16) && !defined(DUK_USE_FUNCPTR16)
  2727. #error config option DUK_USE_FUNCPTR_ENC16 requires option DUK_USE_FUNCPTR16 (which is missing)
  2728. #endif
  2729. #if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS)
  2730. #error unsupported config option used (option has been removed): DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS
  2731. #endif
  2732. #if defined(DUK_USE_HEAPPTR16) && defined(DUK_USE_DEBUG)
  2733. #error config option DUK_USE_HEAPPTR16 conflicts with option DUK_USE_DEBUG (which is also defined)
  2734. #endif
  2735. #if defined(DUK_USE_HEAPPTR_DEC16) && !defined(DUK_USE_HEAPPTR16)
  2736. #error config option DUK_USE_HEAPPTR_DEC16 requires option DUK_USE_HEAPPTR16 (which is missing)
  2737. #endif
  2738. #if defined(DUK_USE_HEAPPTR_ENC16) && !defined(DUK_USE_HEAPPTR16)
  2739. #error config option DUK_USE_HEAPPTR_ENC16 requires option DUK_USE_HEAPPTR16 (which is missing)
  2740. #endif
  2741. #if defined(DUK_USE_INTEGER_BE)
  2742. #error unsupported config option used (option has been removed): DUK_USE_INTEGER_BE
  2743. #endif
  2744. #if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_LE)
  2745. #error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_LE (which is also defined)
  2746. #endif
  2747. #if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_ME)
  2748. #error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_ME (which is also defined)
  2749. #endif
  2750. #if defined(DUK_USE_INTEGER_LE)
  2751. #error unsupported config option used (option has been removed): DUK_USE_INTEGER_LE
  2752. #endif
  2753. #if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_BE)
  2754. #error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_BE (which is also defined)
  2755. #endif
  2756. #if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_ME)
  2757. #error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_ME (which is also defined)
  2758. #endif
  2759. #if defined(DUK_USE_INTEGER_ME)
  2760. #error unsupported config option used (option has been removed): DUK_USE_INTEGER_ME
  2761. #endif
  2762. #if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_LE)
  2763. #error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_LE (which is also defined)
  2764. #endif
  2765. #if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_BE)
  2766. #error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_BE (which is also defined)
  2767. #endif
  2768. #if defined(DUK_USE_MARK_AND_SWEEP)
  2769. #error unsupported config option used (option has been removed): DUK_USE_MARK_AND_SWEEP
  2770. #endif
  2771. #if defined(DUK_USE_MATH_FMAX)
  2772. #error unsupported config option used (option has been removed): DUK_USE_MATH_FMAX
  2773. #endif
  2774. #if defined(DUK_USE_MATH_FMIN)
  2775. #error unsupported config option used (option has been removed): DUK_USE_MATH_FMIN
  2776. #endif
  2777. #if defined(DUK_USE_MATH_ROUND)
  2778. #error unsupported config option used (option has been removed): DUK_USE_MATH_ROUND
  2779. #endif
  2780. #if defined(DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE)
  2781. #error unsupported config option used (option has been removed): DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE
  2782. #endif
  2783. #if defined(DUK_USE_NO_DOUBLE_ALIASING_SELFTEST)
  2784. #error unsupported config option used (option has been removed): DUK_USE_NO_DOUBLE_ALIASING_SELFTEST
  2785. #endif
  2786. #if defined(DUK_USE_OCTAL_SUPPORT)
  2787. #error unsupported config option used (option has been removed): DUK_USE_OCTAL_SUPPORT
  2788. #endif
  2789. #if defined(DUK_USE_PACKED_TVAL_POSSIBLE)
  2790. #error unsupported config option used (option has been removed): DUK_USE_PACKED_TVAL_POSSIBLE
  2791. #endif
  2792. #if defined(DUK_USE_PANIC_ABORT)
  2793. #error unsupported config option used (option has been removed): DUK_USE_PANIC_ABORT
  2794. #endif
  2795. #if defined(DUK_USE_PANIC_EXIT)
  2796. #error unsupported config option used (option has been removed): DUK_USE_PANIC_EXIT
  2797. #endif
  2798. #if defined(DUK_USE_PANIC_HANDLER)
  2799. #error unsupported config option used (option has been removed): DUK_USE_PANIC_HANDLER
  2800. #endif
  2801. #if defined(DUK_USE_PANIC_SEGFAULT)
  2802. #error unsupported config option used (option has been removed): DUK_USE_PANIC_SEGFAULT
  2803. #endif
  2804. #if defined(DUK_USE_POW_NETBSD_WORKAROUND)
  2805. #error unsupported config option used (option has been removed): DUK_USE_POW_NETBSD_WORKAROUND
  2806. #endif
  2807. #if defined(DUK_USE_RDTSC)
  2808. #error unsupported config option used (option has been removed): DUK_USE_RDTSC
  2809. #endif
  2810. #if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_STRINGS)
  2811. #error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_STRINGS (which is missing)
  2812. #endif
  2813. #if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_OBJECTS)
  2814. #error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_OBJECTS (which is missing)
  2815. #endif
  2816. #if defined(DUK_USE_ROM_GLOBAL_CLONE) && defined(DUK_USE_ROM_GLOBAL_INHERIT)
  2817. #error config option DUK_USE_ROM_GLOBAL_CLONE conflicts with option DUK_USE_ROM_GLOBAL_INHERIT (which is also defined)
  2818. #endif
  2819. #if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_STRINGS)
  2820. #error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_STRINGS (which is missing)
  2821. #endif
  2822. #if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_OBJECTS)
  2823. #error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_OBJECTS (which is missing)
  2824. #endif
  2825. #if defined(DUK_USE_ROM_GLOBAL_INHERIT) && defined(DUK_USE_ROM_GLOBAL_CLONE)
  2826. #error config option DUK_USE_ROM_GLOBAL_INHERIT conflicts with option DUK_USE_ROM_GLOBAL_CLONE (which is also defined)
  2827. #endif
  2828. #if defined(DUK_USE_ROM_OBJECTS) && !defined(DUK_USE_ROM_STRINGS)
  2829. #error config option DUK_USE_ROM_OBJECTS requires option DUK_USE_ROM_STRINGS (which is missing)
  2830. #endif
  2831. #if defined(DUK_USE_ROM_STRINGS) && !defined(DUK_USE_ROM_OBJECTS)
  2832. #error config option DUK_USE_ROM_STRINGS requires option DUK_USE_ROM_OBJECTS (which is missing)
  2833. #endif
  2834. #if defined(DUK_USE_SETJMP)
  2835. #error unsupported config option used (option has been removed): DUK_USE_SETJMP
  2836. #endif
  2837. #if defined(DUK_USE_SIGSETJMP)
  2838. #error unsupported config option used (option has been removed): DUK_USE_SIGSETJMP
  2839. #endif
  2840. #if defined(DUK_USE_STRTAB_CHAIN_SIZE) && !defined(DUK_USE_STRTAB_CHAIN)
  2841. #error config option DUK_USE_STRTAB_CHAIN_SIZE requires option DUK_USE_STRTAB_CHAIN (which is missing)
  2842. #endif
  2843. #if defined(DUK_USE_TAILCALL) && defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY)
  2844. #error config option DUK_USE_TAILCALL conflicts with option DUK_USE_NONSTD_FUNC_CALLER_PROPERTY (which is also defined)
  2845. #endif
  2846. #if defined(DUK_USE_UNALIGNED_ACCESSES_POSSIBLE)
  2847. #error unsupported config option used (option has been removed): DUK_USE_UNALIGNED_ACCESSES_POSSIBLE
  2848. #endif
  2849. #if defined(DUK_USE_UNDERSCORE_SETJMP)
  2850. #error unsupported config option used (option has been removed): DUK_USE_UNDERSCORE_SETJMP
  2851. #endif
  2852. #if defined(DUK_USE_USER_INITJS)
  2853. #error unsupported config option used (option has been removed): DUK_USE_USER_INITJS
  2854. #endif
  2855. #if defined(DUK_USE_CPP_EXCEPTIONS) && !defined(__cplusplus)
  2856. #error DUK_USE_CPP_EXCEPTIONS enabled but not compiling with a C++ compiler
  2857. #endif
  2858. /*
  2859. * Convert DUK_USE_BYTEORDER, from whatever source, into currently used
  2860. * internal defines. If detection failed, #error out.
  2861. */
  2862. #if defined(DUK_USE_BYTEORDER)
  2863. #if (DUK_USE_BYTEORDER == 1)
  2864. #define DUK_USE_INTEGER_LE
  2865. #define DUK_USE_DOUBLE_LE
  2866. #elif (DUK_USE_BYTEORDER == 2)
  2867. #define DUK_USE_INTEGER_LE /* integer endianness is little on purpose */
  2868. #define DUK_USE_DOUBLE_ME
  2869. #elif (DUK_USE_BYTEORDER == 3)
  2870. #define DUK_USE_INTEGER_BE
  2871. #define DUK_USE_DOUBLE_BE
  2872. #else
  2873. #error unsupported: byte order invalid
  2874. #endif /* byte order */
  2875. #else
  2876. #error unsupported: byte order detection failed
  2877. #endif /* defined(DUK_USE_BYTEORDER) */
  2878. #endif /* DUK_CONFIG_H_INCLUDED */