ranger-compiler 2.1.70 → 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 +956 -133
  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/{compiler/bin/output.js → dist/rgrc.js} +15377 -7936
  46. package/dist/stdops.rgr +168 -0
  47. package/package.json +196 -39
  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/bin/output.js +0 -23819
  150. package/compiler/ColorConsole.clj +0 -22
  151. package/compiler/ContextOperators.clj +0 -75
  152. package/compiler/FlowEnterVarDef.clj +0 -223
  153. package/compiler/InputFileSystem.clj +0 -276
  154. package/compiler/RangerDocs.clj +0 -7
  155. package/compiler/TFactory.clj +0 -146
  156. package/compiler/TFiles.clj +0 -23
  157. package/compiler/TFlow.clj +0 -39
  158. package/compiler/TNodeFactory.clj +0 -84
  159. package/compiler/TTypes.clj +0 -188
  160. package/compiler/VirtualCompiler.clj +0 -807
  161. package/compiler/bin/ng_Compiler.js +0 -23779
  162. package/compiler/commonmark_plugin.clj +0 -359
  163. package/compiler/feat2.bat +0 -2
  164. package/compiler/feats.bat +0 -9
  165. package/compiler/feature_tests.clj +0 -192
  166. package/compiler/index.js +0 -2
  167. package/compiler/issue_57.clj +0 -25
  168. package/compiler/makefile_plugin.clj +0 -135
  169. package/compiler/markdown_plugin.clj +0 -386
  170. package/compiler/maven_plugin.clj +0 -162
  171. package/compiler/ng_AndroidPageWriter.clj +0 -299
  172. package/compiler/ng_CodeNode.clj +0 -756
  173. package/compiler/ng_CodeNodeCompilerExtensions.clj +0 -839
  174. package/compiler/ng_Compiler.clj +0 -49
  175. package/compiler/ng_CompilerGeneric.clj +0 -260
  176. package/compiler/ng_CompilerOrig.clj +0 -854
  177. package/compiler/ng_DictNode.clj +0 -346
  178. package/compiler/ng_DictNode2.clj +0 -316
  179. package/compiler/ng_Execute.clj +0 -138
  180. package/compiler/ng_Execute1.clj +0 -129
  181. package/compiler/ng_FlowWork.clj +0 -3951
  182. package/compiler/ng_LiveCompiler.clj +0 -1109
  183. package/compiler/ng_RagnerJavaScriptClassWriter.clj +0 -402
  184. package/compiler/ng_RangerActiveOperators.clj +0 -86
  185. package/compiler/ng_RangerAppClassDesc.clj +0 -400
  186. package/compiler/ng_RangerAppEnums.clj +0 -86
  187. package/compiler/ng_RangerAppFunctionDesc.clj +0 -127
  188. package/compiler/ng_RangerAppMessages.clj +0 -15
  189. package/compiler/ng_RangerAppOperatorDesc.clj +0 -20
  190. package/compiler/ng_RangerAppParamDesc.clj +0 -388
  191. package/compiler/ng_RangerAppWriterContext.clj +0 -1793
  192. package/compiler/ng_RangerArgMatch.clj +0 -638
  193. package/compiler/ng_RangerCSharpClassWriter.clj +0 -484
  194. package/compiler/ng_RangerCppClassWriter.clj +0 -1023
  195. package/compiler/ng_RangerDocGenerator.clj +0 -305
  196. package/compiler/ng_RangerFlowParser.clj +0 -4992
  197. package/compiler/ng_RangerFlowParserOrig.clj +0 -4002
  198. package/compiler/ng_RangerGenericClassWriter.clj +0 -573
  199. package/compiler/ng_RangerGolangClassWriter.clj +0 -1766
  200. package/compiler/ng_RangerImmutableExtension.clj +0 -77
  201. package/compiler/ng_RangerJava7ClassWriter.clj +0 -961
  202. package/compiler/ng_RangerJavaScriptClassWriter.clj +0 -1040
  203. package/compiler/ng_RangerKotlinClassWriter.clj +0 -372
  204. package/compiler/ng_RangerLanguageWriters.clj +0 -14
  205. package/compiler/ng_RangerLispParser.clj +0 -873
  206. package/compiler/ng_RangerPHPClassWriter.clj +0 -643
  207. package/compiler/ng_RangerPlugin.clj +0 -41
  208. package/compiler/ng_RangerRangerClassWriter.clj +0 -357
  209. package/compiler/ng_RangerRustClassWriter.clj +0 -420
  210. package/compiler/ng_RangerScalaClassWriter.clj +0 -818
  211. package/compiler/ng_RangerSerializeClass.clj +0 -502
  212. package/compiler/ng_RangerServiceBuilder.clj +0 -63
  213. package/compiler/ng_RangerSwift3ClassWriter.clj +0 -809
  214. package/compiler/ng_RangerSwiftClassWriter.clj +0 -0
  215. package/compiler/ng_RangerTypeClass.clj +0 -45
  216. package/compiler/ng_SourceParser.clj +0 -241
  217. package/compiler/ng_SourceParser2.clj +0 -214
  218. package/compiler/ng_WebPageWriter.clj +0 -39
  219. package/compiler/ng_jsonParser.clj +0 -340
  220. package/compiler/ng_p_test.clj +0 -1711
  221. package/compiler/ng_parser.clj +0 -911
  222. package/compiler/ng_parser2.clj +0 -735
  223. package/compiler/ng_parser2_backup.clj +0 -1679
  224. package/compiler/ng_parser_backup.clj +0 -886
  225. package/compiler/ng_parser_ok.clj +0 -1718
  226. package/compiler/ng_parser_ok2.clj +0 -1717
  227. package/compiler/ng_parser_std_match.clj +0 -687
  228. package/compiler/ng_parser_std_match2.clj +0 -1012
  229. package/compiler/ng_parser_v2.clj +0 -1251
  230. package/compiler/ng_ui.clj +0 -403
  231. package/compiler/ng_ui_test.clj +0 -18
  232. package/compiler/ng_writer.clj +0 -338
  233. package/compiler/ng_xmlParser.clj +0 -472
  234. package/compiler/ng_xmlParser2.clj +0 -317
  235. package/compiler/ng_xmlParser3.clj +0 -251
  236. package/compiler/opdoc.bat +0 -4
  237. package/compiler/operators.md +0 -290
  238. package/compiler/p.bat +0 -4
  239. package/compiler/package.json +0 -10
  240. package/compiler/pcmd.bat +0 -4
  241. package/compiler/pcmd2.bat +0 -3
  242. package/compiler/plaintext_plugin.clj +0 -69
  243. package/compiler/plugin.bat +0 -19
  244. package/compiler/plugin2.bat +0 -4
  245. package/compiler/plugin_app.bat +0 -3
  246. package/compiler/plugin_apps.clj +0 -27
  247. package/compiler/plugins.bat +0 -10
  248. package/compiler/reveal_plugin.clj +0 -409
  249. package/compiler/simplePlugin.clj +0 -780
  250. package/compiler/t.bat +0 -3
  251. package/compiler/test_any.clj +0 -43
  252. package/compiler/test_call.clj +0 -141
  253. package/compiler/test_chain.clj +0 -79
  254. package/compiler/test_json.clj +0 -10
  255. package/compiler/test_lambda.clj +0 -153
  256. package/compiler/test_pcmd.clj +0 -32
  257. package/compiler/test_pcmd2.clj +0 -29
  258. package/compiler/test_plugin.clj +0 -237
  259. package/compiler/test_readfile.clj +0 -13
  260. package/compiler/test_reveal.clj +0 -19
  261. package/compiler/test_slides.clj +0 -312
  262. package/compiler/test_types.clj +0 -143
  263. package/compiler/test_types2.clj +0 -49
  264. package/compiler/test_types3.clj +0 -53
  265. package/compiler/test_var.clj +0 -40
  266. package/compiler/tonpm.bat +0 -14
  267. package/compiler/tonpm2.bat +0 -12
  268. package/compiler/ui_plugin.clj +0 -507
  269. package/compiler/ui_plugin2.clj +0 -427
  270. package/compiler/update-git.bat +0 -3
  271. package/compiler/vcomp.bat +0 -4
  272. package/compiler/viewbuilder_Android.clj +0 -176
  273. package/compiler/viewbuilder_Web.clj +0 -105
  274. package/dist/bin/api.js +0 -32422
  275. package/dist/bin/compiler.d.ts +0 -1638
  276. package/dist/bin/compiler.js +0 -32444
  277. package/examples/3D/bin/test_3d.js +0 -329
  278. package/examples/3D/test_3d.clj +0 -385
  279. package/examples/EVGColor/EVGColor.clj +0 -310
  280. package/examples/EVGColor/EVGColorContext.clj +0 -176
  281. package/examples/EVGColor/bin/EVGColor.js +0 -286
  282. package/examples/EVGColor/bin/minimized.js +0 -286
  283. package/examples/SVGPath/SVGPath.clj +0 -625
  284. package/examples/SVGPath/Vec2.clj +0 -103
  285. package/examples/SVGPath/bin/SVGPath.cpp +0 -887
  286. package/examples/SVGPath/bin/SVGPath.js +0 -682
  287. package/examples/SVGPath/bin/SVGPath.ts +0 -711
  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
@@ -1,1023 +0,0 @@
1
- class RangerCppClassWriter {
2
- Extends (RangerGenericClassWriter)
3
- def compiler:LiveCompiler
4
- def header_created:boolean false
5
- fn adjustType:string (tn:string) {
6
- if (tn == "this") {
7
- return "this"
8
- }
9
- return tn
10
- }
11
-
12
- ; std::string
13
-
14
- fn WriteScalarValue:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
15
- switch node.value_type {
16
- case RangerNodeType.Double {
17
- wr.out(("" + node.double_value) , false)
18
- }
19
- case RangerNodeType.String {
20
- def s:string (this.EncodeString(node ctx wr))
21
- wr.out( "std::string(" + (("\"" + s) + "\"") + ")" , false)
22
- }
23
- case RangerNodeType.Integer {
24
- wr.out(("" + node.int_value) , false)
25
- }
26
- case RangerNodeType.Boolean {
27
- if node.boolean_value {
28
- wr.out("true" false)
29
- } {
30
- wr.out("false" false)
31
- }
32
- }
33
- }
34
- }
35
-
36
- fn getObjectTypeString:string (type_string:string ctx:RangerAppWriterContext) {
37
- switch type_string {
38
- case "char" {
39
- return "char"
40
- }
41
- case "charbuffer" {
42
- return "const char*"
43
- }
44
- case "int" {
45
- return "int"
46
- }
47
- case "string" {
48
- return "std::string"
49
- }
50
- case "boolean" {
51
- return "bool"
52
- }
53
- case "double" {
54
- return "double"
55
- }
56
- }
57
- if(ctx.isEnumDefined(type_string)) {
58
- return "int"
59
- }
60
- if(ctx.isDefinedClass(type_string)) {
61
-
62
- def cc (ctx.findClass(type_string))
63
- if(cc.is_union) {
64
- ; TODO: how about optionals?
65
- return ("r_union_" + type_string)
66
- }
67
-
68
- return "std::shared_ptr<" + type_string + ">"
69
- }
70
- return type_string
71
- }
72
- fn getTypeString2:string (type_string:string ctx:RangerAppWriterContext) {
73
- switch type_string {
74
- case "char" {
75
- return "char"
76
- }
77
- case "charbuffer" {
78
- return "const char*"
79
- }
80
- case "int" {
81
- return "int"
82
- }
83
- case "string" {
84
- return "std::string"
85
- }
86
- case "boolean" {
87
- return "bool"
88
- }
89
- case "double" {
90
- return "double"
91
- }
92
- }
93
- if(ctx.isEnumDefined(type_string)) {
94
- return "int"
95
- }
96
- return type_string
97
- }
98
-
99
- fn writePtr:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
100
- if (node.type_name == "void") {
101
- return
102
- }
103
- }
104
-
105
- fn writeTypeDef:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
106
- def v_type:RangerNodeType node.value_type
107
- def t_name:string node.type_name
108
- def a_name:string node.array_type
109
- def k_name:string node.key_type
110
- if ((v_type == RangerNodeType.Object) || (v_type == RangerNodeType.VRef) || (v_type == RangerNodeType.NoType)) {
111
- v_type = (node.typeNameAsType(ctx))
112
- }
113
- if (node.eval_type != RangerNodeType.NoType) {
114
- v_type = node.eval_type
115
- if ( (strlen node.eval_type_name) > 0 ) {
116
- t_name = node.eval_type_name
117
- }
118
- if ( (strlen node.eval_array_type) > 0 ) {
119
- a_name = node.eval_array_type
120
- }
121
- if ( (strlen node.eval_key_type) > 0 ) {
122
- k_name = node.eval_key_type
123
- }
124
- }
125
- ; std::function<int (int, int)>
126
- switch v_type {
127
- case RangerNodeType.ExpressionType {
128
- def rv:CodeNode (itemAt node.expression_value.children 0)
129
- def sec:CodeNode (itemAt node.expression_value.children 1)
130
- def fc:CodeNode (sec.getFirst())
131
- this.import_lib("<functional>" ctx wr)
132
-
133
- wr.out("std::function<" false)
134
- this.writeTypeDef( rv ctx wr)
135
- wr.out("(" false)
136
- for sec.children arg:CodeNode i {
137
- if( i > 0 ) {
138
- wr.out(", " false)
139
- }
140
- this.writeTypeDef( arg ctx wr)
141
- }
142
- wr.out(")>" false)
143
-
144
- }
145
- case RangerNodeType.Enum {
146
- wr.out("int" false)
147
- }
148
- case RangerNodeType.Integer {
149
- if(node.hasFlag("optional")) {
150
- wr.out(" r_optional_primitive<int> " false)
151
- } {
152
- wr.out("int" false)
153
- }
154
- }
155
- case RangerNodeType.Char {
156
- wr.out("char" false)
157
- }
158
- case RangerNodeType.CharBuffer {
159
- wr.out("const char*" false)
160
- }
161
- case RangerNodeType.Double {
162
- if(node.hasFlag("optional")) {
163
- wr.out(" r_optional_primitive<double> " false)
164
- } {
165
- wr.out("double" false)
166
- }
167
- }
168
- case RangerNodeType.String {
169
- wr.addImport("<string>")
170
- wr.out("std::string" false)
171
- }
172
- case RangerNodeType.Boolean {
173
- wr.out("bool" false)
174
- }
175
- case RangerNodeType.Hash {
176
- wr.out((((("std::map<" + (this.getObjectTypeString(k_name ctx))) + ",") + (this.getObjectTypeString(a_name ctx)))) + ">" , false)
177
- wr.addImport("<map>")
178
- }
179
- case RangerNodeType.Array {
180
- wr.out((("std::vector<" + (this.getObjectTypeString(a_name ctx))) + ">") false)
181
- wr.addImport("<vector>")
182
- }
183
- default {
184
-
185
- if (node.type_name == "void") {
186
- wr.out("void" false)
187
- return
188
- }
189
-
190
- ; r_union_myValues
191
-
192
- if(ctx.isDefinedClass(t_name)) {
193
-
194
- def cc (ctx.findClass(t_name))
195
- if(cc.is_union) {
196
- wr.out("r_union_" false)
197
- wr.out(t_name false)
198
- ; if (node.hasFlag("optional")) {
199
- ; wr.out("?" false)
200
- ; }
201
- return
202
- }
203
- def cc:RangerAppClassDesc (ctx.findClass(t_name))
204
- wr.out("std::shared_ptr<" false)
205
- wr.out(cc.name false)
206
- wr.out(">" false)
207
- return
208
- }
209
-
210
- if(node.hasFlag("optional")) {
211
- wr.out("std::shared_ptr<std::vector<" false)
212
- wr.out((this.getTypeString2(t_name ctx)) false)
213
- wr.out(">" false)
214
- return
215
- }
216
- wr.out((this.getTypeString2(t_name ctx)) false))
217
- }
218
- }
219
- }
220
- fn WriteVRef:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
221
- if (node.vref == "this") {
222
- ; std::dynamic_pointer_cast<RangerAppClassDesc>
223
-
224
- def currC (ctx.getCurrentClass())
225
- if(!null? currC) {
226
- def cc (unwrap currC)
227
- if( (array_length cc.extends_classes) > 0 ) {
228
- wr.out("std::dynamic_pointer_cast<" + cc.name + ">(shared_from_this())" , false)
229
- return
230
- }
231
- }
232
- wr.out("shared_from_this()" false)
233
- return
234
- }
235
- if (node.eval_type == RangerNodeType.Enum) {
236
- def rootObjName:string (itemAt node.ns 0)
237
- if( ( array_length node.ns) > 1 ) {
238
- def enumName:string (itemAt node.ns 1)
239
- def e@(optional):RangerAppEnum (ctx.getEnum(rootObjName))
240
- if (!null? e) {
241
- wr.out(("" + (unwrap (get e.values enumName))) false)
242
- return
243
- }
244
- }
245
- }
246
- def had_static:boolean false
247
- if ((array_length node.nsp) > 0) {
248
- for node.nsp p:RangerAppParamDesc i {
249
- if (i > 0) {
250
- if(had_static) {
251
- wr.out("::" false)
252
- } {
253
- wr.out("->" false)
254
- }
255
- }
256
- if (i == 0) {
257
- def part:string (itemAt node.ns 0)
258
- if(part == "this") {
259
- wr.out("this" false)
260
- continue
261
- }
262
- }
263
- if ((strlen p.compiledName) > 0) {
264
- wr.out((this.adjustType(p.compiledName)) false)
265
- } {
266
- if ((strlen p.name) > 0) {
267
- wr.out((this.adjustType(p.name)) false)
268
- } {
269
- wr.out((this.adjustType( (itemAt node.ns i))) false)
270
- }
271
- }
272
- if (p.isClass()) {
273
- had_static = true
274
- }
275
- }
276
- return
277
- }
278
- if node.hasParamDesc {
279
- def p:RangerAppParamDesc node.paramDesc
280
- wr.out(p.compiledName false)
281
- return
282
- }
283
- for node.ns part:string i {
284
- if (i > 0) {
285
- if had_static {
286
- wr.out("::" false)
287
- } {
288
- wr.out("->" false)
289
- }
290
- }
291
-
292
- if (ctx.hasClass(part)) {
293
- had_static = true
294
- } {
295
- had_static = false
296
- }
297
- wr.out((this.adjustType(part)) false)
298
- }
299
- }
300
- fn writeVarDef:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
301
- if node.hasParamDesc {
302
- def nn:CodeNode (itemAt node.children 1)
303
- def p:RangerAppParamDesc nn.paramDesc
304
- if ((p.ref_cnt == 0) && (p.is_class_variable == false)) {
305
- wr.out("/** unused: " false)
306
- }
307
- if ((p.set_cnt > 0) || p.is_class_variable) {
308
- wr.out("" false)
309
- } {
310
- wr.out("" false)
311
- }
312
- this.writeTypeDef((unwrap p.nameNode) ctx wr)
313
- wr.out(" " false)
314
- wr.out(p.compiledName false)
315
- if ((array_length node.children) > 2) {
316
- wr.out(" = " false)
317
- ctx.setInExpr()
318
- def value:CodeNode (node.getThird())
319
- this.WalkNode(value ctx wr)
320
- ctx.unsetInExpr()
321
- } {
322
- ;if (nn.value_type == RangerNodeType.Array) {
323
- ; wr.out(" = new " false)
324
- ; this.writeTypeDef((unwrap p.nameNode) ctx wr)
325
- ; wr.out("()" false)
326
- ;}
327
- ;if (nn.value_type == RangerNodeType.Hash) {
328
- ; wr.out(" = new " false)
329
- ; this.writeTypeDef((unwrap p.nameNode) ctx wr)
330
- ; wr.out("()" false)
331
- ;}
332
- }
333
- if ((p.ref_cnt == 0) && (p.is_class_variable == true)) {
334
- wr.out(" /** note: unused */" false)
335
- }
336
- if ((p.ref_cnt == 0) && (p.is_class_variable == false)) {
337
- wr.out(" **/ ;" true)
338
- } {
339
- wr.out(";" false)
340
- wr.newline()
341
- }
342
- }
343
- }
344
-
345
- fn disabledVarDef:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
346
- if node.hasParamDesc {
347
- def nn:CodeNode (itemAt node.children 1)
348
- def p:RangerAppParamDesc nn.paramDesc
349
- if ((p.set_cnt > 0) || p.is_class_variable) {
350
- wr.out("" false)
351
- } {
352
- wr.out("" false)
353
- }
354
-
355
- wr.out(p.compiledName false)
356
- if ((array_length node.children) > 2) {
357
- wr.out(" = " false)
358
- ctx.setInExpr()
359
- def value:CodeNode (node.getThird())
360
- this.WalkNode(value ctx wr)
361
- ctx.unsetInExpr()
362
- } {
363
- ;if (nn.value_type == RangerNodeType.Array) {
364
- ; wr.out(" = new " false)
365
- ; this.writeTypeDef((unwrap p.nameNode) ctx wr)
366
- ; wr.out("()" false)
367
- ;}
368
- ;if (nn.value_type == RangerNodeType.Hash) {
369
- ; wr.out(" = new " false)
370
- ; this.writeTypeDef((unwrap p.nameNode) ctx wr)
371
- ; wr.out("()" false)
372
- ;}
373
- }
374
- wr.out(";" false)
375
- wr.newline()
376
- }
377
- }
378
-
379
- fn CreateCallExpression(node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
380
- if node.has_call {
381
- def obj:CodeNode (node.getSecond())
382
- def method:CodeNode (node.getThird())
383
- def args:CodeNode (itemAt node.children 3)
384
-
385
- wr.out("(" false)
386
- ctx.setInExpr()
387
- this.WalkNode( obj ctx wr)
388
- ctx.unsetInExpr()
389
- wr.out(")->" false)
390
- wr.out(method.vref false)
391
- ; this.WriteVRef(fc ctx wr)
392
- wr.out("(" false)
393
- ctx.setInExpr()
394
- for args.children arg:CodeNode i {
395
- if (i > 0) {
396
- wr.out(", " false)
397
- }
398
- ; TODO: optionality check here ?
399
- this.WalkNode(arg ctx wr)
400
- }
401
- ctx.unsetInExpr()
402
- wr.out(")" false)
403
- if ((ctx.expressionLevel()) == 0) {
404
- wr.out(";" true)
405
- }
406
- }
407
- }
408
-
409
- fn CustomOperator:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
410
-
411
- def fc:CodeNode (node.getFirst())
412
- def cmd:string fc.vref
413
-
414
- if( cmd == "return" ) {
415
- if(ctx.isInMain()) {
416
- wr.out("return 0;" true)
417
- } {
418
- wr.out("return;" true)
419
- }
420
- return
421
- }
422
-
423
- if( cmd == "switch" ) {
424
- def condition:CodeNode (node.getSecond())
425
- def case_nodes:CodeNode (node.getThird())
426
- wr.newline()
427
-
428
-
429
- def p@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
430
- p.name = "caseMatched"
431
- p.value_type = RangerNodeType.Boolean
432
- ctx.defineVariable(p.name p)
433
-
434
- def b_has_default false
435
- for case_nodes.children ch:CodeNode i {
436
- def blockName (ch.getFirst())
437
- if (blockName.vref == "default") {
438
- b_has_default = true
439
- }
440
- }
441
- if b_has_default {
442
- wr.out("bool " + p.compiledName + " = false;" , true)
443
- }
444
- for case_nodes.children ch:CodeNode i {
445
- def blockName (ch.getFirst())
446
- if (blockName.vref == "default") {
447
- def defBlock (ch.getSecond())
448
- wr.out("if( ! " false)
449
- wr.out(p.compiledName false )
450
- wr.out(") {" true)
451
- wr.indent(1)
452
- this.WalkNode( defBlock ctx wr )
453
- wr.indent(-1)
454
- wr.out("}" true)
455
- } {
456
- def caseValue (ch.getSecond())
457
- def caseBlock (ch.getThird())
458
- wr.out("if( " false)
459
- this.WalkNode( condition ctx wr )
460
- wr.out(" == " false)
461
- this.WalkNode( caseValue ctx wr )
462
- wr.out(") {" true)
463
- wr.indent(1)
464
- if b_has_default {
465
- wr.out(p.compiledName + " = true;" , true)
466
- }
467
- this.WalkNode( caseBlock ctx wr )
468
- wr.indent(-1)
469
- wr.out("}" true)
470
- }
471
- }
472
-
473
- }
474
- }
475
-
476
- fn CreateMethodCall(node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
477
- ; property access...
478
- def obj:CodeNode (node.getFirst())
479
- def args:CodeNode (node.getSecond())
480
- ctx.setInExpr()
481
- this.WalkNode( obj ctx wr)
482
- ctx.unsetInExpr()
483
- wr.out('(' false)
484
- ctx.setInExpr()
485
- for args.children arg:CodeNode i {
486
- if (i > 0) {
487
- wr.out(', ' false)
488
- }
489
- ; TODO: optionality check here ?
490
- this.WalkNode(arg ctx wr)
491
- }
492
- ctx.unsetInExpr()
493
- wr.out(')' false)
494
- }
495
-
496
-
497
- fn CreatePropertyGet(node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
498
- ; property access...
499
- def obj:CodeNode (node.getSecond())
500
- def prop:CodeNode (node.getThird())
501
- wr.out('(' false)
502
- ctx.setInExpr()
503
- this.WalkNode( obj ctx wr)
504
- ctx.unsetInExpr()
505
- wr.out(')->' false)
506
- this.WalkNode(prop ctx wr)
507
- }
508
-
509
-
510
- fn CreateLambdaCall:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
511
-
512
- def fName:CodeNode (itemAt node.children 0)
513
- def givenArgs:CodeNode (itemAt node.children 1)
514
-
515
- def args:CodeNode
516
- if( (!null? fName.expression_value) ) {
517
- args = ( itemAt fName.expression_value.children 1)
518
- } {
519
- def param (ctx.getVariableDef(fName.vref))
520
- args = ( itemAt param.nameNode.expression_value.children 1)
521
- }
522
-
523
- ctx.setInExpr()
524
- this.WalkNode(fName ctx wr)
525
-
526
- wr.out("(" false)
527
- for args.children arg:CodeNode i {
528
- def n:CodeNode (itemAt givenArgs.children i)
529
- if (i > 0) {
530
- wr.out(", " false)
531
- }
532
- ; wr.out((arg.vref + " : ") false)
533
- if(arg.value_type != RangerNodeType.NoType) {
534
- this.WalkNode(n ctx wr)
535
- }
536
- }
537
- wr.out(")" false)
538
- ctx.unsetInExpr()
539
- if ((ctx.expressionLevel()) == 0) {
540
- wr.out(";" true)
541
- }
542
- }
543
- fn CreateLambda:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
544
-
545
- this.import_lib("<functional>" ctx wr)
546
-
547
- def lambdaCtx (unwrap node.lambda_ctx)
548
- def fnNode:CodeNode (itemAt node.children 0)
549
- def args:CodeNode (itemAt node.children 1)
550
- def body:CodeNode (itemAt node.children 2)
551
-
552
- ; capture by reference, not value
553
- ; http://en.cppreference.com/w/cpp/language/lambda
554
- ; [=] captures all automatic values by copy and current object by reference
555
- ; [&] all by reference
556
-
557
- wr.out("[&" false)
558
-
559
-
560
- for lambdaCtx.captured_variables cname:string i {
561
- def vD (lambdaCtx.getVariableDef( cname ) )
562
-
563
- if( vD.varType == RangerContextVarType.FunctionParameter ) {
564
- wr.out(', ' false)
565
- wr.out( (vD.compiledName) false)
566
- }
567
-
568
- ; is function parameter ?
569
- ; if(vD.)
570
- ; wr.out(', ' false)
571
- ; wr.out( ("&" + vD.compiledName) false)
572
- }
573
-
574
- ;for lambdaCtx.captured_variables cname:string i {
575
- ; if(i>=0) {
576
- ; wr.out(", " false)
577
- ; }
578
- ; def vD (lambdaCtx.getVariableDef( cname ) )
579
- ; capture by reference, not value
580
- ; http://en.cppreference.com/w/cpp/language/lambda
581
- ; [=] captures all automatic values by copy and current object by reference
582
- ; [&] all by reference
583
- ; wr.out( ("&" + vD.compiledName) false)
584
- ;}
585
- wr.out("](" false)
586
-
587
- for args.children arg:CodeNode i {
588
- if (i > 0) {
589
- wr.out(", " false)
590
- }
591
- this.writeTypeDef( arg ctx wr)
592
- wr.out(" " false)
593
- wr.out(arg.vref false)
594
- }
595
- wr.out(") mutable { " true)
596
- wr.indent(1)
597
- lambdaCtx.restartExpressionLevel()
598
- for body.children item:CodeNode i {
599
- this.WalkNode(item lambdaCtx wr)
600
- }
601
- wr.newline()
602
- wr.indent(-1)
603
- wr.out("}" false)
604
- }
605
-
606
- fn writeCppHeaderVar:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter do_initialize:boolean) {
607
- if node.hasParamDesc {
608
- def nn:CodeNode (itemAt node.children 1)
609
- def p:RangerAppParamDesc nn.paramDesc
610
-
611
- ; TODO: optionals...
612
-
613
- if ((p.ref_cnt == 0) && (p.is_class_variable == false)) {
614
- wr.out("/** unused: " false)
615
- }
616
- if ((p.set_cnt > 0) || p.is_class_variable) {
617
- wr.out("" false)
618
- } {
619
- wr.out("" false)
620
- }
621
- this.writeTypeDef((unwrap p.nameNode) ctx wr)
622
- wr.out(" " false)
623
- wr.out(p.compiledName false)
624
- if ((p.ref_cnt == 0) && (p.is_class_variable == true)) {
625
- wr.out(" /** note: unused */" false)
626
- }
627
- if ((p.ref_cnt == 0) && (p.is_class_variable == false)) {
628
- wr.out(" **/ ;" true)
629
- } {
630
- wr.out(";" false)
631
- wr.newline()
632
- }
633
- }
634
- }
635
- fn writeArgsDef:void (fnDesc:RangerAppFunctionDesc ctx:RangerAppWriterContext wr:CodeWriter) {
636
- for fnDesc.params arg:RangerAppParamDesc i {
637
- if (i > 0) {
638
- wr.out("," false)
639
- }
640
- wr.out(" " false)
641
- this.writeTypeDef( (unwrap arg.nameNode) ctx wr)
642
- wr.out(((" " + arg.compiledName) + " ") false)
643
- }
644
- }
645
- fn writeFnCall:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
646
- if node.hasFnCall {
647
- def fc:CodeNode (node.getFirst())
648
- this.WriteVRef(fc ctx wr)
649
- wr.out("(" false)
650
- ctx.setInExpr()
651
- def givenArgs:CodeNode (node.getSecond())
652
- for node.fnDesc.params arg:RangerAppParamDesc i {
653
- if (i > 0) {
654
- wr.out(", " false)
655
- }
656
- if ( i >= ( array_length givenArgs.children) ) {
657
- def defVal:CodeNode (arg.nameNode.getFlag("default"))
658
- if (!null? defVal) {
659
- def fc:CodeNode (defVal.vref_annotation.getFirst())
660
- this.WalkNode(fc ctx wr)
661
- } {
662
- ctx.addError(node "Default argument was missing")
663
- }
664
- continue
665
- }
666
- def n:CodeNode (itemAt givenArgs.children i)
667
- this.WalkNode(n ctx wr)
668
- }
669
- ctx.unsetInExpr()
670
- wr.out(")" false)
671
- if ((ctx.expressionLevel()) == 0) {
672
- wr.out(";" true)
673
- }
674
- }
675
- }
676
- fn writeNewCall:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
677
- if node.hasNewOper {
678
- def cl:RangerAppClassDesc node.clDesc
679
- def fc:CodeNode (node.getSecond())
680
- wr.out(" std::make_shared<" false)
681
- wr.out(node.clDesc.name false)
682
- wr.out(">(" false)
683
- def constr:RangerAppFunctionDesc cl.constructor_fn
684
- def givenArgs:CodeNode (node.getThird())
685
- if (!null? constr) {
686
- for constr.params arg:RangerAppParamDesc i {
687
- def n:CodeNode (itemAt givenArgs.children i)
688
- if (i > 0) {
689
- wr.out(", " false)
690
- }
691
- if ( true || (!null? arg.nameNode) ) {
692
- this.WalkNode(n ctx wr)
693
- }
694
- }
695
- }
696
- wr.out(")" false)
697
- }
698
- }
699
- ; this.createPolyfill( cmdArgs.string_value )
700
-
701
- fn writeArrayLiteral( node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
702
-
703
- this.compiler.createPolyfill("
704
- template< typename T, size_t N >
705
- std::vector<T> r_make_vector_from_array( const T (&data)[N] )
706
- {
707
- return std::vector<T>(data, data+N);
708
- }
709
- " ctx wr)
710
- wr.out("r_make_vector_from_array( (" false)
711
- ; this.writeTypeDef( node ctx wr)
712
- wr.out( (this.getObjectTypeString( node.eval_array_type ctx )) false )
713
- wr.out("[] ) {" false)
714
- node.children.forEach({
715
- if( index > 0 ) {
716
- wr.out(", " false)
717
- }
718
- this.WalkNode( item ctx wr )
719
- })
720
- wr.out("} )" false)
721
- }
722
-
723
- fn writeClassHeader:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
724
- def cl:RangerAppClassDesc node.clDesc
725
- if (null? cl) {
726
- return
727
- }
728
- def inheritedVars:[string:boolean]
729
- wr.out(("class " + cl.name) , false)
730
- if ( ( array_length cl.extends_classes ) > 0 ) {
731
- wr.out(" : " false)
732
- for cl.extends_classes pName:string i {
733
- wr.out("public " false)
734
- wr.out(pName false)
735
- def extC (ctx.findClass(pName))
736
- for extC.variables pvar:RangerAppParamDesc i {
737
- set inheritedVars pvar.name true
738
- }
739
- }
740
- } {
741
- wr.out(" : public std::enable_shared_from_this<" + cl.name + "> " , false)
742
- }
743
-
744
- wr.out(" { " true)
745
- wr.indent(1)
746
- wr.out("public :" true)
747
- wr.indent(1)
748
- for cl.variables pvar:RangerAppParamDesc i {
749
- if( (has inheritedVars pvar.name) == false) {
750
- this.writeCppHeaderVar( (unwrap pvar.node) ctx wr false)
751
- }
752
- }
753
- wr.out("/* class constructor */ " true)
754
- wr.out((cl.name + "(") false)
755
- if cl.has_constructor {
756
- def constr:RangerAppFunctionDesc cl.constructor_fn
757
- this.writeArgsDef((unwrap constr) ctx wr)
758
- }
759
- wr.out(" );" true)
760
- for cl.static_methods variant:RangerAppFunctionDesc i {
761
- if (i == 0) {
762
- wr.out("/* static methods */ " true)
763
- }
764
- wr.out("static " false)
765
- this.writeTypeDef( (unwrap variant.nameNode) ctx wr)
766
- wr.out(((" " + variant.compiledName) + "(") false)
767
- this.writeArgsDef(variant ctx wr)
768
- wr.out(");" true)
769
- }
770
- for cl.defined_variants fnVar:string i {
771
- if (i == 0) {
772
- wr.out("/* instance methods */ " true)
773
- }
774
- def mVs:RangerAppMethodVariants (get cl.method_variants fnVar)
775
- for mVs.variants variant:RangerAppFunctionDesc i {
776
- if(cl.is_inherited) {
777
- wr.out("virtual " false)
778
- }
779
- this.writeTypeDef((unwrap variant.nameNode) ctx wr)
780
- wr.out(((" " + variant.compiledName) + "(") false)
781
- this.writeArgsDef(variant ctx wr)
782
- wr.out(");" true)
783
- }
784
- }
785
- wr.indent(-1)
786
- wr.indent(-1)
787
- wr.out("};" true)
788
- ; wr.out("#endif " true)
789
- }
790
-
791
- fn CreateUnions (parser:RangerFlowParser ctx:RangerAppWriterContext wr:CodeWriter) {
792
- def root (ctx.getRoot())
793
- root.definedClasses.forEach({
794
- ; index == name
795
- ; item == class description
796
- if(item.is_union) {
797
- this.compiler.installFile( "variant.hpp" ctx wr)
798
-
799
- ctx.addPluginNode('makefile' (r.expression (r.expression
800
- (r.vref 'dep')
801
- (r.value 'variant.hpp')
802
- (r.value 'https://github.com/mpark/variant/releases/download/v1.2.2/variant.hpp')
803
- )))
804
- ; (plugin 'makefile' ((dep 'variant.hpp' 'https://github.com/mpark/variant/releases/download/v1.2.2/variant.hpp')))
805
-
806
- ; TODO: implement system class unions too...
807
- wr.out("typedef mpark::variant<" false)
808
- wr.indent(1)
809
- def cnt 0
810
- item.is_union_of.forEach({
811
- if (ctx.isDefinedClass(item)) {
812
- def cl (ctx.findClass(item))
813
- if( false == (cl.isNormalClass() ) ) {
814
- return
815
- }
816
- if( cnt > 0 ) {
817
- wr.out(", " false)
818
- }
819
- wr.out( (this.getObjectTypeString( item ctx ) ) false )
820
- cnt = cnt + 1
821
- } {
822
- if( cnt > 0 ) {
823
- wr.out(", " false)
824
- }
825
- wr.out( (this.getObjectTypeString( item ctx ) ) false )
826
- cnt = cnt + 1
827
- }
828
- })
829
- wr.indent(-1)
830
- wr.out("> r_union_" + index + ";" , true)
831
- wr.addImport("\"variant.hpp\"")
832
- }
833
- })
834
- }
835
-
836
-
837
- fn writeClass:void (node:CodeNode ctx:RangerAppWriterContext orig_wr:CodeWriter) {
838
-
839
- def cl:RangerAppClassDesc node.clDesc
840
- def wr:CodeWriter orig_wr
841
- if (null? cl) {
842
- return
843
- }
844
-
845
- this.import_lib("<memory>" ctx wr)
846
-
847
- for cl.capturedLocals dd@(lives):RangerAppParamDesc i {
848
- if(dd.is_class_variable == false ) {
849
- if ( dd.set_cnt > 0 ) {
850
- if( ctx.hasCompilerFlag("dont-allow-mutate")) {
851
- ctx.addError( (unwrap dd.nameNode) "Mutating captured variable is not allowed")
852
- return
853
- }
854
- }
855
- }
856
- }
857
-
858
- if( header_created == false) {
859
- wr.createTag("c++Imports")
860
- wr.out("" true)
861
- wr.out("// define classes here to avoid compiler errors" true)
862
- wr.createTag("c++ClassDefs")
863
- wr.out("" true)
864
- wr.createTag("c++unions")
865
- wr.createTag("utilities")
866
- wr.out("" true)
867
- wr.out("// header definitions" true)
868
- wr.createTag("c++Header")
869
- wr.out("" true)
870
-
871
- wr.out("int __g_argc;" true)
872
- wr.out("char **__g_argv;" true)
873
-
874
- this.CreateUnions( (unwrap this.compiler.parser) ctx (wr.getTag("c++unions")))
875
-
876
- header_created = true
877
- }
878
- def classWriter:CodeWriter (orig_wr.getTag("c++ClassDefs"))
879
- def headerWriter:CodeWriter (orig_wr.getTag("c++Header"))
880
- def projectName:string "project"
881
-
882
- ; for cl.capturedLocals dd@(lives):RangerAppParamDesc i {
883
- ; if(dd.is_class_variable == false ) {
884
- ; wr.out("// local captured " + dd.name , true)
885
- ; ;print "C++ captured"
886
- ; ;print (dd.node.getLineAsString())
887
- ; dd.node.disabled_node = true
888
- ; cl.addVariable(dd)
889
- ; def csubCtx:RangerAppWriterContext cl.ctx
890
- ; csubCtx.defineVariable(dd.name dd)
891
- ; dd.is_class_variable = true
892
- ; }
893
- ; }
894
-
895
- classWriter.out("class " + cl.name + ";" , true)
896
-
897
- this.writeClassHeader(node ctx headerWriter)
898
-
899
- wr.out((((cl.name + "::") + cl.name) + "(") false)
900
- if cl.has_constructor {
901
- def constr:RangerAppFunctionDesc cl.constructor_fn
902
- this.writeArgsDef( (unwrap constr) ctx wr)
903
- }
904
- wr.out(" ) " false )
905
-
906
- if ( ( array_length cl.extends_classes ) > 0 ) {
907
-
908
- ; wr.out(" public std::enable_shared_from_this<" + cl.name + "> " , false)
909
- for cl.extends_classes pName:string i {
910
- def pcc (ctx.findClass(pName))
911
- if pcc.has_constructor {
912
- wr.out(" : " + pcc.name +"(" , false)
913
- def constr:RangerAppFunctionDesc cl.constructor_fn
914
- for constr.params arg:RangerAppParamDesc i {
915
- if (i > 0) {
916
- wr.out("," false)
917
- }
918
- wr.out(" " false)
919
- wr.out(((" " + arg.name) + " ") false)
920
- }
921
- wr.out(")" false)
922
- }
923
- }
924
- }
925
-
926
- wr.out("{" true)
927
- wr.indent(1)
928
- for cl.variables pvar:RangerAppParamDesc i {
929
- def nn:CodeNode (unwrap pvar.node)
930
- ; if(pvar.is_captured) {
931
- ; continue
932
- ; }
933
- if ((array_length nn.children) > 2) {
934
- def valueNode:CodeNode (itemAt nn.children 2)
935
- wr.out((("this->" + pvar.compiledName) + " = ") false)
936
- this.WalkNode(valueNode ctx wr)
937
- wr.out(";" true)
938
- }
939
- ; if (nn.hasFlag("optional")) {
940
- }
941
- if cl.has_constructor {
942
- def constr:RangerAppFunctionDesc (unwrap cl.constructor_fn)
943
- wr.newline()
944
- def subCtx:RangerAppWriterContext (unwrap constr.fnCtx)
945
- subCtx.is_function = true
946
- this.WalkNode( (unwrap constr.fnBody) subCtx wr)
947
- wr.newline()
948
- }
949
- wr.indent(-1)
950
- wr.out("}" true)
951
- for cl.static_methods variant:RangerAppFunctionDesc i {
952
-
953
- if (variant.nameNode.hasFlag("main")) {
954
- continue _
955
- }
956
- ; wr.out("static " false)
957
- this.writeTypeDef( (unwrap variant.nameNode ) ctx wr)
958
- wr.out(" " false)
959
- wr.out(((" " + cl.name) + "::") false)
960
- wr.out((variant.compiledName + "(") false)
961
- this.writeArgsDef(variant ctx wr)
962
- wr.out(") {" true)
963
- wr.indent(1)
964
- wr.newline()
965
- def subCtx:RangerAppWriterContext (unwrap variant.fnCtx)
966
- subCtx.is_function = true
967
- this.WalkNode( (unwrap variant.fnBody ) subCtx wr)
968
- wr.newline()
969
- wr.indent(-1)
970
- wr.out("}" true)
971
- }
972
- for cl.defined_variants fnVar:string i {
973
- def mVs:RangerAppMethodVariants (get cl.method_variants fnVar)
974
- for mVs.variants variant:RangerAppFunctionDesc i {
975
- this.writeTypeDef((unwrap variant.nameNode )ctx wr)
976
- ;this.writePtr((unwrap variant.nameNode ) ctx wr)
977
- wr.out(" " false)
978
- wr.out(((" " + cl.name) + "::") false)
979
- wr.out((variant.compiledName + "(") false)
980
- this.writeArgsDef(variant ctx wr)
981
- wr.out(") {" true)
982
- wr.indent(1)
983
- wr.newline()
984
- def subCtx:RangerAppWriterContext (unwrap variant.fnCtx )
985
- subCtx.is_function = true
986
- this.WalkNode( (unwrap variant.fnBody ) subCtx wr)
987
- wr.newline()
988
- wr.indent(-1)
989
- wr.out("}" true)
990
- }
991
- }
992
- ; wr.addImport(((("\"" + projectName) + ".hpp") + "\""))
993
-
994
- ;def import_list:[string] (wr.getImports())
995
- ;for import_list codeStr:string i {
996
- ; importFork.out(("#include " + codeStr + "") true)
997
- ;}
998
-
999
- for cl.static_methods variant:RangerAppFunctionDesc i {
1000
- if ( (variant.nameNode.hasFlag("main")) && (variant.nameNode.code.filename == (ctx.getRootFile()))) {
1001
-
1002
- ctx.setCompilerSetting( 'mainclass' (cl.name) )
1003
-
1004
- wr.out("int main(int argc, char* argv[]) {" true)
1005
- wr.indent(1)
1006
-
1007
- wr.out("__g_argc = argc;" true)
1008
- wr.out("__g_argv = argv;" true)
1009
-
1010
- def subCtx:RangerAppWriterContext (unwrap variant.fnCtx)
1011
- subCtx.in_main = true
1012
- subCtx.is_function = true
1013
- this.WalkNode( (unwrap variant.fnBody ) subCtx wr)
1014
- wr.newline()
1015
- wr.out("return 0;" true)
1016
- wr.indent(-1)
1017
- wr.out("}" true)
1018
- }
1019
- }
1020
-
1021
- }
1022
- }
1023
-