ranger-compiler 2.1.69 → 3.0.3

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 (363) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +991 -96
  3. package/{compiler/Lang.clj → dist/Lang.rgr} +2345 -75
  4. package/dist/README.md +116 -0
  5. package/dist/{bin/api.d.ts → api.d.ts} +430 -154
  6. package/dist/api.js +34345 -0
  7. package/{lib/Ajax.clj → dist/lib/Ajax.rgr} +1 -1
  8. package/{lib/CmdParams.clj → dist/lib/CmdParams.rgr} +72 -72
  9. package/{lib/Crypto.clj → dist/lib/Crypto.rgr} +1 -1
  10. package/{lib/DOMLib.clj → dist/lib/DOMLib.rgr} +2 -2
  11. package/{lib/Engine3D.clj → dist/lib/Engine3D.rgr} +1 -1
  12. package/{lib/ImmutableVector.clj → dist/lib/ImmutableVector.rgr} +364 -364
  13. package/{lib/IndexedDB.clj → dist/lib/IndexedDB.rgr} +1 -1
  14. package/{lib/JSON.clj → dist/lib/JSON.rgr} +105 -2
  15. package/{lib/JinxProcess.clj → dist/lib/JinxProcess.rgr} +3 -3
  16. package/{lib/Storage.clj → dist/lib/Storage.rgr} +1 -1
  17. package/{lib/Timers.clj → dist/lib/Timers.rgr} +176 -170
  18. package/{lib/ViewLib.clj → dist/lib/ViewLib.rgr} +1 -1
  19. package/dist/lib/lib/ACEEditor.rgr +5 -0
  20. package/dist/lib/lib/Ajax.rgr +196 -0
  21. package/dist/lib/lib/CmdParams.rgr +72 -0
  22. package/dist/lib/lib/Crypto.rgr +90 -0
  23. package/dist/lib/lib/DOMLib.rgr +307 -0
  24. package/{examples/3D/Engine3D.clj → dist/lib/lib/Engine3D.rgr} +870 -857
  25. package/dist/lib/lib/ImmutableVector.rgr +364 -0
  26. package/dist/lib/lib/IndexedDB.rgr +32 -0
  27. package/{compiler/JSON.clj → dist/lib/lib/JSON.rgr} +106 -3
  28. package/dist/lib/lib/JinxProcess.rgr +838 -0
  29. package/dist/lib/lib/SQL.rgr +44 -0
  30. package/dist/lib/lib/ServiceLib.rgr +9 -0
  31. package/dist/lib/lib/Storage.rgr +89 -0
  32. package/dist/lib/lib/Time.rgr +75 -0
  33. package/dist/lib/lib/Timers.rgr +176 -0
  34. package/dist/lib/lib/TypedArrays.rgr +14 -0
  35. package/dist/lib/lib/ViewLib.rgr +851 -0
  36. package/dist/lib/lib/WebLib.rgr +47 -0
  37. package/dist/lib/lib/WebServerLib.rgr +137 -0
  38. package/{lib/ranger-dir.clj → dist/lib/lib/ranger-dir.rgr} +1 -1
  39. package/{compiler/stdlib.clj → dist/lib/lib/stdlib.rgr} +42 -19
  40. package/{lib/stdops.clj → dist/lib/lib/stdops.rgr} +1 -1
  41. package/dist/lib/ranger-dir.rgr +175 -0
  42. package/{lib/stdlib.clj → dist/lib/stdlib.rgr} +2 -2
  43. package/dist/lib/stdops.rgr +168 -0
  44. package/dist/package.json +47 -0
  45. package/{bin/output.js → dist/rgrc.js} +15377 -7935
  46. package/dist/stdops.rgr +168 -0
  47. package/package.json +196 -38
  48. package/adventofcode/day1/bin/LambdaSignature1.java +0 -3
  49. package/adventofcode/day1/bin/LambdaSignature2.java +0 -3
  50. package/adventofcode/day1/bin/LambdaSignature3.java +0 -3
  51. package/adventofcode/day1/bin/day1.cpp +0 -124
  52. package/adventofcode/day1/bin/day1.go +0 -75
  53. package/adventofcode/day1/bin/day1.js +0 -45
  54. package/adventofcode/day1/bin/day1.php +0 -46
  55. package/adventofcode/day1/bin/day1.scala +0 -48
  56. package/adventofcode/day1/bin/day1.swift +0 -48
  57. package/adventofcode/day1/bin/day1_part2.cpp +0 -180
  58. package/adventofcode/day1/bin/day1_part2.go +0 -123
  59. package/adventofcode/day1/bin/day1_part2.js +0 -76
  60. package/adventofcode/day1/bin/day1_part2.php +0 -88
  61. package/adventofcode/day1/bin/day1_part2.scala +0 -81
  62. package/adventofcode/day1/bin/day1_part2.swift +0 -91
  63. package/adventofcode/day1/bin/day_one.java +0 -38
  64. package/adventofcode/day1/bin/day_one_part_two.java +0 -57
  65. package/adventofcode/day1/bin/operatorsOf.java +0 -37
  66. package/adventofcode/day1/bin/operatorsOf_5.java +0 -10
  67. package/adventofcode/day1/bin/operatorsOfboolean_5.java +0 -10
  68. package/adventofcode/day1/bin/variant.hpp +0 -2416
  69. package/adventofcode/day1/compile.bat +0 -7
  70. package/adventofcode/day1/compile2.bat +0 -7
  71. package/adventofcode/day1/day1.clj +0 -19
  72. package/adventofcode/day1/day1_part2.clj +0 -43
  73. package/adventofcode/day1/input1.txt +0 -1
  74. package/adventofcode/day2/bin/LambdaSignature1.class +0 -0
  75. package/adventofcode/day2/bin/LambdaSignature1.java +0 -3
  76. package/adventofcode/day2/bin/LambdaSignature2.class +0 -0
  77. package/adventofcode/day2/bin/LambdaSignature2.java +0 -3
  78. package/adventofcode/day2/bin/day2.cpp +0 -133
  79. package/adventofcode/day2/bin/day2.go +0 -85
  80. package/adventofcode/day2/bin/day2.js +0 -45
  81. package/adventofcode/day2/bin/day2.php +0 -59
  82. package/adventofcode/day2/bin/day2.scala +0 -54
  83. package/adventofcode/day2/bin/day2.swift +0 -62
  84. package/adventofcode/day2/bin/day2_part2.cpp +0 -150
  85. package/adventofcode/day2/bin/day2_part2.go +0 -101
  86. package/adventofcode/day2/bin/day2_part2.js +0 -54
  87. package/adventofcode/day2/bin/day2_part2.php +0 -80
  88. package/adventofcode/day2/bin/day2_part2.scala +0 -68
  89. package/adventofcode/day2/bin/day2_part2.swift +0 -82
  90. package/adventofcode/day2/bin/day_two.java +0 -61
  91. package/adventofcode/day2/bin/day_two_part_two$1$1$1.class +0 -0
  92. package/adventofcode/day2/bin/day_two_part_two$1$1.class +0 -0
  93. package/adventofcode/day2/bin/day_two_part_two$1.class +0 -0
  94. package/adventofcode/day2/bin/day_two_part_two.class +0 -0
  95. package/adventofcode/day2/bin/day_two_part_two.java +0 -80
  96. package/adventofcode/day2/bin/operatorsOf.class +0 -0
  97. package/adventofcode/day2/bin/operatorsOf.java +0 -18
  98. package/adventofcode/day2/bin/variant.hpp +0 -2416
  99. package/adventofcode/day2/compile.bat +0 -7
  100. package/adventofcode/day2/compile2.bat +0 -7
  101. package/adventofcode/day2/day2.clj +0 -60
  102. package/adventofcode/day2/day2_part2.clj +0 -69
  103. package/adventofcode/day2/input1.txt +0 -1
  104. package/adventofcode/day3/bin/Grid.java +0 -92
  105. package/adventofcode/day3/bin/GridRow.java +0 -5
  106. package/adventofcode/day3/bin/LambdaSignature1.java +0 -3
  107. package/adventofcode/day3/bin/LambdaSignature2.java +0 -3
  108. package/adventofcode/day3/bin/LambdaSignature3.java +0 -3
  109. package/adventofcode/day3/bin/day3.cpp +0 -64
  110. package/adventofcode/day3/bin/day3.go +0 -55
  111. package/adventofcode/day3/bin/day3.js +0 -42
  112. package/adventofcode/day3/bin/day3.php +0 -41
  113. package/adventofcode/day3/bin/day3.scala +0 -52
  114. package/adventofcode/day3/bin/day3.swift +0 -43
  115. package/adventofcode/day3/bin/day3_part2.cpp +0 -216
  116. package/adventofcode/day3/bin/day3_part2.go +0 -188
  117. package/adventofcode/day3/bin/day3_part2.js +0 -123
  118. package/adventofcode/day3/bin/day3_part2.php +0 -135
  119. package/adventofcode/day3/bin/day3_part2.swift +0 -131
  120. package/adventofcode/day3/bin/day_three_part_two.java +0 -43
  121. package/adventofcode/day3/bin/day_two.java +0 -42
  122. package/adventofcode/day3/bin/operatorsOf.java +0 -14
  123. package/adventofcode/day3/bin/variant.hpp +0 -2416
  124. package/adventofcode/day3/compile.bat +0 -7
  125. package/adventofcode/day3/compile2.bat +0 -7
  126. package/adventofcode/day3/day3.clj +0 -42
  127. package/adventofcode/day3/day3_part2.clj +0 -112
  128. package/adventofcode/day4/bin/LambdaSignature1.java +0 -3
  129. package/adventofcode/day4/bin/day4.cpp +0 -118
  130. package/adventofcode/day4/bin/day4.go +0 -75
  131. package/adventofcode/day4/bin/day4.js +0 -40
  132. package/adventofcode/day4/bin/day4.php +0 -52
  133. package/adventofcode/day4/bin/day4.scala +0 -47
  134. package/adventofcode/day4/bin/day4.swift +0 -56
  135. package/adventofcode/day4/bin/day4_part2.go +0 -129
  136. package/adventofcode/day4/bin/day4_part2.js +0 -72
  137. package/adventofcode/day4/bin/day_four.java +0 -41
  138. package/adventofcode/day4/bin/inputData.java +0 -7
  139. package/adventofcode/day4/bin/operatorsOf.java +0 -11
  140. package/adventofcode/day4/bin/variant.hpp +0 -2416
  141. package/adventofcode/day4/compile.bat +0 -7
  142. package/adventofcode/day4/compile2.bat +0 -7
  143. package/adventofcode/day4/day4.clj +0 -32
  144. package/adventofcode/day4/day4_part2.clj +0 -44
  145. package/adventofcode/day4/input.clj +0 -519
  146. package/adventofcode/day4/input.txt +0 -512
  147. package/bin/api.ts +0 -24471
  148. package/bin/compiler.ts +0 -24482
  149. package/compiler/ColorConsole.clj +0 -22
  150. package/compiler/ContextOperators.clj +0 -75
  151. package/compiler/FlowEnterVarDef.clj +0 -223
  152. package/compiler/InputFileSystem.clj +0 -276
  153. package/compiler/RangerDocs.clj +0 -7
  154. package/compiler/TFactory.clj +0 -146
  155. package/compiler/TFiles.clj +0 -23
  156. package/compiler/TFlow.clj +0 -39
  157. package/compiler/TNodeFactory.clj +0 -84
  158. package/compiler/TTypes.clj +0 -188
  159. package/compiler/VirtualCompiler.clj +0 -800
  160. package/compiler/bin/ng_Compiler.js +0 -23779
  161. package/compiler/commonmark_plugin.clj +0 -359
  162. package/compiler/feat2.bat +0 -2
  163. package/compiler/feats.bat +0 -9
  164. package/compiler/feature_tests.clj +0 -192
  165. package/compiler/index.js +0 -2
  166. package/compiler/issue_57.clj +0 -25
  167. package/compiler/makefile_plugin.clj +0 -135
  168. package/compiler/markdown_plugin.clj +0 -386
  169. package/compiler/maven_plugin.clj +0 -162
  170. package/compiler/ng_AndroidPageWriter.clj +0 -299
  171. package/compiler/ng_CodeNode.clj +0 -756
  172. package/compiler/ng_CodeNodeCompilerExtensions.clj +0 -839
  173. package/compiler/ng_Compiler.clj +0 -49
  174. package/compiler/ng_CompilerGeneric.clj +0 -260
  175. package/compiler/ng_CompilerOrig.clj +0 -854
  176. package/compiler/ng_DictNode.clj +0 -346
  177. package/compiler/ng_DictNode2.clj +0 -316
  178. package/compiler/ng_Execute.clj +0 -138
  179. package/compiler/ng_Execute1.clj +0 -129
  180. package/compiler/ng_FlowWork.clj +0 -3951
  181. package/compiler/ng_LiveCompiler.clj +0 -1109
  182. package/compiler/ng_RagnerJavaScriptClassWriter.clj +0 -402
  183. package/compiler/ng_RangerActiveOperators.clj +0 -86
  184. package/compiler/ng_RangerAppClassDesc.clj +0 -400
  185. package/compiler/ng_RangerAppEnums.clj +0 -86
  186. package/compiler/ng_RangerAppFunctionDesc.clj +0 -127
  187. package/compiler/ng_RangerAppMessages.clj +0 -15
  188. package/compiler/ng_RangerAppOperatorDesc.clj +0 -20
  189. package/compiler/ng_RangerAppParamDesc.clj +0 -388
  190. package/compiler/ng_RangerAppWriterContext.clj +0 -1793
  191. package/compiler/ng_RangerArgMatch.clj +0 -638
  192. package/compiler/ng_RangerCSharpClassWriter.clj +0 -484
  193. package/compiler/ng_RangerCppClassWriter.clj +0 -1023
  194. package/compiler/ng_RangerDocGenerator.clj +0 -305
  195. package/compiler/ng_RangerFlowParser.clj +0 -4992
  196. package/compiler/ng_RangerFlowParserOrig.clj +0 -4002
  197. package/compiler/ng_RangerGenericClassWriter.clj +0 -573
  198. package/compiler/ng_RangerGolangClassWriter.clj +0 -1766
  199. package/compiler/ng_RangerImmutableExtension.clj +0 -77
  200. package/compiler/ng_RangerJava7ClassWriter.clj +0 -961
  201. package/compiler/ng_RangerJavaScriptClassWriter.clj +0 -1042
  202. package/compiler/ng_RangerKotlinClassWriter.clj +0 -372
  203. package/compiler/ng_RangerLanguageWriters.clj +0 -14
  204. package/compiler/ng_RangerLispParser.clj +0 -873
  205. package/compiler/ng_RangerPHPClassWriter.clj +0 -643
  206. package/compiler/ng_RangerPlugin.clj +0 -41
  207. package/compiler/ng_RangerRangerClassWriter.clj +0 -357
  208. package/compiler/ng_RangerRustClassWriter.clj +0 -420
  209. package/compiler/ng_RangerScalaClassWriter.clj +0 -818
  210. package/compiler/ng_RangerSerializeClass.clj +0 -502
  211. package/compiler/ng_RangerServiceBuilder.clj +0 -63
  212. package/compiler/ng_RangerSwift3ClassWriter.clj +0 -809
  213. package/compiler/ng_RangerSwiftClassWriter.clj +0 -0
  214. package/compiler/ng_RangerTypeClass.clj +0 -45
  215. package/compiler/ng_SourceParser.clj +0 -241
  216. package/compiler/ng_SourceParser2.clj +0 -214
  217. package/compiler/ng_WebPageWriter.clj +0 -39
  218. package/compiler/ng_jsonParser.clj +0 -340
  219. package/compiler/ng_p_test.clj +0 -1711
  220. package/compiler/ng_parser.clj +0 -911
  221. package/compiler/ng_parser2.clj +0 -735
  222. package/compiler/ng_parser2_backup.clj +0 -1679
  223. package/compiler/ng_parser_backup.clj +0 -886
  224. package/compiler/ng_parser_ok.clj +0 -1718
  225. package/compiler/ng_parser_ok2.clj +0 -1717
  226. package/compiler/ng_parser_std_match.clj +0 -687
  227. package/compiler/ng_parser_std_match2.clj +0 -1012
  228. package/compiler/ng_parser_v2.clj +0 -1251
  229. package/compiler/ng_ui.clj +0 -403
  230. package/compiler/ng_ui_test.clj +0 -18
  231. package/compiler/ng_writer.clj +0 -338
  232. package/compiler/ng_xmlParser.clj +0 -472
  233. package/compiler/ng_xmlParser2.clj +0 -317
  234. package/compiler/ng_xmlParser3.clj +0 -251
  235. package/compiler/opdoc.bat +0 -4
  236. package/compiler/operators.md +0 -290
  237. package/compiler/p.bat +0 -4
  238. package/compiler/package.json +0 -10
  239. package/compiler/pcmd.bat +0 -4
  240. package/compiler/pcmd2.bat +0 -3
  241. package/compiler/plaintext_plugin.clj +0 -69
  242. package/compiler/plugin.bat +0 -19
  243. package/compiler/plugin2.bat +0 -4
  244. package/compiler/plugin_app.bat +0 -3
  245. package/compiler/plugin_apps.clj +0 -27
  246. package/compiler/plugins.bat +0 -10
  247. package/compiler/reveal_plugin.clj +0 -409
  248. package/compiler/simplePlugin.clj +0 -780
  249. package/compiler/t.bat +0 -3
  250. package/compiler/test_any.clj +0 -43
  251. package/compiler/test_call.clj +0 -141
  252. package/compiler/test_chain.clj +0 -79
  253. package/compiler/test_json.clj +0 -10
  254. package/compiler/test_lambda.clj +0 -153
  255. package/compiler/test_pcmd.clj +0 -32
  256. package/compiler/test_pcmd2.clj +0 -29
  257. package/compiler/test_plugin.clj +0 -237
  258. package/compiler/test_readfile.clj +0 -13
  259. package/compiler/test_reveal.clj +0 -19
  260. package/compiler/test_slides.clj +0 -312
  261. package/compiler/test_types.clj +0 -143
  262. package/compiler/test_types2.clj +0 -49
  263. package/compiler/test_types3.clj +0 -53
  264. package/compiler/test_var.clj +0 -40
  265. package/compiler/tonpm.bat +0 -14
  266. package/compiler/tonpm2.bat +0 -12
  267. package/compiler/ui_plugin.clj +0 -507
  268. package/compiler/ui_plugin2.clj +0 -427
  269. package/compiler/update-git.bat +0 -3
  270. package/compiler/vcomp.bat +0 -4
  271. package/compiler/viewbuilder_Android.clj +0 -176
  272. package/compiler/viewbuilder_Web.clj +0 -105
  273. package/dist/bin/api.js +0 -32422
  274. package/dist/bin/api.js.map +0 -1
  275. package/dist/bin/compiler.d.ts +0 -1638
  276. package/dist/bin/compiler.js +0 -32444
  277. package/dist/bin/compiler.js.map +0 -1
  278. package/examples/3D/bin/test_3d.js +0 -329
  279. package/examples/3D/test_3d.clj +0 -385
  280. package/examples/EVGColor/EVGColor.clj +0 -310
  281. package/examples/EVGColor/EVGColorContext.clj +0 -176
  282. package/examples/EVGColor/bin/EVGColor.js +0 -286
  283. package/examples/EVGColor/bin/minimized.js +0 -286
  284. package/examples/SVGPath/SVGPath.clj +0 -625
  285. package/examples/SVGPath/Vec2.clj +0 -103
  286. package/examples/SVGPath/bin/SVGPath.cpp +0 -887
  287. package/examples/SVGPath/bin/SVGPath.js +0 -682
  288. package/examples/SVGPath/bin/minimized.js +0 -578
  289. package/examples/SVGPath/bin/variant.hpp +0 -2416
  290. package/examples/minification/Vec2.clj +0 -103
  291. package/examples/minification/bin/minified.js +0 -44
  292. package/examples/minification/bin/test.js +0 -117
  293. package/examples/minification/test.clj +0 -13
  294. package/fiddle/VirtualCompiler.js +0 -23495
  295. package/fiddle/browser_editor.js +0 -13240
  296. package/fiddle/compileEnv.js +0 -1
  297. package/fiddle/compileEnv.json +0 -1
  298. package/fiddle/lang_data.js +0 -1
  299. package/index.html +0 -18
  300. package/native/httpd/HttpTester.clj +0 -33
  301. package/native/httpd/RangerWebService.clj +0 -81
  302. package/operators.md +0 -290
  303. package/tsconfig.json +0 -29
  304. package/versions/cpp/compiler.cpp +0 -15032
  305. package/versions/es6/compiler.js +0 -12860
  306. package/versions/go/compiler.go +0 -21338
  307. package/versions/java/AfterCodeNode.java +0 -4
  308. package/versions/java/ClassJoinPoint.java +0 -6
  309. package/versions/java/CodeFile.java +0 -42
  310. package/versions/java/CodeFileSystem.java +0 -72
  311. package/versions/java/CodeNode.java +0 -807
  312. package/versions/java/CodeSlice.java +0 -13
  313. package/versions/java/CodeWriter.java +0 -185
  314. package/versions/java/ColorConsole.java +0 -8
  315. package/versions/java/CompilerInterface.java +0 -213
  316. package/versions/java/DictNode.java +0 -353
  317. package/versions/java/LiveCompiler.java +0 -772
  318. package/versions/java/NodeEvalState.java +0 -24
  319. package/versions/java/OpFindResult.java +0 -6
  320. package/versions/java/RangerAppArrayValue.java +0 -7
  321. package/versions/java/RangerAppClassDesc.java +0 -217
  322. package/versions/java/RangerAppEnum.java +0 -14
  323. package/versions/java/RangerAppFunctionDesc.java +0 -20
  324. package/versions/java/RangerAppHashValue.java +0 -11
  325. package/versions/java/RangerAppInterfaceImpl.java +0 -6
  326. package/versions/java/RangerAppMethodVariants.java +0 -6
  327. package/versions/java/RangerAppParamDesc.java +0 -321
  328. package/versions/java/RangerAppTodo.java +0 -6
  329. package/versions/java/RangerAppValue.java +0 -10
  330. package/versions/java/RangerAppWriterContext.java +0 -800
  331. package/versions/java/RangerArgMatch.java +0 -317
  332. package/versions/java/RangerBackReference.java +0 -7
  333. package/versions/java/RangerCSharpClassWriter.java +0 -287
  334. package/versions/java/RangerCompilerMessage.java +0 -9
  335. package/versions/java/RangerCppClassWriter.java +0 -725
  336. package/versions/java/RangerFlowParser.java +0 -2142
  337. package/versions/java/RangerGenericClassWriter.java +0 -367
  338. package/versions/java/RangerGolangClassWriter.java +0 -1379
  339. package/versions/java/RangerJava7ClassWriter.java +0 -652
  340. package/versions/java/RangerJavaScriptClassWriter.java +0 -305
  341. package/versions/java/RangerKotlinClassWriter.java +0 -380
  342. package/versions/java/RangerLispParser.java +0 -845
  343. package/versions/java/RangerNodeValue.java +0 -9
  344. package/versions/java/RangerPHPClassWriter.java +0 -527
  345. package/versions/java/RangerParamEventHandler.java +0 -6
  346. package/versions/java/RangerParamEventList.java +0 -5
  347. package/versions/java/RangerParamEventMap.java +0 -27
  348. package/versions/java/RangerRangerClassWriter.java +0 -268
  349. package/versions/java/RangerRefForce.java +0 -7
  350. package/versions/java/RangerScalaClassWriter.java +0 -365
  351. package/versions/java/RangerSerializeClass.java +0 -148
  352. package/versions/java/RangerSwift3ClassWriter.java +0 -548
  353. package/versions/java/RangerTypeClass.java +0 -17
  354. package/versions/java/SourceCode.java +0 -65
  355. package/versions/php/compiler.php +0 -13830
  356. package/versions/swift3/compiler.swift +0 -12542
  357. /package/{lib/ACEEditor.clj → dist/lib/ACEEditor.rgr} +0 -0
  358. /package/{lib/SQL.clj → dist/lib/SQL.rgr} +0 -0
  359. /package/{lib/ServiceLib.clj → dist/lib/ServiceLib.rgr} +0 -0
  360. /package/{lib/Time.clj → dist/lib/Time.rgr} +0 -0
  361. /package/{lib/TypedArrays.clj → dist/lib/TypedArrays.rgr} +0 -0
  362. /package/{lib/WebLib.clj → dist/lib/WebLib.rgr} +0 -0
  363. /package/{lib/WebServerLib.clj → dist/lib/WebServerLib.rgr} +0 -0
@@ -2,6 +2,43 @@ language {
2
2
 
3
3
  name "Ranger"
4
4
 
5
+ ; ============================================================================
6
+ ; RANGER LANGUAGE DEFINITION FILE
7
+ ; ============================================================================
8
+ ;
9
+ ; This file defines the core language operators and their target-specific
10
+ ; implementations (templates) for each supported compilation target.
11
+ ;
12
+ ; TEMPLATE SYSTEM OVERVIEW
13
+ ; ------------------------
14
+ ; Each operator has a "templates" block with target-specific implementations.
15
+ ; Templates use special commands to generate code:
16
+ ;
17
+ ; (e N) - Emit expression at argument position N (1-based)
18
+ ; (block N) - Emit a code block at argument position N
19
+ ; (typeof N) - Emit the type name of argument N
20
+ ; nl - Newline
21
+ ; I - Increase indentation
22
+ ; i - Decrease indentation
23
+ ; "string" - Literal string output
24
+ ; (imp "x") - Add import statement for module/header "x"
25
+ ; (polyfill "location" "code") - Add polyfill code at specified location
26
+ ; (create_polyfill "code") - Legacy: add polyfill to "utilities" location
27
+ ;
28
+ ; POLYFILL LOCATIONS
29
+ ; ------------------
30
+ ; The (polyfill "location" "code") command places helper code at these locations:
31
+ ;
32
+ ; "imports" - At the very top, with import statements
33
+ ; "after_imports" - After imports, before class definitions
34
+ ; "utilities" - After class definitions (DEFAULT for create_polyfill)
35
+ ; "file_end" - At the very end of the file
36
+ ;
37
+ ; Use "after_imports" for global variables that classes depend on.
38
+ ; Polyfills are deduplicated - identical code won't be added twice.
39
+ ;
40
+ ; ============================================================================
41
+
5
42
  ; compilation targets might be defined here like this
6
43
  targets {
7
44
  ; short common name file extension
@@ -13,6 +50,7 @@ language {
13
50
  cpp Cpp cpp
14
51
  csharp CSharp cs
15
52
  swift3 Swift3 swift
53
+ swift6 Swift6 swift
16
54
  ts TypeScript ts
17
55
  flow Flow flow
18
56
  go Golang go
@@ -26,9 +64,120 @@ language {
26
64
 
27
65
  ; transformations for the reserved words for function names or other keywords
28
66
  reserved_words {
29
- map FnMap
30
- forEach forEachItem
31
- self _self
67
+ * {
68
+ map FnMap
69
+ forEach forEachItem
70
+ self _self
71
+ func _func
72
+ }
73
+ cpp {
74
+ operator _operator
75
+ static _static
76
+ union _union
77
+ bool _bool
78
+ ref _ref
79
+ class _class
80
+ new _new
81
+ delete _delete
82
+ template _template
83
+ namespace _namespace
84
+ virtual _virtual
85
+ public _public
86
+ private _private
87
+ protected _protected
88
+ }
89
+ go {
90
+ type _type
91
+ range _range
92
+ }
93
+ kotlin {
94
+ object _object
95
+ }
96
+ rust {
97
+ type r#type
98
+ static r#static
99
+ ref r#ref
100
+ union r#union
101
+ bool r#bool
102
+ impl r#impl
103
+ }
104
+ swift3 {
105
+ operator _operator
106
+ static _static
107
+ init _init
108
+ }
109
+ swift6 {
110
+ operator _operator
111
+ static _static
112
+ init _init
113
+ }
114
+ python {
115
+ str _str
116
+ int _int
117
+ float _float
118
+ bool _bool
119
+ list _list
120
+ dict _dict
121
+ set _set
122
+ tuple _tuple
123
+ type _type
124
+ id _id
125
+ len _len
126
+ range _range
127
+ print _print
128
+ input _input
129
+ open _open
130
+ file _file
131
+ filter _filter
132
+ sum _sum
133
+ min _min
134
+ max _max
135
+ abs _abs
136
+ round _round
137
+ sorted _sorted
138
+ reversed _reversed
139
+ enumerate _enumerate
140
+ zip _zip
141
+ any _any
142
+ all _all
143
+ iter _iter
144
+ next _next
145
+ object _object
146
+ bytes _bytes
147
+ complex _complex
148
+ property _property
149
+ classmethod _classmethod
150
+ staticmethod _staticmethod
151
+ super _super
152
+ format _format
153
+ hash _hash
154
+ help _help
155
+ hex _hex
156
+ oct _oct
157
+ bin _bin
158
+ chr _chr
159
+ ord _ord
160
+ repr _repr
161
+ ascii _ascii
162
+ eval _eval
163
+ exec _exec
164
+ compile _compile
165
+ globals _globals
166
+ locals _locals
167
+ vars _vars
168
+ dir _dir
169
+ getattr _getattr
170
+ setattr _setattr
171
+ hasattr _hasattr
172
+ delattr _delattr
173
+ isinstance _isinstance
174
+ issubclass _issubclass
175
+ callable _callable
176
+ slice _slice
177
+ frozenset _frozenset
178
+ memoryview _memoryview
179
+ bytearray _bytearray
180
+ }
32
181
  }
33
182
 
34
183
 
@@ -341,7 +490,9 @@ func r_io_get_env( name string) *GoNullable {
341
490
  csharp ('Environment.GetCommandLineArgs()[' (e 1) ' + 1]' (imp "System"))
342
491
  go ( "os.Args[" (e 1) " + 1]" (imp "os"))
343
492
  swift3 ("CommandLine.arguments[" (e 1) " + 1]")
493
+ swift6 ("CommandLine.arguments[" (e 1) " + 1]")
344
494
  es6 ( "process.argv[ 2 + " (e 1) "]")
495
+ rust ( "std::env::args().nth((" (e 1) " + 1) as usize).unwrap_or_default()")
345
496
  ranger ("( shell_arg " (e 1) " )")
346
497
  }
347
498
  }
@@ -350,11 +501,13 @@ func r_io_get_env( name string) *GoNullable {
350
501
  templates {
351
502
  cpp ( "__g_argc - 1")
352
503
  swift3 ("CommandLine.arguments.count - 1")
504
+ swift6 ("CommandLine.arguments.count - 1")
353
505
  csharp ('Environment.GetCommandLineArgs().Length - 1' (imp "System"))
354
506
  php ( "(count($argv) - 1)" )
355
507
  java7 ( "args.length")
356
508
  go ( "int64( len( os.Args) - 1 )" (imp "os"))
357
509
  es6 ( "(process.argv.length - 2)" )
510
+ rust ( "(std::env::args().len() as i64 - 1)")
358
511
  ranger ("( shell_arg_cnt )")
359
512
  }
360
513
  }
@@ -368,6 +521,14 @@ func r_io_get_env( name string) *GoNullable {
368
521
  }
369
522
  }
370
523
 
524
+ path_dirname cmdArg:string ( arg:string ) {
525
+ templates {
526
+ es6 ( 'require("path").dirname(' (e 1) ')')
527
+ ranger ("( path_dirname " (e 1) " )")
528
+ * ( "\"./\"")
529
+ }
530
+ }
531
+
371
532
  install_directory cmdArg:string () {
372
533
  templates {
373
534
  es6 ( "__dirname" )
@@ -456,6 +617,7 @@ func r_file_exists(pathName string, fileName string) bool {
456
617
  "
457
618
  )
458
619
  )
620
+ rust ( "std::path::Path::new(&format!(\"{}/{}\", " (e 1) ", " (e 2) ")).exists()" )
459
621
  }
460
622
  }
461
623
 
@@ -508,6 +670,27 @@ func r_dir_exists(pathName string) bool {
508
670
  }
509
671
  }
510
672
 
673
+ ; Returns the file modification time as Unix timestamp (seconds since epoch)
674
+ file_mtime cmdFileMTime:int (path:string filename:string) {
675
+ templates {
676
+ go ( "r_file_mtime(" (e 1) ", " (e 2) ")"
677
+ (create_polyfill
678
+ "
679
+ func r_file_mtime(pathName string, fileName string) int64 {
680
+ info, err := os.Stat(pathName + \"/\" + fileName)
681
+ if err != nil {
682
+ return 0
683
+ }
684
+ return info.ModTime().Unix()
685
+ }
686
+ "
687
+ )
688
+ )
689
+ es6 ( "require('fs').statSync(" (e 1) " + '/' + " (e 2) ").mtimeMs" )
690
+ ranger ( "(file_mtime " (e 1) " " (e 2) ")" )
691
+ }
692
+ }
693
+
511
694
  create_dir cmdCreateDir:void (path:string) {
512
695
  templates {
513
696
  scala ( "/* create_dir not implemented */ ")
@@ -561,6 +744,22 @@ func r_write_file ( dirName:String, dataToWrite:String ) {
561
744
  try dataToWrite.write(to:path!, atomically: false, encoding: String.Encoding.utf8)
562
745
  } catch {
563
746
 
747
+ }
748
+ }
749
+ ")
750
+
751
+ )
752
+ swift6 ("r_write_file(dirName: " (e 1) " + \"/\" + " (e 2) ", dataToWrite: " (e 3) ") "
753
+ (imp "Foundation")
754
+ (create_polyfill "
755
+ func r_write_file ( dirName:String, dataToWrite:String ) {
756
+ do {
757
+ let fileManager = FileManager.default
758
+ let url = URL(fileURLWithPath: fileManager.currentDirectoryPath)
759
+ let path = url.appendingPathComponent(dirName)
760
+ try dataToWrite.write(to:path, atomically: false, encoding: .utf8)
761
+ } catch {
762
+
564
763
  }
565
764
  }
566
765
  ")
@@ -621,6 +820,14 @@ func r_write_text_file(pathName string, fileName string, txtData string) {
621
820
  "
622
821
  ) )
623
822
 
823
+ rust ( "r_write_file(&" (e 1) ", &" (e 2) ", &" (e 3) ");" nl
824
+ (create_polyfill "
825
+ fn r_write_file(path: &str, filename: &str, data: &str) {
826
+ let full_path = format!(\"{}/{}\", path, filename);
827
+ let _ = std::fs::write(full_path, data);
828
+ }
829
+ "))
830
+
624
831
  }
625
832
  }
626
833
 
@@ -660,6 +867,22 @@ func r_read_file ( dirName:String ) -> String? {
660
867
  res = nil
661
868
  }
662
869
  return res
870
+ }
871
+ ")
872
+ )
873
+ swift6 ("r_read_file(dirName: " (e 1) " + \"/\" + " (e 2) ") "
874
+ (imp "Foundation")
875
+ (create_polyfill "
876
+ func r_read_file ( dirName:String ) -> String? {
877
+ let res: String?
878
+ do {
879
+ res = try String(contentsOfFile:dirName, encoding: .utf8)
880
+ } catch let error {
881
+ print(\"Error reading file: \\(dirName)\")
882
+ print(\"Error: \\(error.localizedDescription)\")
883
+ res = nil
884
+ }
885
+ return res
663
886
  }
664
887
  ")
665
888
  )
@@ -698,6 +921,13 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
698
921
  }
699
922
  return res
700
923
  }
924
+ "))
925
+ rust ( "r_read_file(&" (e 1) ", &" (e 2) ")"
926
+ (create_polyfill "
927
+ fn r_read_file(path: &str, filename: &str) -> Option<String> {
928
+ let full_path = format!(\"{}/{}\", path, filename);
929
+ std::fs::read_to_string(full_path).ok()
930
+ }
701
931
  "))
702
932
  es6 ( "(require('fs').readFileSync( " (e 1) " + '/' + " (e 2) " , 'utf8'))" )
703
933
  }
@@ -707,7 +937,8 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
707
937
  templates {
708
938
  ranger ( nl (e 1) " = " (e 2) nl )
709
939
  scala ( nl (e 1) " = " (e 2) nl )
710
- go ( (custom _ ) )
940
+ go ( (custom _ ) )
941
+ rust ( (custom _) )
711
942
  * ( nl (e 1) " = " (e 2) ";" nl )
712
943
  }
713
944
  }
@@ -716,7 +947,8 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
716
947
  templates {
717
948
  ranger ( nl (e 1) " = " (e 2) nl )
718
949
  scala ( nl (e 1) " = " (e 2) nl )
719
- go ( (custom _ ) )
950
+ go ( (custom _ ) )
951
+ rust ( (custom _) )
720
952
  * ( nl (e 1) " = " (e 2) ";" nl )
721
953
  }
722
954
  }
@@ -731,7 +963,8 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
731
963
  swift ( nl (e 1) " = Optional(" (e 2) ");" nl )
732
964
  java7 ( nl (e 1) " = " (e 2) ";" nl )
733
965
  go ( nl (goset 1) ".value = " (e 2) ";" nl nl (goset 1) ".has_value = true; /* detected as non-optional */" nl )
734
- cpp ( nl ( e 1) " = " (e 2) ";" nl )
966
+ cpp ( nl ( e 1) " = " (e 2) ";" nl )
967
+ rust ( (custom _) )
735
968
  * ( nl (e 1) " = " (e 2) ";" nl )
736
969
  }
737
970
  }
@@ -744,7 +977,8 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
744
977
  "if " (goset 1) ".value != nil {" nl I (goset 1) ".has_value = true" nl i "}" nl
745
978
  )
746
979
  cpp ( nl ( e 1) " = " (e 2) ";" nl )
747
- java7 ( nl (e 1) " = " (e 2) ";" nl )
980
+ java7 ( nl (e 1) " = " (e 2) ";" nl )
981
+ rust ( (custom _) )
748
982
  * ( nl (e 1) " = " (e 2) ";" nl )
749
983
  }
750
984
  }
@@ -792,6 +1026,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
792
1026
  php ( (e 1 ) )
793
1027
  kotlin ( (e 1) "!!" )
794
1028
  swift3 ( (e 1) "!" )
1029
+ swift6 ( (e 1) "!" )
795
1030
  go ( (e 1) ".value.(" (typeof 1) ")" )
796
1031
  cpp ( (e 1) )
797
1032
 
@@ -816,10 +1051,11 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
816
1051
  scala ( (e 1) ".get" )
817
1052
  csharp ( (e 1) )
818
1053
  java7 ( (e 1) )
819
- rust ( (e 1) ".unwrap()" )
1054
+ rust ( (custom _) )
820
1055
  php ( (e 1 ) )
821
1056
  kotlin ( (e 1) "!!" )
822
1057
  swift3 ( (e 1) "!" )
1058
+ swift6 ( (e 1) "!" )
823
1059
  go ( (e 1) ".value.(" (typeof 1) ")" )
824
1060
  cpp ( (e 1) )
825
1061
 
@@ -885,6 +1121,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
885
1121
  templates {
886
1122
  java7 ( (custom _) )
887
1123
  scala( (custom _) )
1124
+ rust ( (custom _) )
888
1125
  ranger ( nl "return " (e 1) nl )
889
1126
  go ( (custom _) )
890
1127
  * ( "return " (ifa 1 ";") (e 1) (eif _) ";" )
@@ -895,6 +1132,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
895
1132
  templates {
896
1133
  ranger ( nl "return " (e 1) nl )
897
1134
  scala( (custom _ ) )
1135
+ rust ( (custom _) )
898
1136
  go ( (custom _) )
899
1137
  * ( "return " (ifa 1 ";") (e 1) (eif _) ";" )
900
1138
  }
@@ -914,7 +1152,8 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
914
1152
  = cmdAssign:void ( left@(optional):T right:T ) {
915
1153
  templates {
916
1154
  ranger ( nl (e 1) " = " (e 2) nl )
917
- scala ( nl (e 1) " = Some(" (e 2) " ) " nl )
1155
+ scala ( nl (e 1) " = Some(" (e 2) " ) " nl )
1156
+ rust ( (custom _) )
918
1157
  * ( nl (e 1) " = " (e 2) ";" nl )
919
1158
  }
920
1159
  }
@@ -923,7 +1162,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
923
1162
  templates {
924
1163
  ranger ( nl (e 1) " = " (e 2) nl )
925
1164
  swift3 ( nl (e 1) " = Optional(" (e 2) ")" )
926
-
1165
+ rust ( (custom _) )
927
1166
  scala ( nl (e 1) " = " (e 2) ".get /* scala optional assigment of values * / " nl )
928
1167
  * ( nl (e 1) " = " (e 2) ";" nl )
929
1168
  }
@@ -932,7 +1171,8 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
932
1171
  = cmdAssign:void ( left@(optional):T right@(optional):T ) {
933
1172
  templates {
934
1173
  ranger ( nl (e 1) " = " (e 2) nl )
935
- scala ( nl (e 1) " = " (e 2) " /* scala optional assigment of values * / " nl )
1174
+ scala ( nl (e 1) " = " (e 2) " /* scala optional assigment of values * / " nl )
1175
+ rust ( (custom _) )
936
1176
  * ( nl (e 1) " = " (e 2) ";" nl )
937
1177
  }
938
1178
  }
@@ -972,6 +1212,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
972
1212
  templates {
973
1213
  go ( "strings.Join([]string{ " (e 1) ",strconv.FormatInt(" (e 2) ", 10) }, \"\")" (imp "strings") (imp "strconv"))
974
1214
  swift3 ( (e 1) " + String(" (e 2)")" )
1215
+ swift6 ( (e 1) " + String(" (e 2)")" )
975
1216
  rust ( "[" (e 1) " , (" (e 2)".to_string()) ].join(\"\")" )
976
1217
  php ( (e 1) " . " (e 2) )
977
1218
  cpp ( (e 1 ) " + std::to_string(" (e 2) ")")
@@ -984,6 +1225,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
984
1225
  go ( (e 1) " + " (e 2) )
985
1226
  go.v2 ( "strings.Join([]string{ " (e 1) "," (e 2) " }, \"\")" (imp "strings"))
986
1227
  php ( (e 1) " . " (e 2) )
1228
+ rust ( "[&*" (e 1) ", &*" (e 2) "].concat()" )
987
1229
  * ( (e 1) " + " (e 2) )
988
1230
  }
989
1231
  }
@@ -993,8 +1235,11 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
993
1235
  go ( "strings.Join([]string{ " (e 1) ",strconv.FormatFloat(" (e 2) ",'f', 6, 64) }, \"\")" (imp "strings") (imp "strconv"))
994
1236
  rust ( "[" (e 1) " , (" (e 2)".to_string()) ].join(\"\")" )
995
1237
  swift3 ( (e 1) " + String(" (e 2)")" )
1238
+ swift6 ( (e 1) " + String(" (e 2)")" )
1239
+ kotlin ( (e 1) " + " (e 2)".toString()" )
996
1240
  cpp ( (e 1 ) " + std::to_string(" (e 2) ")")
997
1241
  php ( (e 1) " . " (e 2) )
1242
+ python ( (e 1) " + str(" (e 2) ")" )
998
1243
  * ( (e 1) " + " (e 2) )
999
1244
  }
1000
1245
  }
@@ -1004,9 +1249,12 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1004
1249
  templates {
1005
1250
  go ( "strings.Join([]string{ " (e 1) ",strconv.FormatInt(" (e 2) ", 10) }, \"\")" (imp "strings") (imp "strconv"))
1006
1251
  swift3 ( (e 1) " + String(" (e 2)")" )
1252
+ swift6 ( (e 1) " + String(" (e 2)")" )
1253
+ kotlin ( (e 1) " + " (e 2)".toString()" )
1007
1254
  rust ( "[" (e 1) " , (" (e 2)".to_string()) ].join(\"\")" )
1008
1255
  cpp ( (e 1 ) " + std::to_string(" (e 2) ")")
1009
1256
  php ( (e 1) " . " (e 2) )
1257
+ python ( (e 1) " + str(" (e 2) ")" )
1010
1258
  * ( (e 1) " + " (e 2) )
1011
1259
  }
1012
1260
  }
@@ -1016,18 +1264,140 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1016
1264
  * ( (e 1) " % " (e 2) )
1017
1265
  }
1018
1266
  }
1267
+
1268
+ ; ============================================================================
1269
+ ; Bitwise operators for integer manipulation
1270
+ ; ============================================================================
1271
+
1272
+ ; Bitwise AND
1273
+ bit_and _:int (left:int right:int) {
1274
+ templates {
1275
+ es6 ( "(" (e 1) " & " (e 2) ")" )
1276
+ go ( "int64(" (e 1) " & " (e 2) ")" )
1277
+ rust ( "((" (e 1) ") & (" (e 2) "))" )
1278
+ cpp ( "((" (e 1) ") & (" (e 2) "))" )
1279
+ java7 ( "((" (e 1) ") & (" (e 2) "))" )
1280
+ python ( "((" (e 1) ") & (" (e 2) "))" )
1281
+ swift6 ( "(Int64(" (e 1) ") & Int64(" (e 2) "))" )
1282
+ csharp ( "((" (e 1) ") & (" (e 2) "))" )
1283
+ * ( "((" (e 1) ") & (" (e 2) "))" )
1284
+ }
1285
+ }
1286
+
1287
+ ; Bitwise OR
1288
+ bit_or _:int (left:int right:int) {
1289
+ templates {
1290
+ es6 ( "(" (e 1) " | " (e 2) ")" )
1291
+ go ( "int64(" (e 1) " | " (e 2) ")" )
1292
+ rust ( "((" (e 1) ") | (" (e 2) "))" )
1293
+ cpp ( "((" (e 1) ") | (" (e 2) "))" )
1294
+ java7 ( "((" (e 1) ") | (" (e 2) "))" )
1295
+ python ( "((" (e 1) ") | (" (e 2) "))" )
1296
+ swift6 ( "(Int64(" (e 1) ") | Int64(" (e 2) "))" )
1297
+ csharp ( "((" (e 1) ") | (" (e 2) "))" )
1298
+ * ( "((" (e 1) ") | (" (e 2) "))" )
1299
+ }
1300
+ }
1301
+
1302
+ ; Bitwise XOR
1303
+ bit_xor _:int (left:int right:int) {
1304
+ templates {
1305
+ es6 ( "(" (e 1) " ^ " (e 2) ")" )
1306
+ go ( "int64(" (e 1) " ^ " (e 2) ")" )
1307
+ rust ( "((" (e 1) ") ^ (" (e 2) "))" )
1308
+ cpp ( "((" (e 1) ") ^ (" (e 2) "))" )
1309
+ java7 ( "((" (e 1) ") ^ (" (e 2) "))" )
1310
+ python ( "((" (e 1) ") ^ (" (e 2) "))" )
1311
+ swift6 ( "(Int64(" (e 1) ") ^ Int64(" (e 2) "))" )
1312
+ csharp ( "((" (e 1) ") ^ (" (e 2) "))" )
1313
+ * ( "((" (e 1) ") ^ (" (e 2) "))" )
1314
+ }
1315
+ }
1316
+
1317
+ ; Bitwise NOT (ones complement)
1318
+ bit_not _:int (value:int) {
1319
+ templates {
1320
+ es6 ( "(~" (e 1) ")" )
1321
+ go ( "int64(^" (e 1) ")" )
1322
+ rust ( "(!" (e 1) ")" )
1323
+ cpp ( "(~" (e 1) ")" )
1324
+ java7 ( "(~" (e 1) ")" )
1325
+ python ( "(~" (e 1) ")" )
1326
+ swift6 ( "(~Int64(" (e 1) "))" )
1327
+ csharp ( "(~" (e 1) ")" )
1328
+ * ( "(~" (e 1) ")" )
1329
+ }
1330
+ }
1331
+
1332
+ ; Bit shift left
1333
+ bit_shl _:int (value:int count:int) {
1334
+ templates {
1335
+ es6 ( "(" (e 1) " << " (e 2) ")" )
1336
+ go ( "int64(" (e 1) " << uint(" (e 2) "))" )
1337
+ rust ( "((" (e 1) ") << (" (e 2) "))" )
1338
+ cpp ( "((" (e 1) ") << (" (e 2) "))" )
1339
+ java7 ( "((" (e 1) ") << (" (e 2) "))" )
1340
+ python ( "((" (e 1) ") << (" (e 2) "))" )
1341
+ swift6 ( "(Int64(" (e 1) ") << Int64(" (e 2) "))" )
1342
+ csharp ( "((" (e 1) ") << (int)(" (e 2) "))" )
1343
+ * ( "((" (e 1) ") << (" (e 2) "))" )
1344
+ }
1345
+ }
1346
+
1347
+ ; Bit shift right (arithmetic/signed)
1348
+ bit_shr _:int (value:int count:int) {
1349
+ templates {
1350
+ es6 ( "(" (e 1) " >> " (e 2) ")" )
1351
+ go ( "int64(" (e 1) " >> uint(" (e 2) "))" )
1352
+ rust ( "((" (e 1) ") >> (" (e 2) "))" )
1353
+ cpp ( "((" (e 1) ") >> (" (e 2) "))" )
1354
+ java7 ( "((" (e 1) ") >> (" (e 2) "))" )
1355
+ python ( "((" (e 1) ") >> (" (e 2) "))" )
1356
+ swift6 ( "(Int64(" (e 1) ") >> Int64(" (e 2) "))" )
1357
+ csharp ( "((" (e 1) ") >> (int)(" (e 2) "))" )
1358
+ * ( "((" (e 1) ") >> (" (e 2) "))" )
1359
+ }
1360
+ }
1361
+
1362
+ ; Bit shift right unsigned (logical)
1363
+ bit_ushr _:int (value:int count:int) {
1364
+ templates {
1365
+ es6 ( "(" (e 1) " >>> " (e 2) ")" )
1366
+ go ( "int64(uint64(" (e 1) ") >> uint(" (e 2) "))" )
1367
+ rust ( "(((" (e 1) ") as u64 >> (" (e 2) ")) as i64)" )
1368
+ cpp ( "(int64_t)((uint64_t)(" (e 1) ") >> (" (e 2) "))" )
1369
+ java7 ( "((" (e 1) ") >>> (" (e 2) "))" )
1370
+ python ( "((" (e 1) " & 0xFFFFFFFF) >> (" (e 2) "))" )
1371
+ swift6 ( "Int64(bitPattern: UInt64(bitPattern: Int64(" (e 1) ")) >> UInt64(" (e 2) "))" )
1372
+ csharp ( "(int)((uint)(" (e 1) ") >> (int)(" (e 2) "))" )
1373
+ * ( "(" (e 1) " >>> " (e 2) ")" )
1374
+ }
1375
+ }
1376
+
1377
+ ; ============================================================================
1019
1378
 
1020
1379
  + cmdPlusOp:string ( left:double right:string ) {
1021
1380
  templates {
1381
+ swift3 ( "String(" (e 1) ") + " (e 2) )
1382
+ swift6 ( "String(" (e 1) ") + " (e 2) )
1383
+ kotlin ( (e 1) ".toString() + " (e 2) )
1022
1384
  * ( (e 1) " + " (e 2) )
1023
1385
  php ( (e 1) " . " (e 2) )
1024
- rust ( "[" (e 1) " , " (e 2) " ].join()" )
1386
+ rust ( "format!(\"{}{}\", " (e 1) ", " (e 2) ")" )
1025
1387
  }
1026
1388
  }
1027
1389
 
1028
1390
  + cmdPlusOp:string ( left:int right:string ) {
1029
- templates { * ( (e 1) " + " (e 2) )
1391
+ templates {
1392
+ go ( "strings.Join([]string{ strconv.FormatInt(" (e 1) ", 10)," (e 2) " }, \"\")" (imp "strings") (imp "strconv"))
1393
+ swift3 ( "String(" (e 1) ") + " (e 2) )
1394
+ swift6 ( "String(" (e 1) ") + " (e 2) )
1395
+ kotlin ( (e 1) ".toString() + " (e 2) )
1396
+ rust ( "format!(\"{}{}\", " (e 1) ", " (e 2) ")" )
1397
+ cpp ( "std::to_string(" (e 1) ") + " (e 2) )
1030
1398
  php ( (e 1) " . " (e 2) )
1399
+ python ( "str(" (e 1) ") + " (e 2) )
1400
+ * ( (e 1) " + " (e 2) )
1031
1401
  } }
1032
1402
 
1033
1403
 
@@ -1035,7 +1405,12 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1035
1405
  * cmdMulOp:int ( left:int right:int ) { templates { * ( (e 1) " * " (e 2) ) } }
1036
1406
 
1037
1407
  / cmdDivOp:double ( left:double right:double ) { templates { * ( (e 1) " / " (e 2) ) } }
1038
- / cmdDivOp:double ( left:int right:int ) { templates { * ( (e 1) " / " (e 2) ) } }
1408
+ / cmdDivOp:double ( left:int right:int ) { templates {
1409
+ go ( "float64(" (e 1) ") / float64(" (e 2) ")" )
1410
+ rust ( "(" (e 1) " as f64) / (" (e 2) " as f64)" )
1411
+ kotlin ( (e 1) ".toDouble() / " (e 2) ".toDouble()" )
1412
+ * ( (e 1) " / " (e 2) )
1413
+ } }
1039
1414
 
1040
1415
  ; optional string operator...
1041
1416
  || _:string ( left:string right:string ) @doc('selects the first string if length > 0, else the second...') {
@@ -1052,6 +1427,9 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1052
1427
  go ( '(func() ' (typeof 2) ' { if ' (e 1) ' { return ' (e 2) ' } else { return ' (e 3) '} }())' )
1053
1428
  cpp ( '(' (e 1) " ? " (e 2) " : " (e 3) ')' )
1054
1429
  scala ( '( if (' (e 1) ") " (e 2) " else " (e 3) ')' )
1430
+ kotlin ( '(if (' (e 1) ') ' (e 2) ' else ' (e 3) ')' )
1431
+ python ( '(' (e 2) " if " (e 1) " else " (e 3) ')' )
1432
+ rust ( 'if ' (e 1) ' { ' (e 2) ' } else { ' (e 3) ' }' )
1055
1433
  * ( (e 1) " ? " (e 2) " : " (e 3) )
1056
1434
  }
1057
1435
  }
@@ -1067,6 +1445,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1067
1445
  templates {
1068
1446
  ranger ( nl (e 1) " = " (e 2) nl )
1069
1447
  go ( (custom _ ) )
1448
+ rust ( (custom _) )
1070
1449
  scala ( (e 1) " = " (e 2) ) ; <-- scala does not require ; here
1071
1450
  * ( (e 1) " = " (e 2) ";" )
1072
1451
  }
@@ -1112,14 +1491,14 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1112
1491
  floor _:int ( value:double ) {
1113
1492
  templates {
1114
1493
  ranger ( "(floor " (e 1) ")" )
1115
- swift3 ( "floor(" (e 1) ")" (imp "Foundation"))
1116
- cpp ( "floor(" (e 1) ")" (imp "<cmath>"))
1117
- csharp ( "Math.Floor(" (e 1) ")" (imp "System"))
1118
- go ( "math.Floor(" (e 1) ")" (imp "math"))
1494
+ swift3 ( "Int(floor(" (e 1) "))" (imp "Foundation"))
1495
+ cpp ( "(int)floor(" (e 1) ")" (imp "<cmath>"))
1496
+ csharp ( "(int)Math.Floor(" (e 1) ")" (imp "System"))
1497
+ go ( "int64(math.Floor(" (e 1) "))" (imp "math"))
1119
1498
  php ( "floor(" (e 1) ")" )
1120
- rust ( "" (e 1) ".floor()" )
1121
- scala ( "math.floor(" (e 1) ")" (imp "scala.math"))
1122
- java7 ( "Math.floor(" (e 1) ")" (imp "java.lang.Math"))
1499
+ rust ( "" (e 1) ".floor() as i64" )
1500
+ scala ( "math.floor(" (e 1) ").toInt" (imp "scala.math"))
1501
+ java7 ( "(int)Math.floor(" (e 1) ")" (imp "java.lang.Math"))
1123
1502
  * ( "Math.floor(" (e 1) ")")
1124
1503
  }
1125
1504
  }
@@ -1204,23 +1583,27 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1204
1583
 
1205
1584
  if cmdIf:void ( condition:boolean then_block:block else@(keyword) else_block:block ) {
1206
1585
  templates {
1586
+ rust @macro(true) ('if ' (e 1) ' { ' (block 2)' } else { '(block 4) ' }' )
1207
1587
  * @macro(true) ('if (' (e 1) ' ) { ' (block 2)' } { '(block 4) ' }' )
1208
1588
  }
1209
1589
  }
1210
1590
  if! cmdIf:void ( condition:boolean then_block:block else@(keyword) else_block:block ) {
1211
1591
  templates {
1592
+ rust @macro(true) ('if false == ' (e 1) ' { ' (block 2)' } else { '(block 4) ' }' )
1212
1593
  * @macro(true) ('if (false == (' (e 1) ' ) ) { ' (block 2)' } { '(block 4) ' }' )
1213
1594
  }
1214
1595
  }
1215
1596
 
1216
1597
  if! cmdIf:void ( condition:boolean then_block:block else_block:block ) {
1217
1598
  templates {
1599
+ rust @macro(true) ('if false == ' (e 1) ' { ' (block 2)' } else { '(block 3) ' }' )
1218
1600
  * @macro(true) ('if (false == (' (e 1) ' ) ) { ' (block 2)' } { '(block 3) ' }' )
1219
1601
  }
1220
1602
  }
1221
1603
 
1222
1604
  if! cmdIf:void ( condition:boolean then_block:block ) {
1223
1605
  templates {
1606
+ rust @macro(true) ('if false == ' (e 1) ' { ' (block 2) ' } ' )
1224
1607
  * @macro(true) ('if (false == (' (e 1) ' ) ) { ' (block 2) ' } ' )
1225
1608
  }
1226
1609
  }
@@ -1231,6 +1614,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1231
1614
  ranger ( "if (" (e 1) " ) {" I nl (block 2) i nl "}" (ifa 3) " {" I nl (block 3) i "}" nl)
1232
1615
  rust ( "if " (e 1) " {" I nl (block 2) i nl "}" (ifa 3) " else {" I nl (block 3) i "}" nl)
1233
1616
  go ( "if " (e 1) " {" I nl (block 2) i nl "}" (ifa 3) " else {" I nl (block 3) i "}" nl)
1617
+ python ( "if " (e 1) ":" I nl (block 2) i nl "else:" I nl (block 3) i nl)
1234
1618
  * ( "if ( " (e 1) " ) {" I nl (block 2) i nl "}" (ifa 3) " else {" I nl (block 3) i "}" nl)
1235
1619
  }
1236
1620
  }
@@ -1240,6 +1624,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1240
1624
  ranger ( "if (" (e 1) ") {" I nl (block 2) nl i "}" nl )
1241
1625
  rust ( "if " (e 1) " {" I nl (block 2) nl i "}" nl )
1242
1626
  go ( "if " (e 1) " {" I nl (block 2) nl i "}" nl )
1627
+ python ( "if " (e 1) ":" I nl (block 2) nl i nl )
1243
1628
  * ( "if ( " (e 1) " ) {" I nl (block 2) nl i "}" nl )
1244
1629
  }
1245
1630
  }
@@ -1261,6 +1646,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1261
1646
  ranger ( "if ( " (e 1) ") ) {" I nl (block 2) i nl "} {" nl I (block 3) i "}" nl)
1262
1647
  scala ( "if ( " (e 1) ".isDefined ) {" nl I (block 2) i nl "}" nl )
1263
1648
  swift3 ( "if ( " (e 1) " != nil ) {" nl I (block 2) i nl "}" nl )
1649
+ swift6 ( "if ( " (e 1) " != nil ) {" nl I (block 2) i nl "}" nl )
1264
1650
  kotlin ( "if ( " (e 1) " != null ) {" nl I (block 2) i nl "}" nl )
1265
1651
  java7 ( "if ( " (e 1) ".isPresent()) {" nl I (block 2) i nl "}" nl )
1266
1652
  csharp ( "if ( " (e 1) ".HasValue) {" nl I (block 2) i nl "}" nl )
@@ -1270,6 +1656,7 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1270
1656
  go ( "if ( " (e 1) ".has_value) {" nl I (block 2) i nl "}" nl )
1271
1657
  cpp ( "if ( " (e 1) " != NULL ) {" nl I (block 2) i nl "}" nl )
1272
1658
  rust ( "if " (e 1) ".is_some() {" nl I (block 2) i nl "}" nl )
1659
+ python ( "if " (e 1) " is not None:" nl I (block 2) i nl )
1273
1660
  * ( "if ( typeof(" ( e 1 ) ") != \"undefined\" ) {" nl I (block 2) i nl "}" nl )
1274
1661
 
1275
1662
  }
@@ -1285,8 +1672,10 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1285
1672
  kotlin ( "if ( " (e 1) " != null ) {" I nl (block 2) i nl "} else {" nl I (block 3) i "}" nl)
1286
1673
  rust ( "if " (e 1) ".is_some() {" I nl (block 2) i nl "} else {" nl I (block 3) i "}" nl)
1287
1674
  swift3 ( "if ( " (e 1) " != nil ) {" I nl (block 2) i nl "} else {" nl I (block 3) i "}" nl)
1675
+ swift6 ( "if ( " (e 1) " != nil ) {" I nl (block 2) i nl "} else {" nl I (block 3) i "}" nl)
1288
1676
  go ( "if ( " (e 1) ".has_value ) {" I nl (block 2) i nl "} else {" nl I (block 3) i "}" nl)
1289
1677
  cpp ( "if ( " (e 1) " != NULL ) {" I nl (block 2) i nl "} else {" nl I (block 3) i "}" nl)
1678
+ python ( "if " (e 1) " is not None:" I nl (block 2) i nl "else:" I nl (block 3) i nl)
1290
1679
  * ( "if ( typeof(" ( e 1 ) ") != \"undefined\" ) {" I nl (block 2) i nl "} else {" nl I (block 3) i "}" nl)
1291
1680
  }
1292
1681
  }
@@ -1438,7 +1827,9 @@ func r_io_read_file( path string , fileName string ) *GoNullable {
1438
1827
  "}" nl
1439
1828
  i nl "} " nl
1440
1829
  (imp "scala.util.control._")
1441
- )
1830
+ )
1831
+ python ( "while " (e 1) ":" nl I (block 2) i nl )
1832
+ rust ( "while " (e 1) " {" nl I (block 2) i nl "}" )
1442
1833
  * ( "while (" (e 1) ") {" nl I (block 2) i nl "}" )
1443
1834
  }
1444
1835
  }
@@ -1500,13 +1891,15 @@ std::vector<T> r_make_vector_from_array( const T (&data)[N] )
1500
1891
  php ( "(!isset(" (e 1) "))")
1501
1892
  cpp ((e 1) " == NULL")
1502
1893
  swift3 ((e 1) " == nil")
1894
+ swift6 ((e 1) " == nil")
1503
1895
  java7 ( (e 1) " == null")
1504
1896
  scala ((e 1) ".isDefined == false ")
1505
1897
  csharp ((e 1) " == null ")
1506
- rust ((e 1) ".is_null()")
1898
+ rust ((e 1) ".is_none()")
1507
1899
  go ( "!" (goset 1 ) ".has_value " )
1508
1900
  kotlin ((e 1) "== null")
1509
1901
  es6 ( "typeof(" ( e 1 ) ") === \"undefined\"")
1902
+ python ((e 1) " is None")
1510
1903
  * ((e 1) "== null")
1511
1904
  }
1512
1905
  }
@@ -1532,12 +1925,14 @@ std::vector<T> r_make_vector_from_array( const T (&data)[N] )
1532
1925
  php ( "(isset(" (e 1) "))")
1533
1926
  scala ((e 1) ".isDefined")
1534
1927
  swift3 ((e 1) " != nil ")
1928
+ swift6 ((e 1) " != nil ")
1535
1929
  cpp ((e 1) " != NULL ")
1536
1930
  java7 ((e 1) " != null ")
1537
1931
  csharp ("" (e 1) " != null")
1538
1932
  rust ((e 1) ".is_some()")
1539
1933
  kotlin ((e 1) " != null")
1540
1934
  go ( (goset 1 ) ".has_value" )
1935
+ python ('(' (e 1) ' is not None)')
1541
1936
  * ('(typeof(' ( e 1 ) ') !== "undefined" && ' (e 1) ' != null ) ')
1542
1937
  }
1543
1938
  }
@@ -1602,10 +1997,12 @@ case class customException(smth:String) extends Exception
1602
1997
  i
1603
1998
  nl I nl "case e: Exception => {" nl I (block 2) i nl "}" i nl "}" nl )
1604
1999
  java7 ( nl "try {" nl I (block 1) i nl "} catch( Exception e) {" nl I (block 2) i nl "}" nl (imp 'java.io.IOException') )
2000
+ kotlin ( nl "try {" nl I (block 1) i nl "} catch( e : Exception ) {" nl I (block 2) i nl "}" nl )
1605
2001
  go ( (custom _) )
1606
2002
  ; go ( "(func () { " nl I "defer func() {" nl I "if r:= recover(); r != nil {" nl I (block 2) i nl "}" nl i "}()" nl (block 1) nl i "})()" nl ) ;"
1607
2003
  ; with swift there is no do without try...
1608
2004
  swift3 ( "do {" nl I (block 1) i nl "} catch { " nl I (block 2) i nl "}" )
2005
+ swift6 ( "do {" nl I (block 1) i nl "} catch { " nl I (block 2) i nl "}" )
1609
2006
  cpp ( nl "try {" nl I (block 1) i nl "} catch( ... ) {" nl I (block 2) i nl "}" nl )
1610
2007
  * ( nl "try {" nl I (block 1) i nl "} catch(e) {" nl I (block 2) i nl "}" nl )
1611
2008
  }
@@ -1617,9 +2014,11 @@ case class customException(smth:String) extends Exception
1617
2014
  templates {
1618
2015
  ranger ( nl "for " (e 1) " " (e 2) ":" (typeof 2) " " (e 3)" {" nl I (block 4) nl i "}" )
1619
2016
  swift3 ( (forkctx _ ) (def 2) (def 3) nl "for ( " (swift_rc 3) " , " (e 2) " ) in " (e 1) ".enumerated() {" nl I (block 4) nl i "}" )
2017
+ swift6 ( (forkctx _ ) (def 2) (def 3) nl "for (" (e 3) ", " (e 2) ") in " (e 1) ".enumerated() {" nl I (block 4) nl i "}" )
1620
2018
  kotlin ( (forkctx _ ) (def 2) (def 3) "for ( " (e 3) " in " (e 1) ".indices ) {" nl I "val " (e 2) " = " (e 1) "[" (e 3) "]" nl (block 4) nl i "}" )
1621
2019
 
1622
- rust ( (forkctx _ ) (def 2) (def 3) "for (" (e 3) ", " (e 2) " ) in " (e 1) ".enumerate() {" nl I (block 4) nl i "}" )
2020
+ ; Use index-based loop for Rust with cloned item - no reassignment needed as item is cloned
2021
+ rust ( (forkctx _ ) (def 2) (def 3) "for " (e 3) " in 0.." (e 1) ".len() {" nl I "let mut " (e 2) " = " (e 1) "[" (e 3) " as usize].clone();" nl (block 4) nl i "}" )
1623
2022
 
1624
2023
  ; idea of go for macro implementation, not working yet...
1625
2024
  go_idea @macro(true) (nl
@@ -1643,6 +2042,7 @@ case class customException(smth:String) extends Exception
1643
2042
  I (typeof 2) " " (e 2) " = " (e 1) ".at(" (e 3) ");" nl (block 4) nl i "}" )
1644
2043
  cpp.old ( (forkctx _ ) (def 2) (def 3) "for ( std::vector< " (typeof 2) ">::size_type " (e 3) " = 0; " (e 3) " != " (e 1) ".size(); " (e 3) "++) {" nl
1645
2044
  I (typeof 2) " " (e 2) " = " (e 1) ".at(" (e 3) ");" nl (block 4) nl i "}" )
2045
+ python ( (forkctx _ ) (def 2) (def 3) "for " (e 3) ", " (e 2) " in enumerate(" (e 1) "):" nl I (block 4) nl i )
1646
2046
  * ( (forkctx _ ) (def 2) (def 3) "for ( let " (e 3) " = 0; " (e 3) " < " (e 1) ".length; " (e 3) "++) {" nl I "var " (e 2) " = " (e 1) "[" (e 3) "];" nl (block 4) nl i "}" )
1647
2047
  }
1648
2048
  }
@@ -1670,6 +2070,7 @@ case class customException(smth:String) extends Exception
1670
2070
  templates {
1671
2071
  ranger ( "(trim " (e 1 ) ")")
1672
2072
  swift3 ( (e 1 ) ".trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)" (imp "Foundation"))
2073
+ swift6 ( (e 1 ) ".trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)" (imp "Foundation"))
1673
2074
  php ( "trim(" (e 1 ) ")")
1674
2075
  cpp ( "r_cpp_trim( " (e 1) ")" (imp "<cctype>") (imp "<string>") (imp "<algorithm>")
1675
2076
  (create_polyfill "
@@ -1683,10 +2084,37 @@ inline std::string r_cpp_trim(std::string &s)
1683
2084
  scala ( (e 1) ".trim" )
1684
2085
  csharp ( (e 1) ".Trim()" (imp "System"))
1685
2086
  go ("strings.TrimSpace(" (e 1) ")" (imp "strings"))
2087
+ python ( (e 1) ".strip()" )
2088
+ rust ( (e 1) ".trim().to_string()" )
1686
2089
  * ( (e 1) ".trim()" )
1687
2090
  }
1688
2091
  }
1689
2092
 
2093
+ ; trim_right - removes whitespace from the right side of string
2094
+ trim_right cmdTrimRight:string ( value:string ) {
2095
+ templates {
2096
+ ranger ( "(trim_right " (e 1 ) ")")
2097
+ swift3 ( (e 1 ) ".trimmingCharacters(in: .whitespaces)" (imp "Foundation"))
2098
+ swift6 ( (e 1 ) ".trimmingCharacters(in: .whitespaces)" (imp "Foundation"))
2099
+ php ( "rtrim(" (e 1 ) ")")
2100
+ cpp ( "r_trim_right( " (e 1) ")" (imp "<string>") (imp "<algorithm>")
2101
+ (create_polyfill "
2102
+ inline std::string r_trim_right(const std::string& s) {
2103
+ auto end = std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base();
2104
+ return std::string(s.begin(), end);
2105
+ }
2106
+ ") )
2107
+ scala ( (e 1) ".replaceAll(\"\\\\s+$\", \"\")" )
2108
+ csharp ( (e 1) ".TrimEnd()" (imp "System"))
2109
+ go ("strings.TrimRight(" (e 1) ", \" \\t\\n\\r\")" (imp "strings"))
2110
+ kotlin ( (e 1) ".trimEnd()" )
2111
+ java7 ( (e 1) ".replaceAll(\"\\\\s+$\", \"\")" )
2112
+ python ( (e 1) ".rstrip()" )
2113
+ rust ( (e 1) ".trim_end().to_string()" )
2114
+ * ( (e 1) ".trimEnd()" )
2115
+ }
2116
+ }
2117
+
1690
2118
  ; wr.out (").to[collection.mutable.ArrayBuffer]" false
1691
2119
  ; kotlin could use also something like: .split(Regex("(?<=[!?])|(?=[!?])"))
1692
2120
  ; swift : .components(separatedBy:
@@ -1715,7 +2143,9 @@ inline std::string r_cpp_trim(std::string &s)
1715
2143
 
1716
2144
  "__Split(" (e 1) ", " (e 2) ")" (imp 'System.Linq'))
1717
2145
  swift3 ( (e 2) ".characters.count == 0 ? Array(" (e 1) ".characters).map { String($0) } : " (e 1) ".components( separatedBy : " (e 2) ")" (imp "Foundation"))
2146
+ swift6 ( (e 2) ".count == 0 ? Array(" (e 1) ").map { String($0) } : " (e 1) ".components( separatedBy : " (e 2) ")" (imp "Foundation"))
1718
2147
  java7( "new ArrayList<String>(Arrays.asList(" (e 1) ".split(" (e 2) ")))" )
2148
+ kotlin ( "if (" (e 2) ".length == 0) " (e 1) ".map { it.toString() }.toMutableList() else " (e 1) ".split(" (e 2) ").toMutableList()" )
1719
2149
  php ( "strlen(" (e 2) ") == 0 ? str_split(" (e 1) ") : " "explode(" (e 2) ", " (e 1) ")")
1720
2150
  go ("strings.Split(" (e 1) ", " (e 2) ")" (imp "strings"))
1721
2151
 
@@ -1745,6 +2175,8 @@ std::vector<std::string> r_str_split(std::string data, std::string token) {
1745
2175
  )
1746
2176
  )
1747
2177
 
2178
+ python ( (e 1) ".split(" (e 2) ") if " (e 2) " else list(" (e 1) ")" )
2179
+ rust ( (e 1) ".split(&*" (e 2) ").map(|s| s.to_string()).collect::<Vec<String>>()" )
1748
2180
  * ( (e 1) ".split(" (e 2) ")")
1749
2181
  }
1750
2182
  }
@@ -1756,9 +2188,12 @@ std::vector<std::string> r_str_split(std::string data, std::string token) {
1756
2188
  java7 ( (e 1) ".length()")
1757
2189
  scala ( (e 1) ".length()")
1758
2190
  swift3 ( (e 1) ".characters.count")
2191
+ swift6 ( (e 1) ".count")
1759
2192
  csharp ( (e 1) ".Length")
1760
2193
  php ( "strlen(" (e 1) ")")
1761
- go ( "int64(len(" (e 1) "))")
2194
+ go ( "int64(len([]rune(" (e 1) ")))")
2195
+ python ( "len(" (e 1) ")")
2196
+ rust ( (e 1) ".chars().count() as i64")
1762
2197
  * ( (e 1) ".length")
1763
2198
  }
1764
2199
  }
@@ -1784,6 +2219,7 @@ std::vector<std::string> r_str_split(std::string data, std::string token) {
1784
2219
  scala ( "new String(" (e 1) ".slice(" (e 2) ", " (e 3) ").map(_.toChar) )")
1785
2220
  java7 ( "new String(" (e 1) "," (e 2) ", " (e 3) " - " (e 2) " )")
1786
2221
  swift3 ( "String(data: Data(bytes:" (e 1) "[" (e 2) " ..< " (e 3) "]), encoding: .utf8)!" (imp "Foundation"))
2222
+ swift6 ( "String(data: Data(" (e 1) "[" (e 2) " ..< " (e 3) "]), encoding: .utf8)!" (imp "Foundation"))
1787
2223
  kotlin ( "String(" (e 1) "," (e 2) ", " (e 3) " - " (e 2) " )")
1788
2224
  go ( "fmt.Sprintf(\"%s\", " (e 1) "[" (e 2) ":" (e 3) "])"
1789
2225
  (imp "fmt")
@@ -1825,6 +2261,456 @@ std::vector<std::string> r_str_split(std::string data, std::string token) {
1825
2261
  }
1826
2262
  }
1827
2263
 
2264
+ ; ============================================================================
2265
+ ; BINARY BUFFER OPERATIONS
2266
+ ; ============================================================================
2267
+ ; These operators provide cross-platform binary buffer manipulation.
2268
+ ; The 'buffer' type maps to: ArrayBuffer (JS), []byte (Go), Vec<u8> (Rust),
2269
+ ; std::vector<uint8_t> (C++), byte[] (Java), bytearray (Python)
2270
+ ; ============================================================================
2271
+
2272
+ ; Allocate a new buffer of specified size (zero-filled)
2273
+ buffer_alloc cmdBufferAlloc:buffer ( size:int ) {
2274
+ templates {
2275
+ ranger ( "(buffer_alloc " (e 1) ")" )
2276
+ es6 ( "(function(){ var b = new ArrayBuffer(" (e 1) "); b._view = new DataView(b); return b; })()" )
2277
+ go ( "make([]byte, " (e 1) ")" )
2278
+ rust ( "vec![0u8; " (e 1) " as usize]" )
2279
+ cpp ( "std::vector<uint8_t>(" (e 1) ", 0)" (imp "<vector>") (imp "<cstdint>") )
2280
+ java7 ( "new byte[(int)" (e 1) "]" )
2281
+ python ( "bytearray(" (e 1) ")" )
2282
+ swift6 ( "[UInt8](repeating: 0, count: Int(" (e 1) "))" )
2283
+ csharp ( "new byte[" (e 1) "]" )
2284
+ }
2285
+ }
2286
+
2287
+ ; Get the length of a buffer in bytes
2288
+ buffer_length cmdBufferLength:int ( buf:buffer ) {
2289
+ templates {
2290
+ ranger ( "(buffer_length " (e 1) ")" )
2291
+ es6 ( (e 1) ".byteLength" )
2292
+ go ( "int64(len(" (e 1) "))" )
2293
+ rust ( (e 1) ".len() as i64" )
2294
+ cpp ( "static_cast<int64_t>(" (e 1) ".size())" )
2295
+ java7 ( (e 1) ".length" )
2296
+ python ( "len(" (e 1) ")" )
2297
+ swift6 ( "Int64(" (e 1) ".count)" )
2298
+ csharp ( (e 1) ".Length" )
2299
+ }
2300
+ }
2301
+
2302
+ ; Read a single byte at offset (returns 0-255)
2303
+ buffer_get cmdBufferGet:int ( buf:buffer offset:int ) {
2304
+ templates {
2305
+ ranger ( "(buffer_get " (e 1) " " (e 2) ")" )
2306
+ es6 ( (e 1) "._view.getUint8(" (e 2) ")" )
2307
+ go ( "int64(" (e 1) "[" (e 2) "])" )
2308
+ rust ( (e 1) "[(" (e 2) ") as usize] as i64" )
2309
+ cpp ( "static_cast<int64_t>(" (e 1) "[" (e 2) "])" )
2310
+ java7 ( "((" (e 1) "[(int)" (e 2) "] & 0xFF))" )
2311
+ python ( (e 1) "[" (e 2) "]" )
2312
+ swift6 ( "Int64(" (e 1) "[Int(" (e 2) ")])" )
2313
+ csharp ( "((int)" (e 1) "[" (e 2) "])" )
2314
+ }
2315
+ }
2316
+
2317
+ ; Write a single byte at offset (value should be 0-255)
2318
+ buffer_set cmdBufferSet:void ( buf:buffer offset:int value:int ) {
2319
+ templates {
2320
+ ranger ( "(buffer_set " (e 1) " " (e 2) " " (e 3) ")" )
2321
+ es6 ( (e 1) "._view.setUint8(" (e 2) ", " (e 3) ")" )
2322
+ go ( (e 1) "[" (e 2) "] = byte(" (e 3) ")" )
2323
+ rust ( (e 1) "[(" (e 2) ") as usize] = " (e 3) " as u8" )
2324
+ cpp ( (e 1) "[" (e 2) "] = static_cast<uint8_t>(" (e 3) ")" )
2325
+ java7 ( (e 1) "[(int)" (e 2) "] = (byte)" (e 3) )
2326
+ python ( (e 1) "[" (e 2) "] = " (e 3) )
2327
+ swift6 ( (e 1) "[Int(" (e 2) ")] = UInt8(" (e 3) ")" )
2328
+ csharp ( (e 1) "[" (e 2) "] = (byte)" (e 3) )
2329
+ }
2330
+ }
2331
+
2332
+ ; Convert string to buffer (UTF-8 encoded)
2333
+ buffer_from_string cmdBufferFromString:buffer ( str:string ) {
2334
+ templates {
2335
+ ranger ( "(buffer_from_string " (e 1) ")" )
2336
+ es6 ( "(function(s){ var b = new ArrayBuffer(s.length); var v = new Uint8Array(b); for(var i=0;i<s.length;i++)v[i]=s.charCodeAt(i); b._view = new DataView(b); return b; })(" (e 1) ")" )
2337
+ go ( "[]byte(" (e 1) ")" )
2338
+ rust ( (e 1) ".as_bytes().to_vec()" )
2339
+ cpp ( "std::vector<uint8_t>(" (e 1) ".begin(), " (e 1) ".end())" )
2340
+ java7 ( (e 1) ".getBytes(java.nio.charset.StandardCharsets.UTF_8)" )
2341
+ python ( "bytearray(" (e 1) ", 'utf-8')" )
2342
+ swift6 ( "Array(" (e 1) ".utf8)" )
2343
+ csharp ( "System.Text.Encoding.UTF8.GetBytes(" (e 1) ")" )
2344
+ }
2345
+ }
2346
+
2347
+ ; Convert buffer to string (UTF-8 decoded)
2348
+ buffer_to_string cmdBufferToString:string ( buf:buffer ) {
2349
+ templates {
2350
+ ranger ( "(buffer_to_string " (e 1) ")" )
2351
+ es6 ( "(function(b){ var v = new Uint8Array(b); return String.fromCharCode.apply(null, v); })(" (e 1) ")" )
2352
+ go ( "string(" (e 1) ")" )
2353
+ rust ( "String::from_utf8_lossy(&" (e 1) ").to_string()" )
2354
+ cpp ( "std::string(" (e 1) ".begin(), " (e 1) ".end())" )
2355
+ java7 ( "new String(" (e 1) ", java.nio.charset.StandardCharsets.UTF_8)" )
2356
+ python ( (e 1) ".decode('utf-8')" )
2357
+ swift6 ( "String(bytes: " (e 1) ", encoding: .utf8) ?? \"\"" )
2358
+ csharp ( "System.Text.Encoding.UTF8.GetString(" (e 1) ")" )
2359
+ }
2360
+ }
2361
+
2362
+ ; Convert buffer to Base64 encoded string
2363
+ buffer_to_base64 cmdBufferToBase64:string ( buf:buffer ) {
2364
+ templates {
2365
+ ranger ( "(buffer_to_base64 " (e 1) ")" )
2366
+ es6 ( "Buffer.from(" (e 1) ").toString('base64')" )
2367
+ go ( "base64.StdEncoding.EncodeToString(" (e 1) ")" (imp "encoding/base64") )
2368
+ rust ( "base64::encode(&" (e 1) ")" )
2369
+ cpp ( "r_buffer_to_base64(" (e 1) ")" (imp "<string>") (imp "<vector>")
2370
+ (create_polyfill "
2371
+ std::string r_buffer_to_base64(const std::vector<uint8_t>& data) {
2372
+ static const char* chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";
2373
+ std::string result;
2374
+ size_t i = 0;
2375
+ while (i < data.size()) {
2376
+ uint32_t n = data[i++] << 16;
2377
+ if (i < data.size()) n |= data[i++] << 8;
2378
+ if (i < data.size()) n |= data[i++];
2379
+ result += chars[(n >> 18) & 0x3F];
2380
+ result += chars[(n >> 12) & 0x3F];
2381
+ result += (i > data.size() + 1) ? '=' : chars[(n >> 6) & 0x3F];
2382
+ result += (i > data.size()) ? '=' : chars[n & 0x3F];
2383
+ }
2384
+ return result;
2385
+ }
2386
+ ")
2387
+ )
2388
+ java7 ( "java.util.Base64.getEncoder().encodeToString(" (e 1) ")" )
2389
+ python ( "base64.b64encode(" (e 1) ").decode('ascii')" (imp "base64") )
2390
+ swift6 ( "Data(" (e 1) ").base64EncodedString()" (imp "Foundation") )
2391
+ csharp ( "Convert.ToBase64String(" (e 1) ")" )
2392
+ }
2393
+ }
2394
+
2395
+ ; Write buffer to a binary file
2396
+ buffer_write_file cmdBufferWriteFile:void ( path:string filename:string buf:buffer ) {
2397
+ templates {
2398
+ ranger ( "(buffer_write_file " (e 1) " " (e 2) " " (e 3) ")" )
2399
+ es6 ( "require('fs').writeFileSync(" (e 1) " + '/' + " (e 2) ", Buffer.from(" (e 3) "))" )
2400
+ go ( "os.WriteFile(" (e 1) " + \"/\" + " (e 2) ", " (e 3) ", 0644)" (imp "os") )
2401
+ rust ( "std::fs::write(format!(\"{}/{}\", " (e 1) ", " (e 2) "), &" (e 3) ").unwrap()" )
2402
+ cpp ( "r_buffer_write_file(" (e 1) ", " (e 2) ", " (e 3) ")" (imp "<fstream>") (imp "<vector>")
2403
+ (create_polyfill "
2404
+ void r_buffer_write_file(const std::string& path, const std::string& filename, const std::vector<uint8_t>& data) {
2405
+ std::ofstream file(path + \"/\" + filename, std::ios::binary);
2406
+ file.write(reinterpret_cast<const char*>(data.data()), data.size());
2407
+ }
2408
+ ")
2409
+ )
2410
+ java7 ( "java.nio.file.Files.write(java.nio.file.Paths.get(" (e 1) " + \"/\" + " (e 2) "), " (e 3) ")" )
2411
+ python ( "open(" (e 1) " + '/' + " (e 2) ", 'wb').write(" (e 3) ")" )
2412
+ swift6 ( "try? Data(" (e 3) ").write(to: URL(fileURLWithPath: " (e 1) " + \"/\" + " (e 2) "))" (imp "Foundation") )
2413
+ csharp ( "System.IO.File.WriteAllBytes(" (e 1) " + \"/\" + " (e 2) ", " (e 3) ")" )
2414
+ }
2415
+ }
2416
+
2417
+ ; Read a binary file into a buffer
2418
+ buffer_read_file cmdBufferReadFile:buffer ( path:string filename:string ) {
2419
+ templates {
2420
+ ranger ( "(buffer_read_file " (e 1) " " (e 2) ")" )
2421
+ es6 ( "(function(){ var b = require('fs').readFileSync(" (e 1) " + '/' + " (e 2) "); var ab = new ArrayBuffer(b.length); var v = new Uint8Array(ab); for(var i=0;i<b.length;i++)v[i]=b[i]; ab._view = new DataView(ab); return ab; })()" )
2422
+ go ( "func() []byte { d, _ := os.ReadFile(filepath.Join(" (e 1) ", " (e 2) ")); return d }()" (imp "os") (imp "path/filepath") )
2423
+ rust ( "std::fs::read(format!(\"{}/{}\", " (e 1) ", " (e 2) ")).unwrap_or_default()" )
2424
+ cpp ( "r_buffer_read_file(" (e 1) ", " (e 2) ")" (imp "<fstream>") (imp "<vector>") (imp "<iterator>")
2425
+ (create_polyfill "
2426
+ std::vector<uint8_t> r_buffer_read_file(const std::string& path, const std::string& filename) {
2427
+ std::ifstream file(path + \"/\" + filename, std::ios::binary);
2428
+ return std::vector<uint8_t>(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>());
2429
+ }
2430
+ ")
2431
+ )
2432
+ java7 ( "java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(" (e 1) " + \"/\" + " (e 2) "))" )
2433
+ python ( "bytearray(open(" (e 1) " + '/' + " (e 2) ", 'rb').read())" )
2434
+ swift6 ( "(try? Data(contentsOf: URL(fileURLWithPath: " (e 1) " + \"/\" + " (e 2) "))).map { Array($0) } ?? []" (imp "Foundation") )
2435
+ csharp ( "System.IO.File.ReadAllBytes(" (e 1) " + \"/\" + " (e 2) ")" )
2436
+ }
2437
+ }
2438
+
2439
+ ; Copy bytes from source buffer to destination buffer
2440
+ buffer_copy cmdBufferCopy:void ( dest:buffer destOffset:int src:buffer srcOffset:int length:int ) {
2441
+ templates {
2442
+ ranger ( "(buffer_copy " (e 1) " " (e 2) " " (e 3) " " (e 4) " " (e 5) ")" )
2443
+ es6 ( "(function(d,dOff,s,sOff,len){ var dv = new Uint8Array(d); var sv = new Uint8Array(s); for(var i=0;i<len;i++) dv[dOff+i]=sv[sOff+i]; })(" (e 1) "," (e 2) "," (e 3) "," (e 4) "," (e 5) ")" )
2444
+ go ( "copy(" (e 1) "[" (e 2) ":], " (e 3) "[" (e 4) ":" (e 4) "+" (e 5) "])" )
2445
+ rust ( (e 1) "[" (e 2) " as usize..(" (e 2) "+" (e 5) ") as usize].copy_from_slice(&" (e 3) "[" (e 4) " as usize..(" (e 4) "+" (e 5) ") as usize])" )
2446
+ cpp ( "std::copy(" (e 3) ".begin()+" (e 4) ", " (e 3) ".begin()+" (e 4) "+" (e 5) ", " (e 1) ".begin()+" (e 2) ")" (imp "<algorithm>") )
2447
+ java7 ( "System.arraycopy(" (e 3) ", (int)" (e 4) ", " (e 1) ", (int)" (e 2) ", (int)" (e 5) ")" )
2448
+ python ( (e 1) "[" (e 2) ":" (e 2) "+" (e 5) "] = " (e 3) "[" (e 4) ":" (e 4) "+" (e 5) "]" )
2449
+ swift6 ( (e 1) ".replaceSubrange(Int(" (e 2) ")..<Int(" (e 2) "+" (e 5) "), with: " (e 3) "[Int(" (e 4) ")..<Int(" (e 4) "+" (e 5) ")])" )
2450
+ csharp ( "Array.Copy(" (e 3) ", (int)" (e 4) ", " (e 1) ", (int)" (e 2) ", (int)" (e 5) ")" )
2451
+ }
2452
+ }
2453
+
2454
+ ; Fill buffer with a byte value
2455
+ buffer_fill cmdBufferFill:void ( buf:buffer value:int start:int end:int ) {
2456
+ templates {
2457
+ ranger ( "(buffer_fill " (e 1) " " (e 2) " " (e 3) " " (e 4) ")" )
2458
+ es6 ( "(function(b,v,s,e){ var arr = new Uint8Array(b); for(var i=s;i<e;i++) arr[i]=v; })(" (e 1) "," (e 2) "," (e 3) "," (e 4) ")" )
2459
+ go ( "for i := " (e 3) "; i < " (e 4) "; i++ { " (e 1) "[i] = byte(" (e 2) ") }" )
2460
+ rust ( (e 1) "[" (e 3) " as usize.." (e 4) " as usize].fill(" (e 2) " as u8)" )
2461
+ cpp ( "std::fill(" (e 1) ".begin()+" (e 3) ", " (e 1) ".begin()+" (e 4) ", static_cast<uint8_t>(" (e 2) "))" (imp "<algorithm>") )
2462
+ java7 ( "java.util.Arrays.fill(" (e 1) ", (int)" (e 3) ", (int)" (e 4) ", (byte)" (e 2) ")" )
2463
+ python ( (e 1) "[" (e 3) ":" (e 4) "] = [" (e 2) "] * (" (e 4) " - " (e 3) ")" )
2464
+ swift6 ( (e 1) ".replaceSubrange(Int(" (e 3) ")..<Int(" (e 4) "), with: repeatElement(UInt8(" (e 2) "), count: Int(" (e 4) "-" (e 3) ")))" )
2465
+ csharp ( "Array.Fill(" (e 1) ", (byte)" (e 2) ", (int)" (e 3) ", (int)(" (e 4) "-" (e 3) "))" )
2466
+ }
2467
+ }
2468
+
2469
+ ; Create a slice/copy of a buffer range
2470
+ buffer_slice cmdBufferSlice:buffer ( buf:buffer start:int end:int ) {
2471
+ templates {
2472
+ ranger ( "(buffer_slice " (e 1) " " (e 2) " " (e 3) ")" )
2473
+ es6 ( "(function(b,s,e){ var slice = b.slice(s,e); slice._view = new DataView(slice); return slice; })(" (e 1) "," (e 2) "," (e 3) ")" )
2474
+ go ( "append([]byte{}, " (e 1) "[" (e 2) ":" (e 3) "]...)" )
2475
+ rust ( (e 1) "[" (e 2) " as usize.." (e 3) " as usize].to_vec()" )
2476
+ cpp ( "std::vector<uint8_t>(" (e 1) ".begin()+" (e 2) ", " (e 1) ".begin()+" (e 3) ")" )
2477
+ java7 ( "java.util.Arrays.copyOfRange(" (e 1) ", (int)" (e 2) ", (int)" (e 3) ")" )
2478
+ python ( "bytearray(" (e 1) "[" (e 2) ":" (e 3) "])" )
2479
+ swift6 ( "Array(" (e 1) "[Int(" (e 2) ")..<Int(" (e 3) ")])" )
2480
+ csharp ( (e 1) "[((int)" (e 2) ")..((int)" (e 3) ")]" )
2481
+ }
2482
+ }
2483
+
2484
+ ; ============================================================================
2485
+ ; INT_BUFFER TYPE - Fixed-size integer array for performance-critical code
2486
+ ; ============================================================================
2487
+ ; Similar to buffer but for int64 values instead of bytes.
2488
+ ; Use for lookup tables, IDCT coefficients, etc. where size is known at init.
2489
+ ; Go: []int64, C++: std::vector<int64_t>, ES6: Int32Array, etc.
2490
+ ; ============================================================================
2491
+
2492
+ ; Allocate a new int_buffer of specified size (zero-filled)
2493
+ int_buffer_alloc cmdIntBufferAlloc:int_buffer ( size:int ) {
2494
+ templates {
2495
+ ranger ( "(int_buffer_alloc " (e 1) ")" )
2496
+ es6 ( "new Int32Array(" (e 1) ")" )
2497
+ go ( "make([]int64, " (e 1) ")" )
2498
+ rust ( "vec![0i64; " (e 1) " as usize]" )
2499
+ cpp ( "std::vector<int64_t>(" (e 1) ", 0)" (imp "<vector>") (imp "<cstdint>") )
2500
+ java7 ( "new long[(int)" (e 1) "]" )
2501
+ python ( "[0] * " (e 1) )
2502
+ swift6 ( "[Int64](repeating: 0, count: Int(" (e 1) "))" )
2503
+ csharp ( "new long[" (e 1) "]" )
2504
+ }
2505
+ }
2506
+
2507
+ ; Get the length of an int_buffer
2508
+ int_buffer_length cmdIntBufferLength:int ( buf:int_buffer ) {
2509
+ templates {
2510
+ ranger ( "(int_buffer_length " (e 1) ")" )
2511
+ es6 ( (e 1) ".length" )
2512
+ go ( "int64(len(" (e 1) "))" )
2513
+ rust ( (e 1) ".len() as i64" )
2514
+ cpp ( "static_cast<int64_t>(" (e 1) ".size())" )
2515
+ java7 ( (e 1) ".length" )
2516
+ python ( "len(" (e 1) ")" )
2517
+ swift6 ( "Int64(" (e 1) ".count)" )
2518
+ csharp ( (e 1) ".Length" )
2519
+ }
2520
+ }
2521
+
2522
+ ; Read an int64 at index
2523
+ int_buffer_get cmdIntBufferGet:int ( buf:int_buffer index:int ) {
2524
+ templates {
2525
+ ranger ( "(int_buffer_get " (e 1) " " (e 2) ")" )
2526
+ es6 ( (e 1) "[" (e 2) "]" )
2527
+ go ( (e 1) "[" (e 2) "]" )
2528
+ rust ( (e 1) "[(" (e 2) ") as usize]" )
2529
+ cpp ( (e 1) "[" (e 2) "]" )
2530
+ java7 ( (e 1) "[(int)" (e 2) "]" )
2531
+ python ( (e 1) "[" (e 2) "]" )
2532
+ swift6 ( (e 1) "[Int(" (e 2) ")]" )
2533
+ csharp ( (e 1) "[" (e 2) "]" )
2534
+ }
2535
+ }
2536
+
2537
+ ; Write an int64 at index
2538
+ int_buffer_set cmdIntBufferSet:void ( buf:int_buffer index:int value:int ) {
2539
+ templates {
2540
+ ranger ( "(int_buffer_set " (e 1) " " (e 2) " " (e 3) ")" )
2541
+ es6 ( (e 1) "[" (e 2) "] = " (e 3) )
2542
+ go ( (e 1) "[" (e 2) "] = " (e 3) )
2543
+ rust ( (e 1) "[(" (e 2) ") as usize] = " (e 3) )
2544
+ cpp ( (e 1) "[" (e 2) "] = " (e 3) )
2545
+ java7 ( (e 1) "[(int)" (e 2) "] = " (e 3) )
2546
+ python ( (e 1) "[" (e 2) "] = " (e 3) )
2547
+ swift6 ( (e 1) "[Int(" (e 2) ")] = " (e 3) )
2548
+ csharp ( (e 1) "[" (e 2) "] = " (e 3) )
2549
+ }
2550
+ }
2551
+
2552
+ ; Fill int_buffer with a value in range [start, end)
2553
+ int_buffer_fill cmdIntBufferFill:void ( buf:int_buffer value:int start:int end:int ) {
2554
+ templates {
2555
+ ranger ( "(int_buffer_fill " (e 1) " " (e 2) " " (e 3) " " (e 4) ")" )
2556
+ es6 ( (e 1) ".fill(" (e 2) ", " (e 3) ", " (e 4) ")" )
2557
+ go ( "for i := " (e 3) "; i < " (e 4) "; i++ { " (e 1) "[i] = " (e 2) " }" )
2558
+ rust ( (e 1) "[" (e 3) " as usize.." (e 4) " as usize].fill(" (e 2) ")" )
2559
+ cpp ( "std::fill(" (e 1) ".begin()+" (e 3) ", " (e 1) ".begin()+" (e 4) ", " (e 2) ")" (imp "<algorithm>") )
2560
+ java7 ( "java.util.Arrays.fill(" (e 1) ", (int)" (e 3) ", (int)" (e 4) ", " (e 2) ")" )
2561
+ python ( (e 1) "[" (e 3) ":" (e 4) "] = [" (e 2) "] * (" (e 4) " - " (e 3) ")" )
2562
+ swift6 ( (e 1) ".replaceSubrange(Int(" (e 3) ")..<Int(" (e 4) "), with: repeatElement(" (e 2) ", count: Int(" (e 4) "-" (e 3) ")))" )
2563
+ csharp ( "Array.Fill(" (e 1) ", " (e 2) ", (int)" (e 3) ", (int)(" (e 4) "-" (e 3) "))" )
2564
+ }
2565
+ }
2566
+
2567
+ ; Copy ints from source to destination
2568
+ int_buffer_copy cmdIntBufferCopy:void ( dest:int_buffer destOffset:int src:int_buffer srcOffset:int length:int ) {
2569
+ templates {
2570
+ ranger ( "(int_buffer_copy " (e 1) " " (e 2) " " (e 3) " " (e 4) " " (e 5) ")" )
2571
+ es6 ( (e 1) ".set(" (e 3) ".subarray(" (e 4) ", " (e 4) "+" (e 5) "), " (e 2) ")" )
2572
+ go ( "copy(" (e 1) "[" (e 2) ":], " (e 3) "[" (e 4) ":" (e 4) "+" (e 5) "])" )
2573
+ rust ( (e 1) "[" (e 2) " as usize..(" (e 2) "+" (e 5) ") as usize].copy_from_slice(&" (e 3) "[" (e 4) " as usize..(" (e 4) "+" (e 5) ") as usize])" )
2574
+ cpp ( "std::copy(" (e 3) ".begin()+" (e 4) ", " (e 3) ".begin()+" (e 4) "+" (e 5) ", " (e 1) ".begin()+" (e 2) ")" (imp "<algorithm>") )
2575
+ java7 ( "System.arraycopy(" (e 3) ", (int)" (e 4) ", " (e 1) ", (int)" (e 2) ", (int)" (e 5) ")" )
2576
+ python ( (e 1) "[" (e 2) ":" (e 2) "+" (e 5) "] = " (e 3) "[" (e 4) ":" (e 4) "+" (e 5) "]" )
2577
+ swift6 ( (e 1) ".replaceSubrange(Int(" (e 2) ")..<Int(" (e 2) "+" (e 5) "), with: " (e 3) "[Int(" (e 4) ")..<Int(" (e 4) "+" (e 5) ")])" )
2578
+ csharp ( "Array.Copy(" (e 3) ", (int)" (e 4) ", " (e 1) ", (int)" (e 2) ", (int)" (e 5) ")" )
2579
+ }
2580
+ }
2581
+
2582
+ ; TODO: int_buffer_from requires variadic argument support in Ranger operators
2583
+ ; Create int_buffer from literal values - for cleaner initialization of lookup tables
2584
+ ; Usage: def cosTable:int_buffer (int_buffer_from 1024 1004 946 851 724 569 392 200)
2585
+ ; int_buffer_from cmdIntBufferFrom:int_buffer ( listOf:expression ) {
2586
+ ; templates {
2587
+ ; ranger ( "(int_buffer_from " (list 1) ")" )
2588
+ ; es6 ( "new Int32Array([" (comma 1) "])" )
2589
+ ; go ( "[]int64{" (comma 1) "}" )
2590
+ ; rust ( "vec![" (comma 1) "]" )
2591
+ ; cpp ( "std::vector<int64_t>{" (comma 1) "}" (imp "<vector>") (imp "<cstdint>") )
2592
+ ; java7 ( "new long[]{" (comma 1) "}" )
2593
+ ; python ( "[" (comma 1) "]" )
2594
+ ; swift6 ( "[" (comma 1) "] as [Int64]" )
2595
+ ; csharp ( "new long[]{" (comma 1) "}" )
2596
+ ; }
2597
+ ; }
2598
+
2599
+ ; ============================================================================
2600
+ ; DOUBLE_BUFFER TYPE - Fixed-size float64 array for performance-critical code
2601
+ ; ============================================================================
2602
+ ; Similar to int_buffer but for float64/double values.
2603
+ ; Use for DSP, signal processing, matrix operations, etc.
2604
+ ; Go: []float64, C++: std::vector<double>, ES6: Float64Array, etc.
2605
+ ; ============================================================================
2606
+
2607
+ ; Allocate a new double_buffer of specified size (zero-filled)
2608
+ double_buffer_alloc cmdDoubleBufferAlloc:double_buffer ( size:int ) {
2609
+ templates {
2610
+ ranger ( "(double_buffer_alloc " (e 1) ")" )
2611
+ es6 ( "new Float64Array(" (e 1) ")" )
2612
+ go ( "make([]float64, " (e 1) ")" )
2613
+ rust ( "vec![0.0f64; " (e 1) " as usize]" )
2614
+ cpp ( "std::vector<double>(" (e 1) ", 0.0)" (imp "<vector>") )
2615
+ java7 ( "new double[(int)" (e 1) "]" )
2616
+ python ( "[0.0] * " (e 1) )
2617
+ swift6 ( "[Double](repeating: 0.0, count: Int(" (e 1) "))" )
2618
+ csharp ( "new double[" (e 1) "]" )
2619
+ }
2620
+ }
2621
+
2622
+ ; Get the length of a double_buffer
2623
+ double_buffer_length cmdDoubleBufferLength:int ( buf:double_buffer ) {
2624
+ templates {
2625
+ ranger ( "(double_buffer_length " (e 1) ")" )
2626
+ es6 ( (e 1) ".length" )
2627
+ go ( "int64(len(" (e 1) "))" )
2628
+ rust ( (e 1) ".len() as i64" )
2629
+ cpp ( "static_cast<int64_t>(" (e 1) ".size())" )
2630
+ java7 ( (e 1) ".length" )
2631
+ python ( "len(" (e 1) ")" )
2632
+ swift6 ( "Int64(" (e 1) ".count)" )
2633
+ csharp ( (e 1) ".Length" )
2634
+ }
2635
+ }
2636
+
2637
+ ; Read a double at index
2638
+ double_buffer_get cmdDoubleBufferGet:double ( buf:double_buffer index:int ) {
2639
+ templates {
2640
+ ranger ( "(double_buffer_get " (e 1) " " (e 2) ")" )
2641
+ es6 ( (e 1) "[" (e 2) "]" )
2642
+ go ( (e 1) "[" (e 2) "]" )
2643
+ rust ( (e 1) "[(" (e 2) ") as usize]" )
2644
+ cpp ( (e 1) "[" (e 2) "]" )
2645
+ java7 ( (e 1) "[(int)" (e 2) "]" )
2646
+ python ( (e 1) "[" (e 2) "]" )
2647
+ swift6 ( (e 1) "[Int(" (e 2) ")]" )
2648
+ csharp ( (e 1) "[" (e 2) "]" )
2649
+ }
2650
+ }
2651
+
2652
+ ; Write a double at index
2653
+ double_buffer_set cmdDoubleBufferSet:void ( buf:double_buffer index:int value:double ) {
2654
+ templates {
2655
+ ranger ( "(double_buffer_set " (e 1) " " (e 2) " " (e 3) ")" )
2656
+ es6 ( (e 1) "[" (e 2) "] = " (e 3) )
2657
+ go ( (e 1) "[" (e 2) "] = " (e 3) )
2658
+ rust ( (e 1) "[(" (e 2) ") as usize] = " (e 3) )
2659
+ cpp ( (e 1) "[" (e 2) "] = " (e 3) )
2660
+ java7 ( (e 1) "[(int)" (e 2) "] = " (e 3) )
2661
+ python ( (e 1) "[" (e 2) "] = " (e 3) )
2662
+ swift6 ( (e 1) "[Int(" (e 2) ")] = " (e 3) )
2663
+ csharp ( (e 1) "[" (e 2) "] = " (e 3) )
2664
+ }
2665
+ }
2666
+
2667
+ ; Fill double_buffer with a value in range [start, end)
2668
+ double_buffer_fill cmdDoubleBufferFill:void ( buf:double_buffer value:double start:int end:int ) {
2669
+ templates {
2670
+ ranger ( "(double_buffer_fill " (e 1) " " (e 2) " " (e 3) " " (e 4) ")" )
2671
+ es6 ( (e 1) ".fill(" (e 2) ", " (e 3) ", " (e 4) ")" )
2672
+ go ( "for i := " (e 3) "; i < " (e 4) "; i++ { " (e 1) "[i] = " (e 2) " }" )
2673
+ rust ( (e 1) "[" (e 3) " as usize.." (e 4) " as usize].fill(" (e 2) ")" )
2674
+ cpp ( "std::fill(" (e 1) ".begin()+" (e 3) ", " (e 1) ".begin()+" (e 4) ", " (e 2) ")" (imp "<algorithm>") )
2675
+ java7 ( "java.util.Arrays.fill(" (e 1) ", (int)" (e 3) ", (int)" (e 4) ", " (e 2) ")" )
2676
+ python ( (e 1) "[" (e 3) ":" (e 4) "] = [" (e 2) "] * (" (e 4) " - " (e 3) ")" )
2677
+ swift6 ( (e 1) ".replaceSubrange(Int(" (e 3) ")..<Int(" (e 4) "), with: repeatElement(" (e 2) ", count: Int(" (e 4) "-" (e 3) ")))" )
2678
+ csharp ( "Array.Fill(" (e 1) ", " (e 2) ", (int)" (e 3) ", (int)(" (e 4) "-" (e 3) "))" )
2679
+ }
2680
+ }
2681
+
2682
+ ; Copy doubles from source to destination
2683
+ double_buffer_copy cmdDoubleBufferCopy:void ( dest:double_buffer destOffset:int src:double_buffer srcOffset:int length:int ) {
2684
+ templates {
2685
+ ranger ( "(double_buffer_copy " (e 1) " " (e 2) " " (e 3) " " (e 4) " " (e 5) ")" )
2686
+ es6 ( (e 1) ".set(" (e 3) ".subarray(" (e 4) ", " (e 4) "+" (e 5) "), " (e 2) ")" )
2687
+ go ( "copy(" (e 1) "[" (e 2) ":], " (e 3) "[" (e 4) ":" (e 4) "+" (e 5) "])" )
2688
+ rust ( (e 1) "[" (e 2) " as usize..(" (e 2) "+" (e 5) ") as usize].copy_from_slice(&" (e 3) "[" (e 4) " as usize..(" (e 4) "+" (e 5) ") as usize])" )
2689
+ cpp ( "std::copy(" (e 3) ".begin()+" (e 4) ", " (e 3) ".begin()+" (e 4) "+" (e 5) ", " (e 1) ".begin()+" (e 2) ")" (imp "<algorithm>") )
2690
+ java7 ( "System.arraycopy(" (e 3) ", (int)" (e 4) ", " (e 1) ", (int)" (e 2) ", (int)" (e 5) ")" )
2691
+ python ( (e 1) "[" (e 2) ":" (e 2) "+" (e 5) "] = " (e 3) "[" (e 4) ":" (e 4) "+" (e 5) "]" )
2692
+ swift6 ( (e 1) ".replaceSubrange(Int(" (e 2) ")..<Int(" (e 2) "+" (e 5) "), with: " (e 3) "[Int(" (e 4) ")..<Int(" (e 4) "+" (e 5) ")])" )
2693
+ csharp ( "Array.Copy(" (e 3) ", (int)" (e 4) ", " (e 1) ", (int)" (e 2) ", (int)" (e 5) ")" )
2694
+ }
2695
+ }
2696
+
2697
+ ; TODO: double_buffer_from requires variadic argument support in Ranger operators
2698
+ ; Create double_buffer from literal values - for cleaner initialization of lookup tables
2699
+ ; Usage: def table:double_buffer (double_buffer_from 1.0 2.0 3.0 4.0)
2700
+ ; double_buffer_from cmdDoubleBufferFrom:double_buffer ( listOf:expression ) {
2701
+ ; templates {
2702
+ ; ranger ( "(double_buffer_from " (list 1) ")" )
2703
+ ; es6 ( "new Float64Array([" (comma 1) "])" )
2704
+ ; go ( "[]float64{" (comma 1) "}" )
2705
+ ; rust ( "vec![" (comma 1) "]" )
2706
+ ; cpp ( "std::vector<double>{" (comma 1) "}" (imp "<vector>") )
2707
+ ; java7 ( "new double[]{" (comma 1) "}" )
2708
+ ; python ( "[" (comma 1) "]" )
2709
+ ; swift6 ( "[" (comma 1) "] as [Double]" )
2710
+ ; csharp ( "new double[]{" (comma 1) "}" )
2711
+ ; }
2712
+ ; }
2713
+
1828
2714
  to_int cmdToInt:int ( value:double ) {
1829
2715
  templates {
1830
2716
  ranger ( "(to_int " (e 1) ")")
@@ -1895,43 +2781,48 @@ std::vector<std::string> r_str_split(std::string data, std::string token) {
1895
2781
  at _:string ( text:string position:int ) {
1896
2782
  templates {
1897
2783
  ranger ( '(at ' (e 1) ' ' ( e 2 ) ')')
1898
- cpp ( 'r_utf8_substr(' (e 1) ', ' (e 2) ', 1)'
2784
+ cpp ( 'r_utf8_char_at(' (e 1) ', ' (e 2) ')'
1899
2785
  (create_polyfill '
1900
- std::string r_utf8_substr(const std::string& str, int start_i, int leng_i)
2786
+ std::string r_utf8_char_at(const std::string& str, int pos_i)
1901
2787
  {
1902
- unsigned int start ((unsigned int)start_i);
1903
- unsigned int leng ((unsigned int)leng_i);
1904
- if (leng==0) { return ""; }
1905
- unsigned int c, i, ix, q, min= (unsigned int) std::string::npos, max=(unsigned int)std::string::npos;
2788
+ unsigned int pos ((unsigned int)pos_i);
2789
+ unsigned int c, i, ix, q;
1906
2790
  for (q=0, i=0, ix=str.length(); i < ix; i++, q++)
1907
2791
  {
1908
- if (q==start){ min=i; }
1909
- if (q<=start+leng || leng==std::string::npos){ max=i; }
2792
+ if (q==pos){
2793
+ c = (unsigned char) str[i];
2794
+ int char_len = 1;
2795
+ if(c<=127) char_len = 1;
2796
+ else if ((c & 0xE0) == 0xC0) char_len = 2;
2797
+ else if ((c & 0xF0) == 0xE0) char_len = 3;
2798
+ else if ((c & 0xF8) == 0xF0) char_len = 4;
2799
+ else return "";
2800
+ return str.substr(i, char_len);
2801
+ }
1910
2802
  c = (unsigned char) str[i];
1911
2803
  if(c<=127) i+=0;
1912
2804
  else if ((c & 0xE0) == 0xC0) i+=1;
1913
2805
  else if ((c & 0xF0) == 0xE0) i+=2;
1914
2806
  else if ((c & 0xF8) == 0xF0) i+=3;
1915
- else return ""; //invalid utf8
2807
+ else return "";
1916
2808
  }
1917
- if (q<=start+leng || leng==std::string::npos){ max=i; }
1918
- if (min==std::string::npos || max==std::string::npos) { return ""; }
1919
- return str.substr(min,max);
2809
+ return "";
1920
2810
  }
1921
- ')
1922
-
2811
+ ')
1923
2812
  )
1924
2813
  csharp ( (e 1) ".Substring(" (e 2) ", 1)")
1925
2814
  php ( "substr(" (e 1) ", " (e 2) ", 1)")
1926
2815
  java7 ( (e 1) ".substring(" (e 2) ", " (e 2) " + 1)")
1927
2816
  kotlin ( (e 1) ".substring(" (e 2) ", " (e 2) " + 1)")
1928
2817
  scala ( (e 1) "(" (e 2) ")")
1929
- go ( (e 1) "[" (e 2) ": (" (e 2) " + 1)]")
2818
+ go ( "string([]rune(" (e 1) ")[" (e 2) "])")
1930
2819
 
1931
2820
  swift3 ( (imp 'Foundation') (e 1) "[" (e 1) ".index(" (e 1) ".startIndex, offsetBy:" (e 2) ")..<" (e 1) ".index(" (e 1) ".startIndex, offsetBy:" (e 2) " + 1)]" )
2821
+ swift6 ( "String(" (e 1) "[" (e 1) ".index(" (e 1) ".startIndex, offsetBy:" (e 2) ")])" )
1932
2822
 
1933
2823
  ; swift3 ( 'Int( ( NSString(string: ' (e 1) ' ) ).character( at: ' (e 2) ' ) )')
1934
2824
  ; swift3 ( (imp 'Foundation') (e 1) '.substring(from: ' (e 1) '.index(' (e 1) '.startIndex, offsetBy: ' (e 2) ' + 1), to: ' (e 1) '.index(' (e 1) '.startIndex, offsetBy: ' (e 2) ' + 1))')
2825
+ rust ( (e 1) ".chars().nth(" (e 2) " as usize).map(|c| c.to_string()).unwrap_or_default()")
1935
2826
  * ( (e 1) '[' (e 2) ']')
1936
2827
  }
1937
2828
  }
@@ -1943,11 +2834,14 @@ std::string r_utf8_substr(const std::string& str, int start_i, int leng_i)
1943
2834
  csharp ( (e 1) "[" (e 2) "]")
1944
2835
  php ( "ord(" (e 1) "[" (e 2) "])")
1945
2836
  java7 ( "(int)" (e 1) ".charAt(" (e 2) ")")
1946
- kotlin ( (e 1) "[" (e 2) "]")
2837
+ kotlin ( (e 1) "[" (e 2) "].code")
1947
2838
  scala ( (e 1) "(" (e 2) ")")
1948
- go ( "int64(" (e 1) "[" (e 2) "])")
2839
+ go ( "int64([]rune(" (e 1) ")[" (e 2) "])")
1949
2840
  swift3 ( "Int( ( NSString(string: " (e 1) " ) ).character( at: " (e 2) " ) )")
1950
- swift3 ( "Int( String( " (e 1) ".characters[" (e 1) ".index(" (e 1) ".startIndex, offsetBy: " (e 2) ")]))!")
2841
+ swift3 ( "Int( String( " (e 1) ".characters[" (e 1) ".index(" (e 1) ".startIndex, offsetBy: " (e 2) ")]))!")
2842
+ swift6 ( "Int(" (e 1) "[" (e 1) ".index(" (e 1) ".startIndex, offsetBy: " (e 2) ")].asciiValue ?? 0)")
2843
+ python ( "ord(" (e 1) "[" (e 2) "])")
2844
+ rust ( (e 1) ".chars().nth(" (e 2) " as usize).unwrap_or('\\0') as i64")
1951
2845
  * ( (e 1) ".charCodeAt(" (e 2) " )")
1952
2846
  }
1953
2847
  }
@@ -1958,11 +2852,14 @@ std::string r_utf8_substr(const std::string& str, int start_i, int leng_i)
1958
2852
  templates {
1959
2853
  ranger ("(keys " (e 1) ")")
1960
2854
  java7 ( "new ArrayList<>(" (e 1) ".keySet())")
2855
+ kotlin ( "ArrayList(" (e 1) ".keys)")
1961
2856
  swift3 ("Array(" (e 1) ".keys)")
2857
+ swift6 ("Array(" (e 1) ".keys)")
1962
2858
  scala ( (e 1) ".keys.to[collection.mutable.ArrayBuffer]")
1963
2859
  php ("array_keys(" (e 1) ")")
1964
2860
  es6 ( "Object.keys(" (e 1) ")")
1965
2861
  csharp ( "new List<String>(" (e 1) ".Keys)")
2862
+ python ( "list(" (e 1) ".keys())" )
1966
2863
  cpp (
1967
2864
  "r_get_keys_of_map<" (r_atype 1) ">(" (e 1) ")"
1968
2865
  (create_polyfill
@@ -2028,15 +2925,18 @@ std::string r_utf8_substr(const std::string& str, int start_i, int leng_i)
2028
2925
  }
2029
2926
  if (q<=start+leng || leng==std::string::npos){ max=i; }
2030
2927
  if (min==std::string::npos || max==std::string::npos) { return ""; }
2031
- return str.substr(min,max);
2928
+ return str.substr(min, max - min);
2032
2929
  }
2033
2930
  ')
2034
2931
 
2035
2932
  )
2036
2933
  csharp ( (e 1) ".Substring(" (e 2) ", " (e 3) " - " (e 2) " )")
2037
2934
  php ( "substr(" (e 1) ", " (e 2) ", " (e 3) " - " (e 2) ")")
2038
- go ( (e 1) "[" (e 2) ":" (e 3) "]")
2935
+ go ( "string([]rune(" (e 1) ")[" (e 2) ":" (e 3) "])")
2039
2936
  swift3 ( (e 1) "[" (e 1) ".index(" (e 1) ".startIndex, offsetBy:" (e 2) ")..<" (e 1) ".index(" (e 1) ".startIndex, offsetBy:" (e 3) ")]" )
2937
+ swift6 ( "String(" (e 1) "[" (e 1) ".index(" (e 1) ".startIndex, offsetBy:" (e 2) ")..<" (e 1) ".index(" (e 1) ".startIndex, offsetBy:" (e 3) ")])" )
2938
+ python ( (e 1) "[" (e 2) ":" (e 3) "]" )
2939
+ rust ( (e 1) ".chars().skip(" (e 2) " as usize).take((" (e 3) " - " (e 2) ") as usize).collect::<String>()")
2040
2940
  * ( (e 1) ".substring(" (e 2) ", " (e 3) " )")
2041
2941
  }
2042
2942
  }
@@ -2069,8 +2969,9 @@ std::string r_utf8_substr(const std::string& str, int start_i, int leng_i)
2069
2969
  swift3 ( "(String( Character( UnicodeScalar(" (e 1) " ) )))")
2070
2970
  php ( "chr(" (e 1) ")")
2071
2971
  scala ( "(" (e 1) ".toChar)")
2072
- go ("string([] byte{byte(" (e 1) ")})")
2972
+ go ("string([]rune{rune(" (e 1) ")})")
2073
2973
  cpp ( "std::string(1, char(" (e 1) "))")
2974
+ rust ( "(char::from_u32(" (e 1) " as u32).unwrap_or('\\0').to_string())" )
2074
2975
  * ( "String.fromCharCode(" (e 1) ")")
2075
2976
  }
2076
2977
  }
@@ -2078,14 +2979,27 @@ std::string r_utf8_substr(const std::string& str, int start_i, int leng_i)
2078
2979
 
2079
2980
  strfromcode cmdStrFromCode:string ( code:int ) {
2080
2981
  templates {
2081
- ranger ( "(strfromcode " (e 1) ")"))
2982
+ ranger ( "(strfromcode " (e 1) ")")
2082
2983
  csharp ( "((char)" (e 1) ").toString()")
2083
2984
  java7 ( "(new String( Character.toChars(" (e 1) ")))")
2084
2985
  swift3 ( "(String( Character( UnicodeScalar(" (e 1) " )! )))")
2085
2986
  php ( "chr(" (e 1) ")")
2086
2987
  scala ( "(" (e 1) ".toChar)")
2087
- go ("string([] byte{byte(" (e 1) ")})")
2988
+ go ("string([]rune{rune(" (e 1) ")})")
2088
2989
  cpp ( "std::string(1, char(" (e 1) "))")
2990
+ rust ( "(char::from_u32(" (e 1) " as u32).unwrap_or('\\0').to_string())" )
2991
+ * ( "String.fromCharCode(" (e 1) ")")
2992
+ }
2993
+ }
2994
+
2995
+ ; Raw byte to string - for binary protocols like PDF WinAnsiEncoding
2996
+ ; Unlike strfromcode, this produces a single raw byte, not UTF-8 encoded
2997
+ rawbytechar cmdRawByteChar:string ( code:int ) {
2998
+ templates {
2999
+ ranger ( "(rawbytechar " (e 1) ")")
3000
+ go ("string([]byte{byte(" (e 1) ")})")
3001
+ cpp ( "std::string(1, char(" (e 1) "))")
3002
+ rust ( "String::from_utf8_lossy(&[" (e 1) " as u8]).to_string()" )
2089
3003
  * ( "String.fromCharCode(" (e 1) ")")
2090
3004
  }
2091
3005
  }
@@ -2099,7 +3013,10 @@ std::string r_utf8_substr(const std::string& str, int start_i, int leng_i)
2099
3013
  scala ( "(" (e 1) ".toString)")
2100
3014
  go ("strconv.FormatInt(" (e 1) ", 10)" (imp "strconv"))
2101
3015
  swift3 ("String(" (e 1) ")")
3016
+ swift6 ("String(" (e 1) ")")
2102
3017
  csharp ( (e 1) ".ToString()" )
3018
+ python ( "str(" (e 1) ")" )
3019
+ rust ( (e 1) ".to_string()" )
2103
3020
  * ( "(" (e 1) ".toString())")
2104
3021
  }
2105
3022
  }
@@ -2112,7 +3029,10 @@ std::string r_utf8_substr(const std::string& str, int start_i, int leng_i)
2112
3029
  php ( "strval(" (e 1) ")")
2113
3030
  scala ( "(" (e 1) ".toString)")
2114
3031
  go ("strconv.Itoa(" (e 1) ")" (imp "strconv"))
2115
- swfit3 ("String(" (e 1) ")")
3032
+ swift3 ("String(" (e 1) ")")
3033
+ swift6 ("String(" (e 1) ")")
3034
+ python ( "str(" (e 1) ")" )
3035
+ rust ( (e 1) ".to_string()" )
2116
3036
  * ( "(" (e 1) ").toString()")
2117
3037
  }
2118
3038
  }
@@ -2126,7 +3046,10 @@ std::string r_utf8_substr(const std::string& str, int start_i, int leng_i)
2126
3046
  php ( "strval(" (e 1) ")")
2127
3047
  scala ( "(" (e 1) ".toString)")
2128
3048
  go ("strconv.FormatFloat(" (e 1) ",'f', 6, 64)" (imp "strconv"))
2129
- swift3 ("String(" (e 1) ")")
3049
+ swift3 ("String(" (e 1) ")")
3050
+ swift6 ("String(" (e 1) ")")
3051
+ python ( "str(" (e 1) ")" )
3052
+ rust ( (e 1) ".to_string()" )
2130
3053
  * ( "(" (e 1) ".toString())")
2131
3054
  }
2132
3055
  }
@@ -2139,7 +3062,26 @@ std::string r_utf8_substr(const std::string& str, int start_i, int leng_i)
2139
3062
  php ( "strval(" (e 1) ")")
2140
3063
  scala ( "(" (e 1) ".toString)")
2141
3064
  go ("strconv.FormatFloat(" (e 1) ",'f', 6, 64)" (imp "strconv"))
2142
- swift3 ("String(" (e 1) ")")
3065
+ swift3 ("String(" (e 1) ")")
3066
+ swift6 ("String(" (e 1) ")")
3067
+ python ( "str(" (e 1) ")" )
3068
+ rust ( (e 1) ".to_string()" )
3069
+ * ( "(" (e 1) ".toString())")
3070
+ }
3071
+ }
3072
+
3073
+ to_string _:string ( value:boolean ) {
3074
+ templates {
3075
+ ranger ( "(to_string " (e 1) ")")
3076
+ cpp ( "(" (e 1) " ? \"true\" : \"false\")" )
3077
+ java7 ( "String.valueOf(" (e 1) " )")
3078
+ php ( "(" (e 1) " ? \"true\" : \"false\")")
3079
+ scala ( "(" (e 1) ".toString)")
3080
+ go ( "strconv.FormatBool(" (e 1) ")" (imp "strconv"))
3081
+ rust ( "(" (e 1) ".to_string())" )
3082
+ swift3 ("String(" (e 1) ")")
3083
+ swift6 ("String(" (e 1) ")")
3084
+ python ( "str(" (e 1) ")" )
2143
3085
  * ( "(" (e 1) ".toString())")
2144
3086
  }
2145
3087
  }
@@ -2223,9 +3165,11 @@ func r_str_2_i64(s string) *GoNullable {
2223
3165
  )
2224
3166
  php ( "is_numeric(" (e 1) ") ? intval(" (e 1) ") : NULL ")
2225
3167
  scala ( "Try(" (e 1) ".toInt).toOption" (imp "scala.util.Try"))
2226
- kotlin ( (e 1) ".toInt()")
2227
- swift3 ("Int(" (e 1) ")")
2228
- csharp( "Int32.Parse(" (e 1) ")" )
3168
+ kotlin ( (e 1) ".toIntOrNull()")
3169
+ swift3 ("Int(" (e 1) ")")
3170
+ swift6 ("Int(" (e 1) ")")
3171
+ csharp( "Int32.Parse(" (e 1) ")" )
3172
+ rust ( (e 1) ".parse::<i64>().ok()" )
2229
3173
  * ( "isNaN( parseInt(" (e 1) ") ) ? undefined : parseInt(" (e 1) ")")
2230
3174
  }
2231
3175
  }
@@ -2301,8 +3245,9 @@ Double _getDoubleOrNull ( String str ) {
2301
3245
  )
2302
3246
  php ( "floatval(" (e 1) ")")
2303
3247
  scala ( "Try(" (e 1) ".toDouble).toOption" (imp "scala.util.Try"))
2304
- kotlin ( (e 1) ".toDouble()")
2305
- swift3 ("Double(" (e 1) ")")
3248
+ kotlin ( (e 1) ".toDoubleOrNull()")
3249
+ swift3 ("Double(" (e 1) ")")
3250
+ rust ( (e 1) ".parse::<f64>().ok()" )
2306
3251
  * ( "isNaN( parseFloat(" (e 1) ") ) ? undefined : parseFloat(" (e 1) ")")
2307
3252
  }
2308
3253
  }
@@ -2355,6 +3300,8 @@ std::string join(const T& v, const std::string& delim) {
2355
3300
  scala ( (e 1) ".mkString(" (e 2) ")" )
2356
3301
  php ( "implode(" (e 2) ", " (e 1) ")")
2357
3302
  swift3 ( (e 1) ".joined(separator:" (e 2) ")")
3303
+ swift6 ( (e 1) ".joined(separator:" (e 2) ")")
3304
+ kotlin ( (e 1) ".joinToString(separator = " (e 2) ")" )
2358
3305
  * ( (e 1) ".join(" (e 2) ")" )
2359
3306
  }
2360
3307
  }
@@ -2370,6 +3317,7 @@ std::string join(const T& v, const std::string& delim) {
2370
3317
  php ( "array_key_exists(" (e 2) " , " (e 1) " )" )
2371
3318
  java7 ( (e 1) ".containsKey(" (e 2) ")" )
2372
3319
  kotlin ( (e 1) ".containsKey(" (e 2) ")" )
3320
+ python ( (e 2) " in " (e 1) )
2373
3321
  go (
2374
3322
 
2375
3323
  (macro (nl "func r_has_key_" (r_ktype 1) "_" (r_atype_fname 1) "( a " (typeof 1) ", key " (r_ktype 1) " ) bool { " nl I
@@ -2381,6 +3329,7 @@ std::string join(const T& v, const std::string& delim) {
2381
3329
  csharp ( (e 1) ".ContainsKey(" (e 2) ")" )
2382
3330
  scala ( (e 1) ".contains(" (e 2) ")" )
2383
3331
  swift3 ( (e 1) "[" (e 2) "] != nil" )
3332
+ swift6 ( (e 1) "[" (e 2) "] != nil" )
2384
3333
  * ( (e 1) "[" (e 2) "] != null" )
2385
3334
  }
2386
3335
  }
@@ -2460,7 +3409,8 @@ r_optional_primitive<int> cpp_get_map_int_value( std::map<" (r_ktype 1) ", int>
2460
3409
  "return res" nl
2461
3410
  i "}" nl ))
2462
3411
  "r_get_" (r_ktype 1) "_" (r_atype_fname 1) "(" (e 1) ", " (e 2) ")"
2463
- )
3412
+ )
3413
+ es6 ( "( " (e 1) ".hasOwnProperty(" (e 2) ") ? " (e 1) "[" (e 2) "] : undefined )" )
2464
3414
  * ( (e 1) "[" (e 2) "]" )
2465
3415
  }
2466
3416
  }
@@ -2469,7 +3419,7 @@ i "}" nl ))
2469
3419
  templates {
2470
3420
  ranger ( "set " (e 1) " " (e 2) " " (e 3) )
2471
3421
  java7 ( (e 1) ".set(" (e 2) ", " (e 3) ");" )
2472
- rust ( (e 1) ".insert(" (e 2) ", " (e 3) ");" )
3422
+ rust ( (e 1) "[" (e 2) " as usize] = " (e 3) ";" )
2473
3423
  scala ( (e 1) "(" (e 2) ") = " (e 3) )
2474
3424
  kotlin ( (e 1) ".set(" (e 2) ", " (e 3) ")" )
2475
3425
  php ( (e 1) "[" (e 2) "] = " (e 3) ";" )
@@ -2510,7 +3460,8 @@ i "}" nl ))
2510
3460
  cpp ( (e 1) ".at(" (e 2) ")" (imp "<vector>"))
2511
3461
  java7 ( (e 1) ".get(" (e 2) ")" )
2512
3462
  ; lift return optional type => safer
2513
- scala ( (e 1) "(" (e 2) ")" )
3463
+ scala ( (e 1) "(" (e 2) ")" )
3464
+ rust ( (e 1) "[" (e 2) " as usize].clone()" )
2514
3465
  * ( (e 1) "[" (e 2) "]" )
2515
3466
  }
2516
3467
  }
@@ -2521,6 +3472,10 @@ i "}" nl ))
2521
3472
  go ( "int64(strings.Index(" (e 1) ", " (e 2) "))" (imp "strings"))
2522
3473
  es6 ( (e 1) ".indexOf(" (e 2 ) ")" )
2523
3474
  java7 ( (e 1) ".indexOf(" (e 2 ) ")" )
3475
+ kotlin ( (e 1) ".indexOf(" (e 2) ")" )
3476
+ python ( (e 1) ".find(" (e 2) ")" )
3477
+ swift3 ( (e 1) ".range(of:" (e 2) ")?.lowerBound.encodedOffset ?? -1" )
3478
+ swift6 ( "(" (e 1) ".range(of:" (e 2) ").map { " (e 1) ".distance(from: " (e 1) ".startIndex, to: $0.lowerBound) } ?? -1)" )
2524
3479
  cpp (
2525
3480
  "r_string_index_of(" (e 1) " , " (e 2) ")"
2526
3481
  (create_polyfill
@@ -2535,9 +3490,157 @@ int r_string_index_of( std::string str, std::string key ) {
2535
3490
  " )
2536
3491
 
2537
3492
  )
3493
+ rust ( "(" (e 1) ".find(&*" (e 2) ").map(|i| i as i64).unwrap_or(-1))" )
2538
3494
  }
2539
3495
  }
2540
3496
 
3497
+ indexOfFrom cmdStringIndexFrom:int (str:string key:string startPos:int) {
3498
+ templates {
3499
+ php( "(($p = strpos(" (e 1) ", " (e 2) ", " (e 3) ")) !== false ? $p : -1)")
3500
+ go ( "func() int64 { idx := strings.Index(" (e 1) "[" (e 3) ":], " (e 2) "); if idx == -1 { return -1 }; return int64(idx) + " (e 3) " }()" (imp "strings"))
3501
+ es6 ( (e 1) ".indexOf(" (e 2 ) ", " (e 3) ")" )
3502
+ java7 ( (e 1) ".indexOf(" (e 2 ) ", (int)" (e 3) ")" )
3503
+ python ( (e 1) ".find(" (e 2) ", " (e 3) ")" )
3504
+ swift3 ( "(" (e 1) ".range(of:" (e 2) ", range: " (e 1) ".index(" (e 1) ".startIndex, offsetBy: " (e 3) ")..<" (e 1) ".endIndex).map { " (e 1) ".distance(from: " (e 1) ".startIndex, to: $0.lowerBound) } ?? -1)" )
3505
+ swift6 ( "(" (e 1) ".range(of:" (e 2) ", range: " (e 1) ".index(" (e 1) ".startIndex, offsetBy: " (e 3) ")..<" (e 1) ".endIndex).map { " (e 1) ".distance(from: " (e 1) ".startIndex, to: $0.lowerBound) } ?? -1)" )
3506
+ cpp (
3507
+ "r_string_index_of_from(" (e 1) " , " (e 2) ", " (e 3) ")"
3508
+ (create_polyfill
3509
+ "
3510
+ int r_string_index_of_from( std::string str, std::string key, int start ) {
3511
+ if (start < 0 || start >= str.length()) return -1;
3512
+ auto n = str.find( key, start );
3513
+ if (n == std::string::npos) {
3514
+ return -1;
3515
+ }
3516
+ return n;
3517
+ }
3518
+ " )
3519
+ )
3520
+ rust ( "(" (e 1) "[" (e 3) " as usize..].find(&*" (e 2) ").map(|i| (i + " (e 3) " as usize) as i64).unwrap_or(-1))" )
3521
+ ranger ( "(indexOfFrom " (e 1) " " (e 2) " " (e 3) ")")
3522
+ }
3523
+ }
3524
+
3525
+ lastIndexOf cmdStringLastIndex:int (str:string key:string) {
3526
+ templates {
3527
+ es6 ( (e 1) ".lastIndexOf(" (e 2 ) ")" )
3528
+ java7 ( (e 1) ".lastIndexOf(" (e 2 ) ")" )
3529
+ python ( (e 1) ".rfind(" (e 2) ")" )
3530
+ go ( "int64(strings.LastIndex(" (e 1) ", " (e 2) "))" (imp "strings"))
3531
+ swift3 ( "(" (e 1) ".range(of:" (e 2) ", options: .backwards).map { " (e 1) ".distance(from: " (e 1) ".startIndex, to: $0.lowerBound) } ?? -1)" )
3532
+ swift6 ( "(" (e 1) ".range(of:" (e 2) ", options: .backwards).map { " (e 1) ".distance(from: " (e 1) ".startIndex, to: $0.lowerBound) } ?? -1)" )
3533
+ php( "strrpos(" (e 1) ", " (e 2) ") !== false ? strrpos(" (e 1) ", " (e 2) ") : -1")
3534
+ cpp (
3535
+ "r_string_last_index_of(" (e 1) " , " (e 2) ")"
3536
+ (create_polyfill
3537
+ "
3538
+ int r_string_last_index_of( std::string str, std::string key ) {
3539
+ auto n = str.rfind( key );
3540
+ if (n == std::string::npos) {
3541
+ return -1;
3542
+ }
3543
+ return n;
3544
+ }
3545
+ " )
3546
+ )
3547
+ rust ( "(" (e 1) ".rfind(&*" (e 2) ").map(|i| i as i64).unwrap_or(-1))" )
3548
+ kotlin ( (e 1) ".lastIndexOf(" (e 2) ")" )
3549
+ ranger ( "(lastIndexOf " (e 1) " " (e 2) ")")
3550
+ }
3551
+ }
3552
+
3553
+ startsWith _:boolean (str:string prefix:string) {
3554
+ templates {
3555
+ ranger ( "(startsWith " (e 1) " " (e 2) ")")
3556
+ es6 ( (e 1) ".startsWith(" (e 2) ")" )
3557
+ java7 ( (e 1) ".startsWith(" (e 2) ")" )
3558
+ go ( "strings.HasPrefix(" (e 1) ", " (e 2) ")" (imp "strings"))
3559
+ php ( "substr(" (e 1) ", 0, strlen(" (e 2) ")) === " (e 2) )
3560
+ swift3 ( (e 1) ".hasPrefix(" (e 2) ")" )
3561
+ swift6 ( (e 1) ".hasPrefix(" (e 2) ")" )
3562
+ csharp ( (e 1) ".StartsWith(" (e 2) ")" )
3563
+ scala ( (e 1) ".startsWith(" (e 2) ")" )
3564
+ cpp ( (e 1) ".rfind(" (e 2) ", 0) == 0" )
3565
+ kotlin ( (e 1) ".startsWith(" (e 2) ")" )
3566
+ python ( (e 1) ".startswith(" (e 2) ")" )
3567
+ rust ( (e 1) ".starts_with(" (e 2) ")" )
3568
+ }
3569
+ }
3570
+
3571
+ endsWith _:boolean (str:string suffix:string) {
3572
+ templates {
3573
+ ranger ( "(endsWith " (e 1) " " (e 2) ")")
3574
+ es6 ( (e 1) ".endsWith(" (e 2) ")" )
3575
+ java7 ( (e 1) ".endsWith(" (e 2) ")" )
3576
+ go ( "strings.HasSuffix(" (e 1) ", " (e 2) ")" (imp "strings"))
3577
+ php ( "substr(" (e 1) ", -strlen(" (e 2) ")) === " (e 2) )
3578
+ swift3 ( (e 1) ".hasSuffix(" (e 2) ")" )
3579
+ swift6 ( (e 1) ".hasSuffix(" (e 2) ")" )
3580
+ csharp ( (e 1) ".EndsWith(" (e 2) ")" )
3581
+ scala ( (e 1) ".endsWith(" (e 2) ")" )
3582
+ rust ( (e 1) ".ends_with(" (e 2) ")" )
3583
+ cpp ( "r_string_ends_with(" (e 1) ", " (e 2) ")"
3584
+ (create_polyfill
3585
+ "
3586
+ bool r_string_ends_with(const std::string& str, const std::string& suffix) {
3587
+ if (suffix.size() > str.size()) return false;
3588
+ return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
3589
+ }
3590
+ " )
3591
+ )
3592
+ kotlin ( (e 1) ".endsWith(" (e 2) ")" )
3593
+ python ( (e 1) ".endswith(" (e 2) ")" )
3594
+ }
3595
+ }
3596
+
3597
+ contains _:boolean (str:string sub:string) {
3598
+ templates {
3599
+ ranger ( "(contains " (e 1) " " (e 2) ")")
3600
+ es6 ( (e 1) ".includes(" (e 2) ")" )
3601
+ java7 ( (e 1) ".contains(" (e 2) ")" )
3602
+ go ( "strings.Contains(" (e 1) ", " (e 2) ")" (imp "strings"))
3603
+ php ( "strpos(" (e 1) ", " (e 2) ") !== false" )
3604
+ swift3 ( (e 1) ".contains(" (e 2) ")" )
3605
+ swift6 ( (e 1) ".contains(" (e 2) ")" )
3606
+ csharp ( (e 1) ".Contains(" (e 2) ")" )
3607
+ scala ( (e 1) ".contains(" (e 2) ")" )
3608
+ cpp ( (e 1) ".find(" (e 2) ") != std::string::npos" )
3609
+ kotlin ( (e 1) ".contains(" (e 2) ")" )
3610
+ python ( (e 2) " in " (e 1) )
3611
+ rust ( (e 1) ".contains(" (e 2) ")" )
3612
+ }
3613
+ }
3614
+
3615
+ replace _:string (str:string oldStr:string newStr:string) {
3616
+ templates {
3617
+ ranger ( "(replace " (e 1) " " (e 2) " " (e 3) ")")
3618
+ es6 ( (e 1) ".replace(" (e 2) ", " (e 3) ")" )
3619
+ java7 ( (e 1) ".replace(" (e 2) ", " (e 3) ")" )
3620
+ go ( "strings.Replace(" (e 1) ", " (e 2) ", " (e 3) ", 1)" (imp "strings"))
3621
+ php ( "str_replace(" (e 2) ", " (e 3) ", " (e 1) ")" )
3622
+ swift3 ( (e 1) ".replacingOccurrences(of: " (e 2) ", with: " (e 3) ")" )
3623
+ swift6 ( (e 1) ".replacingOccurrences(of: " (e 2) ", with: " (e 3) ")" )
3624
+ csharp ( (e 1) ".Replace(" (e 2) ", " (e 3) ")" )
3625
+ scala ( (e 1) ".replace(" (e 2) ", " (e 3) ")" )
3626
+ rust ( (e 1) ".replace(" (e 2) ", " (e 3) ")" )
3627
+ cpp ( "r_string_replace(" (e 1) ", " (e 2) ", " (e 3) ")"
3628
+ (create_polyfill
3629
+ "
3630
+ std::string r_string_replace(std::string str, const std::string& from, const std::string& to) {
3631
+ size_t pos = str.find(from);
3632
+ if (pos != std::string::npos) {
3633
+ str.replace(pos, from.length(), to);
3634
+ }
3635
+ return str;
3636
+ }
3637
+ " )
3638
+ )
3639
+ kotlin ( (e 1) ".replace(" (e 2) ", " (e 3) ")" )
3640
+ python ( (e 1) ".replace(" (e 2) ", " (e 3) ", 1)" )
3641
+ }
3642
+ }
3643
+
2541
3644
  ; array function derived from scala
2542
3645
 
2543
3646
  indexOf cmdIndexOf:int ( array:[T] element:T ) {
@@ -2579,6 +3682,18 @@ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
2579
3682
  i
2580
3683
  "}" nl ) )
2581
3684
  )
3685
+ swift6( "r_index_of(arr:" (e 1) ", elem:" (e 2)")"
3686
+ (macro ("
3687
+ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
3688
+ "if let idx = arr.firstIndex(of: elem) { " nl
3689
+ " return idx " nl
3690
+ "} else { " nl
3691
+ I " return -1 " nl i
3692
+ "} " nl
3693
+ i
3694
+ "}" nl ) )
3695
+ )
3696
+ python ( (e 1) ".index(" (e 2) ") if " (e 2) " in " (e 1) " else -1" )
2582
3697
  * ( (e 1) ".indexOf(" (e 2) ")" )
2583
3698
  }
2584
3699
  }
@@ -2588,11 +3703,13 @@ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
2588
3703
  ranger ( "(remove_index " (e 1) " " (e 2) ")")
2589
3704
  cpp ( (e 1) ".erase( "(e 1)".begin() + " (e 2) " );")
2590
3705
  swift3 ( (e 1) ".remove(at:" (e 2)")")
3706
+ swift6 ( (e 1) ".remove(at:" (e 2)")")
2591
3707
  php ( "array_splice(" (e 1) ", " (e 2 )", 1);")
2592
3708
  kotlin ( (e 1) ".removeAt(" (e 2) ")" )
2593
3709
  java7 ( (e 1) ".remove(" (e 2) ")" )
2594
3710
  scala ( (e 1) ".remove(" (e 2) ")" )
2595
3711
  go ( (e 1) " = append(" (e 1) "[:" (e 2) "], " (e 1) "[" (e 2) "+1:]...)" )
3712
+ python ( (e 1) ".pop(" (e 2) ")" )
2596
3713
  * ( (e 1) ".splice(" (e 2) ", 1).pop();" )
2597
3714
  }
2598
3715
  }
@@ -2603,9 +3720,12 @@ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
2603
3720
  ranger ( nl "insert " (e 1) " " (e 2) " " (e 3) nl)
2604
3721
  es6 ( (e 1) ".splice(" (e 2) ", 0, " (e 3) ");" )
2605
3722
  cpp ( (e 1) ".insert(" (e 1) ".begin() + " (e 2) ", " (e 3) ");")
3723
+ swift6 ( (e 1) ".insert(" (e 3) ", at:" (e 2) ")")
3724
+ kotlin ( (e 1) ".add(" (e 2) ", " (e 3) ")" )
2606
3725
  go( (e 1 ) " = append(" (e 1) "[:" (e 2) "], append(" (typeof 1) "{" (e 3) "}, " (e 1) "[" (e 2) ":]...)...)")
2607
- php ( "array_splice(" (e 1) ", " (e 2) ", 0, " (e 3) ");")
2608
-
3726
+ php ( "array_splice(" (e 1) ", " (e 2) ", 0, " (e 3) ");")
3727
+ python ( (e 1) ".insert(" (e 2) ", " (e 3) ")" )
3728
+ rust ( (e 1) ".insert(" (e 2) " as usize, " (e 3) ");")
2609
3729
  }
2610
3730
  }
2611
3731
 
@@ -2613,21 +3733,55 @@ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
2613
3733
  templates {
2614
3734
  ranger ( nl "remove " (e 1) " " (e 2) nl)
2615
3735
  es6 ( (e 1) ".splice(" (e 2) ", 1);" )
3736
+ swift6 ( (e 1) ".remove(at:" (e 2) ")" )
3737
+ kotlin ( (e 1) ".removeAt(" (e 2) ")" )
2616
3738
  }
2617
- }
3739
+ }
3740
+
3741
+ ; Set value at specific index in array
3742
+ set_at cmdSetAt:void ( array@(mutates):[T] index:int value:T ) {
3743
+ templates {
3744
+ ranger ( nl "set_at " (e 1) " " (e 2) " " (e 3) nl)
3745
+ es6 ( (e 1) "[" (e 2) "] = " (e 3) ";" )
3746
+ go ( (e 1) "[" (e 2) "] = " (e 3) )
3747
+ cpp ( (e 1) "[" (e 2) "] = " (e 3) ";" )
3748
+ swift3 ( (e 1) "[" (e 2) "] = " (e 3) )
3749
+ swift6 ( (e 1) "[" (e 2) "] = " (e 3) )
3750
+ php ( (e 1) "[" (e 2) "] = " (e 3) ";" )
3751
+ python ( (e 1) "[" (e 2) "] = " (e 3) )
3752
+ java7 ( (e 1) ".set(" (e 2) ", " (e 3) ");" )
3753
+ kotlin ( (e 1) "[" (e 2) "] = " (e 3) )
3754
+ csharp ( (e 1) "[" (e 2) "] = " (e 3) ";" )
3755
+ scala ( (e 1) "(" (e 2) ") = " (e 3) )
3756
+ rust ( (e 1) "[" (e 2) " as usize] = " (e 3) ";" )
3757
+ * ( (e 1) "[" (e 2) "] = " (e 3) ";" )
3758
+ }
3759
+ }
2618
3760
 
2619
3761
  push cmdPush@(moves@( 2 1 ) ):void ( array@(mutates):[T] item:T ) {
2620
3762
  templates {
2621
3763
  ranger ( nl "push " (e 1) " " (e 2) "" nl)
2622
3764
  cpp ( (e 1) ".push_back( "(e 2)" );")
2623
3765
  swift3 ( (e 1) ".append(" (e 2)")")
3766
+ swift6 ( (e 1) ".append(" (e 2)")")
2624
3767
  php ( "array_push(" (e 1) ", " (e 2 )");")
3768
+ python ( (e 1) ".append(" (e 2) ")")
2625
3769
  java7 ( (e 1) ".add(" (e 2) ");" )
2626
3770
  go ( (custom _) )
2627
3771
  go ( (e 1) " = append(" (e 1) "," (e 2) ");" )
2628
3772
  kotlin ( (e 1) ".add(" (e 2) ");" )
2629
3773
  csharp ( (e 1) ".Add(" (e 2) ");" )
2630
3774
  scala ( (e 1) ".append(" (e 2) ")" )
3775
+ rust ( (custom _) )
3776
+ rust ( (e 1) ".push(" (e 2) ");" )
3777
+ * ( (e 1) ".push(" (e 2) ");" )
3778
+ }
3779
+ }
3780
+
3781
+ ; push for string arrays in Rust - converts &str to String
3782
+ pushString cmdPushString@(moves@( 2 1 ) ):void ( array@(mutates):[string] item:string ) {
3783
+ templates {
3784
+ rust ( (e 1) ".push(" (e 2) ".to_string());" )
2631
3785
  * ( (e 1) ".push(" (e 2) ");" )
2632
3786
  }
2633
3787
  }
@@ -2638,8 +3792,11 @@ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
2638
3792
  ranger ( "removeLast " (e 1) "")
2639
3793
  cpp ( (e 1) ".pop_back();")
2640
3794
  swift3 ( (e 1) ".removeLast();")
3795
+ swift6 ( (e 1) ".removeLast()")
2641
3796
  php ( "array_pop(" (e 1) " );")
3797
+ python ( (e 1) ".pop()")
2642
3798
  java7 ( (e 1) ".remove(" (e 1) ".size() - 1);" )
3799
+ kotlin ( (e 1) ".removeAt(" (e 1) ".size - 1)" )
2643
3800
  csharp ( "Array.Resize(ref "(e 1) ", " (e 1 )".Length - 1);" )
2644
3801
  scala ( (e 1) ".remove(" (e 1) ".length - 1)" )
2645
3802
  go ( (custom _) )
@@ -2653,7 +3810,9 @@ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
2653
3810
  ranger ( "(length " (e 1) ")")
2654
3811
  cpp ( (e 1) ".size()" )
2655
3812
  swift3 ( (e 1) ".count")
3813
+ swift6 ( (e 1) ".count")
2656
3814
  php ( "count(" (e 1) ")")
3815
+ python ( "len(" (e 1) ")")
2657
3816
  java7 ( (e 1) ".size()" )
2658
3817
  scala ( (e 1) ".length" )
2659
3818
  kotlin ( (e 1) ".size" )
@@ -2668,7 +3827,9 @@ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
2668
3827
  java7 ( (e 1) ".length()")
2669
3828
  scala ( (e 1) ".length()")
2670
3829
  swift3 ( (e 1) ".characters.count")
3830
+ swift6 ( (e 1) ".count")
2671
3831
  csharp ( (e 1) ".Length")
3832
+ python ( "len(" (e 1) ")")
2672
3833
  rust ( (e 1 ) ".len()" )
2673
3834
  go( "int64(len([]rune(" (e 1) ")))")
2674
3835
  php ( "strlen(" (e 1) ")")
@@ -2680,10 +3841,13 @@ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
2680
3841
  ranger ( "(clear " (e 1) ")")
2681
3842
  cpp ( (e 1) ".clear();" )
2682
3843
  swift3 ( (e 1) ".removeAll()")
3844
+ swift6 ( (e 1) ".removeAll()")
2683
3845
  php ( nl (e 1) " = array();" nl)
2684
3846
  java7 ( (e 1) ".clear();" )
3847
+ kotlin ( (e 1) ".clear()" )
2685
3848
  scala ( (e 1) ".clear()" )
2686
- go ( (e 1) " = nil" )
3849
+ go ( (e 1) " = " (e 1) "[:0]" )
3850
+ rust ( custom )
2687
3851
  * ( (e 1) ".length = 0;" nl )
2688
3852
  }
2689
3853
  }
@@ -2755,13 +3919,15 @@ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
2755
3919
  ranger ( "(array_length " (e 1) ")")
2756
3920
  cpp ( '(int)(' (e 1) ".size())" )
2757
3921
  swift3 ( (e 1) ".count")
3922
+ swift6 ( (e 1) ".count")
2758
3923
  php ( "count(" (e 1) ")")
2759
3924
  java7 ( (e 1) ".size()" )
2760
3925
  scala ( (e 1) ".length" )
2761
- rust ( (e 1 ) ".len()" )
3926
+ rust ( "(" (e 1 ) ".len() as i64)" )
2762
3927
  go ( "int64(len(" (e 1 ) "))" )
2763
3928
  kotlin ( (e 1) ".size" )
2764
- csharp ( (e 1) ".Count")
3929
+ csharp ( (e 1) ".Count")
3930
+ python ( "len(" (e 1) ")" )
2765
3931
  * ( (e 1) ".length" )
2766
3932
  }
2767
3933
  }
@@ -2772,6 +3938,7 @@ func r_index_of ( arr:" (typeof 1) " , elem: " (typeof 2) ") -> Int { " nl I
2772
3938
  ranger ( "(array_extract " (e 1) " " (e 2) ")")
2773
3939
  ; TODO: C++ version does not seem to have a clear functino to extrace element from std::vector
2774
3940
  swift3 ( (e 1) ".remove(at:" (e 2)")")
3941
+ swift6 ( (e 1) ".remove(at:" (e 2)")")
2775
3942
  php ( "array_splice(" (e 1) ", " (e 2 )", 1)[0]")
2776
3943
  go ( "r_m_arr_" (rawtype 1) "_extract(" (e 1) ", " (e 2 )")"
2777
3944
 
@@ -2819,16 +3986,843 @@ public <T> T _arr_extract( ArrayList<T> list, Integer i ) {
2819
3986
  go ( nl "fmt.Println( " (e 1) " )" nl (imp "fmt") )
2820
3987
  rust ( nl "println!( \"{}\", " (e 1) " );" nl )
2821
3988
  java7 ( nl "System.out.println(String.valueOf( " (e 1) " ) );" nl (imp "java.io.*"))
2822
- php ( nl "echo( " (e 1) " . \"\\n\");" nl )
3989
+ php ( nl "echo( " (e 1) " . \"\\n\");" nl )
3990
+ python ( nl "print(" (e 1) ")" nl )
2823
3991
  csharp ( nl "Console.WriteLine(" (e 1) ");" nl (imp "System"))
2824
3992
  swift3 ( nl "print(" (e 1) ")" nl)
3993
+ swift6 ( nl "print(" (e 1) ")" nl)
2825
3994
  * ( nl "console.log(" (e 1) ");" nl)
2826
3995
  }
2827
3996
  }
2828
3997
 
3998
+ ; Terminal control operators for console/shell games
3999
+ ; Write text without newline
4000
+ write cmdWrite:void ( text:string) {
4001
+ templates {
4002
+ cpp ( nl "std::cout << " (e 1) " << std::flush;" nl (imp "<iostream>"))
4003
+ go ( nl "fmt.Print( " (e 1) " )" nl (imp "fmt"))
4004
+ rust ( nl "print!(\"{}\", " (e 1) ");" nl)
4005
+ java7 ( nl "System.out.print(String.valueOf(" (e 1) "));" nl)
4006
+ kotlin ( nl "print(" (e 1) ")" nl)
4007
+ php ( nl "echo " (e 1) ";" nl)
4008
+ python ( nl "print(" (e 1) ", end='')" nl)
4009
+ csharp ( nl "Console.Write(" (e 1) ");" nl (imp "System"))
4010
+ swift3 ( nl "print(" (e 1) ", terminator: \"\")" nl)
4011
+ swift6 ( nl "print(" (e 1) ", terminator: \"\")" nl)
4012
+ * ( nl "process.stdout.write(" (e 1) ");" nl)
4013
+ }
4014
+ }
4015
+
4016
+ ; Clear the terminal screen
4017
+ clear_screen cmdClearScreen:void () {
4018
+ templates {
4019
+ cpp ( nl "std::cout << \"\\x1b[2J\\x1b[H\" << std::flush;" nl (imp "<iostream>"))
4020
+ go ( nl "fmt.Print(\"\\x1b[2J\\x1b[H\")" nl (imp "fmt"))
4021
+ rust ( nl "print!(\"\\x1b[2J\\x1b[H\");" nl)
4022
+ java7 ( nl "System.out.print(\"\\033[2J\\033[H\");" nl)
4023
+ kotlin ( nl "print(\"\\u001b[2J\\u001b[H\")" nl)
4024
+ php ( nl "echo \"\\x1b[2J\\x1b[H\";" nl)
4025
+ python ( nl "print(\"\\x1b[2J\\x1b[H\", end='')" nl)
4026
+ csharp ( nl "Console.Write(\"\\x1b[2J\\x1b[H\");" nl (imp "System"))
4027
+ swift3 ( nl "print(\"\\u{1b}[2J\\u{1b}[H\", terminator: \"\")" nl)
4028
+ swift6 ( nl "print(\"\\u{1b}[2J\\u{1b}[H\", terminator: \"\")" nl)
4029
+ * ( nl "process.stdout.write(\"\\x1b[2J\\x1b[H\");" nl)
4030
+ }
4031
+ }
4032
+
4033
+ ; Move cursor to position (1-based coordinates)
4034
+ move_cursor cmdMoveCursor:void ( x:int y:int) {
4035
+ templates {
4036
+ cpp ( nl "std::cout << \"\\x1b[\" << (" (e 2) ") << \";\" << (" (e 1) ") << \"H\" << std::flush;" nl (imp "<iostream>"))
4037
+ go ( nl "fmt.Printf(\"\\x1b[%d;%dH\", " (e 2) ", " (e 1) ")" nl (imp "fmt"))
4038
+ rust ( nl "print!(\"\\x1b[{};{}H\", " (e 2) ", " (e 1) ");" nl)
4039
+ java7 ( nl "System.out.print(\"\\033[\" + (" (e 2) ") + \";\" + (" (e 1) ") + \"H\");" nl)
4040
+ kotlin ( nl "print(\"\\u001b[\" + (" (e 2) ") + \";\" + (" (e 1) ") + \"H\")" nl)
4041
+ php ( nl "echo \"\\x1b[\" . (" (e 2) ") . \";\" . (" (e 1) ") . \"H\";" nl)
4042
+ python ( nl "print(f\"\\x1b[{" (e 2) "};{" (e 1) "}H\", end='')" nl)
4043
+ csharp ( nl "Console.Write($\"\\x1b[{" (e 2) "};{" (e 1) "}H\");" nl (imp "System"))
4044
+ swift3 ( nl "print(\"\\u{1b}[\\(" (e 2) ");\\(" (e 1) ")H\", terminator: \"\")" nl)
4045
+ swift6 ( nl "print(\"\\u{1b}[\\(" (e 2) ");\\(" (e 1) ")H\", terminator: \"\")" nl)
4046
+ * ( nl "process.stdout.write(`\\x1b[${" (e 2) "};${" (e 1) "}H`);" nl)
4047
+ }
4048
+ }
4049
+
4050
+ ; Hide terminal cursor
4051
+ hide_cursor cmdHideCursor:void () {
4052
+ templates {
4053
+ cpp ( nl "std::cout << \"\\x1b[?25l\" << std::flush;" nl (imp "<iostream>"))
4054
+ go ( nl "fmt.Print(\"\\x1b[?25l\")" nl (imp "fmt"))
4055
+ rust ( nl "print!(\"\\x1b[?25l\");" nl)
4056
+ java7 ( nl "System.out.print(\"\\033[?25l\");" nl)
4057
+ kotlin ( nl "print(\"\\u001b[?25l\")" nl)
4058
+ php ( nl "echo \"\\x1b[?25l\";" nl)
4059
+ python ( nl "print(\"\\x1b[?25l\", end='')" nl)
4060
+ csharp ( nl "Console.Write(\"\\x1b[?25l\");" nl (imp "System"))
4061
+ swift3 ( nl "print(\"\\u{1b}[?25l\", terminator: \"\")" nl)
4062
+ swift6 ( nl "print(\"\\u{1b}[?25l\", terminator: \"\")" nl)
4063
+ * ( nl "process.stdout.write(\"\\x1b[?25l\");" nl)
4064
+ }
4065
+ }
4066
+
4067
+ ; Show terminal cursor
4068
+ show_cursor cmdShowCursor:void () {
4069
+ templates {
4070
+ cpp ( nl "std::cout << \"\\x1b[?25h\" << std::flush;" nl (imp "<iostream>"))
4071
+ go ( nl "fmt.Print(\"\\x1b[?25h\")" nl (imp "fmt"))
4072
+ rust ( nl "print!(\"\\x1b[?25h\");" nl)
4073
+ java7 ( nl "System.out.print(\"\\033[?25h\");" nl)
4074
+ kotlin ( nl "print(\"\\u001b[?25h\")" nl)
4075
+ php ( nl "echo \"\\x1b[?25h\";" nl)
4076
+ python ( nl "print(\"\\x1b[?25h\", end='')" nl)
4077
+ csharp ( nl "Console.Write(\"\\x1b[?25h\");" nl (imp "System"))
4078
+ swift3 ( nl "print(\"\\u{1b}[?25h\", terminator: \"\")" nl)
4079
+ swift6 ( nl "print(\"\\u{1b}[?25h\", terminator: \"\")" nl)
4080
+ * ( nl "process.stdout.write(\"\\x1b[?25h\");" nl)
4081
+ }
4082
+ }
4083
+
4084
+ ; Listen for keyboard input - callback receives key:string
4085
+ ; Creates a global key queue/receiver that poll_keypress can use
4086
+ on_keypress cmdOnKeypress:void (keyvar:string code:block) {
4087
+ templates {
4088
+ es6 ( nl
4089
+ "global.r_key_queue = [];" nl
4090
+ "const readline = require('readline');" nl
4091
+ "readline.emitKeypressEvents(process.stdin);" nl
4092
+ "if (process.stdin.isTTY) { process.stdin.setRawMode(true); }" nl
4093
+ "process.stdin.on('keypress', (" (e 1) ", data) => {" nl I
4094
+ "if (data && data.ctrl && data.name === 'c') { process.stdout.write('\\x1b[?25h'); process.exit(); }" nl
4095
+ "if (data && data.name) { " (e 1) " = data.name; global.r_key_queue.push(" (e 1) "); }" nl
4096
+ (block 2)
4097
+ i nl "});" nl
4098
+ )
4099
+ rust ( nl
4100
+ "let (r_key_sender, r_key_receiver) = std::sync::mpsc::channel::<String>();" nl
4101
+ "*R_KEY_RECEIVER.lock().unwrap() = Some(r_key_receiver);" nl
4102
+ "std::thread::spawn(move || {" nl I
4103
+ "r_setup_raw_mode();" nl
4104
+ "loop {" nl I
4105
+ "if let Some(k) = r_read_key() {" nl I
4106
+ "if r_key_sender.send(k).is_err() { break; }" nl
4107
+ i "}" nl
4108
+ i "}" nl
4109
+ i "});" nl
4110
+ (create_polyfill "
4111
+ use std::io::Read;
4112
+ use std::sync::Mutex;
4113
+
4114
+ static R_KEY_RECEIVER: Mutex<Option<std::sync::mpsc::Receiver<String>>> = Mutex::new(None);
4115
+
4116
+ #[cfg(windows)]
4117
+ fn r_setup_raw_mode() {
4118
+ // Windows: nothing needed, we use _getch() which handles raw input
4119
+ }
4120
+
4121
+ #[cfg(unix)]
4122
+ fn r_setup_raw_mode() {
4123
+ use std::process::Command;
4124
+ let _ = Command::new(\"stty\").args([\"-F\", \"/dev/tty\", \"cbreak\", \"min\", \"1\", \"-echo\"]).status();
4125
+ }
4126
+
4127
+ #[cfg(windows)]
4128
+ fn r_read_key() -> Option<String> {
4129
+ extern \"C\" {
4130
+ fn _getch() -> i32;
4131
+ fn _kbhit() -> i32;
4132
+ }
4133
+ unsafe {
4134
+ if _kbhit() == 0 {
4135
+ std::thread::sleep(std::time::Duration::from_millis(10));
4136
+ return None;
4137
+ }
4138
+ let ch = _getch();
4139
+ if ch == 3 { // Ctrl+C
4140
+ print!(\"\\x1b[?25h\");
4141
+ std::process::exit(0);
4142
+ }
4143
+ // Handle Ctrl+key combinations (1-26 map to Ctrl+A through Ctrl+Z)
4144
+ if ch >= 1 && ch <= 26 && ch != 3 {
4145
+ let letter = (ch as u8 + 96) as char; // Convert to lowercase letter
4146
+ return Some(format!(\"ctrl+{}\", letter));
4147
+ }
4148
+ if ch == 224 || ch == 0 { // Extended key
4149
+ let ch2 = _getch();
4150
+ return match ch2 {
4151
+ 72 => Some(\"up\".to_string()),
4152
+ 80 => Some(\"down\".to_string()),
4153
+ 75 => Some(\"left\".to_string()),
4154
+ 77 => Some(\"right\".to_string()),
4155
+ 71 => Some(\"home\".to_string()),
4156
+ 79 => Some(\"end\".to_string()),
4157
+ 73 => Some(\"pageup\".to_string()),
4158
+ 81 => Some(\"pagedown\".to_string()),
4159
+ 82 => Some(\"insert\".to_string()),
4160
+ 83 => Some(\"delete\".to_string()),
4161
+ 59..=68 => Some(format!(\"f{}\", ch2 - 58)), // F1-F10
4162
+ 133 => Some(\"f11\".to_string()),
4163
+ 134 => Some(\"f12\".to_string()),
4164
+ _ => None,
4165
+ };
4166
+ }
4167
+ return match ch {
4168
+ 8 => Some(\"backspace\".to_string()),
4169
+ 9 => Some(\"tab\".to_string()),
4170
+ 13 => Some(\"enter\".to_string()),
4171
+ 27 => Some(\"escape\".to_string()),
4172
+ 32 => Some(\"space\".to_string()),
4173
+ _ => Some((ch as u8 as char).to_string()),
4174
+ };
4175
+ }
4176
+ }
4177
+
4178
+ #[cfg(unix)]
4179
+ fn r_read_key() -> Option<String> {
4180
+ let mut buffer = [0u8; 6];
4181
+ let stdin = std::io::stdin();
4182
+ let mut handle = stdin.lock();
4183
+ if handle.read(&mut buffer[0..1]).is_ok() {
4184
+ if buffer[0] == 3 { // Ctrl+C
4185
+ print!(\"\\x1b[?25h\");
4186
+ std::process::exit(0);
4187
+ }
4188
+ // Handle Ctrl+key combinations (1-26 map to Ctrl+A through Ctrl+Z)
4189
+ if buffer[0] >= 1 && buffer[0] <= 26 && buffer[0] != 3 {
4190
+ let letter = (buffer[0] + 96) as char;
4191
+ return Some(format!(\"ctrl+{}\", letter));
4192
+ }
4193
+ if buffer[0] == 27 { // Escape sequence
4194
+ if handle.read(&mut buffer[1..2]).is_ok() && buffer[1] == 91 {
4195
+ if handle.read(&mut buffer[2..3]).is_ok() {
4196
+ // Check for extended sequences like F5-F12, etc.
4197
+ if buffer[2] >= 49 && buffer[2] <= 54 {
4198
+ if handle.read(&mut buffer[3..5]).is_ok() {
4199
+ let seq = &buffer[2..5];
4200
+ return match seq {
4201
+ [49, 53, 126] => Some(\"f5\".to_string()),
4202
+ [49, 55, 126] => Some(\"f6\".to_string()),
4203
+ [49, 56, 126] => Some(\"f7\".to_string()),
4204
+ [49, 57, 126] => Some(\"f8\".to_string()),
4205
+ [50, 48, 126] => Some(\"f9\".to_string()),
4206
+ [50, 49, 126] => Some(\"f10\".to_string()),
4207
+ [50, 51, 126] => Some(\"f11\".to_string()),
4208
+ [50, 52, 126] => Some(\"f12\".to_string()),
4209
+ [50, 126, _] => Some(\"insert\".to_string()),
4210
+ [51, 126, _] => Some(\"delete\".to_string()),
4211
+ [53, 126, _] => Some(\"pageup\".to_string()),
4212
+ [54, 126, _] => Some(\"pagedown\".to_string()),
4213
+ _ => Some(\"escape\".to_string()),
4214
+ };
4215
+ }
4216
+ }
4217
+ return match buffer[2] {
4218
+ 65 => Some(\"up\".to_string()),
4219
+ 66 => Some(\"down\".to_string()),
4220
+ 67 => Some(\"right\".to_string()),
4221
+ 68 => Some(\"left\".to_string()),
4222
+ 70 => Some(\"end\".to_string()),
4223
+ 72 => Some(\"home\".to_string()),
4224
+ // F1-F4 on some terminals
4225
+ 80 => Some(\"f1\".to_string()),
4226
+ 81 => Some(\"f2\".to_string()),
4227
+ 82 => Some(\"f3\".to_string()),
4228
+ 83 => Some(\"f4\".to_string()),
4229
+ _ => Some(\"escape\".to_string()),
4230
+ };
4231
+ }
4232
+ }
4233
+ return Some(\"escape\".to_string());
4234
+ }
4235
+ return match buffer[0] {
4236
+ 8 | 127 => Some(\"backspace\".to_string()),
4237
+ 9 => Some(\"tab\".to_string()),
4238
+ 10 | 13 => Some(\"enter\".to_string()),
4239
+ 32 => Some(\"space\".to_string()),
4240
+ _ => Some((buffer[0] as char).to_string()),
4241
+ };
4242
+ }
4243
+ None
4244
+ }
4245
+ ")
4246
+ )
4247
+ python ( nl
4248
+ "_ = " (e 1) nl
4249
+ "def _keypress_listener():" nl I
4250
+ "global r_key_queue, r_key_lock" nl
4251
+ "import time" nl
4252
+ "if sys.platform == 'win32':" nl I
4253
+ "import msvcrt" nl
4254
+ "while True:" nl I
4255
+ "if msvcrt.kbhit():" nl I
4256
+ "ch = msvcrt.getch()" nl
4257
+ "if ch == b'\\x03': break" nl
4258
+ "if ch in (b'\\x00', b'\\xe0'):" nl I
4259
+ "ch2 = msvcrt.getch()" nl
4260
+ "k = {b'H': 'up', b'P': 'down', b'K': 'left', b'M': 'right'}.get(ch2, '')" nl i
4261
+ "else:" nl I
4262
+ "k = ch.decode('latin-1') if ch != b' ' else 'space'" nl i
4263
+ "if k:" nl I
4264
+ "with r_key_lock:" nl I
4265
+ "r_key_queue.append(k)" nl i i i
4266
+ "else:" nl I
4267
+ "time.sleep(0.01)" nl i i i
4268
+ "else:" nl I
4269
+ "import tty, termios" nl
4270
+ "fd = sys.stdin.fileno()" nl
4271
+ "old = termios.tcgetattr(fd)" nl
4272
+ "try:" nl I
4273
+ "tty.setraw(fd)" nl
4274
+ "while True:" nl I
4275
+ "ch = sys.stdin.read(1)" nl
4276
+ "if ch == '\\x03': break" nl
4277
+ "if ch == '\\x1b':" nl I
4278
+ "ch2 = sys.stdin.read(2)" nl
4279
+ "k = {'[A': 'up', '[B': 'down', '[C': 'right', '[D': 'left'}.get(ch2, 'escape')" nl i
4280
+ "elif ch == ' ':" nl I
4281
+ "k = 'space'" nl i
4282
+ "else:" nl I
4283
+ "k = ch" nl i
4284
+ "with r_key_lock:" nl I
4285
+ "r_key_queue.append(k)" nl i i i
4286
+ "finally:" nl I
4287
+ "termios.tcsetattr(fd, termios.TCSADRAIN, old)" nl i i i
4288
+ "threading.Thread(target=_keypress_listener, daemon=True).start()" nl
4289
+ (imp "threading")
4290
+ (imp "sys")
4291
+ (polyfill "after_imports" "
4292
+ r_key_queue = []
4293
+ r_key_lock = threading.Lock()
4294
+ ")
4295
+ )
4296
+ go ( nl
4297
+ "_ = " (e 1) nl
4298
+ "r_key_channel = make(chan string, 100)" nl
4299
+ "go func() {" nl I
4300
+ "r_setup_raw_mode()" nl
4301
+ "for {" nl I
4302
+ "if k := r_read_key(); k != \"\" {" nl I
4303
+ "r_key_channel <- k" nl
4304
+ "time.Sleep(50 * time.Millisecond)" nl
4305
+ i "}" nl
4306
+ i "}" nl i
4307
+ "}()" nl
4308
+ (imp "os")
4309
+ (imp "os/exec")
4310
+ (imp "fmt")
4311
+ (imp "runtime")
4312
+ (imp "syscall")
4313
+ (imp "time")
4314
+ (imp "unsafe")
4315
+ (polyfill "utilities" "
4316
+ var r_key_channel chan string
4317
+
4318
+ var (
4319
+ msvcrt = syscall.NewLazyDLL(\"msvcrt.dll\")
4320
+ kbhit = msvcrt.NewProc(\"_kbhit\")
4321
+ getch = msvcrt.NewProc(\"_getch\")
4322
+ )
4323
+
4324
+ var _ = unsafe.Sizeof(0) // suppress unused import
4325
+
4326
+ func r_setup_raw_mode() {
4327
+ if runtime.GOOS != \"windows\" {
4328
+ exec.Command(\"stty\", \"-F\", \"/dev/tty\", \"cbreak\", \"min\", \"1\").Run()
4329
+ exec.Command(\"stty\", \"-F\", \"/dev/tty\", \"-echo\").Run()
4330
+ }
4331
+ }
4332
+
4333
+ func r_read_key() string {
4334
+ if runtime.GOOS == \"windows\" {
4335
+ ret, _, _ := kbhit.Call()
4336
+ if ret == 0 {
4337
+ time.Sleep(10 * time.Millisecond)
4338
+ return \"\"
4339
+ }
4340
+ ch, _, _ := getch.Call()
4341
+ if ch == 3 { // Ctrl+C
4342
+ fmt.Print(\"\\x1b[?25h\")
4343
+ os.Exit(0)
4344
+ }
4345
+ if ch == 224 || ch == 0 { // Extended key
4346
+ ch2, _, _ := getch.Call()
4347
+ switch ch2 {
4348
+ case 72:
4349
+ return \"up\"
4350
+ case 80:
4351
+ return \"down\"
4352
+ case 75:
4353
+ return \"left\"
4354
+ case 77:
4355
+ return \"right\"
4356
+ }
4357
+ return \"\"
4358
+ }
4359
+ switch ch {
4360
+ case 8:
4361
+ return \"backspace\"
4362
+ case 9:
4363
+ return \"tab\"
4364
+ case 13:
4365
+ return \"enter\"
4366
+ case 27:
4367
+ return \"escape\"
4368
+ case 32:
4369
+ return \"space\"
4370
+ }
4371
+ return string(rune(ch))
4372
+ }
4373
+ var b []byte = make([]byte, 3)
4374
+ n, err := os.Stdin.Read(b[:1])
4375
+ if err != nil || n == 0 {
4376
+ return \"\"
4377
+ }
4378
+ if b[0] == 3 { // Ctrl+C
4379
+ fmt.Print(\"\\x1b[?25h\")
4380
+ os.Exit(0)
4381
+ }
4382
+ if b[0] == 27 { // Escape sequence
4383
+ os.Stdin.Read(b[1:3])
4384
+ if b[1] == 91 {
4385
+ switch b[2] {
4386
+ case 65:
4387
+ return \"up\"
4388
+ case 66:
4389
+ return \"down\"
4390
+ case 67:
4391
+ return \"right\"
4392
+ case 68:
4393
+ return \"left\"
4394
+ }
4395
+ }
4396
+ return \"escape\"
4397
+ }
4398
+ switch b[0] {
4399
+ case 8, 127:
4400
+ return \"backspace\"
4401
+ case 9:
4402
+ return \"tab\"
4403
+ case 10, 13:
4404
+ return \"enter\"
4405
+ case 32:
4406
+ return \"space\"
4407
+ }
4408
+ return string(b[0])
4409
+ }
4410
+ ")
4411
+ )
4412
+ cpp ( nl
4413
+ "std::thread([]() {" nl I
4414
+ "r_setup_raw_mode();" nl
4415
+ "while (true) {" nl I
4416
+ "std::string k = r_read_key();" nl
4417
+ "if (!k.empty()) {" nl I
4418
+ "{" nl I
4419
+ "std::lock_guard<std::mutex> lock(r_key_mutex);" nl
4420
+ "r_key_queue.push(k);" nl
4421
+ i "}" nl
4422
+ "std::this_thread::sleep_for(std::chrono::milliseconds(50));" nl
4423
+ i "}" nl
4424
+ i "}" nl i
4425
+ "}).detach();" nl
4426
+ (imp "<thread>")
4427
+ (imp "<mutex>")
4428
+ (imp "<queue>")
4429
+ (polyfill "utilities" "
4430
+ #include <string>
4431
+ #include <queue>
4432
+ #include <mutex>
4433
+ #include <thread>
4434
+ #include <chrono>
4435
+
4436
+ std::queue<std::string> r_key_queue;
4437
+ std::mutex r_key_mutex;
4438
+
4439
+ #ifdef _WIN32
4440
+ #include <conio.h>
4441
+ void r_setup_raw_mode() {}
4442
+ std::string r_read_key() {
4443
+ if (!_kbhit()) {
4444
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
4445
+ return \"\";
4446
+ }
4447
+ int ch = _getch();
4448
+ if (ch == 3) { std::cout << \"\\x1b[?25h\"; exit(0); }
4449
+ if (ch == 224 || ch == 0) {
4450
+ int ch2 = _getch();
4451
+ switch (ch2) {
4452
+ case 72: return \"up\";
4453
+ case 80: return \"down\";
4454
+ case 75: return \"left\";
4455
+ case 77: return \"right\";
4456
+ }
4457
+ return \"\";
4458
+ }
4459
+ switch (ch) {
4460
+ case 8: return \"backspace\";
4461
+ case 9: return \"tab\";
4462
+ case 13: return \"enter\";
4463
+ case 27: return \"escape\";
4464
+ case 32: return \"space\";
4465
+ }
4466
+ return std::string(1, (char)ch);
4467
+ }
4468
+ #else
4469
+ #include <termios.h>
4470
+ #include <unistd.h>
4471
+ void r_setup_raw_mode() {
4472
+ system(\"stty cbreak min 1 -echo\");
4473
+ }
4474
+ std::string r_read_key() {
4475
+ char buf[3];
4476
+ if (read(STDIN_FILENO, buf, 1) <= 0) return \"\";
4477
+ if (buf[0] == 3) { std::cout << \"\\x1b[?25h\"; exit(0); }
4478
+ if (buf[0] == 27) {
4479
+ read(STDIN_FILENO, buf+1, 2);
4480
+ if (buf[1] == 91) {
4481
+ switch (buf[2]) {
4482
+ case 65: return \"up\";
4483
+ case 66: return \"down\";
4484
+ case 67: return \"right\";
4485
+ case 68: return \"left\";
4486
+ }
4487
+ }
4488
+ return \"escape\";
4489
+ }
4490
+ switch (buf[0]) {
4491
+ case 8: case 127: return \"backspace\";
4492
+ case 9: return \"tab\";
4493
+ case 10: case 13: return \"enter\";
4494
+ case 32: return \"space\";
4495
+ }
4496
+ return std::string(1, buf[0]);
4497
+ }
4498
+ #endif
4499
+ ")
4500
+ )
4501
+ swift3 ( nl
4502
+ "_ = " (e 1) nl
4503
+ "r_key_channel = DispatchQueue(label: \"keypress\")" nl
4504
+ "r_key_channel!.async {" nl I
4505
+ "r_setup_raw_mode()" nl
4506
+ "while true {" nl I
4507
+ "if let k = r_read_key(), !k.isEmpty {" nl I
4508
+ "r_key_queue_lock.lock()" nl
4509
+ "r_key_queue.append(k)" nl
4510
+ "r_key_queue_lock.unlock()" nl
4511
+ "Thread.sleep(forTimeInterval: 0.05)" nl
4512
+ i "}" nl
4513
+ i "}" nl i
4514
+ "}" nl
4515
+ (imp "Foundation")
4516
+ (polyfill "after_imports" "
4517
+ var r_key_channel: DispatchQueue? = nil
4518
+ var r_key_queue: [String] = []
4519
+ var r_key_queue_lock = NSLock()
4520
+
4521
+ func r_setup_raw_mode() {
4522
+ let _ = system(\"stty cbreak min 1 -echo\")
4523
+ }
4524
+
4525
+ func r_read_key() -> String? {
4526
+ var buf = [UInt8](repeating: 0, count: 3)
4527
+ let n = read(STDIN_FILENO, &buf, 1)
4528
+ if n <= 0 { return nil }
4529
+ if buf[0] == 3 { // Ctrl+C
4530
+ print(\"\\u{1b}[?25h\", terminator: \"\")
4531
+ exit(0)
4532
+ }
4533
+ if buf[0] == 27 { // Escape sequence
4534
+ let _ = read(STDIN_FILENO, &buf[1], 2)
4535
+ if buf[1] == 91 {
4536
+ switch buf[2] {
4537
+ case 65: return \"up\"
4538
+ case 66: return \"down\"
4539
+ case 67: return \"right\"
4540
+ case 68: return \"left\"
4541
+ default: break
4542
+ }
4543
+ }
4544
+ return \"escape\"
4545
+ }
4546
+ switch buf[0] {
4547
+ case 8, 127: return \"backspace\"
4548
+ case 9: return \"tab\"
4549
+ case 10, 13: return \"enter\"
4550
+ case 32: return \"space\"
4551
+ default: return String(UnicodeScalar(buf[0]))
4552
+ }
4553
+ }
4554
+ ")
4555
+ )
4556
+ swift6 ( nl
4557
+ "_ = " (e 1) nl
4558
+ "r_key_channel = DispatchQueue(label: \"keypress\")" nl
4559
+ "r_key_channel!.async {" nl I
4560
+ "r_setup_raw_mode()" nl
4561
+ "while true {" nl I
4562
+ "if let k = r_read_key(), !k.isEmpty {" nl I
4563
+ "r_key_queue_lock.lock()" nl
4564
+ "r_key_queue.append(k)" nl
4565
+ "r_key_queue_lock.unlock()" nl
4566
+ i "}" nl
4567
+ "Thread.sleep(forTimeInterval: 0.01)" nl
4568
+ i "}" nl i
4569
+ "}" nl
4570
+ (imp "Foundation")
4571
+ (polyfill "after_imports" "
4572
+ var r_key_channel: DispatchQueue? = nil
4573
+ var r_key_queue: [String] = []
4574
+ var r_key_queue_lock = NSLock()
4575
+
4576
+ #if os(Windows)
4577
+ @_silgen_name(\"_kbhit\") func _kbhit() -> Int32
4578
+ @_silgen_name(\"_getch\") func _getch() -> Int32
4579
+
4580
+ func r_setup_raw_mode() {
4581
+ // No setup needed on Windows
4582
+ }
4583
+
4584
+ func r_read_key() -> String? {
4585
+ if _kbhit() == 0 { return nil }
4586
+ let ch = _getch()
4587
+ if ch == 3 { // Ctrl+C
4588
+ print(\"\\u{1b}[?25h\", terminator: \"\")
4589
+ exit(0)
4590
+ }
4591
+ if ch == 224 || ch == 0 { // Extended key
4592
+ let ch2 = _getch()
4593
+ switch ch2 {
4594
+ case 72: return \"up\"
4595
+ case 80: return \"down\"
4596
+ case 75: return \"left\"
4597
+ case 77: return \"right\"
4598
+ default: return \"\"
4599
+ }
4600
+ }
4601
+ switch ch {
4602
+ case 8: return \"backspace\"
4603
+ case 9: return \"tab\"
4604
+ case 13: return \"enter\"
4605
+ case 27: return \"escape\"
4606
+ case 32: return \"space\"
4607
+ default: return String(UnicodeScalar(UInt8(ch)))
4608
+ }
4609
+ }
4610
+ #else
4611
+ func r_setup_raw_mode() {
4612
+ let _ = system(\"stty cbreak min 1 -echo\")
4613
+ }
4614
+
4615
+ func r_read_key() -> String? {
4616
+ var buf = [UInt8](repeating: 0, count: 3)
4617
+ let n = read(STDIN_FILENO, &buf, 1)
4618
+ if n <= 0 { return nil }
4619
+ if buf[0] == 3 { // Ctrl+C
4620
+ print(\"\\u{1b}[?25h\", terminator: \"\")
4621
+ exit(0)
4622
+ }
4623
+ if buf[0] == 27 { // Escape sequence
4624
+ let _ = read(STDIN_FILENO, &buf[1], 2)
4625
+ if buf[1] == 91 {
4626
+ switch buf[2] {
4627
+ case 65: return \"up\"
4628
+ case 66: return \"down\"
4629
+ case 67: return \"right\"
4630
+ case 68: return \"left\"
4631
+ default: break
4632
+ }
4633
+ }
4634
+ return \"escape\"
4635
+ }
4636
+ switch buf[0] {
4637
+ case 8, 127: return \"backspace\"
4638
+ case 9: return \"tab\"
4639
+ case 10, 13: return \"enter\"
4640
+ case 32: return \"space\"
4641
+ default: return String(UnicodeScalar(buf[0]))
4642
+ }
4643
+ }
4644
+ #endif
4645
+ ")
4646
+ )
4647
+ kotlin ( nl
4648
+ "r_key_channel = java.util.concurrent.LinkedBlockingQueue<String>()" nl
4649
+ "Thread {" nl I
4650
+ "r_setup_raw_mode()" nl
4651
+ "while (true) {" nl I
4652
+ "val k = r_read_key()" nl
4653
+ "if (k.isNotEmpty()) {" nl I
4654
+ "r_key_channel?.offer(k)" nl
4655
+ i "}" nl
4656
+ i "}" nl i
4657
+ "}.start()" nl
4658
+ (polyfill "after_imports" "
4659
+ var r_key_channel: java.util.concurrent.BlockingQueue<String>? = null
4660
+ var r_windows_key_process: Process? = null
4661
+ var r_windows_key_reader: java.io.BufferedReader? = null
4662
+
4663
+ fun r_setup_raw_mode() {
4664
+ val os = System.getProperty(\"os.name\").lowercase()
4665
+ if (os.contains(\"win\")) {
4666
+ // Start a persistent PowerShell process for reading keys
4667
+ val pb = ProcessBuilder(\"powershell\", \"-NoProfile\", \"-Command\",
4668
+ \"[Console]::TreatControlCAsInput = \\$true; while(\\$true) { \\$k = \\$host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); [Console]::WriteLine(\\$k.VirtualKeyCode) }\")
4669
+ pb.redirectErrorStream(true)
4670
+ r_windows_key_process = pb.start()
4671
+ r_windows_key_reader = r_windows_key_process?.inputStream?.bufferedReader()
4672
+ } else {
4673
+ Runtime.getRuntime().exec(arrayOf(\"/bin/sh\", \"-c\", \"stty -F /dev/tty cbreak min 1 -echo\"))
4674
+ }
4675
+ // Add shutdown hook to restore cursor
4676
+ Runtime.getRuntime().addShutdownHook(Thread {
4677
+ print(\"\\u001b[?25h\")
4678
+ r_windows_key_process?.destroyForcibly()
4679
+ })
4680
+ }
4681
+
4682
+ fun r_read_key(): String {
4683
+ val os = System.getProperty(\"os.name\").lowercase()
4684
+ if (os.contains(\"win\")) {
4685
+ // Read from persistent PowerShell process (blocks until key available)
4686
+ try {
4687
+ val reader = r_windows_key_reader ?: return \"\"
4688
+ val line = reader.readLine() ?: return \"\"
4689
+ val code = line.trim().toIntOrNull() ?: return \"\"
4690
+ if (code == 3 || code == 67) { // Ctrl+C check
4691
+ print(\"\\u001b[?25h\")
4692
+ r_windows_key_process?.destroyForcibly()
4693
+ System.exit(0)
4694
+ }
4695
+ return when (code) {
4696
+ 38 -> \"up\"
4697
+ 40 -> \"down\"
4698
+ 37 -> \"left\"
4699
+ 39 -> \"right\"
4700
+ 32 -> \"space\"
4701
+ 13 -> \"enter\"
4702
+ 27 -> \"escape\"
4703
+ 8 -> \"backspace\"
4704
+ 9 -> \"tab\"
4705
+ else -> if (code in 65..90) code.toChar().lowercase() else \"\"
4706
+ }
4707
+ } catch (e: Exception) { return \"\" }
4708
+ } else {
4709
+ // Unix: read from stdin
4710
+ try {
4711
+ val buf = ByteArray(3)
4712
+ val n = System.`in`.read(buf, 0, 1)
4713
+ if (n <= 0) return \"\"
4714
+ if (buf[0].toInt() == 3) { // Ctrl+C
4715
+ print(\"\\u001b[?25h\")
4716
+ System.exit(0)
4717
+ }
4718
+ if (buf[0].toInt() == 27) { // Escape sequence
4719
+ System.`in`.read(buf, 1, 2)
4720
+ if (buf[1].toInt() == 91) {
4721
+ return when (buf[2].toInt()) {
4722
+ 65 -> \"up\"
4723
+ 66 -> \"down\"
4724
+ 67 -> \"right\"
4725
+ 68 -> \"left\"
4726
+ else -> \"escape\"
4727
+ }
4728
+ }
4729
+ return \"escape\"
4730
+ }
4731
+ return when (buf[0].toInt()) {
4732
+ 8, 127 -> \"backspace\"
4733
+ 9 -> \"tab\"
4734
+ 10, 13 -> \"enter\"
4735
+ 32 -> \"space\"
4736
+ else -> buf[0].toInt().toChar().toString()
4737
+ }
4738
+ } catch (e: Exception) { return \"\" }
4739
+ }
4740
+ }
4741
+ ")
4742
+ )
4743
+ * ( nl "// on_keypress not implemented for this target" nl)
4744
+ }
4745
+ }
4746
+
4747
+ ; Poll for keypress (non-blocking, for use in game loops)
4748
+ ; Returns empty string if no key is available
4749
+ poll_keypress cmdPollKey:string () {
4750
+ templates {
4751
+ es6 ( "(global.r_key_queue && global.r_key_queue.length > 0 ? global.r_key_queue.shift() : \"\")" )
4752
+ rust (
4753
+ "{" nl I
4754
+ "if let Some(ref recv) = *R_KEY_RECEIVER.lock().unwrap() {" nl I
4755
+ "recv.try_recv().unwrap_or_default()" nl
4756
+ i "} else { String::new() }" nl
4757
+ i "}"
4758
+ )
4759
+ go (
4760
+ "func() string { select { case k := <-r_key_channel: return k; default: return \"\" } }()"
4761
+ )
4762
+ cpp (
4763
+ "[&]() -> std::string { std::lock_guard<std::mutex> lock(r_key_mutex); if (r_key_queue.empty()) return \"\"; std::string k = r_key_queue.front(); r_key_queue.pop(); return k; }()"
4764
+ )
4765
+ python (
4766
+ "(r_key_queue.pop(0) if r_key_queue else \"\")"
4767
+ )
4768
+ swift3 (
4769
+ "{ () -> String in r_key_queue_lock.lock(); defer { r_key_queue_lock.unlock() }; if r_key_queue.isEmpty { return \"\" }; return r_key_queue.removeFirst() }()"
4770
+ )
4771
+ swift6 (
4772
+ "{ () -> String in r_key_queue_lock.lock(); defer { r_key_queue_lock.unlock() }; if r_key_queue.isEmpty { return \"\" }; return r_key_queue.removeFirst() }()"
4773
+ )
4774
+ kotlin (
4775
+ "(r_key_channel?.poll() ?: \"\")"
4776
+ )
4777
+ * ( "\"\"" )
4778
+ }
4779
+ }
4780
+
4781
+ ; Sleep for specified milliseconds (blocking)
4782
+ sleep_ms cmdSleepMs@(async):void (ms:int) {
4783
+ templates {
4784
+ es6 ( nl "await new Promise(r => setTimeout(r, " (e 1) "));" nl )
4785
+ rust ( nl "std::thread::sleep(std::time::Duration::from_millis(" (e 1) " as u64));" nl )
4786
+ go ( nl "time.Sleep(time.Duration(" (e 1) ") * time.Millisecond)" nl (imp "time"))
4787
+ cpp ( nl "std::this_thread::sleep_for(std::chrono::milliseconds(" (e 1) "));" nl (imp "<chrono>") (imp "<thread>"))
4788
+ java7 ( nl "try { Thread.sleep(" (e 1) "); } catch (InterruptedException e) {}" nl )
4789
+ kotlin ( nl "Thread.sleep(" (e 1) ".toLong())" nl )
4790
+ python ( nl "time.sleep(" (e 1) " / 1000.0)" nl (imp "time"))
4791
+ csharp ( nl "System.Threading.Thread.Sleep(" (e 1) ");" nl )
4792
+ php ( nl "usleep(" (e 1) " * 1000);" nl )
4793
+ swift3 ( nl "usleep(UInt32(" (e 1) " * 1000))" nl )
4794
+ swift6 ( nl "Thread.sleep(forTimeInterval: Double(" (e 1) ") / 1000.0)" nl (imp "Foundation"))
4795
+ * ( nl "// sleep_ms not implemented" nl )
4796
+ }
4797
+ }
4798
+
4799
+ exit cmdExit:void ( code:int) {
4800
+ templates {
4801
+ ranger ( nl "exit " (e 1) nl)
4802
+ cpp ( nl "exit(" (e 1) ");" nl (imp "<cstdlib>"))
4803
+ kotlin ( nl "System.exit(" (e 1) ")" nl )
4804
+ scala ( nl "System.exit(" (e 1) ")" nl )
4805
+ go ( nl "os.Exit(" (e 1) ")" nl (imp "os"))
4806
+ rust ( nl "std::process::exit(" (e 1) ");" nl )
4807
+ java7 ( nl "System.exit(" (e 1) ");" nl )
4808
+ php ( nl "exit(" (e 1) ");" nl )
4809
+ python ( nl "sys.exit(" (e 1) ")" nl (imp "sys"))
4810
+ csharp ( nl "Environment.Exit(" (e 1) ");" nl (imp "System"))
4811
+ swift3 ( nl "exit(Int32(" (e 1) "))" nl (imp "Foundation"))
4812
+ * ( nl "process.exit(" (e 1) ");" nl)
4813
+ }
4814
+ }
4815
+
2829
4816
  to_lowercase _:string (s:string) {
2830
4817
  templates {
2831
4818
  es6 ((e 1) '.toLowerCase()')
4819
+ java7 ((e 1) '.toLowerCase()')
4820
+ go ( "strings.ToLower(" (e 1) ")" (imp "strings"))
4821
+ php ("strtolower(" (e 1) ")")
4822
+ csharp ((e 1) ".ToLower()")
4823
+ swift3 ((e 1) ".lowercased()")
4824
+ scala ((e 1) ".toLowerCase()")
4825
+ python ((e 1) ".lower()")
2832
4826
  }
2833
4827
  }
2834
4828
  to_uppercase _:string (s:string) {
@@ -2840,6 +4834,7 @@ public <T> T _arr_extract( ArrayList<T> list, Integer i ) {
2840
4834
  java7 ( (e 1) ".toUpperCase()")
2841
4835
  php( "strtoupper(" (e 1) ")")
2842
4836
  csharp ( (e 1) ".ToUpper()" )
4837
+ python ( (e 1) ".upper()" )
2843
4838
  cpp (
2844
4839
  "r_cpp_str_to_uppercase(" (e 1) ")"
2845
4840
  (imp "<algorithm>")
@@ -2872,6 +4867,7 @@ std::string r_cpp_str_to_uppercase(std::string original)
2872
4867
  java7 ("Double.valueOf(" (e 1) ")")
2873
4868
  cpp ("(double)(" (e 1) ")")
2874
4869
  php ( (e 1) )
4870
+ rust ("(" (e 1) " as f64)")
2875
4871
  }
2876
4872
  }
2877
4873
 
@@ -3045,6 +5041,7 @@ std::string r_cpp_str_to_uppercase(std::string original)
3045
5041
  go ( "" (e 1) ".has_value && " "" (e 2) ".has_value")
3046
5042
  cpp ( "" (e 1) "!= NULL && " "" (e 2) " != NULL")
3047
5043
  kotlin ( (e 1) " != null && " (e 2) " != null")
5044
+ python ( '(' (e 1) " is not None and " (e 2) " is not None)")
3048
5045
 
3049
5046
  * ( "typeof(" ( e 1 ) ") != \"undefined\" && typeof(" ( e 2 ) ") != \"undefined\"" )
3050
5047
  }
@@ -3062,6 +5059,7 @@ std::string r_cpp_str_to_uppercase(std::string original)
3062
5059
  go ( (e 1) " && " "" (e 2) ".has_value")
3063
5060
  cpp ( (e 1) " && " "" (e 2) "!= NULL ")
3064
5061
  kotlin ( (e 1) " && " (e 2) " != null")
5062
+ python ( (e 1) " and " (e 2) " is not None")
3065
5063
  cpp (e 1) " && " (e 2)
3066
5064
  * ( (e 1) " && " "typeof(" ( e 2 ) ") != \"undefined\"")
3067
5065
  }
@@ -3079,6 +5077,7 @@ std::string r_cpp_str_to_uppercase(std::string original)
3079
5077
  go ( "" (e 1) ".has_value && " (e 2) )
3080
5078
  cpp ( "" (e 1) " != NULL && " (e 2) )
3081
5079
  kotlin ( ""(e 1) " != null && " (e 2) )
5080
+ python ( (e 1) " is not None and " (e 2) )
3082
5081
  cpp (e 1) " && " (e 2)
3083
5082
  * ( "typeof(" ( e 1 ) ") != \"undefined\"" " && " (e 2) )
3084
5083
  }
@@ -3086,22 +5085,293 @@ std::string r_cpp_str_to_uppercase(std::string original)
3086
5085
 
3087
5086
 
3088
5087
 
3089
- && cmdLogicAnd:boolean ( left:boolean right:boolean ) { templates { * ( (e 1) " && " (e 2) ) } }
3090
- && cmdLogicAnd:boolean ( p1:boolean p2:boolean p3:boolean) { templates { * ( (e 1) " && " (e 2) " && " (e 3) ) } }
3091
- && cmdLogicAnd:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean ) { templates { * ( (e 1) " && " (e 2) " && " (e 3) " && " (e 4) ) } }
3092
- && cmdLogicAnd:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean p5:boolean ) { templates { * ( (e 1) " && " (e 2) " && " (e 3) " && " (e 4) " && " (e 5) ) } }
5088
+ && cmdLogicAnd:boolean ( left:boolean right:boolean ) {
5089
+ templates {
5090
+ python ( (e 1) " and " (e 2) )
5091
+ * ( (e 1) " && " (e 2) )
5092
+ }
5093
+ }
5094
+ && cmdLogicAnd:boolean ( p1:boolean p2:boolean p3:boolean) {
5095
+ templates {
5096
+ python ( (e 1) " and " (e 2) " and " (e 3) )
5097
+ * ( (e 1) " && " (e 2) " && " (e 3) )
5098
+ }
5099
+ }
5100
+ && cmdLogicAnd:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean ) {
5101
+ templates {
5102
+ python ( (e 1) " and " (e 2) " and " (e 3) " and " (e 4) )
5103
+ * ( (e 1) " && " (e 2) " && " (e 3) " && " (e 4) )
5104
+ }
5105
+ }
5106
+ && cmdLogicAnd:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean p5:boolean ) {
5107
+ templates {
5108
+ python ( (e 1) " and " (e 2) " and " (e 3) " and " (e 4) " and " (e 5) )
5109
+ * ( (e 1) " && " (e 2) " && " (e 3) " && " (e 4) " && " (e 5) )
5110
+ }
5111
+ }
3093
5112
  && cmdLogicAnd:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean p5:boolean p6:boolean ) { templates { * ( (e 1) " && " (e 2) " && " (e 3) " && " (e 4) " && " (e 5) " && " (e 6) ) } }
3094
5113
  && cmdLogicAnd:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean p5:boolean p6:boolean p7:boolean ) { templates { * ( (e 1) " && " (e 2) " && " (e 3) " && " (e 4) " && " (e 5) " && " (e 6) " && " (e 7) ) } }
3095
5114
 
3096
- || cmdLogicOr:boolean ( left:boolean right:boolean ) { templates { * ( (e 1) " || " (e 2) ) } }
3097
- || cmdLogicOr:boolean ( p1:boolean p2:boolean p3:boolean ) { templates { * ( (e 1) " || " (e 2) " || " (e 3) ) } }
3098
- || cmdLogicOr:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean ) { templates { * ( (e 1) " || " (e 2) " || " (e 3) " || " (e 4) ) } }
3099
- || cmdLogicOr:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean p5:boolean ) { templates { * ( (e 1) " || " (e 2) " || " (e 3) " || " (e 4) " || " (e 5) ) } }
3100
- || cmdLogicOr:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean p5:boolean p6:boolean ) { templates { * ( (e 1) " || " (e 2) " || " (e 3) " || " (e 4) " || " (e 5) " || " (e 6) ) } }
5115
+ || cmdLogicOr:boolean ( left:boolean right:boolean ) {
5116
+ templates {
5117
+ python ( (e 1) " or " (e 2) )
5118
+ * ( (e 1) " || " (e 2) )
5119
+ }
5120
+ }
5121
+ || cmdLogicOr:boolean ( p1:boolean p2:boolean p3:boolean ) {
5122
+ templates {
5123
+ python ( (e 1) " or " (e 2) " or " (e 3) )
5124
+ * ( (e 1) " || " (e 2) " || " (e 3) )
5125
+ }
5126
+ }
5127
+ || cmdLogicOr:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean ) {
5128
+ templates {
5129
+ python ( (e 1) " or " (e 2) " or " (e 3) " or " (e 4) )
5130
+ * ( (e 1) " || " (e 2) " || " (e 3) " || " (e 4) )
5131
+ }
5132
+ }
5133
+ || cmdLogicOr:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean p5:boolean ) {
5134
+ templates {
5135
+ python ( (e 1) " or " (e 2) " or " (e 3) " or " (e 4) " or " (e 5) )
5136
+ * ( (e 1) " || " (e 2) " || " (e 3) " || " (e 4) " || " (e 5) )
5137
+ }
5138
+ }
5139
+ || cmdLogicOr:boolean ( p1:boolean p2:boolean p3:boolean p4:boolean p5:boolean p6:boolean ) {
5140
+ templates {
5141
+ python ( (e 1) " or " (e 2) " or " (e 3) " or " (e 4) " or " (e 5) " or " (e 6) )
5142
+ * ( (e 1) " || " (e 2) " || " (e 3) " || " (e 4) " || " (e 5) " || " (e 6) )
5143
+ }
5144
+ }
5145
+
5146
+ ; ============================================================================
5147
+ ; HTTP Request Operators
5148
+ ; ============================================================================
5149
+
5150
+ http_get_method cmdHttpGetMethod:string (req:HttpRequest) {
5151
+ templates {
5152
+ go ( (e 1) ".Method" )
5153
+ es6 ( (e 1) ".method" )
5154
+ * ( "/* http_get_method not implemented */" )
5155
+ }
5156
+ }
5157
+
5158
+ http_get_path cmdHttpGetPath:string (req:HttpRequest) {
5159
+ templates {
5160
+ go ( (e 1) ".URL.Path" )
5161
+ es6 ( (e 1) ".url" )
5162
+ * ( "/* http_get_path not implemented */" )
5163
+ }
5164
+ }
5165
+
5166
+ http_get_param cmdHttpGetParam:string (req:HttpRequest name:string) {
5167
+ templates {
5168
+ go ( (e 1) ".PathValue(" (e 2) ")" )
5169
+ es6 ( (e 1) ".params[" (e 2) "]" )
5170
+ * ( "/* http_get_param not implemented */" )
5171
+ }
5172
+ }
5173
+
5174
+ http_get_query cmdHttpGetQuery:string (req:HttpRequest name:string) {
5175
+ templates {
5176
+ go ( (e 1) ".URL.Query().Get(" (e 2) ")" )
5177
+ es6 ( (e 1) ".query[" (e 2) "]" )
5178
+ * ( "/* http_get_query not implemented */" )
5179
+ }
5180
+ }
5181
+
5182
+ http_get_header cmdHttpGetHeader:string (req:HttpRequest name:string) {
5183
+ templates {
5184
+ go ( (e 1) ".Header.Get(" (e 2) ")" )
5185
+ es6 ( (e 1) ".headers.get(" (e 2) ")" )
5186
+ * ( "/* http_get_header not implemented */" )
5187
+ }
5188
+ }
5189
+
5190
+ ; ============================================================================
5191
+ ; HTTP Response Operators
5192
+ ; ============================================================================
5193
+
5194
+ http_set_status cmdHttpSetStatus:void (res:HttpResponse code:int) {
5195
+ templates {
5196
+ go ( (e 1) ".WriteHeader(int(" (e 2) "))" nl )
5197
+ es6 ( (e 1) ".status(" (e 2) ")" nl )
5198
+ * ( "/* http_set_status not implemented */" nl )
5199
+ }
5200
+ }
5201
+
5202
+ http_set_header cmdHttpSetHeader:void (res:HttpResponse name:string value:string) {
5203
+ templates {
5204
+ go ( (e 1) ".Header().Set(" (e 2) ", " (e 3) ")" nl )
5205
+ es6 ( (e 1) ".setHeader(" (e 2) ", " (e 3) ")" nl )
5206
+ * ( "/* http_set_header not implemented */" nl )
5207
+ }
5208
+ }
5209
+
5210
+ http_send cmdHttpSend:void (res:HttpResponse body:string) {
5211
+ templates {
5212
+ go ( (e 1) ".Write([]byte(" (e 2) "))" nl )
5213
+ es6 ( (e 1) ".send(" (e 2) ")" nl )
5214
+ * ( "/* http_send not implemented */" nl )
5215
+ }
5216
+ }
5217
+
5218
+ http_send_bytes cmdHttpSendBytes:void (res:HttpResponse content:charbuffer) {
5219
+ templates {
5220
+ go ( (e 1) ".Write(" (e 2) ")" nl )
5221
+ es6 ( (e 1) ".send(Buffer.from(" (e 2) "))" nl )
5222
+ * ( "/* http_send_bytes not implemented */" nl )
5223
+ }
5224
+ }
5225
+
5226
+ http_send_buffer cmdHttpSendBuffer:void (res:HttpResponse content:buffer) {
5227
+ templates {
5228
+ go ( (e 1) ".Write(" (e 2) ")" nl )
5229
+ es6 ( (e 1) ".send(Buffer.from(" (e 2) "))" nl )
5230
+ * ( "/* http_send_buffer not implemented */" nl )
5231
+ }
5232
+ }
5233
+
5234
+ ; ============================================================================
5235
+ ; SSE (Server-Sent Events) Operators
5236
+ ; ============================================================================
5237
+
5238
+ sse_send cmdSSESend:void (client:SSEClient event:string data:string) {
5239
+ templates {
5240
+ go (
5241
+ "fmt.Fprintf(" (e 1) ".Writer, \"event: %s\\ndata: %s\\n\\n\", " (e 2) ", " (e 3) ")" nl
5242
+ (e 1) ".Flusher.Flush()" nl
5243
+ (imp "fmt")
5244
+ )
5245
+ es6 ( (e 1) ".send(" (e 2) ", " (e 3) ")" nl )
5246
+ * ( "/* sse_send not implemented */" nl )
5247
+ }
5248
+ }
5249
+
5250
+ sse_is_connected cmdSSEIsConnected:boolean (client:SSEClient) {
5251
+ templates {
5252
+ go ( (e 1) ".IsConnected" )
5253
+ es6 ( (e 1) ".isConnected()" )
5254
+ * ( "false /* sse_is_connected not implemented */" )
5255
+ }
5256
+ }
5257
+
5258
+ ; HTTP Server Lifecycle Operators
5259
+ ; These are special operators - the Go writer will detect @(HttpServer) class
5260
+ ; and generate route setup code when start is called on HttpServer
5261
+
5262
+ ; Start HTTP server - wires up all @(GET), @(POST), @(SSE) routes and starts listening
5263
+ ; Usage: start server 8080 OR start server (uses default port from annotation)
5264
+ ; The Go writer generates http.HandleFunc calls for each annotated method
5265
+ start@(moves@( 1 )) cmdHttpServerStart:void (server:HttpServer port:int) {
5266
+ templates {
5267
+ go ( (custom _) )
5268
+ es6 ( (e 1) ".start(" (e 2) ")" )
5269
+ * ( "/* start HttpServer not implemented */" )
5270
+ }
5271
+ }
3101
5272
 
5273
+ ; Stop HTTP server gracefully
5274
+ ; Usage: stop server
5275
+ stop@(moves@( 1 )) cmdHttpServerStop:void (server:HttpServer) {
5276
+ templates {
5277
+ go ( (e 1) ".Shutdown(context.Background())" )
5278
+ es6 ( (e 1) ".stop()" )
5279
+ * ( "/* stop HttpServer not implemented */" )
5280
+ }
5281
+ }
3102
5282
 
3103
5283
  }
3104
5284
 
3105
5285
 
3106
5286
 
3107
5287
  }
5288
+
5289
+ ; ============================================================================
5290
+ ; SYSTEM CLASS: buffer
5291
+ ; ============================================================================
5292
+ ; Binary buffer type for low-level byte operations.
5293
+ ; This provides a unified buffer type across all target languages.
5294
+ ; ============================================================================
5295
+
5296
+ systemclass buffer {
5297
+ es6 ArrayBuffer
5298
+ go "[]byte"
5299
+ rust "Vec<u8>"
5300
+ cpp "std::vector<uint8_t>"
5301
+ java7 "byte[]"
5302
+ python bytearray
5303
+ swift6 "[UInt8]"
5304
+ csharp "byte[]"
5305
+ kotlin ByteArray
5306
+ scala "Array[Byte]"
5307
+ }
5308
+
5309
+ ; SYSTEM CLASS: int_buffer
5310
+ ; ============================================================================
5311
+ ; Fixed-size int64 array for performance-critical code.
5312
+ ; Use for lookup tables, DCT coefficients, pixel buffers, etc.
5313
+ ; ============================================================================
5314
+
5315
+ systemclass int_buffer {
5316
+ es6 Int32Array
5317
+ go "[]int64"
5318
+ rust "Vec<i64>"
5319
+ cpp "std::vector<int64_t>"
5320
+ java7 "long[]"
5321
+ python list
5322
+ swift6 "[Int64]"
5323
+ csharp "long[]"
5324
+ kotlin LongArray
5325
+ scala "Array[Long]"
5326
+ }
5327
+
5328
+ ; SYSTEM CLASS: double_buffer
5329
+ ; ============================================================================
5330
+ ; Fixed-size float64 array for performance-critical code.
5331
+ ; Use for DSP, signal processing, matrix operations, etc.
5332
+ ; ============================================================================
5333
+
5334
+ systemclass double_buffer {
5335
+ es6 Float64Array
5336
+ go "[]float64"
5337
+ rust "Vec<f64>"
5338
+ cpp "std::vector<double>"
5339
+ java7 "double[]"
5340
+ python list
5341
+ swift6 "[Double]"
5342
+ csharp "double[]"
5343
+ kotlin DoubleArray
5344
+ scala "Array[Double]"
5345
+ }
5346
+
5347
+ ; ============================================================================
5348
+ ; SYSTEM CLASSES: HTTP Server Types
5349
+ ; ============================================================================
5350
+ ; HTTP server types for building web servers and APIs.
5351
+ ; These are used with the @(HttpServer) annotation system.
5352
+ ; See PLAN_HTTP.md for details.
5353
+ ; ============================================================================
5354
+
5355
+ ; HTTP Request object - represents an incoming HTTP request
5356
+ systemclass HttpRequest {
5357
+ es6 Request
5358
+ go "*http.Request" ((imp '"net/http"'))
5359
+ }
5360
+
5361
+ ; HTTP Response Writer - for writing HTTP responses
5362
+ systemclass HttpResponse {
5363
+ es6 Response
5364
+ go "http.ResponseWriter" ((imp '"net/http"'))
5365
+ }
5366
+
5367
+ ; Server-Sent Events client - for SSE streaming connections
5368
+ systemclass SSEClient {
5369
+ es6 SSEClient
5370
+ go "*SSEClient"
5371
+ }
5372
+
5373
+ ; HTTP Server instance - for server control
5374
+ systemclass HttpServer {
5375
+ es6 Server
5376
+ go "*http.Server" ((imp '"net/http"'))
5377
+ }