duk_config.h-modular-static 111 KB

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