duk_config.h 109 KB

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