@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
@@ -5,6 +5,7 @@
5
5
  #include <math.h>
6
6
  #include <string.h>
7
7
  #include <stdlib.h>
8
+ #include <unistd.h>
8
9
  #include "compile.h"
9
10
  #include "bytecode.h"
10
11
  #include "locfile.h"
@@ -158,8 +159,15 @@ block gen_const_global(jv constant, const char *name) {
158
159
  return inst_block(i);
159
160
  }
160
161
 
162
+ block gen_op_pushk_under(jv constant) {
163
+ assert(opcode_describe(PUSHK_UNDER)->flags & OP_HAS_CONSTANT);
164
+ inst* i = inst_new(PUSHK_UNDER);
165
+ i->imm.constant = constant;
166
+ return inst_block(i);
167
+ }
168
+
161
169
  int block_is_const(block b) {
162
- return (block_is_single(b) && b.first->op == LOADK);
170
+ return (block_is_single(b) && (b.first->op == LOADK || b.first->op == PUSHK_UNDER));
163
171
  }
164
172
 
165
173
  int block_is_const_inf(block b) {
@@ -219,6 +227,10 @@ block gen_op_bound(opcode op, block binder) {
219
227
  return b;
220
228
  }
221
229
 
230
+ block gen_dictpair(block k, block v) {
231
+ return BLOCK(gen_subexp(k), gen_subexp(v), gen_op_simple(INSERT));
232
+ }
233
+
222
234
 
223
235
  static void inst_join(inst* a, inst* b) {
224
236
  assert(a && b);
@@ -480,6 +492,18 @@ jv block_take_imports(block* body) {
480
492
  return imports;
481
493
  }
482
494
 
495
+ jv block_list_funcs(block body, int omit_underscores) {
496
+ jv funcs = jv_object(); // Use the keys for set semantics.
497
+ for (inst *pos = body.first; pos != NULL; pos = pos->next) {
498
+ if (pos->op == CLOSURE_CREATE || pos->op == CLOSURE_CREATE_C) {
499
+ if (pos->symbol != NULL && (!omit_underscores || pos->symbol[0] != '_')) {
500
+ funcs = jv_object_set(funcs, jv_string_fmt("%s/%i", pos->symbol, pos->nformals), jv_null());
501
+ }
502
+ }
503
+ }
504
+ return jv_keys_unsorted(funcs);
505
+ }
506
+
483
507
  block gen_module(block metadata) {
484
508
  inst* i = inst_new(MODULEMETA);
485
509
  i->imm.constant = block_const(metadata);
@@ -495,23 +519,26 @@ jv block_module_meta(block b) {
495
519
  return jv_null();
496
520
  }
497
521
 
498
- block gen_import(const char* name, block metadata, const char* as, int is_data) {
499
- assert(metadata.first == NULL || block_is_const(metadata));
522
+ block gen_import(const char* name, const char* as, int is_data) {
500
523
  inst* i = inst_new(DEPS);
501
- jv meta;
502
- if (block_is_const(metadata))
503
- meta = block_const(metadata);
504
- else
505
- meta = jv_object();
524
+ jv meta = jv_object();
506
525
  if (as != NULL)
507
526
  meta = jv_object_set(meta, jv_string("as"), jv_string(as));
508
527
  meta = jv_object_set(meta, jv_string("is_data"), is_data ? jv_true() : jv_false());
509
528
  meta = jv_object_set(meta, jv_string("relpath"), jv_string(name));
510
529
  i->imm.constant = meta;
511
- block_free(metadata);
512
530
  return inst_block(i);
513
531
  }
514
532
 
533
+ block gen_import_meta(block import, block metadata) {
534
+ assert(block_is_single(import) && import.first->op == DEPS);
535
+ assert(block_is_const(metadata) && block_const_kind(metadata) == JV_KIND_OBJECT);
536
+ inst *i = import.first;
537
+ i->imm.constant = jv_object_merge(block_const(metadata), i->imm.constant);
538
+ block_free(metadata);
539
+ return import;
540
+ }
541
+
515
542
  block gen_function(const char* name, block formals, block body) {
516
543
  inst* i = inst_new(CLOSURE_CREATE);
517
544
  for (inst* i = formals.last; i; i = i->prev) {
@@ -547,9 +574,15 @@ block gen_call(const char* name, block args) {
547
574
  return b;
548
575
  }
549
576
 
550
-
551
-
552
577
  block gen_subexp(block a) {
578
+ if (block_is_noop(a)) {
579
+ return gen_op_simple(DUP);
580
+ }
581
+ if (block_is_single(a) && a.first->op == LOADK) {
582
+ jv c = block_const(a);
583
+ block_free(a);
584
+ return gen_op_pushk_under(c);
585
+ }
553
586
  return BLOCK(gen_op_simple(SUBEXP_BEGIN), a, gen_op_simple(SUBEXP_END));
554
587
  }
555
588
 
@@ -567,17 +600,24 @@ block gen_const_object(block expr) {
567
600
  jv k = jv_null();
568
601
  jv v = jv_null();
569
602
  for (inst *i = expr.first; i; i = i->next) {
570
- if (i->op != SUBEXP_BEGIN ||
603
+ if (i->op == PUSHK_UNDER) {
604
+ k = jv_copy(i->imm.constant);
605
+ i = i->next;
606
+ } else if (i->op != SUBEXP_BEGIN ||
571
607
  i->next == NULL ||
572
608
  i->next->op != LOADK ||
573
609
  i->next->next == NULL ||
574
610
  i->next->next->op != SUBEXP_END) {
575
611
  is_const = 0;
576
612
  break;
613
+ } else {
614
+ k = jv_copy(i->next->imm.constant);
615
+ i = i->next->next->next;
577
616
  }
578
- k = jv_copy(i->next->imm.constant);
579
- i = i->next->next->next;
580
- if (i == NULL ||
617
+ if (i != NULL && i->op == PUSHK_UNDER) {
618
+ v = jv_copy(i->imm.constant);
619
+ i = i->next;
620
+ } else if (i == NULL ||
581
621
  i->op != SUBEXP_BEGIN ||
582
622
  i->next == NULL ||
583
623
  i->next->op != LOADK ||
@@ -585,13 +625,18 @@ block gen_const_object(block expr) {
585
625
  i->next->next->op != SUBEXP_END) {
586
626
  is_const = 0;
587
627
  break;
628
+ } else {
629
+ v = jv_copy(i->next->imm.constant);
630
+ i = i->next->next->next;
588
631
  }
589
- v = jv_copy(i->next->imm.constant);
590
- i = i->next->next->next;
591
632
  if (i == NULL || i->op != INSERT) {
592
633
  is_const = 0;
593
634
  break;
594
635
  }
636
+ if (jv_get_kind(k) != JV_KIND_STRING) {
637
+ is_const = 0;
638
+ break;
639
+ }
595
640
  o = jv_object_set(o, k, v);
596
641
  k = jv_null();
597
642
  v = jv_null();
@@ -689,17 +734,91 @@ static block bind_matcher(block matcher, block body) {
689
734
  // block_has_only_binders(matcher), which is not true here as matchers
690
735
  // may also contain code to extract the correct elements
691
736
  for (inst* i = matcher.first; i; i = i->next) {
692
- if (i->op == STOREV && !i->bound_by)
737
+ if ((i->op == STOREV || i->op == STOREVN) && !i->bound_by)
693
738
  block_bind_subblock(inst_block(i), body, OP_HAS_VARIABLE, 0);
694
739
  }
695
740
  return BLOCK(matcher, body);
696
741
  }
697
742
 
743
+
744
+ // Extract destructuring var names from the block
745
+ // *vars should be a jv_object (for set semantics)
746
+ static void block_get_unbound_vars(block b, jv *vars) {
747
+ assert(vars != NULL);
748
+ assert(jv_get_kind(*vars) == JV_KIND_OBJECT);
749
+ for (inst* i = b.first; i; i = i->next) {
750
+ if (i->subfn.first) {
751
+ block_get_unbound_vars(i->subfn, vars);
752
+ continue;
753
+ }
754
+ if ((i->op == STOREV || i->op == STOREVN) && i->bound_by == NULL) {
755
+ *vars = jv_object_set(*vars, jv_string(i->symbol), jv_true());
756
+ }
757
+ }
758
+ }
759
+
760
+ /* Build wrappers around destructuring matchers so that we can chain them
761
+ * when we have errors. The approach is as follows:
762
+ * DESTRUCTURE_ALT NEXT_MATCHER (unless last matcher)
763
+ * existing_matcher_block
764
+ * JUMP BODY
765
+ */
766
+ static block bind_alternation_matchers(block matchers, block body) {
767
+ block preamble = {0};
768
+ block altmatchers = {0};
769
+ block mb = {0};
770
+ block final_matcher = matchers;
771
+
772
+ // Pass through the matchers to find all destructured names.
773
+ while (final_matcher.first && final_matcher.first->op == DESTRUCTURE_ALT) {
774
+ block_append(&altmatchers, inst_block(block_take(&final_matcher)));
775
+ }
776
+
777
+ // We don't have any alternations here, so we can use the simplest case.
778
+ if (altmatchers.first == NULL) {
779
+ return bind_matcher(final_matcher, body);
780
+ }
781
+
782
+ // Collect var names
783
+ jv all_vars = jv_object();
784
+ block_get_unbound_vars(altmatchers, &all_vars);
785
+ block_get_unbound_vars(final_matcher, &all_vars);
786
+
787
+ // We need a preamble of STOREVs to which to bind the matchers and the body.
788
+ jv_object_keys_foreach(all_vars, key) {
789
+ preamble = BLOCK(preamble,
790
+ gen_op_simple(DUP),
791
+ gen_const(jv_null()),
792
+ gen_op_unbound(STOREV, jv_string_value(key)));
793
+ jv_free(key);
794
+ }
795
+ jv_free(all_vars);
796
+
797
+ // Now we build each matcher in turn
798
+ for (inst *i = altmatchers.first; i; i = i->next) {
799
+ block submatcher = i->subfn;
800
+
801
+ // If we're successful, jump to the end of the matchers
802
+ submatcher = BLOCK(submatcher, gen_op_target(JUMP, final_matcher));
803
+
804
+ // DESTRUCTURE_ALT to the end of this submatcher so we can skip to the next one on error
805
+ mb = BLOCK(mb, gen_op_target(DESTRUCTURE_ALT, submatcher), submatcher);
806
+
807
+ // We're done with this inst and we don't want it anymore
808
+ // But we can't let it free the submatcher block.
809
+ i->subfn.first = i->subfn.last = NULL;
810
+ }
811
+ // We're done with these insts now.
812
+ block_free(altmatchers);
813
+
814
+ return bind_matcher(preamble, BLOCK(mb, final_matcher, body));
815
+ }
816
+
698
817
  block gen_reduce(block source, block matcher, block init, block body) {
699
818
  block res_var = gen_op_var_fresh(STOREV, "reduce");
700
819
  block loop = BLOCK(gen_op_simple(DUPN),
701
820
  source,
702
- bind_matcher(matcher,
821
+ bind_alternation_matchers(matcher,
703
822
  BLOCK(gen_op_bound(LOADVN, res_var),
704
823
  body,
705
824
  gen_op_bound(STOREV, res_var))),
@@ -720,7 +839,7 @@ block gen_foreach(block source, block matcher, block init, block update, block e
720
839
  source,
721
840
  // destructure the value into variable(s) for all the code
722
841
  // in the body to see
723
- bind_matcher(matcher,
842
+ bind_alternation_matchers(matcher,
724
843
  // load the loop state variable
725
844
  BLOCK(gen_op_bound(LOADVN, state_var),
726
845
  // generate updated state
@@ -826,6 +945,17 @@ block gen_or(block a, block b) {
826
945
  gen_const(jv_false())))));
827
946
  }
828
947
 
948
+ block gen_destructure_alt(block matcher) {
949
+ for (inst *i = matcher.first; i; i = i->next) {
950
+ if (i->op == STOREV) {
951
+ i->op = STOREVN;
952
+ }
953
+ }
954
+ inst* i = inst_new(DESTRUCTURE_ALT);
955
+ i->subfn = matcher;
956
+ return inst_block(i);
957
+ }
958
+
829
959
  block gen_var_binding(block var, const char* name, block body) {
830
960
  return gen_destructure(var, gen_op_unbound(STOREV, name), body);
831
961
  }
@@ -838,9 +968,16 @@ block gen_array_matcher(block left, block curr) {
838
968
  // `left` was returned by this function, so the third inst is the
839
969
  // constant containing the previously used index
840
970
  assert(left.first->op == DUP);
841
- assert(left.first->next->op == SUBEXP_BEGIN);
842
- assert(left.first->next->next->op == LOADK);
843
- index = 1 + (int) jv_number_value(left.first->next->next->imm.constant);
971
+ assert(left.first->next != NULL);
972
+ inst *i = NULL;
973
+ if (left.first->next->op == PUSHK_UNDER) {
974
+ i = left.first->next;
975
+ } else {
976
+ assert(left.first->next->op == SUBEXP_BEGIN);
977
+ assert(left.first->next->next->op == LOADK);
978
+ i = left.first->next->next;
979
+ }
980
+ index = 1 + (int) jv_number_value(i->imm.constant);
844
981
  }
845
982
 
846
983
  // `left` goes at the end so that the const index is in a predictable place
@@ -853,13 +990,19 @@ block gen_object_matcher(block name, block curr) {
853
990
  curr);
854
991
  }
855
992
 
856
- block gen_destructure(block var, block matcher, block body) {
993
+ block gen_destructure(block var, block matchers, block body) {
857
994
  // var bindings can be added after coding the program; leave the TOP first.
858
995
  block top = gen_noop();
859
996
  if (body.first && body.first->op == TOP)
860
997
  top = inst_block(block_take(&body));
861
998
 
862
- return BLOCK(top, gen_op_simple(DUP), var, bind_matcher(matcher, body));
999
+ if (matchers.first && matchers.first->op == DESTRUCTURE_ALT) {
1000
+ block_append(&var, gen_op_simple(DUP));
1001
+ } else {
1002
+ top = BLOCK(top, gen_op_simple(DUP));
1003
+ }
1004
+
1005
+ return BLOCK(top, gen_subexp(var), gen_op_simple(POP), bind_alternation_matchers(matchers, body));
863
1006
  }
864
1007
 
865
1008
  // Like gen_var_binding(), but bind `break`'s wildcard unbound variable
@@ -870,7 +1013,7 @@ static block gen_wildvar_binding(block var, const char* name, block body) {
870
1013
  }
871
1014
 
872
1015
  block gen_cond(block cond, block iftrue, block iffalse) {
873
- return BLOCK(gen_op_simple(DUP), cond,
1016
+ return BLOCK(gen_op_simple(DUP), BLOCK(gen_subexp(cond), gen_op_simple(POP)),
874
1017
  gen_condbranch(BLOCK(gen_op_simple(POP), iftrue),
875
1018
  BLOCK(gen_op_simple(POP), iffalse)));
876
1019
  }
@@ -963,16 +1106,46 @@ static int count_cfunctions(block b) {
963
1106
  return n;
964
1107
  }
965
1108
 
1109
+ #ifndef WIN32
1110
+ extern char **environ;
1111
+ #endif
1112
+
1113
+ static jv
1114
+ make_env(jv env)
1115
+ {
1116
+ if (jv_is_valid(env))
1117
+ return jv_copy(env);
1118
+ jv r = jv_object();
1119
+ if (environ == NULL)
1120
+ return r;
1121
+ for (size_t i = 0; environ[i] != NULL; i++) {
1122
+ const char *eq;
1123
+
1124
+ if ((eq = strchr(environ[i], '=')) == NULL)
1125
+ r = jv_object_delete(r, jv_string(environ[i]));
1126
+ else
1127
+ r = jv_object_set(r, jv_string_sized(environ[i], eq - environ[i]), jv_string(eq + 1));
1128
+ }
1129
+ return jv_copy(r);
1130
+ }
966
1131
 
967
1132
  // Expands call instructions into a calling sequence
968
- static int expand_call_arglist(block* b) {
1133
+ static int expand_call_arglist(block* b, jv args, jv *env) {
969
1134
  int errors = 0;
970
1135
  block ret = gen_noop();
971
1136
  for (inst* curr; (curr = block_take(b));) {
972
1137
  if (opcode_describe(curr->op)->flags & OP_HAS_BINDING) {
973
- if (!curr->bound_by) {
1138
+ if (!curr->bound_by && curr->op == LOADV && strcmp(curr->symbol, "ENV") == 0) {
1139
+ curr->op = LOADK;
1140
+ *env = curr->imm.constant = make_env(*env);
1141
+ } else if (!curr->bound_by && curr->op == LOADV && jv_object_has(jv_copy(args), jv_string(curr->symbol))) {
1142
+ curr->op = LOADK;
1143
+ curr->imm.constant = jv_object_get(jv_copy(args), jv_string(curr->symbol));
1144
+ } else if (!curr->bound_by) {
974
1145
  if (curr->symbol[0] == '*' && curr->symbol[1] >= '1' && curr->symbol[1] <= '3' && curr->symbol[2] == '\0')
975
1146
  locfile_locate(curr->locfile, curr->source, "jq: error: break used outside labeled control structure");
1147
+ else if (curr->op == LOADV)
1148
+ locfile_locate(curr->locfile, curr->source, "jq: error: $%s is not defined", curr->symbol);
976
1149
  else
977
1150
  locfile_locate(curr->locfile, curr->source, "jq: error: %s/%d is not defined", curr->symbol, block_count_actuals(curr->arglist));
978
1151
  errors++;
@@ -1025,7 +1198,7 @@ static int expand_call_arglist(block* b) {
1025
1198
  i->subfn = gen_noop();
1026
1199
  inst_free(i);
1027
1200
  // arguments should be pushed in reverse order, prepend them to prelude
1028
- errors += expand_call_arglist(&body);
1201
+ errors += expand_call_arglist(&body, args, env);
1029
1202
  prelude = BLOCK(gen_subexp(body), prelude);
1030
1203
  actual_args++;
1031
1204
  }
@@ -1047,12 +1220,12 @@ static int expand_call_arglist(block* b) {
1047
1220
  return errors;
1048
1221
  }
1049
1222
 
1050
- static int compile(struct bytecode* bc, block b, struct locfile* lf) {
1223
+ static int compile(struct bytecode* bc, block b, struct locfile* lf, jv args, jv *env) {
1051
1224
  int errors = 0;
1052
1225
  int pos = 0;
1053
1226
  int var_frame_idx = 0;
1054
1227
  bc->nsubfunctions = 0;
1055
- errors += expand_call_arglist(&b);
1228
+ errors += expand_call_arglist(&b, args, env);
1056
1229
  b = BLOCK(b, gen_op_simple(RET));
1057
1230
  jv localnames = jv_array();
1058
1231
  for (inst* curr = b.first; curr; curr = curr->next) {
@@ -1097,7 +1270,7 @@ static int compile(struct bytecode* bc, block b, struct locfile* lf) {
1097
1270
  bc->codelen = pos;
1098
1271
  bc->debuginfo = jv_object_set(bc->debuginfo, jv_string("locals"), localnames);
1099
1272
  if (bc->nsubfunctions) {
1100
- bc->subfunctions = jv_mem_alloc(sizeof(struct bytecode*) * bc->nsubfunctions);
1273
+ bc->subfunctions = jv_mem_calloc(sizeof(struct bytecode*), bc->nsubfunctions);
1101
1274
  for (inst* curr = b.first; curr; curr = curr->next) {
1102
1275
  if (curr->op == CLOSURE_CREATE) {
1103
1276
  struct bytecode* subfn = jv_mem_alloc(sizeof(struct bytecode));
@@ -1115,14 +1288,14 @@ static int compile(struct bytecode* bc, block b, struct locfile* lf) {
1115
1288
  params = jv_array_append(params, jv_string(param->symbol));
1116
1289
  }
1117
1290
  subfn->debuginfo = jv_object_set(subfn->debuginfo, jv_string("params"), params);
1118
- errors += compile(subfn, curr->subfn, lf);
1291
+ errors += compile(subfn, curr->subfn, lf, args, env);
1119
1292
  curr->subfn = gen_noop();
1120
1293
  }
1121
1294
  }
1122
1295
  } else {
1123
1296
  bc->subfunctions = 0;
1124
1297
  }
1125
- uint16_t* code = jv_mem_alloc(sizeof(uint16_t) * bc->codelen);
1298
+ uint16_t* code = jv_mem_calloc(sizeof(uint16_t), bc->codelen);
1126
1299
  bc->code = code;
1127
1300
  pos = 0;
1128
1301
  jv constant_pool = jv_array();
@@ -1180,17 +1353,20 @@ static int compile(struct bytecode* bc, block b, struct locfile* lf) {
1180
1353
  return errors;
1181
1354
  }
1182
1355
 
1183
- int block_compile(block b, struct bytecode** out, struct locfile* lf) {
1356
+ int block_compile(block b, struct bytecode** out, struct locfile* lf, jv args) {
1184
1357
  struct bytecode* bc = jv_mem_alloc(sizeof(struct bytecode));
1185
1358
  bc->parent = 0;
1186
1359
  bc->nclosures = 0;
1187
1360
  bc->globals = jv_mem_alloc(sizeof(struct symbol_table));
1188
1361
  int ncfunc = count_cfunctions(b);
1189
1362
  bc->globals->ncfunctions = 0;
1190
- bc->globals->cfunctions = jv_mem_alloc(sizeof(struct cfunction) * ncfunc);
1363
+ bc->globals->cfunctions = jv_mem_calloc(sizeof(struct cfunction), ncfunc);
1191
1364
  bc->globals->cfunc_names = jv_array();
1192
1365
  bc->debuginfo = jv_object_set(jv_object(), jv_string("name"), jv_null());
1193
- int nerrors = compile(bc, b, lf);
1366
+ jv env = jv_invalid();
1367
+ int nerrors = compile(bc, b, lf, args, &env);
1368
+ jv_free(args);
1369
+ jv_free(env);
1194
1370
  assert(bc->globals->ncfunctions == ncfunc);
1195
1371
  if (nerrors > 0) {
1196
1372
  bytecode_free(bc);
@@ -29,10 +29,12 @@ block gen_op_target(opcode op, block target);
29
29
  block gen_op_unbound(opcode op, const char* name);
30
30
  block gen_op_bound(opcode op, block binder);
31
31
  block gen_op_var_fresh(opcode op, const char* name);
32
+ block gen_op_pushk_under(jv constant);
32
33
 
33
34
  block gen_module(block metadata);
34
35
  jv block_module_meta(block b);
35
- block gen_import(const char* name, block metadata, const char *as, int is_data);
36
+ block gen_import(const char* name, const char *as, int is_data);
37
+ block gen_import_meta(block import, block metadata);
36
38
  block gen_function(const char* name, block formals, block body);
37
39
  block gen_param_regular(const char* name);
38
40
  block gen_param(const char* name);
@@ -48,11 +50,13 @@ block gen_definedor(block a, block b);
48
50
  block gen_condbranch(block iftrue, block iffalse);
49
51
  block gen_and(block a, block b);
50
52
  block gen_or(block a, block b);
53
+ block gen_dictpair(block k, block v);
51
54
 
52
55
  block gen_var_binding(block var, const char* name, block body);
53
56
  block gen_array_matcher(block left, block curr);
54
57
  block gen_object_matcher(block name, block curr);
55
58
  block gen_destructure(block var, block matcher, block body);
59
+ block gen_destructure_alt(block matcher);
56
60
 
57
61
  block gen_cond(block cond, block iftrue, block iffalse);
58
62
  block gen_try_handler(block handler);
@@ -74,8 +78,9 @@ block block_bind_referenced(block binder, block body, int bindflags);
74
78
  block block_drop_unreferenced(block body);
75
79
 
76
80
  jv block_take_imports(block* body);
81
+ jv block_list_funcs(block body, int omit_underscores);
77
82
 
78
- int block_compile(block, struct bytecode**, struct locfile*);
83
+ int block_compile(block, struct bytecode**, struct locfile*, jv);
79
84
 
80
85
  void block_free(block);
81
86
 
File without changes