@port-labs/jq-node-bindings 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/binding.gyp +3 -3
  2. package/configure +8 -6
  3. package/deps/jq/.travis.yml +184 -35
  4. package/deps/jq/AUTHORS +31 -30
  5. package/deps/jq/COPYING +2 -2
  6. package/deps/jq/KEYS +8 -0
  7. package/deps/jq/Makefile.am +85 -70
  8. package/deps/jq/NEWS +5 -4
  9. package/deps/jq/README.md +18 -9
  10. package/deps/jq/appveyor.yml +53 -0
  11. package/deps/jq/compile-ios.sh +5 -5
  12. package/deps/jq/config/m4/check-math-func.m4 +7 -2
  13. package/deps/jq/configure.ac +130 -68
  14. package/deps/jq/docs/Rakefile +14 -135
  15. package/deps/jq/docs/Rakefile.manual +49 -0
  16. package/deps/jq/docs/Rakefile.website +76 -0
  17. package/deps/jq/docs/content/2.download/default.yml +115 -39
  18. package/deps/jq/docs/content/3.manual/manual.yml +641 -231
  19. package/deps/jq/docs/content/3.manual/v1.3/manual.yml +130 -130
  20. package/deps/jq/docs/content/3.manual/v1.4/manual.yml +160 -160
  21. package/deps/jq/docs/content/3.manual/v1.5/manual.yml +2878 -0
  22. package/deps/jq/docs/content/3.manual/v1.6/manual.yml +3287 -0
  23. package/deps/jq/docs/content/index/index.yml +28 -6
  24. package/deps/jq/docs/public/.htaccess +2 -2
  25. package/deps/jq/docs/public/css/base.scss +141 -59
  26. package/deps/jq/docs/public/js/manual-search.js +52 -0
  27. package/deps/jq/docs/site.yml +1 -10
  28. package/deps/jq/docs/templates/default.liquid +10 -10
  29. package/deps/jq/docs/templates/index.liquid +45 -32
  30. package/deps/jq/docs/templates/manual.liquid +67 -90
  31. package/deps/jq/docs/templates/shared/_footer.liquid +10 -5
  32. package/deps/jq/docs/templates/shared/_head.liquid +17 -12
  33. package/deps/jq/docs/templates/shared/_navbar.liquid +27 -0
  34. package/deps/jq/jq.1.prebuilt +523 -139
  35. package/deps/jq/modules/oniguruma/AUTHORS +1 -0
  36. package/deps/jq/modules/oniguruma/CMakeLists.txt +86 -0
  37. package/deps/jq/modules/oniguruma/COPYING +28 -0
  38. package/deps/jq/modules/oniguruma/ChangeLog +0 -0
  39. package/deps/jq/modules/oniguruma/HISTORY +2138 -0
  40. package/deps/jq/modules/oniguruma/Makefile.am +33 -0
  41. package/deps/jq/modules/oniguruma/NEWS +0 -0
  42. package/deps/jq/modules/oniguruma/README +189 -0
  43. package/deps/jq/modules/oniguruma/README.ja +195 -0
  44. package/deps/jq/modules/oniguruma/README.md +203 -0
  45. package/deps/jq/modules/oniguruma/cmake/dist.cmake +321 -0
  46. package/deps/jq/modules/oniguruma/compile +348 -0
  47. package/deps/jq/modules/oniguruma/config.guess +1754 -0
  48. package/deps/jq/modules/oniguruma/config.sub +1890 -0
  49. package/deps/jq/modules/oniguruma/configure.ac +87 -0
  50. package/deps/jq/modules/oniguruma/contributed/libfuzzer-onig.cpp +31 -0
  51. package/deps/jq/modules/oniguruma/depcomp +791 -0
  52. package/deps/jq/modules/oniguruma/dist.info +10 -0
  53. package/deps/jq/modules/oniguruma/doc/API +660 -0
  54. package/deps/jq/modules/oniguruma/doc/API.ja +667 -0
  55. package/deps/jq/modules/oniguruma/doc/FAQ +12 -0
  56. package/deps/jq/modules/oniguruma/doc/FAQ.ja +22 -0
  57. package/deps/jq/modules/oniguruma/doc/RE +436 -0
  58. package/deps/jq/modules/oniguruma/doc/RE.ja +448 -0
  59. package/deps/jq/modules/oniguruma/doc/UNICODE_PROPERTIES +698 -0
  60. package/deps/jq/modules/oniguruma/index.html +181 -0
  61. package/deps/jq/modules/oniguruma/index_ja.html +184 -0
  62. package/deps/jq/modules/oniguruma/install-sh +541 -0
  63. package/deps/jq/modules/oniguruma/m4/.whatever +0 -0
  64. package/deps/jq/modules/oniguruma/make_win32.bat +3 -0
  65. package/deps/jq/modules/oniguruma/make_win64.bat +3 -0
  66. package/deps/jq/modules/oniguruma/missing +215 -0
  67. package/deps/jq/modules/oniguruma/onig-config.in +78 -0
  68. package/deps/jq/modules/oniguruma/oniguruma.pc.cmake.in +13 -0
  69. package/deps/jq/modules/oniguruma/oniguruma.pc.in +14 -0
  70. package/deps/jq/modules/oniguruma/sample/CMakeLists.txt +28 -0
  71. package/deps/jq/modules/oniguruma/sample/Makefile.am +34 -0
  72. package/deps/jq/modules/oniguruma/sample/bug_fix.c +131 -0
  73. package/deps/jq/modules/oniguruma/sample/crnl.c +127 -0
  74. package/deps/jq/modules/oniguruma/sample/encode.c +308 -0
  75. package/deps/jq/modules/oniguruma/sample/listcap.c +110 -0
  76. package/deps/jq/modules/oniguruma/sample/names.c +75 -0
  77. package/deps/jq/modules/oniguruma/sample/posix.c +96 -0
  78. package/deps/jq/modules/oniguruma/sample/scan.c +88 -0
  79. package/deps/jq/modules/oniguruma/sample/simple.c +59 -0
  80. package/deps/jq/modules/oniguruma/sample/sql.c +76 -0
  81. package/deps/jq/modules/oniguruma/sample/syntax.c +76 -0
  82. package/deps/jq/modules/oniguruma/sample/user_property.c +87 -0
  83. package/deps/jq/modules/oniguruma/src/Makefile.am +58 -0
  84. package/deps/jq/modules/oniguruma/src/Makefile.windows +183 -0
  85. package/deps/jq/modules/oniguruma/src/ascii.c +61 -0
  86. package/deps/jq/modules/oniguruma/src/big5.c +190 -0
  87. package/deps/jq/modules/oniguruma/src/config.h.cmake.in +71 -0
  88. package/deps/jq/modules/oniguruma/src/config.h.win32 +84 -0
  89. package/deps/jq/modules/oniguruma/src/config.h.win64 +84 -0
  90. package/deps/jq/modules/oniguruma/src/cp1251.c +203 -0
  91. package/deps/jq/modules/oniguruma/src/euc_jp.c +310 -0
  92. package/deps/jq/modules/oniguruma/src/euc_jp_prop.c +158 -0
  93. package/deps/jq/modules/oniguruma/src/euc_jp_prop.gperf +27 -0
  94. package/deps/jq/modules/oniguruma/src/euc_kr.c +188 -0
  95. package/deps/jq/modules/oniguruma/src/euc_tw.c +171 -0
  96. package/deps/jq/modules/oniguruma/src/gb18030.c +538 -0
  97. package/deps/jq/modules/oniguruma/src/gperf_fold_key_conv.py +67 -0
  98. package/deps/jq/modules/oniguruma/src/gperf_unfold_key_conv.py +55 -0
  99. package/deps/jq/modules/oniguruma/src/iso8859_1.c +275 -0
  100. package/deps/jq/modules/oniguruma/src/iso8859_10.c +242 -0
  101. package/deps/jq/modules/oniguruma/src/iso8859_11.c +99 -0
  102. package/deps/jq/modules/oniguruma/src/iso8859_13.c +231 -0
  103. package/deps/jq/modules/oniguruma/src/iso8859_14.c +244 -0
  104. package/deps/jq/modules/oniguruma/src/iso8859_15.c +238 -0
  105. package/deps/jq/modules/oniguruma/src/iso8859_16.c +240 -0
  106. package/deps/jq/modules/oniguruma/src/iso8859_2.c +238 -0
  107. package/deps/jq/modules/oniguruma/src/iso8859_3.c +238 -0
  108. package/deps/jq/modules/oniguruma/src/iso8859_4.c +240 -0
  109. package/deps/jq/modules/oniguruma/src/iso8859_5.c +229 -0
  110. package/deps/jq/modules/oniguruma/src/iso8859_6.c +99 -0
  111. package/deps/jq/modules/oniguruma/src/iso8859_7.c +225 -0
  112. package/deps/jq/modules/oniguruma/src/iso8859_8.c +99 -0
  113. package/deps/jq/modules/oniguruma/src/iso8859_9.c +231 -0
  114. package/deps/jq/modules/oniguruma/src/koi8.c +253 -0
  115. package/deps/jq/modules/oniguruma/src/koi8_r.c +215 -0
  116. package/deps/jq/modules/oniguruma/src/make_unicode_fold.sh +22 -0
  117. package/deps/jq/modules/oniguruma/src/make_unicode_fold_data.py +306 -0
  118. package/deps/jq/modules/oniguruma/src/make_unicode_property.sh +18 -0
  119. package/deps/jq/modules/oniguruma/src/make_unicode_property_data.py +545 -0
  120. package/deps/jq/modules/oniguruma/src/mktable.c +1184 -0
  121. package/deps/jq/modules/oniguruma/src/onig_init.c +45 -0
  122. package/deps/jq/modules/oniguruma/src/oniggnu.h +85 -0
  123. package/deps/jq/modules/oniguruma/src/onigposix.h +169 -0
  124. package/deps/jq/modules/oniguruma/src/oniguruma.h +841 -0
  125. package/deps/jq/modules/oniguruma/src/regcomp.c +6300 -0
  126. package/deps/jq/modules/oniguruma/src/regenc.c +917 -0
  127. package/deps/jq/modules/oniguruma/src/regenc.h +243 -0
  128. package/deps/jq/modules/oniguruma/src/regerror.c +393 -0
  129. package/deps/jq/modules/oniguruma/src/regexec.c +3856 -0
  130. package/deps/jq/modules/oniguruma/src/regext.c +202 -0
  131. package/deps/jq/modules/oniguruma/src/reggnu.c +147 -0
  132. package/deps/jq/modules/oniguruma/src/regint.h +779 -0
  133. package/deps/jq/modules/oniguruma/src/regparse.c +5403 -0
  134. package/deps/jq/modules/oniguruma/src/regparse.h +351 -0
  135. package/deps/jq/modules/oniguruma/src/regposerr.c +105 -0
  136. package/deps/jq/modules/oniguruma/src/regposix.c +306 -0
  137. package/deps/jq/modules/oniguruma/src/regsyntax.c +315 -0
  138. package/deps/jq/modules/oniguruma/src/regtrav.c +76 -0
  139. package/deps/jq/modules/oniguruma/src/regversion.c +57 -0
  140. package/deps/jq/modules/oniguruma/src/sjis.c +341 -0
  141. package/deps/jq/modules/oniguruma/src/sjis_prop.c +158 -0
  142. package/deps/jq/modules/oniguruma/src/sjis_prop.gperf +27 -0
  143. package/deps/jq/modules/oniguruma/src/st.c +589 -0
  144. package/deps/jq/modules/oniguruma/src/st.h +68 -0
  145. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold1_key.c +2250 -0
  146. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold2_key.c +203 -0
  147. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold3_key.c +113 -0
  148. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold_data.c +1225 -0
  149. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data.c +24742 -0
  150. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data_posix.c +4846 -0
  151. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_unfold_key.c +2571 -0
  152. package/deps/jq/modules/oniguruma/src/unicode.c +664 -0
  153. package/deps/jq/modules/oniguruma/src/unicode_fold1_key.c +2548 -0
  154. package/deps/jq/modules/oniguruma/src/unicode_fold2_key.c +203 -0
  155. package/deps/jq/modules/oniguruma/src/unicode_fold3_key.c +113 -0
  156. package/deps/jq/modules/oniguruma/src/unicode_fold_data.c +1366 -0
  157. package/deps/jq/modules/oniguruma/src/unicode_property_data.c +25306 -0
  158. package/deps/jq/modules/oniguruma/src/unicode_property_data_posix.c +4940 -0
  159. package/deps/jq/modules/oniguruma/src/unicode_unfold_key.c +2854 -0
  160. package/deps/jq/modules/oniguruma/src/utf16_be.c +235 -0
  161. package/deps/jq/modules/oniguruma/src/utf16_le.c +245 -0
  162. package/deps/jq/modules/oniguruma/src/utf32_be.c +194 -0
  163. package/deps/jq/modules/oniguruma/src/utf32_le.c +194 -0
  164. package/deps/jq/modules/oniguruma/src/utf8.c +335 -0
  165. package/deps/jq/modules/oniguruma/test/Makefile.am +28 -0
  166. package/deps/jq/modules/oniguruma/test/testc.c +874 -0
  167. package/deps/jq/modules/oniguruma/test/testu.c +916 -0
  168. package/deps/jq/modules/oniguruma/test-driver +153 -0
  169. package/deps/jq/modules/oniguruma/windows/testc.c +869 -0
  170. package/deps/jq/scripts/crosscompile +2 -1
  171. package/deps/jq/scripts/gen_utf8_tables.py +2 -3
  172. package/deps/jq/scripts/update-website +29 -0
  173. package/deps/jq/scripts/version +7 -2
  174. package/deps/jq/sig/jq-release.key +41 -0
  175. package/deps/jq/sig/v1.3/jq-linux-x86.asc +17 -0
  176. package/deps/jq/sig/v1.3/jq-linux-x86_64.asc +17 -0
  177. package/deps/jq/sig/v1.3/jq-osx-x86.asc +17 -0
  178. package/deps/jq/sig/v1.3/jq-osx-x86_64.asc +17 -0
  179. package/deps/jq/sig/v1.3/jq-win32.exe.asc +17 -0
  180. package/deps/jq/sig/v1.3/jq-win64.exe.asc +17 -0
  181. package/deps/jq/sig/v1.3/sha256sum.txt +6 -0
  182. package/deps/jq/sig/v1.4/jq-linux-x86.asc +17 -0
  183. package/deps/jq/sig/v1.4/jq-linux-x86_64.asc +17 -0
  184. package/deps/jq/sig/v1.4/jq-osx-x86.asc +17 -0
  185. package/deps/jq/sig/v1.4/jq-osx-x86_64.asc +17 -0
  186. package/deps/jq/sig/v1.4/jq-solaris11-32.asc +17 -0
  187. package/deps/jq/sig/v1.4/jq-solaris11-64.asc +17 -0
  188. package/deps/jq/sig/v1.4/jq-win32.exe.asc +17 -0
  189. package/deps/jq/sig/v1.4/jq-win64.exe.asc +17 -0
  190. package/deps/jq/sig/v1.4/sha256sum.txt +8 -0
  191. package/deps/jq/sig/v1.5/jq-linux32-no-oniguruma.asc +17 -0
  192. package/deps/jq/sig/v1.5/jq-linux32.asc +17 -0
  193. package/deps/jq/sig/v1.5/jq-linux64.asc +17 -0
  194. package/deps/jq/sig/v1.5/jq-osx-amd64.asc +17 -0
  195. package/deps/jq/sig/v1.5/jq-win32.exe.asc +17 -0
  196. package/deps/jq/sig/v1.5/jq-win64.exe.asc +17 -0
  197. package/deps/jq/sig/v1.5/sha256sum.txt +5 -0
  198. package/deps/jq/sig/v1.5rc1/jq-linux-x86_64-static.asc +17 -0
  199. package/deps/jq/sig/v1.5rc1/jq-win32.exe.asc +17 -0
  200. package/deps/jq/sig/v1.5rc1/jq-win64.exe.asc +17 -0
  201. package/deps/jq/sig/v1.5rc1/sha256sum.txt +3 -0
  202. package/deps/jq/sig/v1.5rc2/jq-linux-x86.asc +17 -0
  203. package/deps/jq/sig/v1.5rc2/jq-linux-x86_64.asc +17 -0
  204. package/deps/jq/sig/v1.5rc2/jq-osx-x86_64.asc +17 -0
  205. package/deps/jq/sig/v1.5rc2/jq-win32.exe.asc +17 -0
  206. package/deps/jq/sig/v1.5rc2/jq-win64.exe.asc +17 -0
  207. package/deps/jq/sig/v1.5rc2/sha256sum.txt +5 -0
  208. package/deps/jq/sig/v1.6/jq-linux32.asc +16 -0
  209. package/deps/jq/sig/v1.6/jq-linux64.asc +16 -0
  210. package/deps/jq/sig/v1.6/jq-osx-amd64.asc +16 -0
  211. package/deps/jq/sig/v1.6/jq-win32.exe.asc +16 -0
  212. package/deps/jq/sig/v1.6/jq-win64.exe.asc +16 -0
  213. package/deps/jq/sig/v1.6/sha256sum.txt +5 -0
  214. package/deps/jq/{builtin.c → src/builtin.c} +449 -344
  215. package/deps/jq/{builtin.h → src/builtin.h} +0 -0
  216. package/deps/jq/src/builtin.jq +311 -0
  217. package/deps/jq/{bytecode.c → src/bytecode.c} +0 -0
  218. package/deps/jq/{bytecode.h → src/bytecode.h} +0 -0
  219. package/deps/jq/{compile.c → src/compile.c} +213 -37
  220. package/deps/jq/{compile.h → src/compile.h} +7 -2
  221. package/deps/jq/{exec_stack.h → src/exec_stack.h} +0 -0
  222. package/deps/jq/{execute.c → src/execute.c} +127 -24
  223. package/deps/jq/{inject_errors.c → src/inject_errors.c} +0 -0
  224. package/deps/jq/{jq.h → src/jq.h} +13 -2
  225. package/deps/jq/{jq_parser.h → src/jq_parser.h} +0 -0
  226. package/deps/jq/{jq_test.c → src/jq_test.c} +1 -1
  227. package/deps/jq/{jv.c → src/jv.c} +24 -5
  228. package/deps/jq/{jv.h → src/jv.h} +46 -11
  229. package/deps/jq/{jv_alloc.c → src/jv_alloc.c} +0 -0
  230. package/deps/jq/{jv_alloc.h → src/jv_alloc.h} +0 -0
  231. package/deps/jq/{jv_aux.c → src/jv_aux.c} +38 -14
  232. package/deps/jq/{jv_dtoa.c → src/jv_dtoa.c} +4 -5
  233. package/deps/jq/{jv_dtoa.h → src/jv_dtoa.h} +0 -0
  234. package/deps/jq/src/jv_file.c +81 -0
  235. package/deps/jq/{jv_parse.c → src/jv_parse.c} +8 -2
  236. package/deps/jq/{jv_print.c → src/jv_print.c} +80 -27
  237. package/deps/jq/{jv_unicode.c → src/jv_unicode.c} +28 -4
  238. package/deps/jq/{jv_unicode.h → src/jv_unicode.h} +1 -0
  239. package/deps/jq/{jv_utf8_tables.h → src/jv_utf8_tables.h} +0 -0
  240. package/deps/jq/{lexer.c → src/lexer.c} +317 -292
  241. package/deps/jq/{lexer.h → src/lexer.h} +16 -12
  242. package/deps/jq/{lexer.l → src/lexer.l} +5 -4
  243. package/deps/jq/src/libm.h +291 -0
  244. package/deps/jq/{linker.c → src/linker.c} +5 -3
  245. package/deps/jq/{linker.h → src/linker.h} +0 -0
  246. package/deps/jq/{locfile.c → src/locfile.c} +1 -1
  247. package/deps/jq/{locfile.h → src/locfile.h} +0 -0
  248. package/deps/jq/{main.c → src/main.c} +202 -100
  249. package/deps/jq/{opcode_list.h → src/opcode_list.h} +4 -0
  250. package/deps/jq/{parser.c → src/parser.c} +1149 -1069
  251. package/deps/jq/{parser.h → src/parser.h} +28 -24
  252. package/deps/jq/{parser.y → src/parser.y} +108 -52
  253. package/deps/jq/{util.c → src/util.c} +12 -9
  254. package/deps/jq/{util.h → src/util.h} +0 -0
  255. package/deps/jq/tests/base64.test +35 -0
  256. package/deps/jq/tests/base64test +5 -0
  257. package/deps/jq/tests/jq-f-test.sh +4 -0
  258. package/deps/jq/tests/jq.test +305 -21
  259. package/deps/jq/tests/jqtest +1 -1
  260. package/deps/jq/tests/mantest +1 -1
  261. package/deps/jq/tests/onig.test +13 -0
  262. package/deps/jq/tests/onigtest +1 -1
  263. package/deps/jq/tests/optional.test +20 -0
  264. package/deps/jq/tests/optionaltest +5 -0
  265. package/deps/jq/tests/setup +7 -1
  266. package/deps/jq/tests/shtest +133 -29
  267. package/deps/jq/tests/utf8-truncate.jq +3 -0
  268. package/deps/jq/tests/utf8test +10 -0
  269. package/lib/index.js +7 -1
  270. package/package.json +3 -3
  271. package/test/santiy.test.js +24 -0
  272. package/deps/jq/docs/default_manpage.md +0 -22
  273. package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.css +0 -1058
  274. package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.min.css +0 -9
  275. package/deps/jq/docs/public/bootstrap/css/bootstrap.css +0 -5224
  276. package/deps/jq/docs/public/bootstrap/css/bootstrap.min.css +0 -9
  277. package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings-white.png +0 -0
  278. package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings.png +0 -0
  279. package/deps/jq/docs/public/bootstrap/js/bootstrap.js +0 -2027
  280. package/deps/jq/docs/public/bootstrap/js/bootstrap.min.js +0 -6
  281. package/deps/jq/docs/templates/shared/_header.liquid +0 -26
  282. package/deps/jq/jq.1.default +0 -39
  283. package/deps/jq/jv_file.c +0 -49
  284. package/deps/jq/libm.h +0 -160
  285. package/deps/jq/setup.sh +0 -33
  286. package/reports/jest-port-api.xml +0 -35
@@ -40,6 +40,10 @@ struct jq_state {
40
40
  int initial_execution;
41
41
  unsigned next_label;
42
42
 
43
+ int halted;
44
+ jv exit_code;
45
+ jv error_message;
46
+
43
47
  jv attrs;
44
48
  jq_input_cb input_cb;
45
49
  void *input_cb_data;
@@ -64,7 +68,7 @@ struct frame {
64
68
  stack_ptr env; // jq stack address of frame to return to
65
69
  stack_ptr retdata; // jq stack address to unwind to on RET
66
70
  uint16_t* retaddr; // jq bytecode return address
67
- union frame_entry entries[0]; // nclosures + nlocals
71
+ union frame_entry entries[]; // nclosures + nlocals
68
72
  };
69
73
 
70
74
  static int frame_size(struct bytecode* bc) {
@@ -242,6 +246,28 @@ static void path_append(jq_state* jq, jv component, jv value_at_path) {
242
246
  }
243
247
  }
244
248
 
249
+ /* For f_getpath() */
250
+ jv
251
+ _jq_path_append(jq_state *jq, jv v, jv p, jv value_at_path) {
252
+ if (jq->subexp_nest != 0 ||
253
+ jv_get_kind(jq->path) != JV_KIND_ARRAY ||
254
+ !jv_is_valid(value_at_path)) {
255
+ jv_free(v);
256
+ jv_free(p);
257
+ return value_at_path;
258
+ }
259
+ if (!jv_identical(v, jv_copy(jq->value_at_path))) {
260
+ jv_free(p);
261
+ return value_at_path;
262
+ }
263
+ if (jv_get_kind(p) == JV_KIND_ARRAY)
264
+ jq->path = jv_array_concat(jq->path, p);
265
+ else
266
+ jq->path = jv_array_append(jq->path, p);
267
+ jv_free(jq->value_at_path);
268
+ return jv_copy(jq->value_at_path = value_at_path);
269
+ }
270
+
245
271
  uint16_t* stack_restore(jq_state *jq){
246
272
  while (!stack_pop_will_free(&jq->stk, jq->fork_top)) {
247
273
  if (stack_pop_will_free(&jq->stk, jq->stk_top)) {
@@ -285,6 +311,9 @@ static void jq_reset(jq_state *jq) {
285
311
  jv_free(jq->error);
286
312
  jq->error = jv_null();
287
313
 
314
+ jq->halted = 0;
315
+ jv_free(jq->exit_code);
316
+ jv_free(jq->error_message);
288
317
  if (jv_get_kind(jq->path) != JV_KIND_INVALID)
289
318
  jv_free(jq->path);
290
319
  jq->path = jv_null();
@@ -320,6 +349,11 @@ jv jq_next(jq_state *jq) {
320
349
  jq->initial_execution = 0;
321
350
  assert(jv_get_kind(jq->error) == JV_KIND_NULL);
322
351
  while (1) {
352
+ if (jq->halted) {
353
+ if (jq->debug_trace_enabled)
354
+ printf("\t<halted>\n");
355
+ return jv_invalid();
356
+ }
323
357
  uint16_t opcode = *pc;
324
358
  raising = 0;
325
359
 
@@ -331,10 +365,9 @@ jv jq_next(jq_state *jq) {
331
365
  if (!backtracking) {
332
366
  int stack_in = opdesc->stack_in;
333
367
  if (stack_in == -1) stack_in = pc[1];
368
+ param = jq->stk_top;
334
369
  for (int i=0; i<stack_in; i++) {
335
- if (i == 0) {
336
- param = jq->stk_top;
337
- } else {
370
+ if (i != 0) {
338
371
  printf(" | ");
339
372
  param = *stack_block_next(&jq->stk, param);
340
373
  }
@@ -344,6 +377,12 @@ jv jq_next(jq_state *jq) {
344
377
  //printf(" -- ");
345
378
  //jv_dump(jv_copy(jq->path), 0);
346
379
  }
380
+ if (jq->debug_trace_enabled & JQ_DEBUG_TRACE_DETAIL) {
381
+ while ((param = *stack_block_next(&jq->stk, param))) {
382
+ printf(" || ");
383
+ jv_dump(jv_copy(*(jv*)stack_block(&jq->stk, param)), JV_PRINT_REFCOUNT);
384
+ }
385
+ }
347
386
  } else {
348
387
  printf("\t<backtracking>");
349
388
  }
@@ -417,6 +456,15 @@ jv jq_next(jq_state *jq) {
417
456
  break;
418
457
  }
419
458
 
459
+ case PUSHK_UNDER: {
460
+ jv v = jv_array_get(jv_copy(frame_current(jq)->bc->constants), *pc++);
461
+ assert(jv_is_valid(v));
462
+ jv v2 = stack_pop(jq);
463
+ stack_push(jq, v);
464
+ stack_push(jq, v2);
465
+ break;
466
+ }
467
+
420
468
  case POP: {
421
469
  jv_free(stack_pop(jq));
422
470
  break;
@@ -514,6 +562,8 @@ jv jq_next(jq_state *jq) {
514
562
  break;
515
563
  }
516
564
 
565
+ case STOREVN:
566
+ stack_save(jq, pc - 1, stack_get_pos(jq));
517
567
  case STOREV: {
518
568
  uint16_t level = *pc++;
519
569
  uint16_t v = *pc++;
@@ -529,6 +579,16 @@ jv jq_next(jq_state *jq) {
529
579
  break;
530
580
  }
531
581
 
582
+ case ON_BACKTRACK(STOREVN): {
583
+ uint16_t level = *pc++;
584
+ uint16_t v = *pc++;
585
+ jv* var = frame_local_var(jq, v, level);
586
+ jv_free(*var);
587
+ *var = jv_null();
588
+ goto do_backtrack;
589
+ break;
590
+ }
591
+
532
592
  case STORE_GLOBAL: {
533
593
  // Get the constant
534
594
  jv val = jv_array_get(jv_copy(frame_current(jq)->bc->constants), *pc++);
@@ -739,21 +799,29 @@ jv jq_next(jq_state *jq) {
739
799
  }
740
800
 
741
801
  case FORK_OPT:
802
+ case DESTRUCTURE_ALT:
742
803
  case FORK: {
743
804
  stack_save(jq, pc - 1, stack_get_pos(jq));
744
805
  pc++; // skip offset this time
745
806
  break;
746
807
  }
747
808
 
748
- case ON_BACKTRACK(FORK_OPT): {
809
+ case ON_BACKTRACK(FORK_OPT):
810
+ case ON_BACKTRACK(DESTRUCTURE_ALT): {
749
811
  if (jv_is_valid(jq->error)) {
750
812
  // `try EXP ...` backtracked here (no value, `empty`), so we backtrack more
751
813
  jv_free(stack_pop(jq));
752
814
  goto do_backtrack;
753
815
  }
754
816
  // `try EXP ...` exception caught in EXP
755
- jv_free(stack_pop(jq)); // free the input
756
- stack_push(jq, jv_invalid_get_msg(jq->error)); // push the error's message
817
+ // DESTRUCTURE_ALT doesn't want the error message on the stack,
818
+ // as we would just want to throw it away anyway.
819
+ if (opcode != ON_BACKTRACK(DESTRUCTURE_ALT)) {
820
+ jv_free(stack_pop(jq)); // free the input
821
+ stack_push(jq, jv_invalid_get_msg(jq->error)); // push the error's message
822
+ } else {
823
+ jv_free(jq->error);
824
+ }
757
825
  jq->error = jv_null();
758
826
  uint16_t offset = *pc++;
759
827
  pc += offset;
@@ -932,6 +1000,10 @@ jq_state *jq_init(void) {
932
1000
  jq->curr_frame = 0;
933
1001
  jq->error = jv_null();
934
1002
 
1003
+ jq->halted = 0;
1004
+ jq->exit_code = jv_invalid();
1005
+ jq->error_message = jv_invalid();
1006
+
935
1007
  jq->err_cb = default_err_cb;
936
1008
  jq->err_cb_data = stderr;
937
1009
 
@@ -974,11 +1046,7 @@ void jq_start(jq_state *jq, jv input, int flags) {
974
1046
 
975
1047
  stack_push(jq, input);
976
1048
  stack_save(jq, jq->bc->code, stack_get_pos(jq));
977
- if (flags & JQ_DEBUG_TRACE) {
978
- jq->debug_trace_enabled = 1;
979
- } else {
980
- jq->debug_trace_enabled = 0;
981
- }
1049
+ jq->debug_trace_enabled = flags & JQ_DEBUG_TRACE_ALL;
982
1050
  jq->initial_execution = 1;
983
1051
  }
984
1052
 
@@ -1066,9 +1134,26 @@ static struct bytecode *optimize(struct bytecode *bc) {
1066
1134
  return optimize_code(bc);
1067
1135
  }
1068
1136
 
1137
+ static jv
1138
+ args2obj(jv args)
1139
+ {
1140
+ if (jv_get_kind(args) == JV_KIND_OBJECT)
1141
+ return args;
1142
+ assert(jv_get_kind(args) == JV_KIND_ARRAY);
1143
+ jv r = jv_object();
1144
+ jv kk = jv_string("name");
1145
+ jv vk = jv_string("value");
1146
+ jv_array_foreach(args, i, v)
1147
+ r = jv_object_set(r, jv_object_get(jv_copy(v), kk), jv_object_get(v, vk));
1148
+ jv_free(args);
1149
+ jv_free(kk);
1150
+ jv_free(vk);
1151
+ return r;
1152
+ }
1153
+
1069
1154
  int jq_compile_args(jq_state *jq, const char* str, jv args) {
1070
1155
  jv_nomem_handler(jq->nomem_handler, jq->nomem_handler_data);
1071
- assert(jv_get_kind(args) == JV_KIND_ARRAY);
1156
+ assert(jv_get_kind(args) == JV_KIND_ARRAY || jv_get_kind(args) == JV_KIND_OBJECT);
1072
1157
  struct locfile* locations;
1073
1158
  locations = locfile_init(jq, "<top-level>", str, strlen(str));
1074
1159
  block program;
@@ -1079,29 +1164,22 @@ int jq_compile_args(jq_state *jq, const char* str, jv args) {
1079
1164
  }
1080
1165
  int nerrors = load_program(jq, locations, &program);
1081
1166
  if (nerrors == 0) {
1082
- jv_array_foreach(args, i, arg) {
1083
- jv name = jv_object_get(jv_copy(arg), jv_string("name"));
1084
- jv value = jv_object_get(arg, jv_string("value"));
1085
- program = gen_var_binding(gen_const(value), jv_string_value(name), program);
1086
- jv_free(name);
1087
- }
1088
-
1089
1167
  nerrors = builtins_bind(jq, &program);
1090
1168
  if (nerrors == 0) {
1091
- nerrors = block_compile(program, &jq->bc, locations);
1169
+ nerrors = block_compile(program, &jq->bc, locations, args = args2obj(args));
1092
1170
  }
1093
- }
1171
+ } else
1172
+ jv_free(args);
1094
1173
  if (nerrors)
1095
1174
  jq_report_error(jq, jv_string_fmt("jq: %d compile %s", nerrors, nerrors > 1 ? "errors" : "error"));
1096
1175
  if (jq->bc)
1097
1176
  jq->bc = optimize(jq->bc);
1098
- jv_free(args);
1099
1177
  locfile_free(locations);
1100
1178
  return jq->bc != NULL;
1101
1179
  }
1102
1180
 
1103
1181
  int jq_compile(jq_state *jq, const char* str) {
1104
- return jq_compile_args(jq, str, jv_array());
1182
+ return jq_compile_args(jq, str, jv_object());
1105
1183
  }
1106
1184
 
1107
1185
  jv jq_get_jq_origin(jq_state *jq) {
@@ -1153,3 +1231,28 @@ void jq_get_debug_cb(jq_state *jq, jq_msg_cb *cb, void **data) {
1153
1231
  *cb = jq->debug_cb;
1154
1232
  *data = jq->debug_cb_data;
1155
1233
  }
1234
+
1235
+ void
1236
+ jq_halt(jq_state *jq, jv exit_code, jv error_message)
1237
+ {
1238
+ assert(!jq->halted);
1239
+ jq->halted = 1;
1240
+ jq->exit_code = exit_code;
1241
+ jq->error_message = error_message;
1242
+ }
1243
+
1244
+ int
1245
+ jq_halted(jq_state *jq)
1246
+ {
1247
+ return jq->halted;
1248
+ }
1249
+
1250
+ jv jq_get_exit_code(jq_state *jq)
1251
+ {
1252
+ return jv_copy(jq->exit_code);
1253
+ }
1254
+
1255
+ jv jq_get_error_message(jq_state *jq)
1256
+ {
1257
+ return jv_copy(jq->error_message);
1258
+ }
File without changes
@@ -2,9 +2,13 @@
2
2
  #define JQ_H
3
3
 
4
4
  #include <stdio.h>
5
- #include <jv.h>
5
+ #include "jv.h"
6
6
 
7
- enum {JQ_DEBUG_TRACE = 1};
7
+ enum {
8
+ JQ_DEBUG_TRACE = 1,
9
+ JQ_DEBUG_TRACE_DETAIL = 2,
10
+ JQ_DEBUG_TRACE_ALL = JQ_DEBUG_TRACE | JQ_DEBUG_TRACE_DETAIL,
11
+ };
8
12
 
9
13
  typedef struct jq_state jq_state;
10
14
  typedef void (*jq_msg_cb)(void *, jv);
@@ -22,6 +26,11 @@ void jq_start(jq_state *, jv value, int);
22
26
  jv jq_next(jq_state *);
23
27
  void jq_teardown(jq_state **);
24
28
 
29
+ void jq_halt(jq_state *, jv, jv);
30
+ int jq_halted(jq_state *);
31
+ jv jq_get_exit_code(jq_state *);
32
+ jv jq_get_error_message(jq_state *);
33
+
25
34
  typedef jv (*jq_input_cb)(jq_state *, void *);
26
35
  void jq_set_input_cb(jq_state *, jq_input_cb, void *);
27
36
  void jq_get_input_cb(jq_state *, jq_input_cb *, void **);
@@ -57,4 +66,6 @@ jv jq_util_input_get_position(jq_state*);
57
66
  jv jq_util_input_get_current_filename(jq_state*);
58
67
  jv jq_util_input_get_current_line(jq_state*);
59
68
 
69
+ int jq_set_colors(const char *);
70
+
60
71
  #endif /* !JQ_H */
File without changes
@@ -157,7 +157,7 @@ static void run_jq_tests(jv lib_dirs, int verbose, FILE *testdata) {
157
157
  printf(" for test at line number %u: %s\n", lineno, prog);
158
158
  pass = 0;
159
159
  }
160
- jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOUR|JV_PRINT_REFCOUNT));
160
+ jv as_string = jv_dump_string(jv_copy(expected), rand() & ~(JV_PRINT_COLOR|JV_PRINT_REFCOUNT));
161
161
  jv reparsed = jv_parse_sized(jv_string_value(as_string), jv_string_length_bytes(jv_copy(as_string)));
162
162
  assert(jv_equal(jv_copy(expected), jv_copy(reparsed)));
163
163
  jv_free(as_string);
@@ -6,6 +6,7 @@
6
6
  #include <string.h>
7
7
  #include <stdarg.h>
8
8
  #include <limits.h>
9
+ #include <math.h>
9
10
 
10
11
  #include "jv_alloc.h"
11
12
  #include "jv.h"
@@ -295,10 +296,18 @@ static jv jvp_array_slice(jv a, int start, int end) {
295
296
  jv_free(a);
296
297
  return jv_array();
297
298
  }
298
- // FIXME FIXME FIXME large offsets
299
- a.offset += start;
300
- a.size = end - start;
301
- return a;
299
+
300
+ if (a.offset + start >= 1 << (sizeof(a.offset) * CHAR_BIT)) {
301
+ jv r = jv_array_sized(end - start);
302
+ for (int i = start; i < end; i++)
303
+ r = jv_array_append(r, jv_array_get(jv_copy(a), i));
304
+ jv_free(a);
305
+ return r;
306
+ } else {
307
+ a.offset += start;
308
+ a.size = end - start;
309
+ return a;
310
+ }
302
311
  }
303
312
 
304
313
  /*
@@ -1105,6 +1114,16 @@ jv jv_object_get(jv object, jv key) {
1105
1114
  return val;
1106
1115
  }
1107
1116
 
1117
+ int jv_object_has(jv object, jv key) {
1118
+ assert(jv_get_kind(object) == JV_KIND_OBJECT);
1119
+ assert(jv_get_kind(key) == JV_KIND_STRING);
1120
+ jv* slot = jvp_object_read(object, key);
1121
+ int res = slot ? 1 : 0;
1122
+ jv_free(object);
1123
+ jv_free(key);
1124
+ return res;
1125
+ }
1126
+
1108
1127
  jv jv_object_set(jv object, jv key, jv value) {
1109
1128
  assert(jv_get_kind(object) == JV_KIND_OBJECT);
1110
1129
  assert(jv_get_kind(key) == JV_KIND_STRING);
@@ -1302,7 +1321,7 @@ int jv_identical(jv a, jv b) {
1302
1321
  r = a.u.ptr == b.u.ptr;
1303
1322
  break;
1304
1323
  case JV_KIND_NUMBER:
1305
- r = a.u.number == b.u.number;
1324
+ r = memcmp(&a.u.number, &b.u.number, sizeof(a.u.number)) == 0;
1306
1325
  break;
1307
1326
  default:
1308
1327
  r = 1;
@@ -92,7 +92,7 @@ jv jv_array_indexes(jv, jv);
92
92
  #define JV_ARRAY_9(e1,e2,e3,e4,e5,e6,e7,e8,e9) (jv_array_append(JV_ARRAY_8(e1,e2,e3,e4,e5,e6,e7,e8),e9))
93
93
  #define JV_ARRAY_IDX(_1,_2,_3,_4,_5,_6,_7,_8,_9,NAME,...) NAME
94
94
  #define JV_ARRAY(...) \
95
- JV_ARRAY_IDX(__VA_ARGS__, JV_ARRAY_9, JV_ARRAY_8, JV_ARRAY_7, JV_ARRAY_6, JV_ARRAY_5, JV_ARRAY_4, JV_ARRAY_3, JV_ARRAY_2, JV_ARRAY_1)(__VA_ARGS__)
95
+ JV_ARRAY_IDX(__VA_ARGS__, JV_ARRAY_9, JV_ARRAY_8, JV_ARRAY_7, JV_ARRAY_6, JV_ARRAY_5, JV_ARRAY_4, JV_ARRAY_3, JV_ARRAY_2, JV_ARRAY_1, dummy)(__VA_ARGS__)
96
96
 
97
97
  #ifdef __GNUC__
98
98
  #define JV_PRINTF_LIKE(fmt_arg_num, args_num) \
@@ -123,6 +123,7 @@ jv jv_string_implode(jv j);
123
123
 
124
124
  jv jv_object(void);
125
125
  jv jv_object_get(jv object, jv key);
126
+ int jv_object_has(jv object, jv key);
126
127
  jv jv_object_set(jv object, jv key, jv value);
127
128
  jv jv_object_delete(jv object, jv key);
128
129
  int jv_object_length(jv object);
@@ -144,17 +145,51 @@ jv jv_object_iter_value(jv, int);
144
145
  : 0; \
145
146
  jv_i__ = jv_object_iter_next(t, jv_i__)) \
146
147
 
147
- #define JV_OBJECT_1(k) (jv_object_set(jv_object(),(k),jv_null()))
148
+ #define jv_object_keys_foreach(t, k) \
149
+ for (int jv_i__ = jv_object_iter(t), jv_j__ = 1; jv_j__; jv_j__ = 0) \
150
+ for (jv k; \
151
+ jv_object_iter_valid((t), jv_i__) ? \
152
+ (k = jv_object_iter_key(t, jv_i__), \
153
+ 1) \
154
+ : 0; \
155
+ jv_i__ = jv_object_iter_next(t, jv_i__))
156
+
157
+ #define JV_OBJECT_1(k1) (jv_object_set(jv_object(),(k1),jv_null()))
148
158
  #define JV_OBJECT_2(k1,v1) (jv_object_set(jv_object(),(k1),(v1)))
149
- #define JV_OBJECT_3(k1,v1,k2) (jv_object_set(JV_OBJECT_2(k1,v1),k2,jv_null()))
150
- #define JV_OBJECT_4(k1,v1,k2,v2) (jv_object_set(JV_OBJECT_2(k1,v1),k2,v2))
151
- #define JV_OBJECT_5(k1,v1,k2,v2,k3) (jv_object_set(JV_OBJECT_4(k1,v1,k2,v2),k3,jv_null))
152
- #define JV_OBJECT_6(k1,v1,k2,v2,k3,v3) (jv_object_set(JV_OBJECT_4(k1,v1,k2,v2),k3,v3))
153
- #define JV_OBJECT_7(k1,v1,k2,v2,k3,v3,k4) (jv_object_set(JV_OBJECT_6(k1,v1,k2,v2,k3,v3),k4,jv_null()))
154
- #define JV_OBJECT_8(k1,v1,k2,v2,k3,v3,k4,v4) (jv_object_set(JV_OBJECT_6(k1,v1,k2,v2,k3,v3),k4,v4))
155
- #define JV_OBJECT_IDX(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
159
+ #define JV_OBJECT_3(k1,v1,k2) (jv_object_set(JV_OBJECT_2((k1),(v1)),(k2),jv_null()))
160
+ #define JV_OBJECT_4(k1,v1,k2,v2) (jv_object_set(JV_OBJECT_2((k1),(v1)),(k2),(v2)))
161
+ #define JV_OBJECT_5(k1,v1,k2,v2,k3) (jv_object_set(JV_OBJECT_4((k1),(v1),(k2),(v2)),(k3),jv_null()))
162
+ #define JV_OBJECT_6(k1,v1,k2,v2,k3,v3) (jv_object_set(JV_OBJECT_4((k1),(v1),(k2),(v2)),(k3),(v3)))
163
+ #define JV_OBJECT_7(k1,v1,k2,v2,k3,v3,k4) (jv_object_set(JV_OBJECT_6((k1),(v1),(k2),(v2),(k3),(v3)),(k4),jv_null()))
164
+ #define JV_OBJECT_8(k1,v1,k2,v2,k3,v3,k4,v4) (jv_object_set(JV_OBJECT_6((k1),(v1),(k2),(v2),(k3),(v3)),(k4),(v4)))
165
+ #define JV_OBJECT_9(k1,v1,k2,v2,k3,v3,k4,v4,k5) \
166
+ (jv_object_set(JV_OBJECT_8((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4)),(k5),jv_null()))
167
+ #define JV_OBJECT_10(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5) \
168
+ (jv_object_set(JV_OBJECT_8((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4)),(k5),(v5)))
169
+ #define JV_OBJECT_11(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6) \
170
+ (jv_object_set(JV_OBJECT_10((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5)),(k6),jv_null()))
171
+ #define JV_OBJECT_12(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6) \
172
+ (jv_object_set(JV_OBJECT_10((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5)),(k6),(v6)))
173
+ #define JV_OBJECT_13(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7) \
174
+ (jv_object_set(JV_OBJECT_12((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6)),(k7),jv_null()))
175
+ #define JV_OBJECT_14(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7) \
176
+ (jv_object_set(JV_OBJECT_12((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6)),(k7),(v7)))
177
+ #define JV_OBJECT_15(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8) \
178
+ (jv_object_set(JV_OBJECT_14((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6),(k7),(v7)),(k8),jv_null()))
179
+ #define JV_OBJECT_16(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8,v8) \
180
+ (jv_object_set(JV_OBJECT_14((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6),(k7),(v7)),(k8),(v8)))
181
+ #define JV_OBJECT_17(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8,v8,k9) \
182
+ (jv_object_set(JV_OBJECT_16((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6),(k7),(v7),(k8),(v8)),(k9),jv_null()))
183
+ #define JV_OBJECT_18(k1,v1,k2,v2,k3,v3,k4,v4,k5,v5,k6,v6,k7,v7,k8,v8,k9,v9) \
184
+ (jv_object_set(JV_OBJECT_16((k1),(v1),(k2),(v2),(k3),(v3),(k4),(v4),(k5),(v5),(k6),(v6),(k7),(v7),(k8),(v8)),(k9),(v9)))
185
+ #define JV_OBJECT_IDX(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,NAME,...) NAME
156
186
  #define JV_OBJECT(...) \
157
- JV_OBJECT_IDX(__VA_ARGS__, JV_OBJECT_8, JV_OBJECT_7, JV_OBJECT_6, JV_OBJECT_5, JV_OBJECT_4, JV_OBJECT_3, JV_OBJECT_2, JV_OBJECT_1)(__VA_ARGS__)
187
+ JV_OBJECT_IDX(__VA_ARGS__, \
188
+ JV_OBJECT_18, JV_OBJECT_17, JV_OBJECT_16, JV_OBJECT_15, \
189
+ JV_OBJECT_14, JV_OBJECT_13, JV_OBJECT_12, JV_OBJECT_11, \
190
+ JV_OBJECT_10, JV_OBJECT_9, JV_OBJECT_8, JV_OBJECT_7, \
191
+ JV_OBJECT_6, JV_OBJECT_5, JV_OBJECT_4, JV_OBJECT_3, \
192
+ JV_OBJECT_2, JV_OBJECT_1)(__VA_ARGS__)
158
193
 
159
194
 
160
195
 
@@ -163,7 +198,7 @@ int jv_get_refcnt(jv);
163
198
  enum jv_print_flags {
164
199
  JV_PRINT_PRETTY = 1,
165
200
  JV_PRINT_ASCII = 2,
166
- JV_PRINT_COLOUR = 4,
201
+ JV_PRINT_COLOR = 4, JV_PRINT_COLOUR = 4,
167
202
  JV_PRINT_SORTED = 8,
168
203
  JV_PRINT_INVALID = 16,
169
204
  JV_PRINT_REFCOUNT = 32,
File without changes
File without changes
@@ -214,7 +214,7 @@ jv jv_has(jv t, jv k) {
214
214
  }
215
215
 
216
216
  // assumes keys is a sorted array
217
- jv jv_dels(jv t, jv keys) {
217
+ static jv jv_dels(jv t, jv keys) {
218
218
  assert(jv_get_kind(keys) == JV_KIND_ARRAY);
219
219
  assert(jv_is_valid(t));
220
220
 
@@ -222,13 +222,17 @@ jv jv_dels(jv t, jv keys) {
222
222
  // no change
223
223
  } else if (jv_get_kind(t) == JV_KIND_ARRAY) {
224
224
  // extract slices, they must be handled differently
225
- jv orig_keys = keys;
226
- keys = jv_array();
225
+ jv neg_keys = jv_array();
226
+ jv nonneg_keys = jv_array();
227
227
  jv new_array = jv_array();
228
228
  jv starts = jv_array(), ends = jv_array();
229
- jv_array_foreach(orig_keys, i, key) {
229
+ jv_array_foreach(keys, i, key) {
230
230
  if (jv_get_kind(key) == JV_KIND_NUMBER) {
231
- keys = jv_array_append(keys, key);
231
+ if (jv_number_value(key) < 0) {
232
+ neg_keys = jv_array_append(neg_keys, key);
233
+ } else {
234
+ nonneg_keys = jv_array_append(nonneg_keys, key);
235
+ }
232
236
  } else if (jv_get_kind(key) == JV_KIND_OBJECT) {
233
237
  int start, end;
234
238
  if (parse_slice(jv_copy(t), key, &start, &end)) {
@@ -248,18 +252,30 @@ jv jv_dels(jv t, jv keys) {
248
252
  }
249
253
  }
250
254
 
251
- int kidx = 0;
255
+ int neg_idx = 0;
256
+ int nonneg_idx = 0;
257
+ int len = jv_array_length(jv_copy(t));
252
258
  jv_array_foreach(t, i, elem) {
253
259
  int del = 0;
254
- while (kidx < jv_array_length(jv_copy(keys))) {
255
- int delidx = (int)jv_number_value(jv_array_get(jv_copy(keys), kidx));
260
+ while (neg_idx < jv_array_length(jv_copy(neg_keys))) {
261
+ int delidx = len + (int)jv_number_value(jv_array_get(jv_copy(neg_keys), neg_idx));
256
262
  if (i == delidx) {
257
263
  del = 1;
258
264
  }
259
265
  if (i < delidx) {
260
266
  break;
261
267
  }
262
- kidx++;
268
+ neg_idx++;
269
+ }
270
+ while (nonneg_idx < jv_array_length(jv_copy(nonneg_keys))) {
271
+ int delidx = (int)jv_number_value(jv_array_get(jv_copy(nonneg_keys), nonneg_idx));
272
+ if (i == delidx) {
273
+ del = 1;
274
+ }
275
+ if (i < delidx) {
276
+ break;
277
+ }
278
+ nonneg_idx++;
263
279
  }
264
280
  for (int sidx=0; !del && sidx<jv_array_length(jv_copy(starts)); sidx++) {
265
281
  if ((int)jv_number_value(jv_array_get(jv_copy(starts), sidx)) <= i &&
@@ -273,9 +289,10 @@ jv jv_dels(jv t, jv keys) {
273
289
  jv_free(elem);
274
290
  }
275
291
  arr_out:
292
+ jv_free(neg_keys);
293
+ jv_free(nonneg_keys);
276
294
  jv_free(starts);
277
295
  jv_free(ends);
278
- jv_free(orig_keys);
279
296
  jv_free(t);
280
297
  t = new_array;
281
298
  } else if (jv_get_kind(t) == JV_KIND_OBJECT) {
@@ -390,6 +407,11 @@ static jv delpaths_sorted(jv object, jv paths, int start) {
390
407
  }
391
408
 
392
409
  jv jv_delpaths(jv object, jv paths) {
410
+ if (jv_get_kind(paths) != JV_KIND_ARRAY) {
411
+ jv_free(object);
412
+ jv_free(paths);
413
+ return jv_invalid_with_msg(jv_string("Paths must be specified as an array"));
414
+ }
393
415
  paths = jv_sort(paths, jv_copy(paths));
394
416
  jv_array_foreach(paths, i, elem) {
395
417
  if (jv_get_kind(elem) != JV_KIND_ARRAY) {
@@ -443,7 +465,7 @@ jv jv_keys_unsorted(jv x) {
443
465
  jv jv_keys(jv x) {
444
466
  if (jv_get_kind(x) == JV_KIND_OBJECT) {
445
467
  int nkeys = jv_object_length(jv_copy(x));
446
- jv* keys = jv_mem_alloc(sizeof(jv) * nkeys);
468
+ jv* keys = jv_mem_calloc(sizeof(jv), nkeys);
447
469
  int kidx = 0;
448
470
  jv_object_foreach(x, key, value) {
449
471
  keys[kidx++] = key;
@@ -549,14 +571,15 @@ int jv_cmp(jv a, jv b) {
549
571
  struct sort_entry {
550
572
  jv object;
551
573
  jv key;
574
+ int index;
552
575
  };
553
576
 
554
577
  static int sort_cmp(const void* pa, const void* pb) {
555
578
  const struct sort_entry* a = pa;
556
579
  const struct sort_entry* b = pb;
557
580
  int r = jv_cmp(jv_copy(a->key), jv_copy(b->key));
558
- // comparing by address if r == 0 makes the sort stable
559
- return r ? r : (int)(a - b);
581
+ // comparing by index if r == 0 makes the sort stable
582
+ return r ? r : (a->index - b->index);
560
583
  }
561
584
 
562
585
  static struct sort_entry* sort_items(jv objects, jv keys) {
@@ -564,10 +587,11 @@ static struct sort_entry* sort_items(jv objects, jv keys) {
564
587
  assert(jv_get_kind(keys) == JV_KIND_ARRAY);
565
588
  assert(jv_array_length(jv_copy(objects)) == jv_array_length(jv_copy(keys)));
566
589
  int n = jv_array_length(jv_copy(objects));
567
- struct sort_entry* entries = jv_mem_alloc(sizeof(struct sort_entry) * n);
590
+ struct sort_entry* entries = jv_mem_calloc(sizeof(struct sort_entry), n);
568
591
  for (int i=0; i<n; i++) {
569
592
  entries[i].object = jv_array_get(jv_copy(objects), i);
570
593
  entries[i].key = jv_array_get(jv_copy(keys), i);
594
+ entries[i].index = i;
571
595
  }
572
596
  jv_free(objects);
573
597
  jv_free(keys);
@@ -2327,7 +2327,7 @@ retlow1:
2327
2327
  jvp_strtod
2328
2328
  (struct dtoa_context* C, const char *s00, char **se)
2329
2329
  {
2330
- int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1;
2330
+ int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1, test_scale;
2331
2331
  int esign, i, j, k, nd, nd0, nf, nz, nz0, nz1, sign;
2332
2332
  CONST char *s, *s0, *s1;
2333
2333
  double aadj, aadj1;
@@ -2941,12 +2941,11 @@ jvp_strtod
2941
2941
  if (!word1(&rv)
2942
2942
  && !(word0(&rv) & Frac_mask)) {
2943
2943
  y = word0(&rv) & Exp_mask;
2944
+ test_scale = y;
2944
2945
  #ifdef Avoid_Underflow
2945
- if (!bc.scale || y > 2*P*Exp_msk1)
2946
- #else
2947
- if (y)
2946
+ test_scale = (!bc.scale || y > 2*P*Exp_msk1);
2948
2947
  #endif
2949
- {
2948
+ if (test_scale) {
2950
2949
  delta = lshift(C, delta,Log2P);
2951
2950
  if (cmp(C, delta, bs) <= 0)
2952
2951
  adj.d = -0.5;
File without changes