ranger-compiler 2.1.70 → 3.0.4

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 +114 -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,3951 +0,0 @@
1
-
2
- Import "stdlib.clj"
3
- Import "ng_RangerAppMessages.clj"
4
- Import "ng_RangerAppParamDesc.clj"
5
- Import "ng_RangerAppFunctionDesc.clj"
6
- Import "ng_RangerAppClassDesc.clj"
7
- Import "ng_RangerTypeClass.clj"
8
- Import "ng_CodeNode.clj"
9
- Import "ng_RangerAppWriterContext.clj"
10
- Import "ng_writer.clj"
11
- Import "ng_parser.clj"
12
- Import "ng_RangerArgMatch.clj"
13
- Import "ng_DictNode.clj"
14
- Import "ng_RangerSerializeClass.clj"
15
- Import "ng_RangerImmutableExtension.clj"
16
-
17
- class ClassJoinPoint {
18
- def class_def:RangerAppClassDesc
19
- def node@(weak):CodeNode
20
- }
21
-
22
- class NodeWalkResult {
23
- def not_enough_args false
24
- def last_was_block false
25
- def walk_later@(weak):[WalkLater]
26
- def arg_eval_start 0
27
- def last_walked 0
28
- }
29
-
30
-
31
- class WalkLater {
32
- def arg@(weak):CodeNode
33
- def callArg@(weak):CodeNode
34
- }
35
-
36
- class RangerFlowParser {
37
-
38
- def hasRootPath false
39
- def rootPath:string ""
40
- def _debug false
41
- ; def is_chaining false
42
- ; def chainRoot:CodeNode
43
-
44
- def stdCommands@(optional):CodeNode
45
- def lastProcessedNode@(weak):CodeNode
46
- def collectWalkAtEnd:[CodeNode]
47
- def walkAlso@(weak):[CodeNode]
48
- def serializedClasses@(weak):[RangerAppClassDesc]
49
- def immutableClasses@(weak):[RangerAppClassDesc]
50
- def classesWithTraits:[ClassJoinPoint]
51
- def collectedIntefaces:[RangerAppClassDesc]
52
- def definedInterfaces:[string:boolean]
53
-
54
- def signatureCnt 0
55
- def argSignatureCnt 0
56
- def mainCnt 0
57
- def isDefinedSignature:[string:int]
58
- def isDefinedArgSignature:[string:int]
59
-
60
- def extendedClasses:[string:string]
61
-
62
- fn searchLib:string (paths:[string] libname:string) {
63
- for paths path:string i {
64
- if( file_exists path libname ) {
65
- return path
66
- }
67
- }
68
- return ""
69
- }
70
- fn getVoidNameSignature:string () {
71
- def s "void"
72
- if(has isDefinedSignature s) {
73
- def cc (unwrap (get isDefinedSignature s))
74
- return ("void_" + cc)
75
- }
76
- signatureCnt = signatureCnt + 1
77
- set isDefinedSignature s signatureCnt
78
- return ( "void_" + signatureCnt )
79
- }
80
-
81
- fn getNameSignature:string (node:CodeNode) {
82
- def s ( (node.type_name) + (node.buildTypeSignature()) )
83
- if(has isDefinedSignature s) {
84
- def cc (unwrap (get isDefinedSignature s))
85
- if(cc == 1) {
86
- return node.type_name
87
- }
88
- return ("_" + cc)
89
- }
90
- signatureCnt = signatureCnt + 1
91
- set isDefinedSignature s signatureCnt
92
- if(signatureCnt == 1) {
93
- return node.type_name
94
- }
95
- return ( node.type_name + "_" + signatureCnt )
96
- }
97
-
98
- fn getArgsSignature:string (node:CodeNode) {
99
- def exp_s ""
100
- for node.children arg:CodeNode i {
101
- exp_s = exp_s + (arg.buildTypeSignature())
102
- exp_s = exp_s + ","
103
- }
104
- if(has isDefinedArgSignature exp_s) {
105
- def cc (unwrap (get isDefinedArgSignature exp_s))
106
- if(cc == 1) {
107
- return ""
108
- }
109
- return ("_" + cc)
110
- }
111
- signatureCnt = signatureCnt + 1
112
- set isDefinedArgSignature exp_s signatureCnt
113
- if(signatureCnt == 1) {
114
- return ""
115
- }
116
- return ( "_" + signatureCnt )
117
- }
118
-
119
- fn cmdEnum:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
120
- def fNameNode:CodeNode (itemAt node.children 1)
121
- def enumList:CodeNode (itemAt node.children 2)
122
- def new_enum:RangerAppEnum (new RangerAppEnum ())
123
- for enumList.children item:CodeNode i {
124
- new_enum.add(item.vref)
125
- }
126
- set ctx.definedEnums fNameNode.vref new_enum
127
- }
128
- fn initStdCommands:void () {
129
- }
130
-
131
- fn findLanguageOper@(optional weak):CodeNode (details:CodeNode ctx:RangerAppWriterContext) {
132
- def langName:string (ctx.getTargetLang())
133
- def rv:CodeNode
134
- for details.children det:CodeNode i {
135
- if ( (array_length det.children ) > 0) {
136
- def fc:CodeNode (itemAt det.children 0)
137
- if (fc.vref == "templates") {
138
- def tplList:CodeNode (itemAt det.children 1)
139
- for tplList.children tpl:CodeNode i {
140
- def tplName:CodeNode (tpl.getFirst())
141
- ; def tplImpl@(optional):CodeNode
142
- ; tplImpl = (tpl.getSecond())
143
- if ((tplName.vref != "*") && (tplName.vref != langName)) {
144
- continue
145
- }
146
- rv = tpl
147
- return rv
148
- }
149
- }
150
- }
151
- }
152
- return rv
153
- }
154
-
155
- fn buildMacro:CodeNode ( langOper@(optional):CodeNode args:CodeNode ctx:RangerAppWriterContext ) {
156
-
157
- def subCtx:RangerAppWriterContext (ctx.fork())
158
- def wr:CodeWriter (new CodeWriter ())
159
- def lcc:LiveCompiler (new LiveCompiler())
160
- lcc.langWriter = (new RangerRangerClassWriter ())
161
- lcc.langWriter.compiler = lcc
162
-
163
- subCtx.targetLangName = "ranger"
164
- subCtx.restartExpressionLevel()
165
-
166
- def macroNode:CodeNode (unwrap langOper)
167
- def cmdList:CodeNode (macroNode.getSecond())
168
- ;walkCommandList:void (cmd:CodeNode node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
169
- lcc.walkCommandList( cmdList args subCtx wr )
170
-
171
- def lang_str:string (wr.getCode())
172
- ; print " macro generated code : " + lang_str
173
-
174
- def lang_code:SourceCode (new SourceCode ( lang_str ) )
175
- lang_code.filename = "<macro " + macroNode.vref + ">"
176
- def lang_parser:RangerLispParser (new RangerLispParser (lang_code))
177
- lang_parser.parse()
178
-
179
- def node@(lives):CodeNode (unwrap lang_parser.rootNode)
180
- return node
181
- }
182
-
183
- fn walkNodeArguments:NodeWalkResult ( arg_eval_start:int args:CodeNode callArgs:CodeNode codeDef:CodeNode ctx:RangerAppWriterContext blockCtx:RangerAppWriterContext wr:CodeWriter ) {
184
-
185
- def res (new NodeWalkResult)
186
-
187
- for args.children arg@(lives):CodeNode i {
188
- if( i < arg_eval_start) {
189
- continue
190
- }
191
- res.arg_eval_start = i
192
-
193
- if( (array_length callArgs.children) <= (i + 1)) {
194
- res.not_enough_args = true
195
- break
196
- }
197
-
198
- def callArg@(lives):CodeNode (itemAt callArgs.children (i + 1))
199
- if (arg.hasFlag("define")) {
200
- def p@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
201
- p.name = callArg.vref
202
- p.value_type = arg.value_type
203
- p.node = callArg
204
- p.nameNode = callArg
205
- p.is_optional = false
206
- p.init_cnt = 1
207
- ctx.defineVariable(p.name p)
208
-
209
- callArg.hasParamDesc = true
210
- callArg.ownParamDesc = p
211
- callArg.paramDesc = p
212
- if ((strlen callArg.type_name) == 0) {
213
- callArg.type_name = arg.type_name
214
- callArg.value_type = arg.value_type
215
- }
216
- callArg.eval_type = arg.value_type
217
- callArg.eval_type_name = arg.type_name
218
- }
219
- if (arg.hasFlag("ignore")) {
220
- continue _
221
- }
222
- if (arg.hasFlag("noeval")) {
223
- callArg.eval_type = callArg.value_type
224
- callArg.eval_type_name = callArg.type_name
225
- callArg.eval_array_type = callArg.array_type
226
- callArg.eval_key_type = callArg.key_type
227
- continue _
228
- }
229
- res.last_walked = (i + 1)
230
- if( arg.value_type == RangerNodeType.ExpressionType ) {
231
- if(codeDef.is_block_node == false) {
232
- def later@(lives) (new WalkLater)
233
- later.arg = arg
234
- later.callArg = callArg
235
- push res.walk_later later
236
- }
237
- } {
238
- if(arg.type_name == "block" || (arg.hasFlag("block"))) {
239
- ; NOTE: blockCtx is used to walk the given block, necessary for example macros
240
- this.WalkNode(callArg blockCtx wr)
241
- res.last_was_block = true
242
- } {
243
- ; (inCtx.forkWithOps( (itemAt ch.children 3) ))
244
- ctx.setInExpr()
245
- this.WalkNode(callArg ctx wr)
246
- ctx.unsetInExpr()
247
- if( (strlen arg.type_name) > 0 ) {
248
- this.convertToUnion( arg.type_name callArg ctx wr)
249
- }
250
- res.last_was_block = false
251
- }
252
- if( arg.hasFlag("mutates")) {
253
- if(callArg.hasParamDesc) {
254
- if(callArg.paramDesc && (!null? callArg.paramDesc.propertyClass)) {
255
- if(callArg.paramDesc.propertyClass.nameNode.hasFlag("immutable")) {
256
- def propC (callArg.paramDesc.propertyClass)
257
- def currC (ctx.getCurrentClass())
258
- if( (unwrap currC) != (unwrap propC) ) {
259
- res.not_enough_args = true
260
- }
261
- }
262
- }
263
- }
264
- }
265
-
266
- }
267
- }
268
- return res
269
- }
270
-
271
- fn stdParamMatch:boolean (callArgs@(lives):CodeNode inCtx:RangerAppWriterContext wr:CodeWriter require_all_match:boolean) {
272
- stdCommands = (inCtx.getStdCommands())
273
- def callFnName:CodeNode (callArgs.getFirst())
274
- def cmds:CodeNode stdCommands
275
- def some_matched:boolean false
276
- def found_fn:boolean false
277
- def added_ns ""
278
- def missed_args:[string]
279
- def ctx:RangerAppWriterContext (inCtx.fork())
280
- def lang_name:string (ctx.getTargetLang())
281
- def expects_error:boolean false
282
- def err_cnt:int (inCtx.getErrorCount())
283
- def arg_eval_start 0
284
- if( callArgs.hasBooleanProperty("error")) {
285
- expects_error = true
286
- }
287
-
288
- ; TODO: continue pushing the operators into the methodChain
289
- ; + add into the method chain the detected operator
290
- ; + check that chain can be a mix of actual operators or calls
291
- ; surround_static( (static_fn_foo()).map() ).filter()
292
- def in_chain false
293
- def call_arg_cnt 0
294
- for callArgs.children ca:CodeNode i {
295
- def name (ca.vref)
296
- if( ( (strlen name) > 0 ) && ( ( charAt name 0) == (charcode ".")) ) {
297
- ; list.add(2).add(2)
298
- in_chain = true
299
- ca.is_part_of_chain = true
300
- }
301
- if in_chain {
302
- ca.is_part_of_chain = true
303
- } {
304
- call_arg_cnt = call_arg_cnt + 1
305
- }
306
- }
307
-
308
- if in_chain {
309
- def fc (callArgs.getFirst())
310
- def sc (callArgs.getSecond())
311
- def thrd (callArgs.getThird())
312
- def i call_arg_cnt
313
- def chainRoot:CodeNode (callArgs)
314
- def innerNode@(weak):CodeNode
315
- def newNode (callArgs.newExpressionNode())
316
- newNode.children.push( (fc.copy()) ) ;
317
- newNode.children.push( (sc.copy()) ) ;
318
- newNode.children.push( (thrd.copy()) ) ;
319
- innerNode = newNode
320
- def chain_cnt 0
321
- def chlen (array_length callArgs.children)
322
-
323
- while ( i < (chlen - 1) ) {
324
- def fc (itemAt callArgs.children i)
325
- def args@(lives) (itemAt callArgs.children (i + 1))
326
- def name (fc.vref)
327
- if( ( (strlen name) > 0 ) && ( ( charAt name 0) == (charcode ".")) ) {
328
- def method_name (substring name 1 (strlen name))
329
- def newNode (callArgs.newExpressionNode())
330
- newNode.add( (callArgs.newVRefNode("call") ) )
331
- newNode.add( (innerNode.copy() ) )
332
- newNode.add( (callArgs.newVRefNode(method_name)) )
333
- newNode.add( (args.copy()))
334
- innerNode = newNode
335
- chain_cnt = chain_cnt + 1
336
- } {
337
- ctx.addError(callArgs "Invalid chaining op")
338
- }
339
- i = i + 2
340
- }
341
- if ( chain_cnt > 0 ) {
342
- callArgs.getChildrenFrom( (unwrap innerNode ) )
343
- callArgs.tag = "chainroot"
344
- callArgs.flow_done = false
345
- this.WalkNode( callArgs ctx wr)
346
- return true
347
- } {
348
- ctx.addError( callArgs "Invalid chain")
349
- return true
350
- }
351
- }
352
-
353
- ; print "stdParamMatch -> " + callFnName.vref
354
- def op_list (ctx.getOperators(callFnName.vref))
355
-
356
- def origCallArgs (callArgs.copy())
357
-
358
- for op_list ch@(lives):CodeNode main_index {
359
- def fc:CodeNode (ch.getFirst())
360
- def nameNode:CodeNode (ch.getSecond())
361
- def args:CodeNode (ch.getThird())
362
-
363
- ; if loop is done two times, remove the old NS definition
364
- ctx.removeOpNs( added_ns )
365
- ctx.addOpNs( fc.vref )
366
- added_ns = fc.vref
367
-
368
- def line_index:int (callArgs.getLine())
369
- ; def callerArgCnt:int (((array_length callArgs.children) - 1))
370
- def callerArgCnt (call_arg_cnt - 1)
371
- def fnArgCnt:int (array_length args.children)
372
- def has_eval_ctx:boolean false
373
- def is_macro:boolean false
374
- def is_static_fn false
375
- def static_fn_name ""
376
- def static_class_name ""
377
- def static_nameNode@(weak):CodeNode
378
- if (nameNode.hasFlag("newcontext")) {
379
- ctx = (inCtx.fork())
380
- has_eval_ctx = true
381
- }
382
- def expanding_node:boolean (nameNode.hasFlag("expands"))
383
- if ( (callerArgCnt == fnArgCnt) || expanding_node) {
384
- def details_list:CodeNode (itemAt ch.children 3)
385
- def langOper:CodeNode (this.findLanguageOper( details_list ctx ))
386
- if(null? langOper) {
387
- ; ctx.addError( callArgs "Did not find language based operator")
388
- continue
389
- }
390
- if( ( langOper.hasBooleanProperty("macro") ) || ( (nameNode.hasFlag("macro"))) ) {
391
- is_macro = true
392
- }
393
-
394
- def codeDef (langOper.getSecond())
395
-
396
- ; if(codeDef.is_block_node) {
397
- ; args = (args.rebuildWithType( (new RangerArgMatch) false ))
398
- ; }
399
- def match:RangerArgMatch (new RangerArgMatch ())
400
- def last_walked:int 0
401
- def last_was_block false
402
- def walk_later@(weak):[WalkLater]
403
- def not_enough_args false
404
-
405
- def WalkA (this.walkNodeArguments( arg_eval_start args callArgs codeDef ctx ctx wr))
406
-
407
- not_enough_args = WalkA.not_enough_args
408
- last_was_block = WalkA.last_was_block
409
- walk_later = WalkA.walk_later
410
- last_walked = WalkA.last_walked
411
-
412
- if not_enough_args {
413
- continue
414
- }
415
-
416
- if expanding_node {
417
- for callArgs.children caCh:CodeNode i2 {
418
- if(i2 > last_walked) {
419
- if last_was_block {
420
- def sCtx (ctx.forkWithOps( (itemAt ch.children 3) ))
421
- this.WalkNode(caCh sCtx wr)
422
- } {
423
- ctx.setInExpr()
424
- this.WalkNode(caCh ctx wr)
425
- ctx.unsetInExpr()
426
- }
427
- }
428
- }
429
- }
430
-
431
- def all_matched:boolean (match.matchArguments(args callArgs ctx 1))
432
- if all_matched {
433
- for walk_later later:WalkLater i {
434
- def ca (unwrap later.callArg)
435
- def aa (unwrap later.arg)
436
-
437
- def newNode:CodeNode (new CodeNode ( (unwrap ca.code) ca.sp ca.ep))
438
- ; def match:RangerArgMatch (new RangerArgMatch ())
439
- def fnDef:CodeNode (unwrap aa.expression_value)
440
- def copyOf:CodeNode (fnDef.rebuildWithType( match false ))
441
- def ffc:CodeNode (itemAt copyOf.children 0)
442
- ffc.vref = "fun"
443
- def itemCopy:CodeNode (ca.rebuildWithType (match false))
444
- push copyOf.children itemCopy
445
- def cnt:int ( array_length ca.children )
446
- while( cnt > 0) {
447
- removeLast ca.children
448
- cnt = cnt - 1
449
- }
450
- for copyOf.children ch@(lives):CodeNode i {
451
- push ca.children ch
452
- }
453
- ; -->
454
- ; def sCtx (ctx.forkWithOps( (itemAt ch.children 3) ))
455
- def sCtx (ctx.fork())
456
-
457
- this.WalkNode(ca sCtx wr)
458
- ; last_was_block = true
459
-
460
- }
461
- }
462
- if(codeDef.is_block_node && (all_matched)) {
463
-
464
- def nSig ""
465
- if( (array_length args.children) > 0) {
466
- def arg0 (args.getFirst())
467
- nSig = ( (this.getNameSignature(arg0)) )
468
- } {
469
- nSig = ( (this.getVoidNameSignature()) )
470
- }
471
- ;print "---- static method ----"
472
- ;print "arg0 " + (arg0.getCode())
473
- def new_cl ( ctx.createOpStaticClass( nSig ) )
474
- this.WalkNode( (unwrap new_cl.classNode ) ctx wr)
475
- def bodyCopy (codeDef.rebuildWithType(match true))
476
- def argsCopy (args.rebuildWithType(match true))
477
- def nameCopy (nameNode.rebuildWithType(match true))
478
-
479
- def sigN (ctx.transformOpNameWord( fc.vref ))
480
- def argsSig ( sigN + (this.getArgsSignature(argsCopy)) )
481
-
482
- ; print "Args sig for " + nSig + " == " + (argsSig)
483
-
484
- if( false == (new_cl.hasStaticMethod(argsSig))) {
485
- def sMethod ( ctx.createStaticMethod( argsSig new_cl nameCopy argsCopy bodyCopy this) )
486
- static_nameNode = nameCopy
487
- def fCtx (unwrap sMethod.fnCtx)
488
- fCtx.currentMethod = sMethod
489
- fCtx.is_function = true
490
- def m:RangerAppFunctionDesc sMethod
491
- fCtx.in_static_method = true
492
- if (nameCopy.hasFlag("weak")) {
493
- m.changeStrength(0 1 nameNode)
494
- } {
495
- m.changeStrength(1 1 nameNode)
496
- }
497
- fCtx.setInMethod()
498
- for m.params v@(lives):RangerAppParamDesc i {
499
- fCtx.defineVariable(v.name v)
500
- v.nameNode.eval_type = (v.nameNode.typeNameAsType(fCtx))
501
- v.nameNode.eval_type_name = v.nameNode.type_name
502
- }
503
- this.WalkNodeChildren( bodyCopy fCtx wr)
504
- fCtx.unsetInMethod()
505
- fCtx.in_static_method = false
506
- fCtx.function_level_context = true
507
- ;if (fnBody.didReturnAtIndex == -1) {
508
- ; if (cn.type_name != "void") {
509
- ; ctx.addError(node "Function does not return any values!")
510
- ; }
511
- ;}
512
- for fCtx.localVarNames n:string i {
513
- def p:RangerAppParamDesc (get fCtx.localVariables n)
514
- if (p.set_cnt > 0) {
515
- if(p.is_immutable) {
516
- ctx.addError( callArgs "Immutable variable was assigned")
517
- }
518
- def defNode:CodeNode p.node
519
- defNode.setFlag("mutable")
520
- def nNode:CodeNode p.nameNode
521
- nNode.setFlag("mutable")
522
- }
523
- }
524
- } {
525
- def sMethod ( new_cl.findStaticMethod( argsSig ) )
526
- static_nameNode = sMethod.nameNode
527
- }
528
- is_static_fn = true
529
- static_fn_name = argsSig
530
- static_class_name = new_cl.name
531
- }
532
- if all_matched {
533
-
534
- if is_static_fn {
535
-
536
- ;is_static_fn = true
537
- ;static_fn_name = sMethod.name
538
-
539
- def firstArg (callArgs.getFirst())
540
- firstArg.vref = static_class_name + "." + static_fn_name
541
- firstArg.flow_done = false
542
- firstArg.value_type = RangerNodeType.VRef
543
- clear firstArg.ns
544
- push firstArg.ns static_class_name
545
- push firstArg.ns static_fn_name
546
-
547
- def newArgs:CodeNode (new CodeNode ( (unwrap callArgs.code) callArgs.sp callArgs.ep) )
548
- ; note: noeval flag is used here to mark a parameter which is matched but not evaluated
549
- ; if(arg.hasFlag("noeval"))
550
- for callArgs.children ca:CodeNode i {
551
- if ca.is_part_of_chain {
552
- continue
553
- }
554
- if( i > 0) {
555
- def arg (itemAt args.children (i - 1))
556
- if( arg.hasFlag("noeval")) {
557
- continue
558
- }
559
- push newArgs.children ca
560
- }
561
- }
562
- def arg_len:int (array_length callArgs.children)
563
- while (arg_len > 1 ) {
564
- removeLast callArgs.children
565
- arg_len = arg_len - 1
566
- }
567
- push callArgs.children newArgs
568
-
569
- callArgs.flow_done = false
570
- this.WalkNode ( callArgs ctx wr)
571
- match.setRvBasedOn((unwrap static_nameNode) callArgs)
572
- ctx.removeOpNs( added_ns )
573
- return true
574
- }
575
-
576
- if is_macro {
577
-
578
- ; create new macro so that block is evaluated in the ranger context
579
- ; def macroArgs (origCallArgs.copy())
580
- ; def mCtx (ctx.fork())
581
- ; mCtx.targetLangName = "ranger"
582
- ; def WalkA (this.walkNodeArguments( 0 args macroArgs codeDef ctx mCtx wr))
583
-
584
- ; TODO: check the effect of chaining here...
585
- def macroNode:CodeNode ( this.buildMacro( langOper callArgs ctx ) )
586
- ; print "macro: " + (macroNode.getCode())
587
- def arg_len:int (array_length callArgs.children)
588
- while (arg_len > 0 ) {
589
- removeLast callArgs.children
590
- arg_len = arg_len - 1
591
- }
592
- push callArgs.children macroNode
593
- macroNode.parent = callArgs
594
- this.WalkNode( macroNode ctx wr)
595
- match.setRvBasedOn(nameNode callArgs)
596
- ; print "--- macro was walked -- "
597
- ctx.removeOpNs( added_ns )
598
-
599
- return true
600
- }
601
-
602
- if (nameNode.hasFlag("moves")) {
603
- def moves_opt@(optional):CodeNode (nameNode.getFlag("moves"))
604
- def moves:CodeNode (unwrap moves_opt)
605
- def ann:CodeNode moves.vref_annotation
606
- def from:CodeNode (ann.getFirst())
607
- def to:CodeNode (ann.getSecond())
608
- def cA:CodeNode (itemAt callArgs.children from.int_value)
609
- def cA2:CodeNode (itemAt callArgs.children to.int_value)
610
- if cA.hasParamDesc {
611
- def pp:RangerAppParamDesc cA.paramDesc
612
- def pp2:RangerAppParamDesc cA2.paramDesc
613
- pp.moveRefTo(callArgs (unwrap pp2) ctx)
614
- }
615
- }
616
- if (nameNode.hasFlag("returns")) {
617
- ; print "==> returns flag for " + (callArgs.getLineAsString())
618
- def activeFn:RangerAppFunctionDesc (ctx.getCurrentMethod())
619
- if ( (activeFn.nameNode.type_name != "void") || (activeFn.nameNode.value_type == RangerNodeType.ExpressionType)) {
620
-
621
- if ( (array_length callArgs.children) < 2 ) {
622
- ctx.addError(callArgs " missing return value !!!")
623
- } {
624
- def returnedValue:CodeNode (itemAt callArgs.children 1)
625
- def validated_returnvalue false
626
- if(activeFn.nameNode.value_type == RangerNodeType.ExpressionType) {
627
- validated_returnvalue = true
628
- ; lambda format of the called function
629
- def fnExpr (activeFn.nameNode.expression_value)
630
- if(null? fnExpr) {
631
- ctx.addError( (unwrap activeFn.nameNode) "returned anonymous function should have a method signature")
632
- } {
633
- if( (returnedValue.value_type != RangerNodeType.ExpressionType ) &&
634
- (returnedValue.eval_type != RangerNodeType.ExpressionType) ) {
635
- ctx.addError(returnedValue "Function should return anonymous function!")
636
- } {
637
-
638
- if( returnedValue.hasParamDesc && (!null? returnedValue.paramDesc.nameNode)) {
639
- def rExpr returnedValue.paramDesc.nameNode.expression_value
640
- this.matchLambdaArgs( (unwrap fnExpr) (unwrap rExpr) ctx wr )
641
- } {
642
- def rExpr returnedValue.expression_value
643
- this.matchLambdaArgs( (unwrap fnExpr) (unwrap rExpr) ctx wr )
644
- }
645
- }
646
- }
647
- }
648
-
649
- if( validated_returnvalue == false ) {
650
- if ((match.doesMatch( (unwrap activeFn.nameNode) returnedValue ctx)) == false) {
651
- if(activeFn.nameNode.ifNoTypeSetToEvalTypeOf( returnedValue)) {
652
- ; sets the type
653
- } {
654
- ctx.addError(returnedValue "invalid return value type!!!")
655
- }
656
- }
657
- }
658
- def argNode:CodeNode (unwrap activeFn.nameNode)
659
- if( returnedValue.hasFlag("optional")) {
660
- if ( false == (argNode.hasFlag("optional")) ) {
661
- ctx.addError(callArgs ( "function return value optionality does not match, expected non-optional return value, optional given at " + (argNode.getCode())) )
662
- }
663
- }
664
-
665
- if( argNode.hasFlag("optional")) {
666
- if ( false == (returnedValue.hasFlag("optional")) ) {
667
- ctx.addError(callArgs ( "function return value optionality does not match, expected optional return value " + (argNode.getCode())) )
668
- }
669
- }
670
-
671
- def pp:RangerAppParamDesc returnedValue.paramDesc
672
- if (!null? pp) {
673
- pp.moveRefTo(callArgs activeFn ctx)
674
- }
675
-
676
-
677
- }
678
- }
679
- if (null? callArgs.parent) {
680
- ctx.addError(callArgs "did not have parent")
681
- print ("no parent => " + (callArgs.getCode()))
682
- }
683
- callArgs.parent.didReturnAtIndex = (indexOf callArgs.parent.children callArgs)
684
- }
685
- if ((nameNode.hasFlag("returns")) == false) {
686
- match.setRvBasedOn(nameNode callArgs)
687
- }
688
- if has_eval_ctx {
689
- callArgs.evalCtx = ctx
690
- }
691
- def nodeP:CodeNode callArgs.parent
692
- if (!null? nodeP) {
693
- } {
694
- }
695
- def sig:string (nameNode.buildTypeSignatureUsingMatch(match))
696
- ; def ts:RangerTypeClass (callArgs.createTypeSignatureForName(sig ctx))
697
- ; callArgs.typeClass = ts
698
- some_matched = true
699
- callArgs.has_operator = true
700
- callArgs.op_index = main_index
701
- callArgs.operator_node = ch
702
- for args.children arg:CodeNode arg_index {
703
- if arg.has_vref_annotation {
704
- def anns:CodeNode arg.vref_annotation
705
- for anns.children ann:CodeNode i {
706
- if (ann.vref == "mutates") {
707
- def theArg:CodeNode (itemAt callArgs.children (arg_index + 1))
708
- if theArg.hasParamDesc {
709
- theArg.paramDesc.set_cnt = (theArg.paramDesc.set_cnt + 1)
710
- }
711
- }
712
- }
713
- }
714
- }
715
- ; print "some_matched for op operator_node -> " + (ch.getLineAsString())
716
- break _
717
- }
718
- }
719
-
720
- }
721
- if ( require_all_match == true && some_matched == false) {
722
- ;print "===================== MATCH ERROR 2 ====================="
723
- ;print ("stdMatch -> Could not match argument types for " + callFnName.vref)
724
- ;print (callArgs.getCode())
725
- ;def line_index:int (callArgs.getLine())
726
- ;print ((callArgs.getFilename()) + " Line: " + line_index)
727
- ;for callArgs.children ca:CodeNode i {
728
- ; print ((((((("arg " + i) + " eval_type : ") + ca.eval_type) + " eval_type_name = ") + ca.eval_type_name) + " type : ") + ca.type_name)
729
- ;}
730
- ctx.addError(callArgs ("Could not match argument types for " + callFnName.vref))
731
- } {
732
- ; match OK
733
- }
734
- if(expects_error) {
735
- def cnt_now:int (ctx.getErrorCount())
736
- if (cnt_now == err_cnt) {
737
- ctx.addParserError( callArgs "LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt + " : " +cnt_now)
738
- }
739
- } {
740
- def cnt_now:int (ctx.getErrorCount())
741
- if (cnt_now > err_cnt) {
742
- ctx.addParserError( callArgs "LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt + " : " +cnt_now)
743
- }
744
- }
745
- ctx.removeOpNs( added_ns )
746
- return some_matched
747
- }
748
- fn cmdImport:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
749
- return false
750
- }
751
- fn getThisName:string () {
752
- return "this"
753
- }
754
- fn WriteThisVar:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
755
- }
756
- fn WriteVRef:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
757
- if (node.vref == "_") {
758
- return
759
- }
760
-
761
- def rootObjName:string (itemAt node.ns 0)
762
- if (ctx.isInStatic()) {
763
- if(rootObjName == "this") {
764
- ctx.addError(node "This can not be used in static context")
765
- }
766
- }
767
- if (ctx.isEnumDefined(rootObjName)) {
768
- def enumName:string (itemAt node.ns 1)
769
- def ee@(optional):RangerAppEnum (ctx.getEnum(rootObjName))
770
- def e:RangerAppEnum (unwrap ee)
771
- if (has e.values enumName) {
772
- node.eval_type = RangerNodeType.Enum
773
- node.eval_type_name = rootObjName
774
- node.int_value = (unwrap (get e.values enumName))
775
- ;def ts:RangerTypeClass (node.createTypeSignatureForName(rootObjName ctx))
776
- ;ts.value_type = RangerNodeType.Enum
777
- ;node.typeClass = ts
778
- } {
779
- ctx.addError(node ("Undefined Enum " + rootObjName + "." + enumName))
780
- node.eval_type = RangerNodeType.InvalidType
781
- }
782
- return
783
- }
784
- if (node.vref == (this.getThisName())) {
785
- def cd@(optional):RangerAppClassDesc (ctx.getCurrentClass())
786
- def thisClassDesc:RangerAppClassDesc cd
787
- node.eval_type = RangerNodeType.Object
788
- node.eval_type_name = thisClassDesc.name
789
- node.ref_type = RangerNodeRefType.StrongImmutable
790
- ; def ts:RangerTypeClass (thisClassDesc.nameNode.createTypeSignature(ctx))
791
- ;node.typeClass = ts
792
- return
793
- }
794
-
795
- if( ctx.isCapturing()) {
796
- if( (ctx.isVarDefined(rootObjName)) ) {
797
- if ( (ctx.isLocalToCapture(rootObjName)) == false ) {
798
- ; is_captured
799
- def captDef@(lives):RangerAppParamDesc (ctx.getVariableDef(rootObjName))
800
- def cd@(optional):RangerAppClassDesc (ctx.getCurrentClass())
801
- ; capturedLocals
802
- push cd.capturedLocals captDef
803
-
804
- captDef.is_captured = true
805
- ctx.addCapturedVariable( rootObjName)
806
- }
807
- }
808
- }
809
- if ( rootObjName == "this" || (ctx.isVarDefined(rootObjName)) ) {
810
-
811
- def vDef2:RangerAppParamDesc (ctx.getVariableDef(rootObjName))
812
- def activeFn:RangerAppFunctionDesc (ctx.getCurrentMethod())
813
- def vDef@(optional):RangerAppParamDesc (this.findParamDesc(node ctx wr))
814
-
815
- if(!null? vDef) {
816
- node.hasParamDesc = true
817
- node.ownParamDesc = vDef
818
- node.paramDesc = vDef
819
- vDef.ref_cnt = (1 + vDef.ref_cnt)
820
- def vNameNode:CodeNode vDef.nameNode
821
- if (!null? vNameNode) {
822
- if (vNameNode.hasFlag("optional")) {
823
- node.setFlag("optional")
824
- }
825
- ;def ts:RangerTypeClass (vNameNode.createTypeSignature(ctx))
826
- ;node.typeClass = ts
827
- node.eval_type = (vNameNode.typeNameAsType(ctx))
828
- node.eval_type_name = vNameNode.type_name
829
- if (vNameNode.value_type == RangerNodeType.Array) {
830
- node.eval_type = RangerNodeType.Array
831
- node.eval_array_type = vNameNode.array_type
832
- }
833
- if (vNameNode.value_type == RangerNodeType.Hash) {
834
- node.eval_type = RangerNodeType.Hash
835
- node.eval_key_type = vNameNode.key_type
836
- node.eval_array_type = vNameNode.array_type
837
- }
838
- }
839
- }
840
- } {
841
- def class_or_this:boolean (rootObjName == (this.getThisName()))
842
- if (ctx.isDefinedClass(rootObjName)) {
843
- class_or_this = true
844
- node.eval_type = RangerNodeType.Class
845
- node.eval_type_name = rootObjName
846
- }
847
- if (ctx.hasTemplateNode(rootObjName)) {
848
- class_or_this = true
849
- }
850
- if (false == class_or_this) {
851
- def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
852
- def desc:RangerAppClassDesc (unwrap udesc)
853
-
854
- if(node.vref == "fun") {
855
- ; print "TODO: fix the 'fun'"
856
- } {
857
- ctx.addError(node ("WriteVREF -> Undefined variable " + node.vref + " in class " + desc.name + " node : " + (node.getCode())))
858
- ctx.addError(node ("WriteVREF -> Undefined variable " + rootObjName + " in class " + desc.name + " node : " + (node.parent.getCode())))
859
- }
860
-
861
-
862
- }
863
- return
864
- }
865
- }
866
- fn CreateClass:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
867
- }
868
- fn DefineVar:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
869
- }
870
- fn WriteComment:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
871
- }
872
- fn cmdLog:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
873
- }
874
- fn cmdDoc:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
875
- }
876
- fn cmdGitDoc:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
877
- }
878
- fn cmdNative:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
879
- }
880
- fn LangInit:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
881
- }
882
- fn getWriterLang:string () {
883
- return "_"
884
- }
885
- fn StartCodeWriting:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
886
- }
887
- fn Constructor:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
888
- this.shouldHaveChildCnt(3 node ctx "Method expexts four arguments")
889
- def cn:CodeNode (itemAt node.children 1)
890
- def fnBody:CodeNode (itemAt node.children 2)
891
- def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
892
- def desc:RangerAppClassDesc (unwrap udesc)
893
-
894
- def m:RangerAppFunctionDesc desc.constructor_fn
895
-
896
- ; m.fnCtx
897
- def subCtx:RangerAppWriterContext (unwrap m.fnCtx)
898
-
899
- subCtx.is_function = true
900
- subCtx.currentMethod = m
901
- subCtx.setInMethod()
902
- for m.params v@(lives):RangerAppParamDesc i {
903
- subCtx.defineVariable(v.name v)
904
- }
905
- this.WalkNodeChildren(fnBody subCtx wr)
906
- subCtx.unsetInMethod()
907
- if (fnBody.didReturnAtIndex >= 0) {
908
- ctx.addError(node "constructor should not return any values!")
909
- }
910
- for subCtx.localVarNames n:string i {
911
- def p:RangerAppParamDesc (get subCtx.localVariables n)
912
- if (p.set_cnt > 0) {
913
- if(p.is_immutable) {
914
- ctx.addError( node "Immutable variable was assigned a value")
915
- }
916
- def defNode:CodeNode p.node
917
- defNode.setFlag("mutable")
918
- def nNode:CodeNode p.nameNode
919
- nNode.setFlag("mutable")
920
- }
921
- }
922
- }
923
- fn WriteScalarValue:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
924
- node.eval_type = node.value_type
925
- switch node.value_type {
926
- case RangerNodeType.Double {
927
- node.eval_type_name = "double"
928
- }
929
- case RangerNodeType.String {
930
- node.eval_type_name = "string"
931
- }
932
-
933
- case RangerNodeType.Integer {
934
- node.eval_type_name = "int"
935
- }
936
- case RangerNodeType.Boolean {
937
- node.eval_type_name = "boolean"
938
- }
939
- }
940
- }
941
-
942
- fn buildGenericClass:void (tpl:CodeNode node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
943
- def root:RangerAppWriterContext (ctx.getRoot())
944
- def cn:CodeNode (tpl.getSecond())
945
- def newName:CodeNode (node.getSecond())
946
- def tplArgs:CodeNode cn.vref_annotation
947
- def givenArgs:CodeNode newName.vref_annotation
948
- def sign:string (cn.vref + (givenArgs.getCode()))
949
- if (has root.classSignatures sign) {
950
- return
951
- }
952
- print ("could build generic class... " + cn.vref)
953
- def match:RangerArgMatch (new RangerArgMatch ())
954
- for tplArgs.children arg:CodeNode i {
955
- def given:CodeNode (itemAt givenArgs.children i)
956
- print ((" setting " + arg.vref) + " => " + given.vref)
957
- if (false == (match.add(arg.vref given.vref ctx))) {
958
- print "set failed!"
959
- } {
960
- print "set OK"
961
- }
962
- print (" T == " + (match.getTypeName(arg.vref)))
963
- }
964
- print (" T == " + (match.getTypeName("T")))
965
- def newClassNode:CodeNode (tpl.rebuildWithType(match false))
966
- print "build done"
967
- print (newClassNode.getCode())
968
- def sign:string (cn.vref + (givenArgs.getCode()))
969
- print ("signature ==> " + sign)
970
- def cName:CodeNode (newClassNode.getSecond())
971
- def friendlyName:string (root.createSignature(cn.vref sign))
972
- print ("class common name => " + friendlyName)
973
- cName.vref = friendlyName
974
- cName.has_vref_annotation = false
975
- print (newClassNode.getCode())
976
- this.WalkCollectMethods(newClassNode ctx wr)
977
- this.WalkNode(newClassNode root wr)
978
- print "the class collected the methods..."
979
- }
980
- fn cmdNew:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
981
- ; "
982
- if ((array_length node.children) < 2) {
983
- ctx.addError(node "the new operator expects at lest two arguments")
984
- return
985
- }
986
- if ((array_length node.children) < 3) {
987
- def expr (new CodeNode ( (unwrap node.code) node.sp node.ep))
988
- expr.expression = true
989
- push node.children expr
990
- ; ctx.addError(node "the new operator expects at lest two arguments")
991
- ; return
992
- }
993
- def obj:CodeNode (node.getSecond())
994
- def params:CodeNode (node.getThird())
995
- def currC@(lives):RangerAppClassDesc
996
- def b_template:boolean false
997
-
998
- def expects_error:boolean false
999
- def err_cnt:int (ctx.getErrorCount())
1000
- if( node.hasBooleanProperty("error")) {
1001
- expects_error = true
1002
- }
1003
-
1004
- ; transform generic trait into a class if necessary
1005
- if(obj.has_vref_annotation) {
1006
- this.CheckVRefTypeAnnotationOf( obj ctx wr )
1007
- }
1008
-
1009
- if (ctx.hasTemplateNode(obj.vref)) {
1010
- b_template = true
1011
- def tpl:CodeNode (ctx.findTemplateNode(obj.vref))
1012
- if obj.has_vref_annotation {
1013
- this.buildGenericClass(tpl node ctx wr)
1014
- currC = (ctx.findClassWithSign(obj))
1015
- if (!null? currC) {
1016
- print ("@@ class was found " + obj.vref)
1017
- }
1018
- } {
1019
- ctx.addError(node "generic class requires a type annotation")
1020
- return
1021
- }
1022
- }
1023
- this.WalkNode(obj ctx wr)
1024
- for params.children arg:CodeNode i {
1025
- ctx.setInExpr()
1026
- this.WalkNode(arg ctx wr)
1027
- ctx.unsetInExpr()
1028
- }
1029
- node.eval_type = RangerNodeType.Object
1030
- node.eval_type_name = obj.vref
1031
- if (b_template == false) {
1032
- currC = (ctx.findClass(obj.vref))
1033
- }
1034
- node.hasNewOper = true
1035
- node.clDesc = currC
1036
- def fnDescr:RangerAppFunctionDesc currC.constructor_fn
1037
- if (!null? fnDescr) {
1038
- if( (array_length fnDescr.params) > (array_length params.children)) {
1039
- ctx.addError(node "Not enough arguments for class constructor " + (fnDescr.node.getLineAsString()))
1040
- return
1041
- }
1042
- for fnDescr.params param:RangerAppParamDesc i {
1043
- def has_default:boolean false
1044
- if (param.nameNode.hasFlag("default")) {
1045
- has_default = true
1046
- }
1047
-
1048
- if( (array_length params.children) <= i) {
1049
- if has_default {
1050
- continue _
1051
- }
1052
- ctx.addError(node "Missing arguments for function")
1053
- ctx.addError( (unwrap param.nameNode) "To fix the previous error: Check original function declaration")
1054
- }
1055
-
1056
- def argNode:CodeNode (itemAt params.children i)
1057
-
1058
- if (false == (this.areEqualTypes( (unwrap param.nameNode) argNode ctx))) {
1059
- ctx.addError(argNode ("ERROR, invalid argument type for " + currC.name + " constructor "))
1060
- }
1061
-
1062
- def pNode:CodeNode (unwrap param.nameNode)
1063
- if( pNode.hasFlag("optional")) {
1064
- if ( false == (argNode.hasFlag("optional")) ) {
1065
- ctx.addError(node ( "new parameter optionality does not match, expected optional parameter" + (argNode.getCode())) )
1066
- }
1067
- }
1068
- if( argNode.hasFlag("optional")) {
1069
- if ( false == (pNode.hasFlag("optional")) ) {
1070
- ctx.addError(node ( "new parameter optionality does not match, expected non-optional, optional given" + (argNode.getCode())) )
1071
- }
1072
- }
1073
- }
1074
- }
1075
-
1076
- if(expects_error) {
1077
- def cnt_now:int (ctx.getErrorCount())
1078
- if (cnt_now == err_cnt) {
1079
- ctx.addParserError( node "LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt + " : " +cnt_now)
1080
- }
1081
- } {
1082
- def cnt_now:int (ctx.getErrorCount())
1083
- if (cnt_now > err_cnt) {
1084
- ctx.addParserError( node "LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt + " : " +cnt_now)
1085
- }
1086
- }
1087
- }
1088
- fn transformParams:[CodeNode] ( list:[CodeNode] fnArgs:[RangerAppParamDesc] ctx:RangerAppWriterContext) {
1089
- def res:[CodeNode]
1090
- for list item:CodeNode i {
1091
- if(item.is_block_node) {
1092
- def newNode:CodeNode (new CodeNode ( (unwrap item.code) item.sp item.ep))
1093
- def fnArg:RangerAppParamDesc (itemAt fnArgs i)
1094
- def nn:CodeNode (fnArg.nameNode)
1095
- if(null? nn.expression_value) {
1096
- ctx.addError( item "Parameter is not lambda expression")
1097
- break
1098
- }
1099
- def fnDef:CodeNode (unwrap nn.expression_value)
1100
- def match:RangerArgMatch (new RangerArgMatch ())
1101
- def copyOf:CodeNode (fnDef.rebuildWithType( match false ))
1102
- ; example:
1103
- ; fn mapToStrings:[string] ( callback:( f:string (item:T)) ) {
1104
- def fc:CodeNode (itemAt copyOf.children 0)
1105
- fc.vref = "fun"
1106
- ; then add the block as the last children
1107
- def itemCopy:CodeNode (item.rebuildWithType (match false))
1108
- push copyOf.children itemCopy
1109
- def cnt:int ( array_length item.children )
1110
- while( cnt > 0) {
1111
- removeLast item.children
1112
- cnt = cnt - 1
1113
- }
1114
- for copyOf.children ch@(lives):CodeNode i {
1115
- ; ch.flow_done = false
1116
- push item.children ch
1117
- }
1118
-
1119
- }
1120
- push res item
1121
- }
1122
- return res
1123
- }
1124
-
1125
- fn cmdCall:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1126
-
1127
- def obj (node.getSecond())
1128
- def method (node.getThird())
1129
- def callArgs (itemAt node.children 3)
1130
-
1131
- ; test if the method could be operator
1132
- ; (call 4 + (5))
1133
- def possible_cmd method.vref
1134
- def op_list (ctx.getOperators(possible_cmd))
1135
- for op_list cmd:CodeNode i {
1136
-
1137
- def altVersion ( node.newExpressionNode() )
1138
- def origCopy ( node.copy() )
1139
-
1140
- altVersion.add( (node.newVRefNode( possible_cmd)) )
1141
- altVersion.add( (obj.copy()) )
1142
- for callArgs.children ca:CodeNode i {
1143
- altVersion.add( (ca.copy()) )
1144
- }
1145
- altVersion.parent = node
1146
- node.getChildrenFrom( altVersion )
1147
- if ( this.stdParamMatch(node ctx wr false) ) {
1148
- return true
1149
- } {
1150
- ; no match
1151
- node.getChildrenFrom( origCopy )
1152
- }
1153
- }
1154
-
1155
- ; refresh the variables...
1156
- def obj (node.getSecond())
1157
- def method (node.getThird())
1158
- def callArgs (itemAt node.children 3)
1159
-
1160
- this.WalkNode( obj ctx wr )
1161
-
1162
- if(ctx.isDefinedClass(obj.eval_type_name)) {
1163
- def cl (ctx.findClass(obj.eval_type_name))
1164
- def m (cl.findMethod(method.vref))
1165
- if(!null? m) {
1166
- node.has_call = true
1167
- ctx.setInExpr()
1168
- for callArgs.children callArg:CodeNode i {
1169
- this.WalkNode( callArg ctx wr)
1170
- }
1171
- ctx.unsetInExpr()
1172
-
1173
- def nn:CodeNode m.nameNode
1174
- node.eval_type = (nn.typeNameAsType(ctx))
1175
- node.eval_type_name = nn.type_name
1176
- node.eval_array_type = nn.array_type
1177
- node.eval_key_type = nn.key_type
1178
-
1179
- return true
1180
- } {
1181
- ctx.addError(node ("Class " + obj.eval_type_name + " does not have method " + method.vref))
1182
- return false
1183
- }
1184
- }
1185
- ; TODO: set the correct return value from the function call:
1186
-
1187
- def op_list (ctx.getOperators(method.vref))
1188
- for op_list cmd:CodeNode i {
1189
- }
1190
-
1191
- return true
1192
- }
1193
-
1194
- ; getAnon:(_:string ( n:string )) ()
1195
- ; (fn:string (nn:string) {
1196
- fn matchLambdaArgs:boolean (n1:CodeNode n2:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1197
- def chLen1 (array_length n1.children)
1198
- def chLen2 (array_length n2.children)
1199
- if(chLen1 < 2) {
1200
- ctx.addError(n1 "Invalid Lambda definition, missing args or return value")
1201
- return false
1202
- }
1203
- if(chLen2 < 2) {
1204
- ctx.addError(n2 "Invalid Lambda definition, missing args or return value")
1205
- return false
1206
- }
1207
- ; create copies, just in case...
1208
- def rv1 (n1.getFirst())
1209
- def args1 (n1.getSecond())
1210
- def rv2 (n2.getFirst())
1211
- def args2 (n2.getSecond())
1212
-
1213
- def rvExpr1 (n1.newExpressionNode())
1214
- rvExpr1.push( (rv1.copy()) )
1215
- def rvExpr2 (n2.newExpressionNode())
1216
- rvExpr2.push( (rv2.copy()) )
1217
-
1218
- def argsExpr1 (args1.copy())
1219
- def argsExpr2 (args2.copy())
1220
-
1221
- def all_matched true
1222
-
1223
- if( (array_length argsExpr1.children) != (array_length argsExpr2.children) ) {
1224
- ctx.addError(n2 "Invalid parameter count for the lambda expression")
1225
- return false
1226
- }
1227
-
1228
- argsExpr1.children.forEach({
1229
- def item2 (itemAt argsExpr2.children index)
1230
- if ( item2.value_type != item.value_type ) {
1231
- all_matched = false
1232
- }
1233
- if ( item2.type_name != item.type_name ) {
1234
- all_matched = false
1235
- }
1236
- if ( item2.array_type != item.array_type ) {
1237
- all_matched = false
1238
- }
1239
- if ( item2.key_type != item.key_type ) {
1240
- all_matched = false
1241
- }
1242
- if ( all_matched && item.value_type == RangerNodeType.ExpressionType ) {
1243
- if( false == (this.matchLambdaArgs( (unwrap item.expression_value) (unwrap item2.expression_value) ctx wr) ) ) {
1244
- all_matched = false
1245
- }
1246
- }
1247
- })
1248
- if( all_matched == false) {
1249
- ctx.addError(n2 "Invalid lambda argument types")
1250
- return false
1251
- }
1252
-
1253
- rvExpr1.children.forEach({
1254
- def item2 (itemAt rvExpr2.children index)
1255
- if ( item2.value_type != item.value_type ) {
1256
- all_matched = false
1257
- }
1258
- if ( item2.type_name != item.type_name ) {
1259
- all_matched = false
1260
- }
1261
- if ( item2.array_type != item.array_type ) {
1262
- all_matched = false
1263
- }
1264
- if ( item2.key_type != item.key_type ) {
1265
- all_matched = false
1266
- }
1267
- if ( all_matched && item.value_type == RangerNodeType.ExpressionType ) {
1268
- if( false == (this.matchLambdaArgs( (unwrap item.expression_value) (unwrap item2.expression_value) ctx wr) ) ) {
1269
- all_matched = false
1270
- }
1271
- }
1272
- })
1273
-
1274
- if( all_matched == false) {
1275
- ctx.addError(n2 "Invalid lambda return value type")
1276
- return false
1277
- }
1278
- return true
1279
- }
1280
-
1281
- fn cmdLocalCall:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1282
- ; "
1283
- def fnNode@(lives):CodeNode (node.getFirst())
1284
- def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
1285
- def desc:RangerAppClassDesc (unwrap udesc)
1286
- def expects_error:boolean false
1287
- def err_cnt:int (ctx.getErrorCount())
1288
- if( node.hasBooleanProperty("error")) {
1289
- expects_error = true
1290
- }
1291
-
1292
- ; print "localCall : " + (node.getCode())
1293
- ; print "childnode count : " + (array_length node.children)
1294
- ; collect also the chain here..
1295
-
1296
- ; obj.foo() .bar() .foor2()
1297
- ; --> obj.foo() will be the innerNode...
1298
-
1299
- def chlen (array_length node.children)
1300
-
1301
- if( chlen > 2) {
1302
- def i 2
1303
- def chainRoot:CodeNode (node)
1304
- def innerNode@(weak):CodeNode
1305
- def newNode (node.newExpressionNode())
1306
- def sc (node.getSecond())
1307
- newNode.add( (fnNode.copy()) )
1308
- newNode.add( (sc.copy()) )
1309
- innerNode = newNode
1310
-
1311
- def chain_cnt 0
1312
- ; push the first into bottom of stack
1313
- ; obj.foo.something ()
1314
- while ( i < (chlen - 1) ) {
1315
- def fc (itemAt node.children i)
1316
- def args@(lives) (itemAt node.children (i + 1))
1317
- def name (fc.vref)
1318
- if( ( (strlen name) > 0 ) && ( ( charAt name 0) == (charcode ".")) ) {
1319
- def method_name (substring name 1 (strlen name))
1320
- def newNode (node.newExpressionNode())
1321
- newNode.add( (node.newVRefNode("call") ) )
1322
- newNode.add( (innerNode.copy() ) )
1323
- newNode.add( (node.newVRefNode(method_name)) )
1324
- newNode.add( (args.copy()))
1325
- innerNode = newNode
1326
- chain_cnt = chain_cnt + 1
1327
- } {
1328
- ctx.addError(node "Invalid chaining op")
1329
- }
1330
- i = i + 2
1331
- }
1332
- if ( chain_cnt > 0 ) {
1333
- node.getChildrenFrom( (unwrap innerNode ) )
1334
- node.tag = "chainroot"
1335
- node.flow_done = false
1336
- this.WalkNode( node ctx wr)
1337
- return true
1338
- }
1339
- }
1340
-
1341
-
1342
- if ((array_length fnNode.ns) > 1) {
1343
-
1344
- def rootName (itemAt fnNode.ns 0)
1345
- def vDef2 (ctx.getVariableDef(rootName))
1346
- if( (rootName != "this") && (vDef2.init_cnt == 0) && (vDef2.set_cnt == 0) ) {
1347
- if( (vDef2.is_class_variable == false ) && ( (ctx.isDefinedClass(rootName)) == false ) ) {
1348
- ctx.addError( node ("Call to uninitialized object " + rootName) )
1349
- }
1350
- }
1351
-
1352
- def vFnDef@(optional):RangerAppFunctionDesc (this.findFunctionDesc(fnNode ctx wr))
1353
- if (!null? vFnDef) {
1354
-
1355
- vFnDef.ref_cnt = (vFnDef.ref_cnt + 1)
1356
- def subCtx:RangerAppWriterContext (ctx.fork())
1357
- node.hasFnCall = true
1358
- node.fnDesc = vFnDef
1359
- def p@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
1360
- p.name = fnNode.vref
1361
- p.value_type = fnNode.value_type
1362
- p.node = fnNode
1363
- p.nameNode = fnNode
1364
- p.varType = RangerContextVarType.Function
1365
- subCtx.defineVariable(p.name p)
1366
- this.WalkNode(fnNode subCtx wr)
1367
- def callParams:CodeNode (itemAt node.children 1)
1368
- def nodeList:[CodeNode] (this.transformParams( callParams.children vFnDef.params subCtx))
1369
- for nodeList arg:CodeNode i {
1370
- ; expression as parameter is a lambda
1371
- ctx.setInExpr()
1372
- if(arg.isFirstVref("fun")) {
1373
- arg.flow_done = false
1374
- arg.forTree({
1375
- item.flow_done = false
1376
- })
1377
- }
1378
- this.WalkNode(arg subCtx wr)
1379
- ctx.unsetInExpr()
1380
- def fnArg:RangerAppParamDesc (itemAt vFnDef.params i)
1381
- def callArgP:RangerAppParamDesc arg.paramDesc
1382
- if (!null? callArgP) {
1383
- callArgP.moveRefTo(node fnArg ctx)
1384
- }
1385
- }
1386
- def cp_len:int (array_length callParams.children)
1387
- if( cp_len > ( array_length vFnDef.params )) {
1388
- def lastCallParam:CodeNode (itemAt callParams.children (cp_len - 1))
1389
- ctx.addError( lastCallParam "Too many arguments for function")
1390
- ctx.addError( (unwrap vFnDef.nameNode) "NOTE: To fix the previous error: Check original function declaration which was")
1391
- }
1392
- for vFnDef.params param:RangerAppParamDesc i {
1393
- if( (array_length callParams.children) <= i) {
1394
- if (param.nameNode.hasFlag("default")) {
1395
- continue
1396
- }
1397
- ctx.addError(node "Missing arguments for function")
1398
- ctx.addError( (unwrap param.nameNode) "NOTE: To fix the previous error: Check original function declaration which was")
1399
- break
1400
- }
1401
- def argNode:CodeNode (itemAt callParams.children i)
1402
- if (false == (this.areEqualTypes( (unwrap param.nameNode) argNode ctx))) {
1403
- ctx.addError(argNode ("ERROR, invalid argument type for method " + vFnDef.name))
1404
- }
1405
- def pNode:CodeNode (unwrap param.nameNode)
1406
- if( pNode.hasFlag("optional")) {
1407
- if ( false == (argNode.hasFlag("optional")) ) {
1408
- ctx.addError(node ( "function parameter optionality does not match, consider making parameter optional " + (argNode.getCode())) )
1409
- }
1410
- }
1411
- if( argNode.hasFlag("optional")) {
1412
- if ( false == (pNode.hasFlag("optional")) ) {
1413
- ctx.addError(node ( "function parameter optionality does not match, consider unwrapping " + (argNode.getCode())) )
1414
- }
1415
- }
1416
- }
1417
- def nn:CodeNode vFnDef.nameNode
1418
- node.eval_type = (nn.typeNameAsType(ctx))
1419
- node.eval_type_name = nn.type_name
1420
- node.eval_array_type = nn.array_type
1421
- node.eval_key_type = nn.key_type
1422
-
1423
- if(node.eval_type == RangerNodeType.ExpressionType) {
1424
- ; console.log("Call expression ", vFnDef.name, nn.expression_value.getCode())
1425
- node.expression_value = (nn.expression_value.copy())
1426
- }
1427
-
1428
- if(nn.hasFlag("optional")) {
1429
- node.setFlag("optional")
1430
- }
1431
-
1432
- if(expects_error) {
1433
- def cnt_now:int (ctx.getErrorCount())
1434
- if (cnt_now == err_cnt) {
1435
- ctx.addParserError( node "LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt + " : " +cnt_now)
1436
- }
1437
- } {
1438
- def cnt_now:int (ctx.getErrorCount())
1439
- if (cnt_now > err_cnt) {
1440
- ctx.addParserError( node "LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt + " : " +cnt_now)
1441
- }
1442
- }
1443
- return true
1444
- } {
1445
- ctx.addError(node "Called Object or Property was not defined")
1446
- }
1447
- }
1448
- if (desc.hasMethod(fnNode.vref)) {
1449
- def fnDescr@(optional):RangerAppFunctionDesc (desc.findMethod(fnNode.vref))
1450
- def subCtx:RangerAppWriterContext (ctx.fork())
1451
- node.hasFnCall = true
1452
- node.fnDesc = fnDescr
1453
- def p@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
1454
- p.name = fnNode.vref
1455
- p.value_type = fnNode.value_type
1456
- p.node = fnNode
1457
- p.nameNode = fnNode
1458
- p.varType = RangerContextVarType.Function
1459
- subCtx.defineVariable(p.name p)
1460
- this.WriteThisVar(fnNode subCtx wr)
1461
- this.WalkNode(fnNode subCtx wr)
1462
- for node.children arg:CodeNode i {
1463
- if (i < 1) {
1464
- continue _
1465
- }
1466
- ctx.setInExpr()
1467
- this.WalkNode(arg subCtx wr)
1468
- ctx.unsetInExpr()
1469
- }
1470
- for fnDescr.params param:RangerAppParamDesc i {
1471
- if( (array_length node.children) <= (i + 1)) {
1472
- ctx.addError(node "Argument was not defined")
1473
- break
1474
- }
1475
-
1476
- def argNode:CodeNode (itemAt node.children (i + 1))
1477
- if (false == (this.areEqualTypes( (unwrap param.nameNode) argNode ctx))) {
1478
- ctx.addError(argNode ("ERROR, invalid argument type for " + desc.name + " method " + fnDescr.name))
1479
- }
1480
- }
1481
- def nn:CodeNode fnDescr.nameNode
1482
- nn.defineNodeTypeTo(node ctx)
1483
- if(expects_error) {
1484
- def cnt_now:int (ctx.getErrorCount())
1485
- if (cnt_now == err_cnt) {
1486
- ctx.addParserError( node "LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt + " : " +cnt_now)
1487
- }
1488
- } {
1489
- def cnt_now:int (ctx.getErrorCount())
1490
- if (cnt_now > err_cnt) {
1491
- ctx.addParserError( node "LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt + " : " +cnt_now)
1492
- }
1493
- }
1494
- return true
1495
- }
1496
- ; TODO: first lambda call check comes here... continue to other variants later
1497
- if (ctx.isVarDefined(fnNode.vref)) {
1498
- def d (ctx.getVariableDef(fnNode.vref))
1499
-
1500
- d.ref_cnt = (1 + d.ref_cnt)
1501
-
1502
- if(d.nameNode.value_type == RangerNodeType.ExpressionType) {
1503
-
1504
- def cnNode1 (itemAt node.children 0)
1505
- this.WalkNode(cnNode1 ctx wr)
1506
-
1507
- def lambdaDefArgs (itemAt d.nameNode.expression_value.children 1)
1508
- def callParams:CodeNode (itemAt node.children 1)
1509
- for callParams.children arg:CodeNode i {
1510
- ctx.setInExpr()
1511
- this.WalkNode(arg ctx wr)
1512
- ctx.unsetInExpr()
1513
- }
1514
- ; function return value should be assigned
1515
- def lambdaDef (itemAt d.nameNode.expression_value.children 0)
1516
- def lambdaArgs (itemAt d.nameNode.expression_value.children 1)
1517
-
1518
- def all_matched true
1519
- if( (array_length callParams.children) != (array_length lambdaArgs.children) ) {
1520
- ctx.addError(node "Invalid parameter count for the lambda expression")
1521
- }
1522
-
1523
- lambdaArgs.children.forEach({
1524
- def item2 (itemAt callParams.children index)
1525
- ; note: eval types can be different
1526
- if ( item2.eval_type_name != item.type_name ) {
1527
- print "--> eval eval_type_name " + item2.eval_type_name + " <> " + item.type_name
1528
- all_matched = false
1529
- }
1530
- if ( item2.eval_array_type != item.array_type ) {
1531
- print "--> eval eval_array_type " + item2.eval_array_type + " <> " + item.array_type
1532
- all_matched = false
1533
- }
1534
- if ( item2.eval_key_type != item.key_type ) {
1535
- print "--> eval eval_key_type " + item2.eval_key_type + " <> " + item.key_type
1536
- all_matched = false
1537
- }
1538
- })
1539
- if( all_matched == false) {
1540
- ctx.addError(node "Invalid types for lambda call")
1541
- }
1542
-
1543
- ; matchLambdaArgs
1544
-
1545
-
1546
- ; TODO: check the lambda function call arguments....
1547
- ;for lambdaArgs.children lArg:CodeNode i {
1548
- ; lArg.defineNodeTypeTo( lArg ctx )
1549
- ; if( (array_length callParams.children) <= i) {
1550
- ; if (lArg.hasFlag("default")) {
1551
- ; continue
1552
- ; }
1553
- ; ctx.addError(node "Missing arguments for function")
1554
- ; ctx.addError( lArg "NOTE: To fix the previous error: Check original function declaration which was")
1555
- ; break
1556
- ; }
1557
- ; def argNode:CodeNode (itemAt callParams.children i)
1558
- ; if (false == (this.areEqualTypes( lArg argNode ctx))) {
1559
- ; ctx.addError(argNode ("ERROR, invalid argument type for lambda call "))
1560
- ; }
1561
- ; def pNode:CodeNode lArg
1562
- ; if( pNode.hasFlag("optional")) {
1563
- ; if ( false == (argNode.hasFlag("optional")) ) {
1564
- ; ctx.addError(argNode ( "function parameter optionality does not match, consider making parameter optional " ) )
1565
- ; }
1566
- ; }
1567
- ; if( argNode.hasFlag("optional")) {
1568
- ; if ( false == (pNode.hasFlag("optional")) ) {
1569
- ; ctx.addError(lArg ( "function parameter optionality does not match, consider unwrapping ") )
1570
- ; }
1571
- ; }
1572
- ;}
1573
-
1574
- node.has_lambda_call = true
1575
- node.eval_type = (lambdaDef.typeNameAsType(ctx))
1576
- node.eval_type_name = lambdaDef.type_name
1577
- node.eval_array_type = lambdaDef.array_type
1578
- node.eval_key_type = lambdaDef.key_type
1579
- return true
1580
- })
1581
- }
1582
- return false
1583
- ; -------------------------------------------------
1584
- ctx.addError(node ("ERROR, could not find class " + desc.name + " method " + fnNode.vref))
1585
- ctx.addError(node ("definition : " + (node.getCode())))
1586
- if(expects_error) {
1587
- def cnt_now:int (ctx.getErrorCount())
1588
- if (cnt_now == err_cnt) {
1589
- ctx.addParserError( node "LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt + " : " +cnt_now)
1590
- }
1591
- } {
1592
- def cnt_now:int (ctx.getErrorCount())
1593
- if (cnt_now > err_cnt) {
1594
- ctx.addParserError( node "LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt + " : " +cnt_now)
1595
- }
1596
- }
1597
- return false
1598
- }
1599
- fn cmdReturn:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1600
- node.has_operator = true
1601
- node.op_index = 5
1602
- if ((array_length node.children) > 1) {
1603
- def fc:CodeNode (node.getSecond())
1604
- if (fc.vref == "_") {
1605
- } {
1606
- ctx.setInExpr()
1607
- this.WalkNode(fc ctx wr)
1608
- ctx.unsetInExpr()
1609
- def activeFn:RangerAppFunctionDesc (ctx.getCurrentMethod())
1610
- if fc.hasParamDesc {
1611
- fc.paramDesc.return_cnt = (1 + fc.paramDesc.return_cnt)
1612
- fc.paramDesc.ref_cnt = (1 + fc.paramDesc.ref_cnt)
1613
- }
1614
- def currFn:RangerAppFunctionDesc (ctx.getCurrentMethod())
1615
- if fc.hasParamDesc {
1616
- def pp:RangerAppParamDesc fc.paramDesc
1617
- pp.moveRefTo(node currFn ctx)
1618
- } {
1619
- }
1620
- }
1621
- }
1622
- }
1623
-
1624
- ; obj.firstChild.name = "name of firstChild"
1625
- ; obj = (call obj set_firstChild ( (call obj.firstChild set_name ("name of firstChild")) ))
1626
- fn transformImmutableAssigment:CodeNode (node:CodeNode) {
1627
-
1628
- def target (node.getSecond()) ; obj.firstChild.name
1629
- def assign_value (node.getThird()) ; "name of firstChild"
1630
- def root (node.newExpressionNode())
1631
-
1632
- root.add( (node.newVRefNode("=")))
1633
- root.add( (node.newVRefNode( (itemAt target.ns 0) ))) ; obj
1634
-
1635
- def i 1
1636
- def cnt (array_length target.ns)
1637
- def valueExpression (node.newExpressionNode())
1638
- def obj_ref (itemAt target.ns 0)
1639
- def currentParent@(weak temp) root
1640
- while( i < cnt ) {
1641
- def callExpr@(lives) (node.newExpressionNode())
1642
- callExpr.add( (node.newVRefNode("call")))
1643
- callExpr.add( (node.newVRefNode(obj_ref)))
1644
- def next_ref (itemAt target.ns (i))
1645
- def set_ref ("set_" + next_ref )
1646
- callExpr.add( (node.newVRefNode(set_ref)))
1647
- i = i + 1
1648
- if( i < cnt ) {
1649
- obj_ref = obj_ref + "." + next_ref
1650
- def paramsNode (node.newExpressionNode())
1651
- paramsNode.add(callExpr)
1652
- currentParent.add( paramsNode )
1653
- currentParent = callExpr
1654
- } {
1655
- def callParams (node.newExpressionNode())
1656
- callParams.add((assign_value.copy()))
1657
- callExpr.add( callParams )
1658
- def paramsNode (node.newExpressionNode())
1659
- paramsNode.add( (callExpr.copy()) )
1660
- currentParent.add( paramsNode )
1661
- }
1662
- }
1663
- return root
1664
- }
1665
-
1666
- fn cmdAssign:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1667
-
1668
- def target:CodeNode (node.getSecond())
1669
- this.WalkNode(target ctx wr)
1670
-
1671
- ; immutable check which denies assigent operation
1672
- if(target.hasParamDesc) {
1673
- if( !null? target.paramDesc.propertyClass) {
1674
- def nn (unwrap target.paramDesc.propertyClass.nameNode)
1675
- if(nn.hasFlag("immutable")) {
1676
-
1677
- def do_transform false
1678
- def propC (target.paramDesc.propertyClass)
1679
- def currC (ctx.getCurrentClass())
1680
- if( (unwrap currC) == (unwrap propC) ) {
1681
- if( (itemAt target.ns 0) == "this" ) {
1682
- ; ctx.addError( node "Assigment to immutable class this variable")
1683
- do_transform = true
1684
- }
1685
- } {
1686
- ; ctx.addError( node "Assigment to immutable class node")
1687
- do_transform = true
1688
- }
1689
-
1690
- if do_transform {
1691
-
1692
- def n1:CodeNode (node.getSecond())
1693
- def n2:CodeNode (node.getThird())
1694
- this.WalkNode(n1 ctx wr)
1695
- ctx.setInExpr()
1696
- this.WalkNode(n2 ctx wr)
1697
- ctx.unsetInExpr()
1698
-
1699
- this.convertToUnion( n1.eval_type_name n2 ctx wr)
1700
-
1701
- ; --> should test here
1702
- this.shouldBeEqualTypes( n1 n2 ctx "Can not assign variable.")
1703
-
1704
- def immAss (this.transformImmutableAssigment(node))
1705
- ; print "immutable assigment => " + (immAss.getCode())
1706
- node.getChildrenFrom( immAss )
1707
- ; print "eventual assigment => " + (node.getCode())
1708
- this.cmdAssign( node ctx wr)
1709
- return
1710
- } {
1711
-
1712
- }
1713
- }
1714
- }
1715
- }
1716
-
1717
- def chlen (array_length node.children)
1718
- ; res = test.foo() <- 4 nodes
1719
- if(chlen > 3) {
1720
- def i 3
1721
- def chainRoot:CodeNode (node.getThird()) ; test.foo
1722
- def innerNode@(weak) (chainRoot)
1723
- def chain_cnt 0
1724
- if( chainRoot.expression == false) {
1725
- def args (itemAt node.children 3) ; ()
1726
- def newNode (node.newExpressionNode())
1727
- def sc (node.getSecond())
1728
- newNode.add( (chainRoot.copy()) )
1729
- newNode.add( (args.copy()) )
1730
- innerNode = newNode
1731
- args.is_part_of_chain = true
1732
- i = i + 1
1733
- chain_cnt = chain_cnt + 1
1734
- }
1735
- ; push the first into bottom of stack
1736
- ; obj.foo.something ()
1737
- while ( i < (chlen - 1) ) {
1738
- ; TODO: error checks if no args given ? i + 1 may fail
1739
- def fc (itemAt node.children i)
1740
- def args@(lives) (itemAt node.children (i + 1))
1741
- def name (fc.vref)
1742
- if( ( (strlen name) > 0 ) && ( ( charAt name 0) == (charcode ".")) ) {
1743
- def method_name (substring name 1 (strlen name))
1744
- def newNode (node.newExpressionNode())
1745
- newNode.add( (node.newVRefNode("call") ) )
1746
- newNode.add( (innerNode.copy() ) )
1747
- newNode.add( (node.newVRefNode(method_name)) )
1748
- newNode.add( (args.copy()))
1749
- innerNode = newNode
1750
- chain_cnt = chain_cnt + 1
1751
- fc.is_part_of_chain = true
1752
- args.is_part_of_chain = true
1753
- } {
1754
- ctx.addError(node ( "Invalid chaining op -> " + (fc.getCode()) ) )
1755
- ctx.addError(node ("assign with invalid code = " + (node.getCode())))
1756
- }
1757
- i = i + 2
1758
- }
1759
- if ( chain_cnt > 0 ) {
1760
- def remove_cnt (chlen - 3)
1761
- while(remove_cnt > 0 ) {
1762
- removeLast node.children
1763
- remove_cnt = remove_cnt - 1
1764
- }
1765
- chainRoot.getChildrenFrom( innerNode )
1766
- chainRoot.tag = "chainroot"
1767
- chainRoot.flow_done = false
1768
- chainRoot.expression = true
1769
- chainRoot.vref = ""
1770
- chainRoot.value_type = RangerNodeType.NoType
1771
- node.flow_done = false
1772
- this.WalkNode( node ctx wr)
1773
- return true
1774
- }
1775
- }
1776
-
1777
- wr.newline()
1778
- def n1:CodeNode (node.getSecond())
1779
- def n2:CodeNode (node.getThird())
1780
- this.WalkNode(n1 ctx wr)
1781
- ctx.setInExpr()
1782
- this.WalkNode(n2 ctx wr)
1783
- ctx.unsetInExpr()
1784
- if n1.hasParamDesc {
1785
- n1.paramDesc.ref_cnt = (n1.paramDesc.ref_cnt + 1)
1786
- n1.paramDesc.set_cnt = (n1.paramDesc.set_cnt + 1)
1787
- }
1788
- if n2.hasParamDesc {
1789
- n2.paramDesc.ref_cnt = (n2.paramDesc.ref_cnt + 1)
1790
- }
1791
- if (n2.hasFlag("optional")) {
1792
- if (false == (n1.hasFlag("optional"))) {
1793
- ctx.addError(node "Can not assign optional to non-optional type")
1794
- }
1795
- }
1796
- this.stdParamMatch(node ctx wr true)
1797
- this.convertToUnion( n1.eval_type_name n2 ctx wr)
1798
- this.shouldBeEqualTypes( n1 n2 ctx "Can not assign variable.")
1799
- }
1800
- fn EnterTemplateClass:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1801
- }
1802
- fn EnterClass:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1803
- def body_index ( (node.chlen()) - 1)
1804
- if( (array_length node.children) != 3) {
1805
- if( (node.chlen()) == 5 ) {
1806
-
1807
- } {
1808
- ctx.addError(node "Invalid class declaration")
1809
- return
1810
- }
1811
- }
1812
- if(node.hasBooleanProperty("trait")) {
1813
- return
1814
- }
1815
- def cn:CodeNode (itemAt node.children 1)
1816
- def cBody:CodeNode (itemAt node.children body_index)
1817
- def desc@(lives):RangerAppClassDesc (ctx.findClass(cn.vref))
1818
- ;if cn.has_vref_annotation {
1819
- ; print "--> generic class, not processed"
1820
- ; return
1821
- ;}
1822
- def subCtx:RangerAppWriterContext (unwrap desc.ctx)
1823
- subCtx.setCurrentClass(desc)
1824
- subCtx.class_level_context = true
1825
- for desc.variables p:RangerAppParamDesc i {
1826
- def vNode:CodeNode p.node
1827
- if ((array_length vNode.children) > 2) {
1828
- def value:CodeNode (itemAt vNode.children 2)
1829
- ctx.setInExpr()
1830
- this.WalkNode(value ctx wr)
1831
- ctx.unsetInExpr()
1832
- }
1833
- p.is_class_variable = true
1834
- p.nameNode.eval_type = (p.nameNode.typeNameAsType(ctx))
1835
- p.nameNode.eval_type_name = p.nameNode.type_name
1836
- }
1837
- for cBody.children fNode:CodeNode i {
1838
- if ((fNode.isFirstVref("fn")) || (fNode.isFirstVref("constructor")) || (fNode.isFirstVref("Constructor"))) {
1839
- this.WalkNode(fNode subCtx wr)
1840
- }
1841
- }
1842
- for cBody.children fNode:CodeNode i {
1843
- if ((fNode.isFirstVref("fn")) || (fNode.isFirstVref("PublicMethod"))) {
1844
- this.WalkNode(fNode subCtx wr)
1845
- }
1846
- }
1847
- def staticCtx:RangerAppWriterContext (ctx.fork())
1848
- staticCtx.setCurrentClass(desc)
1849
- for cBody.children fNode:CodeNode i {
1850
- if ((fNode.isFirstVref("sfn")) || (fNode.isFirstVref("StaticMethod")) || (fNode.isFirstVref("static"))) {
1851
- this.WalkNode(fNode staticCtx wr)
1852
- }
1853
- }
1854
- node.hasClassDescription = true
1855
- node.clDesc = desc
1856
- desc.classNode = node
1857
- }
1858
- fn EnterMethod:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1859
- this.shouldHaveChildCnt(4 node ctx "Method expexts four arguments")
1860
- def cn:CodeNode (itemAt node.children 1)
1861
- def fnBody:CodeNode (itemAt node.children 3)
1862
- def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
1863
- def desc:RangerAppClassDesc (unwrap udesc)
1864
- def um@(optional):RangerAppFunctionDesc (desc.findMethod(cn.vref))
1865
- def m:RangerAppFunctionDesc (unwrap um)
1866
- def subCtx:RangerAppWriterContext (unwrap m.fnCtx)
1867
- subCtx.function_level_context = true
1868
- subCtx.currentMethod = m
1869
- for m.params v:RangerAppParamDesc i {
1870
- v.nameNode.eval_type = (v.nameNode.typeNameAsType(subCtx))
1871
- v.nameNode.eval_type_name = v.nameNode.type_name
1872
- ctx.hadValidType( (unwrap v.nameNode) )
1873
- }
1874
- subCtx.setInMethod()
1875
- this.WalkNodeChildren(fnBody subCtx wr)
1876
- subCtx.unsetInMethod()
1877
- if (fnBody.didReturnAtIndex == -1) {
1878
- if (cn.type_name != "void") {
1879
- ctx.addError(node "Function does not return any values!")
1880
- }
1881
- }
1882
- for subCtx.localVarNames n:string i {
1883
- def p:RangerAppParamDesc (get subCtx.localVariables n)
1884
- if (p.set_cnt > 0) {
1885
- if(p.is_immutable) {
1886
- ctx.addError( (unwrap p.nameNode) "Immutable variable was assigned a value")
1887
- }
1888
- def defNode:CodeNode p.node
1889
- defNode.setFlag("mutable")
1890
- def nNode:CodeNode p.nameNode
1891
- nNode.setFlag("mutable")
1892
- }
1893
- }
1894
- }
1895
- fn EnterStaticMethod:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1896
- this.shouldHaveChildCnt(4 node ctx "Method expexts four arguments")
1897
- def cn:CodeNode (itemAt node.children 1)
1898
- def fnBody:CodeNode (itemAt node.children 3)
1899
- def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
1900
- def desc:RangerAppClassDesc (unwrap udesc)
1901
- def subCtx:RangerAppWriterContext (ctx.fork())
1902
- subCtx.is_function = true
1903
- def um@(optional):RangerAppFunctionDesc (desc.findStaticMethod(cn.vref))
1904
- def m:RangerAppFunctionDesc (unwrap um)
1905
- subCtx.currentMethod = m
1906
- subCtx.in_static_method = true
1907
- m.fnCtx = subCtx
1908
- if (cn.hasFlag("weak")) {
1909
- m.changeStrength(0 1 node)
1910
- } {
1911
- m.changeStrength(1 1 node)
1912
- }
1913
- subCtx.setInMethod()
1914
- for m.params v@(lives):RangerAppParamDesc i {
1915
- subCtx.defineVariable(v.name v)
1916
- v.nameNode.eval_type = (v.nameNode.typeNameAsType(ctx))
1917
- v.nameNode.eval_type_name = v.nameNode.type_name
1918
- }
1919
- this.WalkNodeChildren(fnBody subCtx wr)
1920
- subCtx.unsetInMethod()
1921
- subCtx.in_static_method = false
1922
- subCtx.function_level_context = true
1923
- if (fnBody.didReturnAtIndex == -1) {
1924
- if (cn.type_name != "void") {
1925
- ctx.addError(node "Function does not return any values!")
1926
- }
1927
- }
1928
- for subCtx.localVarNames n:string i {
1929
- def p:RangerAppParamDesc (get subCtx.localVariables n)
1930
- if (p.set_cnt > 0) {
1931
- if(p.is_immutable) {
1932
- ctx.addError( (unwrap p.nameNode) "Immutable variable was assigned a value")
1933
- }
1934
- def defNode:CodeNode p.node
1935
- defNode.setFlag("mutable")
1936
- def nNode:CodeNode p.nameNode
1937
- nNode.setFlag("mutable")
1938
- }
1939
- }
1940
- }
1941
-
1942
- fn EnterStaticMethod2:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1943
- this.shouldHaveChildCnt(5 node ctx "Method expexts four arguments")
1944
- def cn:CodeNode (itemAt node.children 2)
1945
- def fnBody:CodeNode (itemAt node.children 4)
1946
- def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
1947
- def desc:RangerAppClassDesc (unwrap udesc)
1948
- def subCtx:RangerAppWriterContext (ctx.fork())
1949
- subCtx.is_function = true
1950
- def um@(optional):RangerAppFunctionDesc (desc.findStaticMethod(cn.vref))
1951
- def m:RangerAppFunctionDesc (unwrap um)
1952
- subCtx.currentMethod = m
1953
- subCtx.in_static_method = true
1954
- m.fnCtx = subCtx
1955
- if (cn.hasFlag("weak")) {
1956
- m.changeStrength(0 1 node)
1957
- } {
1958
- m.changeStrength(1 1 node)
1959
- }
1960
- subCtx.setInMethod()
1961
- for m.params v@(lives):RangerAppParamDesc i {
1962
- subCtx.defineVariable(v.name v)
1963
- v.nameNode.eval_type = (v.nameNode.typeNameAsType(ctx))
1964
- v.nameNode.eval_type_name = v.nameNode.type_name
1965
- }
1966
- this.WalkNodeChildren(fnBody subCtx wr)
1967
- subCtx.unsetInMethod()
1968
- subCtx.in_static_method = false
1969
- subCtx.function_level_context = true
1970
- if (fnBody.didReturnAtIndex == -1) {
1971
- if (cn.type_name != "void") {
1972
- ctx.addError(node "Function does not return any values!")
1973
- }
1974
- }
1975
- for subCtx.localVarNames n:string i {
1976
- def p:RangerAppParamDesc (get subCtx.localVariables n)
1977
- if (p.set_cnt > 0) {
1978
- if(p.is_immutable) {
1979
- ctx.addError( (unwrap p.nameNode) "Immutable variable was assigned a value")
1980
- }
1981
- def defNode:CodeNode p.node
1982
- defNode.setFlag("mutable")
1983
- def nNode:CodeNode p.nameNode
1984
- nNode.setFlag("mutable")
1985
- }
1986
- }
1987
- }
1988
-
1989
- fn EnterLambdaMethod:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
1990
-
1991
- def args:CodeNode (itemAt node.children 1)
1992
- def body@(lives):CodeNode (itemAt node.children 2)
1993
- def subCtx:RangerAppWriterContext (ctx.fork())
1994
-
1995
- if(ctx.isInStatic()) {
1996
- ; ctx.addError(node "Lambda definitions in static context are not allowed")
1997
- }
1998
- subCtx.is_capturing = true
1999
-
2000
- ;for args.children arg@(lives):CodeNode i {
2001
- ; def v@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
2002
- ; v.name = arg.vref
2003
- ; v.node = arg
2004
- ; v.nameNode = arg
2005
- ; arg.hasParamDesc = true
2006
- ; arg.paramDesc = v
2007
- ; subCtx.defineVariable(v.name v)
2008
- ;}
2009
- def cn:CodeNode (itemAt node.children 0)
2010
- def m@(lives):RangerAppFunctionDesc (new RangerAppFunctionDesc ())
2011
- m.name = "lambda"
2012
- m.node = node
2013
- m.nameNode = (itemAt node.children 0)
2014
- subCtx.is_function = true
2015
- subCtx.currentMethod = m
2016
- ; m.fnCtx = subCtx
2017
- if (cn.hasFlag("weak")) {
2018
- m.changeStrength(0 1 node)
2019
- } {
2020
- m.changeStrength(1 1 node)
2021
- }
2022
- m.fnBody = (itemAt node.children 2)
2023
- for args.children arg@(lives):CodeNode ii {
2024
-
2025
- this.CheckTypeAnnotationOf( arg subCtx wr )
2026
-
2027
- def p2@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
2028
-
2029
- p2.name = arg.vref
2030
- p2.value_type = arg.value_type
2031
- p2.node = arg
2032
- p2.nameNode = arg
2033
- p2.init_cnt = 1
2034
- p2.refType = RangerNodeRefType.Weak
2035
- p2.initRefType = RangerNodeRefType.Weak
2036
- if (args.hasBooleanProperty("strong")) {
2037
- p2.refType = RangerNodeRefType.Strong
2038
- p2.initRefType = RangerNodeRefType.Strong
2039
- }
2040
- p2.varType = RangerContextVarType.FunctionParameter
2041
- push m.params p2
2042
- arg.hasParamDesc = true
2043
- arg.paramDesc = p2
2044
- arg.eval_type = arg.value_type
2045
- arg.eval_type_name = arg.type_name
2046
- if (arg.hasFlag("strong")) {
2047
- p2.changeStrength(1 1 (unwrap p2.nameNode))
2048
- } {
2049
- arg.setFlag("lives")
2050
- p2.changeStrength(0 1 (unwrap p2.nameNode))
2051
- }
2052
- ; subCtx.hadValidType(p2.nameNode)
2053
- subCtx.defineVariable(p2.name p2)
2054
- }
2055
-
2056
- def cnt:int ( array_length body.children )
2057
- ; def activeFn:RangerAppFunctionDesc (ctx.getCurrentMethod())
2058
-
2059
- for body.children item:CodeNode i {
2060
- this.WalkNode(item subCtx wr)
2061
- if( i == ( (array_length body.children ) - 1) ) {
2062
- if( (array_length item.children ) > 0) {
2063
- def fc (item.getFirst())
2064
- if(fc.vref != "return") {
2065
- cn.type_name = "void"
2066
- }
2067
- }
2068
- }
2069
- }
2070
- node.has_lambda = true
2071
- node.lambda_ctx = subCtx
2072
- node.eval_type = RangerNodeType.ExpressionType
2073
- node.eval_function = node
2074
- node.expression_value = (node.copy())
2075
- }
2076
-
2077
- ; myClass@(xxx)
2078
- fn CheckVRefTypeAnnotationOf:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2079
- if(node.has_vref_annotation) {
2080
- def tAnn (node.vref_annotation)
2081
- if(false == (ctx.isDefinedClass(node.vref))) {
2082
- ctx.addError(node ("Trait class " + node.vref + " is not defined"))
2083
- } {
2084
- def testC (ctx.findClass(node.vref))
2085
- if(testC.is_trait) {
2086
- if (testC.node.hasExpressionProperty("params")) {
2087
- def params (testC.node.getExpressionProperty("params"))
2088
-
2089
- def cnt (array_length tAnn.children)
2090
- def tstr ""
2091
- for tAnn.children ch:CodeNode i {
2092
- this.CheckVRefTypeAnnotationOf( ch ctx wr )
2093
- tstr = tstr + "_" + ch.vref
2094
- }
2095
- ; def fp (tAnn.getFirst())
2096
- ; this.CheckVRefTypeAnnotationOf( fp ctx wr )
2097
- def class_name ( testC.name + tstr)
2098
- def ann (unwrap tAnn)
2099
- ctx.createTraitInstanceClass( testC.name class_name ann this )
2100
- node.vref = class_name
2101
- node.has_vref_annotation = false
2102
- return true
2103
- }
2104
- }
2105
- }
2106
- }
2107
- return false
2108
- }
2109
-
2110
- ; def xxx:vectorOf@(int)
2111
- fn CheckTypeAnnotationOf:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2112
- if(node.has_type_annotation) {
2113
- def tAnn (node.type_annotation)
2114
- if(false == (ctx.isDefinedClass(node.type_name))) {
2115
- ctx.addError(node ("Trait class " + node.type_name + " is not defined"))
2116
- } {
2117
- def testC (ctx.findClass(node.type_name))
2118
- if(testC.is_trait) {
2119
- if (testC.node.hasExpressionProperty("params")) {
2120
- def params (testC.node.getExpressionProperty("params"))
2121
-
2122
- def cnt (array_length tAnn.children)
2123
- def tstr ""
2124
- for tAnn.children ch:CodeNode i {
2125
- this.CheckVRefTypeAnnotationOf( ch ctx wr )
2126
- tstr = tstr + "_" + ch.vref
2127
- }
2128
- def class_name ( testC.name + tstr)
2129
-
2130
- ; def fp (tAnn.getFirst())
2131
- ; this.CheckVRefTypeAnnotationOf( fp ctx wr )
2132
- ; def class_name ( testC.name + "_" + fp.vref)
2133
- def ann (unwrap tAnn)
2134
- ; print "creating trait class " + class_name + " tann count is == " + cnt
2135
- ctx.createTraitInstanceClass( testC.name class_name ann this )
2136
- node.type_name = class_name
2137
- node.has_type_annotation = false
2138
- return true
2139
- }
2140
- }
2141
- }
2142
- }
2143
- return false
2144
- }
2145
-
2146
- fn EnterVarDef:void (node@(lives):CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2147
- if (ctx.isInMethod()) {
2148
-
2149
- def chlen (array_length node.children)
2150
-
2151
- if(chlen > 1) {
2152
- def tName (node.getSecond())
2153
- this.CheckTypeAnnotationOf(tName ctx wr)
2154
- ; transform type def into generic trait into a class if necessary
2155
- ; def obj:foo@(double)
2156
- }
2157
- ; res = test.foo() <- 4 nodes
2158
- if(chlen > 3) {
2159
- def i 3
2160
- def chainRoot:CodeNode (node.getThird()) ; test.foo
2161
- def innerNode@(weak) (chainRoot)
2162
- def chain_cnt 0
2163
- if( chainRoot.expression == false) {
2164
- def args (itemAt node.children 3) ; ()
2165
- def newNode (node.newExpressionNode())
2166
- def sc (node.getSecond())
2167
- newNode.add( (chainRoot.copy()) )
2168
- newNode.add( (args.copy()) )
2169
- innerNode = newNode
2170
-
2171
- ; should you just remove the "last" items ?
2172
- args.is_part_of_chain = true
2173
- i = i + 1
2174
- }
2175
- ; push the first into bottom of stack
2176
- ; obj.foo.something ()
2177
- while ( i < (chlen - 1) ) {
2178
- ; TODO: error checks if no args given ? i + 1 may fail
2179
- def fc (itemAt node.children i)
2180
- def args@(lives) (itemAt node.children (i + 1))
2181
- def name (fc.vref)
2182
- if( ( (strlen name) > 0 ) && ( ( charAt name 0) == (charcode ".")) ) {
2183
- def method_name (substring name 1 (strlen name))
2184
- def newNode (node.newExpressionNode())
2185
- newNode.add( (node.newVRefNode("call") ) )
2186
- newNode.add( (innerNode.copy() ) )
2187
- newNode.add( (node.newVRefNode(method_name)) )
2188
- newNode.add( (args.copy()))
2189
- innerNode = newNode
2190
- chain_cnt = chain_cnt + 1
2191
- fc.is_part_of_chain = true
2192
- args.is_part_of_chain = true
2193
- } {
2194
- ctx.addError(node ( "Invalid chaining op -> " + (fc.getCode()) ) )
2195
- ctx.addError(node ("assign with invalid code = " + (node.getCode())))
2196
- }
2197
- i = i + 2
2198
- }
2199
- if ( chain_cnt > 0 ) {
2200
- def remove_cnt (chlen - 3)
2201
- while(remove_cnt > 0 ) {
2202
- removeLast node.children
2203
- remove_cnt = remove_cnt - 1
2204
- }
2205
- chainRoot.getChildrenFrom( innerNode )
2206
- chainRoot.tag = "chainroot"
2207
- chainRoot.flow_done = false
2208
- chainRoot.expression = true
2209
- chainRoot.vref = ""
2210
- chainRoot.value_type = RangerNodeType.NoType
2211
- node.flow_done = false
2212
- this.WalkNode( chainRoot ctx wr)
2213
- ; this.WalkNode( node ctx wr)
2214
- return true
2215
- } {
2216
- this.WalkNode( chainRoot ctx wr)
2217
- }
2218
- }
2219
-
2220
- if ((array_length node.children) > 3) {
2221
- ctx.addError(node "invalid variable definition")
2222
- return
2223
- }
2224
- if ((array_length node.children) < 2) {
2225
- ctx.addError(node "invalid variable definition")
2226
- return
2227
- }
2228
- def cn@(lives):CodeNode (itemAt node.children 1)
2229
- def p:RangerAppParamDesc (new RangerAppParamDesc ())
2230
- def defaultArg:CodeNode
2231
- def is_immutable false
2232
- if ((array_length node.children) == 2) {
2233
- if ((cn.value_type != RangerNodeType.Array) && (cn.value_type != RangerNodeType.Hash)) {
2234
- cn.setFlag("optional")
2235
- }
2236
- }
2237
- if ((strlen cn.vref) == 0) {
2238
- ctx.addError(node "invalid variable definition")
2239
- }
2240
- if (cn.hasFlag("weak")) {
2241
- p.changeStrength(0 1 node)
2242
- } {
2243
- p.changeStrength(1 1 node)
2244
- }
2245
- node.hasVarDef = true
2246
- if(cn.value_type == RangerNodeType.ExpressionType) {
2247
- print "Expression node..."
2248
- }
2249
- if ((array_length node.children) > 2) {
2250
- p.init_cnt = 1
2251
- p.def_value = (itemAt node.children 2)
2252
- p.is_optional = false
2253
- defaultArg = (itemAt node.children 2)
2254
- ctx.setInExpr()
2255
- this.WalkNode( (unwrap defaultArg) ctx wr)
2256
- ctx.unsetInExpr()
2257
- if (defaultArg.hasFlag("optional")) {
2258
- cn.setFlag("optional")
2259
- }
2260
- if (defaultArg.hasFlag("immutable")) {
2261
- cn.setFlag("immutable")
2262
- }
2263
-
2264
- if( defaultArg.hasParamDesc ) {
2265
- def paramDesc (unwrap defaultArg.paramDesc)
2266
- if( !null? paramDesc.propertyClass) {
2267
- if( paramDesc.propertyClass.nameNode.hasFlag("immutable") ) {
2268
- ; TODO: add hash support
2269
- if (defaultArg.eval_type == RangerNodeType.Array || defaultArg.eval_type == RangerNodeType.Hash) {
2270
- is_immutable = true
2271
- ; ctx.addError( node "creating a mutable copy of immutable array is currently not permitted")
2272
- }
2273
- }
2274
- }
2275
- if( paramDesc.is_immutable) {
2276
- is_immutable = true
2277
- }
2278
- }
2279
-
2280
- if (defaultArg.eval_type == RangerNodeType.Array) {
2281
- node.op_index = 1
2282
- }
2283
- if (cn.value_type == RangerNodeType.Enum) {
2284
- cn.eval_type_name = (itemAt defaultArg.ns 0)
2285
- }
2286
- if (cn.value_type == RangerNodeType.Char) {
2287
- if ((defaultArg.eval_type != RangerNodeType.Integer) && (defaultArg.eval_type != RangerNodeType.Char)) {
2288
- ctx.addError( (unwrap defaultArg) ("Char should be assigned char or integer value --> " + (defaultArg.getCode())))
2289
- } {
2290
- defaultArg.eval_type = RangerNodeType.Char
2291
- }
2292
- }
2293
- } {
2294
- if ((cn.value_type != RangerNodeType.Hash) && (cn.value_type != RangerNodeType.Array) && (false == (cn.hasFlag("optional")))) {
2295
- cn.setFlag("optional")
2296
- }
2297
- }
2298
- ; simple local variable type inference
2299
- if ((array_length node.children) > 2) {
2300
- if( ( (strlen cn.type_name) == 0) && ( (strlen cn.array_type) == 0 ) ) {
2301
- def nodeValue:CodeNode (itemAt node.children 2)
2302
- if(nodeValue.eval_type == RangerNodeType.ExpressionType) {
2303
- if(!null? nodeValue.expression_value) {
2304
- cn.expression_value = ( nodeValue.expression_value.copy() )
2305
- } {
2306
- if( (null? node.expression_value)) {
2307
- ; infer the node type
2308
- def copyOf (nodeValue.rebuildWithType( (new RangerArgMatch () ) false))
2309
- removeLast copyOf.children
2310
- cn.expression_value = copyOf
2311
- }
2312
- }
2313
- }
2314
- cn.value_type = nodeValue.eval_type
2315
- cn.type_name = nodeValue.eval_type_name
2316
- cn.array_type = nodeValue.eval_array_type
2317
- cn.key_type = nodeValue.eval_key_type
2318
- }
2319
- }
2320
- ; after type inference, check the validity of the type
2321
- ctx.hadValidType(cn)
2322
- cn.defineNodeTypeTo(cn ctx)
2323
-
2324
- p.name = cn.vref
2325
- if (p.value_type == RangerNodeType.NoType) {
2326
- if ((0 == (strlen cn.type_name)) && (!null? defaultArg)) {
2327
- p.value_type = defaultArg.eval_type
2328
- cn.type_name = defaultArg.eval_type_name
2329
- cn.eval_type_name = defaultArg.eval_type_name
2330
- cn.value_type = defaultArg.eval_type
2331
- }
2332
- } {
2333
- p.value_type = cn.value_type
2334
- }
2335
- p.node = node
2336
- p.nameNode = cn
2337
- p.varType = RangerContextVarType.LocalVariable
2338
- if is_immutable {
2339
- p.is_immutable = is_immutable
2340
- }
2341
- if cn.has_vref_annotation {
2342
- ctx.log(node "ann" "At a variable -> Found has_vref_annotation annotated reference ")
2343
- def ann:CodeNode cn.vref_annotation
2344
- if ((array_length ann.children) > 0) {
2345
- def fc:CodeNode (itemAt ann.children 0)
2346
- ctx.log(node "ann" ("value of first annotation " + fc.vref + " and variable name " + cn.vref))
2347
- }
2348
- }
2349
- if cn.has_type_annotation {
2350
- ctx.log(node "ann" "At a variable -> Found annotated reference ")
2351
- def ann:CodeNode cn.type_annotation
2352
- if ((array_length ann.children) > 0) {
2353
- def fc:CodeNode (itemAt ann.children 0)
2354
- ctx.log(node "ann" ("value of first annotation " + fc.vref + " and variable name " + cn.vref))
2355
- }
2356
- }
2357
- cn.hasParamDesc = true
2358
- cn.ownParamDesc = p
2359
- cn.paramDesc = p
2360
- node.hasParamDesc = true
2361
- node.paramDesc = p
2362
- cn.eval_type = (cn.typeNameAsType(ctx))
2363
- cn.eval_type_name = cn.type_name
2364
-
2365
-
2366
- if ((array_length node.children) > 2) {
2367
-
2368
- if(!null? defaultArg) {
2369
- this.convertToUnion( cn.eval_type_name (unwrap defaultArg) ctx wr)
2370
- }
2371
-
2372
- if (cn.eval_type != defaultArg.eval_type) {
2373
- ; TODO: function to check compability
2374
- if( ( cn.eval_type == RangerNodeType.Char && defaultArg.eval_type == RangerNodeType.Integer ) ||
2375
- ( cn.eval_type == RangerNodeType.Integer && defaultArg.eval_type == RangerNodeType.Char ) ) {
2376
-
2377
- } {
2378
- ctx.addError(node ((("Variable was assigned an incompatible type. Types were " + cn.eval_type) + " vs ") + defaultArg.eval_type))
2379
- }
2380
-
2381
- }
2382
- } {
2383
- p.is_optional = true
2384
- }
2385
- ctx.defineVariable(p.name p)
2386
- this.DefineVar(node ctx wr)
2387
- if ((array_length node.children) > 2) {
2388
- this.shouldBeEqualTypes(cn (unwrap p.def_value) ctx "Variable was assigned an incompatible type.")
2389
- }
2390
- } {
2391
- def cn:CodeNode (itemAt node.children 1)
2392
- cn.eval_type = (cn.typeNameAsType(ctx))
2393
- cn.eval_type_name = cn.type_name
2394
- this.DefineVar(node ctx wr)
2395
- if ((array_length node.children) > 2) {
2396
- this.shouldBeEqualTypes((itemAt node.children 1) (itemAt node.children 2) ctx "Variable was assigned an incompatible type.")
2397
- }
2398
- }
2399
- }
2400
- fn WalkNodeChildren:void (node@(lives):CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2401
- if (node.hasStringProperty("todo")) {
2402
- ctx.addTodo(node (node.getStringProperty("todo")))
2403
- }
2404
- if node.expression {
2405
- def is_chaining false
2406
- def last_is_assign false
2407
- def chainRoot@(weak):CodeNode
2408
- def innerNode@(weak):CodeNode
2409
- def assignNode@(weak):CodeNode
2410
- def newNode:CodeNode
2411
- ;"
2412
- def ch_len (array_length node.children)
2413
- for node.children item:CodeNode i {
2414
- def did_find false
2415
- if(has item.children) {
2416
- def fc (item.getFirst())
2417
- def name (fc.vref)
2418
-
2419
- if( ( (strlen name) > 0 ) && ( ( charAt name 0) == (charcode ".")) ) {
2420
- did_find = true
2421
- if(i>0) {
2422
- def last_line (itemAt node.children (i - 1))
2423
- if (is_chaining == false ) {
2424
- last_line.createChainTarget()
2425
- is_chaining = true
2426
- if(!null? last_line.chainTarget) {
2427
- chainRoot = last_line.chainTarget
2428
- innerNode = last_line.chainTarget
2429
- assignNode = last_line
2430
- last_is_assign = true
2431
- } {
2432
- chainRoot = last_line
2433
- innerNode = last_line
2434
- }
2435
- }
2436
- def method_name (substring name 1 (strlen name))
2437
- def mArgs (item.getSecond())
2438
- if(last_is_assign) {
2439
- push assignNode.children (fc.copy())
2440
- push assignNode.children (mArgs.copy())
2441
- } {
2442
- newNode = (node.newExpressionNode())
2443
- newNode.add( (node.newVRefNode("call") ) )
2444
- newNode.add( (innerNode.copy() ) )
2445
- newNode.add( (node.newVRefNode(method_name)) )
2446
- newNode.add( (mArgs.copy()) )
2447
- innerNode = newNode
2448
- }
2449
- item.is_part_of_chain = true
2450
- }
2451
- }
2452
- }
2453
- if(did_find == false || (i == (ch_len - 1) ) ) {
2454
- if( is_chaining && (last_is_assign == false)) {
2455
- chainRoot.getChildrenFrom( (unwrap innerNode ) )
2456
- chainRoot.tag = "chainroot"
2457
- }
2458
- is_chaining = false
2459
- last_is_assign = false
2460
- }
2461
- }
2462
- for node.children item:CodeNode i {
2463
- item.parent = node
2464
- this.WalkNode(item ctx wr)
2465
- node.copyEvalResFrom(item)
2466
- }
2467
- }
2468
- }
2469
- fn matchNode:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2470
- if (0 == (array_length node.children)) {
2471
- return false
2472
- }
2473
- def fc:CodeNode (node.getFirst())
2474
- stdCommands = (ctx.getStdCommands())
2475
- def op_list (ctx.getOperators(fc.vref))
2476
- for op_list cmd:CodeNode i {
2477
- def cmdName:CodeNode (cmd.getFirst())
2478
- if (cmdName.vref == fc.vref) {
2479
- this.stdParamMatch(node ctx wr true)
2480
- if (!null? node.parent) {
2481
- ; node.parent.copyEvalResFrom(node)
2482
- }
2483
- return true
2484
- }
2485
- }
2486
- ; convert into a call because it handles the lambda functions correctly
2487
- if( (array_length fc.ns) > 1 ) {
2488
- def possible_cmd (last fc.ns)
2489
- def op_list (ctx.getOperators(possible_cmd))
2490
- for op_list cmd:CodeNode i {
2491
-
2492
- def m (new RangerArgMatch)
2493
- def altVersion ( node.rebuildWithType (m false) )
2494
- def origCopy ( node.rebuildWithType (m false) )
2495
-
2496
- def args (node.getSecond())
2497
- def nn (fc.copy())
2498
- removeLast nn.ns
2499
-
2500
- def objName (join nn.ns ".")
2501
-
2502
- def newNode (node.newExpressionNode())
2503
- newNode.add( ( node.newVRefNode("call")) )
2504
- newNode.add( ( node.newVRefNode(objName)) )
2505
- newNode.add( ( node.newVRefNode(possible_cmd)))
2506
- newNode.add( ( args.copy()))
2507
- node.getChildrenFrom( newNode )
2508
-
2509
- node.flow_done = false
2510
- this.WalkNode( node ctx wr)
2511
- return true
2512
- }
2513
- }
2514
-
2515
- return false
2516
- }
2517
- fn StartWalk:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2518
- ; walkAlso
2519
- this.WalkNode(node ctx wr)
2520
- for walkAlso ch:CodeNode i {
2521
- this.WalkNode(ch ctx wr)
2522
- }
2523
- }
2524
- fn WalkNode:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2525
- def line_index:int (node.getLine())
2526
- if node.flow_done {
2527
- return true
2528
- }
2529
- node.flow_ctx = ctx
2530
- node.flow_done = true
2531
- this.lastProcessedNode = node
2532
- if (node.hasStringProperty("todo")) {
2533
- ctx.addTodo(node (node.getStringProperty("todo")))
2534
- }
2535
- ; currently skip...
2536
- if(node.is_part_of_chain) {
2537
- return true
2538
- }
2539
- if (node.isPrimitive()) {
2540
- if ((ctx.expressionLevel()) == 0) {
2541
- ctx.addError( node "Primitive element at top level!")
2542
- }
2543
- this.WriteScalarValue(node ctx wr)
2544
- return true
2545
- }
2546
- if (node.value_type == RangerNodeType.VRef) {
2547
- this.WriteVRef(node ctx wr)
2548
- return true
2549
- }
2550
- if (node.value_type == RangerNodeType.Comment) {
2551
- this.WriteComment(node ctx wr)
2552
- return true
2553
- }
2554
- if (node.isFirstVref("call")) {
2555
- this.cmdCall(node ctx wr)
2556
- return true
2557
- }
2558
- if (node.isFirstVref("fun")) {
2559
- this.EnterLambdaMethod(node ctx wr)
2560
- return true
2561
- }
2562
- if (node.isFirstVref("fn")) {
2563
- if(ctx.isInMethod()) {
2564
- this.EnterLambdaMethod(node ctx wr)
2565
- return true
2566
- }
2567
- }
2568
- if (node.isFirstVref("Extends")) {
2569
- return true
2570
- }
2571
- if (node.isFirstVref("operator")) {
2572
- return true
2573
- }
2574
- if (node.isFirstVref("extends")) {
2575
- return true
2576
- }
2577
- if (node.isFirstVref("extension")) {
2578
- this.EnterClass(node ctx wr)
2579
- return true
2580
- }
2581
- if (node.isFirstVref("operators")) {
2582
- return true
2583
- }
2584
- if (node.isFirstVref("systemclass")) {
2585
- return true
2586
- }
2587
- if (node.isFirstVref("systemunion")) {
2588
- return true
2589
- }
2590
- if (node.isFirstVref("union")) {
2591
- return true
2592
- }
2593
- if (node.isFirstVref("Import")) {
2594
- this.cmdImport(node ctx wr)
2595
- return true
2596
- }
2597
- if (node.isFirstVref("def")) {
2598
- this.EnterVarDef(node ctx wr)
2599
- return true
2600
- }
2601
- if (node.isFirstVref("let")) {
2602
- this.EnterVarDef(node ctx wr)
2603
- return true
2604
- }
2605
- if (node.isFirstVref("TemplateClass")) {
2606
- this.EnterTemplateClass(node ctx wr)
2607
- return true
2608
- }
2609
- if (node.isFirstVref("CreateClass")) {
2610
- this.EnterClass(node ctx wr)
2611
- return true
2612
- }
2613
- if (node.isFirstVref("class")) {
2614
- this.EnterClass(node ctx wr)
2615
- return true
2616
- }
2617
- if (node.isFirstVref("trait")) {
2618
- ; this.EnterClass(node ctx wr)
2619
- return true
2620
- }
2621
- if (node.isFirstVref("PublicMethod")) {
2622
- this.EnterMethod(node ctx wr)
2623
- return true
2624
- }
2625
- if (node.isFirstVref("StaticMethod")) {
2626
- this.EnterStaticMethod(node ctx wr)
2627
- return true
2628
- }
2629
- if (node.isFirstVref("fn")) {
2630
- this.EnterMethod(node ctx wr)
2631
- return true
2632
- }
2633
- if (node.isFirstVref("sfn")) {
2634
- this.EnterStaticMethod(node ctx wr)
2635
- return true
2636
- }
2637
- if (node.isFirstVref("static")) {
2638
- this.EnterStaticMethod2(node ctx wr)
2639
- return true
2640
- }
2641
- if (node.isFirstVref("=")) {
2642
- this.cmdAssign(node ctx wr)
2643
- return true
2644
- }
2645
- if ( (node.isFirstVref("Constructor")) || (node.isFirstVref("constructor")) ) {
2646
- this.Constructor(node ctx wr)
2647
- return true
2648
- }
2649
- if (node.isFirstVref("new")) {
2650
- this.cmdNew(node ctx wr)
2651
- return true
2652
- }
2653
- if (node.isFirstVref("enum")) {
2654
- return true
2655
- }
2656
- if (this.matchNode(node ctx wr)) {
2657
- return true
2658
- }
2659
- if ((array_length node.children) > 0) {
2660
- def fc:CodeNode (itemAt node.children 0)
2661
- if (fc.value_type == RangerNodeType.VRef) {
2662
- def was_called:boolean true
2663
- switch fc.vref {
2664
- case "Enum" {
2665
- ; this.cmdEnum(node ctx wr)
2666
- was_called = true
2667
- }
2668
- default {
2669
- was_called = false
2670
- }
2671
- }
2672
- if was_called {
2673
- return true
2674
- }
2675
- if ((array_length node.children) > 1) {
2676
- if (this.cmdLocalCall(node ctx wr)) {
2677
- return true
2678
- }
2679
- }
2680
- }
2681
- }
2682
- if node.expression {
2683
- for node.children item:CodeNode i {
2684
- item.parent = node
2685
- if(!null? item.evalCtx) {
2686
- this.WalkNode(item (unwrap item.evalCtx) wr)
2687
- } {
2688
- this.WalkNode(item ctx wr)
2689
- }
2690
- node.copyEvalResFrom(item)
2691
- }
2692
- return true
2693
- }
2694
- ctx.addError(node "Could not understand this part")
2695
-
2696
- return true
2697
- }
2698
-
2699
- fn clearImports:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2700
-
2701
- if (node.isFirstVref("Import")) {
2702
- node.expression = true
2703
- node.vref = ""
2704
- removeLast node.children
2705
- removeLast node.children
2706
- } {
2707
- for node.children item:CodeNode i {
2708
- this.clearImports(item ctx wr)
2709
- }
2710
- }
2711
- }
2712
-
2713
- fn mergeImports:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2714
- if (node.isFirstVref("Import")) {
2715
- def fNameNode:CodeNode (itemAt node.children 1)
2716
- def import_file:string fNameNode.string_value
2717
- if (has ctx.already_imported import_file) {
2718
- return
2719
- }
2720
- set ctx.already_imported import_file true
2721
-
2722
- def root_path "."
2723
- if hasRootPath {
2724
- root_path = rootPath
2725
- }
2726
-
2727
- ; --
2728
- def rootCtx (ctx.getRoot())
2729
- def filePathIs (this.searchLib( rootCtx.libraryPaths import_file ))
2730
-
2731
- if( ( file_exists filePathIs import_file ) == false ) {
2732
- ctx.addError(node ("Could not import file " + import_file))
2733
- return
2734
- ;"
2735
- }
2736
-
2737
- def c:string (read_file filePathIs import_file)
2738
- def code:SourceCode (new SourceCode ( (unwrap c)))
2739
- code.filename = import_file
2740
- def parser:RangerLispParser (new RangerLispParser (code))
2741
- parser.parse()
2742
- node.expression = true
2743
- node.vref = ""
2744
- removeLast node.children
2745
- removeLast node.children
2746
-
2747
- def rn:CodeNode (unwrap parser.rootNode)
2748
- this.mergeImports( rn ctx wr)
2749
- push node.children rn
2750
- } {
2751
- for node.children item:CodeNode i {
2752
- this.mergeImports(item ctx wr)
2753
- }
2754
- }
2755
- }
2756
- ; this.CollectMethods( (unwrap parser.rootNode ) ctx wr)
2757
- fn CollectMethods:void (node@(lives):CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2758
- this.WalkCollectMethods(node ctx wr)
2759
- ;
2760
- extendedClasses.forEach({
2761
- def ch (ctx.findClass(index))
2762
- def parent (ctx.findClass(item))
2763
- ch.addParentClass(item)
2764
- parent.is_inherited = true
2765
-
2766
- parent.variables.forEach({
2767
- ch.ctx.defineVariable(item.name item)
2768
- })
2769
- })
2770
-
2771
- for classesWithTraits point:ClassJoinPoint i {
2772
- def cl:RangerAppClassDesc (unwrap point.class_def)
2773
- def joinPoint:CodeNode (unwrap point.node)
2774
- def traitClassDef@(lives):CodeNode (itemAt point.node.children 1)
2775
- def name:string (traitClassDef.vref)
2776
- ; print "trait " + name + " to class " + cl.name
2777
- def t:RangerAppClassDesc (ctx.findClass(name))
2778
- if( (array_length t.extends_classes) > 0 ) {
2779
- ctx.addError( (unwrap point.node) ("Can not join class " + name + " because it is inherited. Currently on base classes can be used as traits." ))
2780
- continue
2781
- }
2782
- if(t.has_constructor) {
2783
- ctx.addError( (unwrap point.node) ("Can not join class " + name + " because it has a constructor function" ))
2784
- } {
2785
- ; def clBody:CodeNode (itemAt t.node.children 2)
2786
- def origBody:CodeNode (itemAt cl.node.children 2)
2787
- def match:RangerArgMatch (new RangerArgMatch ())
2788
- def params (t.node.getExpressionProperty("params"))
2789
- def initParams (point.node.getExpressionProperty("params"))
2790
- def traitParams (new RangerTraitParams)
2791
-
2792
- ; print "building trait for class " + cl.name
2793
- if( (!null? params) && (!null? initParams) ) {
2794
- for params.children typeName:CodeNode i {
2795
- def pArg (itemAt initParams.children i)
2796
- if ( 0 == (strlen pArg.vref) ) {
2797
- match.addNode( typeName.vref pArg)
2798
- } {
2799
- match.add(typeName.vref pArg.vref ctx)
2800
- ; print "- add " + typeName.vref + " => " +pArg.vref
2801
- }
2802
- push traitParams.param_names typeName.vref
2803
- set traitParams.values typeName.vref pArg.vref
2804
- }
2805
- set cl.trait_params name traitParams
2806
- } {
2807
- match.add("T" cl.name ctx)
2808
- }
2809
-
2810
- ; print "traitparam values == " + (keys traitParams.values)
2811
-
2812
- ctx.setCurrentClass( cl )
2813
-
2814
- def traitClass (ctx.findClass(traitClassDef.vref))
2815
- for traitClass.variables pvar:RangerAppParamDesc i {
2816
- def ccopy:CodeNode (pvar.node.rebuildWithType(match true))
2817
- this.WalkCollectMethods( ccopy ctx wr )
2818
- push origBody.children ccopy
2819
- }
2820
- for traitClass.defined_variants fnVar:string i {
2821
- def mVs:RangerAppMethodVariants (get traitClass.method_variants fnVar)
2822
- for mVs.variants variant:RangerAppFunctionDesc i {
2823
- def ccopy:CodeNode (variant.node.rebuildWithType(match true))
2824
- this.WalkCollectMethods( ccopy ctx wr )
2825
- push origBody.children ccopy
2826
- }
2827
- }
2828
- for traitClass.static_methods variant:RangerAppFunctionDesc i {
2829
- def ccopy:CodeNode (variant.node.rebuildWithType(match true))
2830
- this.WalkCollectMethods( ccopy ctx wr )
2831
- push origBody.children ccopy
2832
- }
2833
-
2834
- ; def copy_of_body:CodeNode (clBody.rebuildWithType(match true))
2835
- ;joinPoint.vref = "does"
2836
- ;joinPoint.value_type = RangerNodeType.NoType
2837
- ;joinPoint.expression = true
2838
- ;def chCnt:int (array_length joinPoint.children)
2839
- ;while( chCnt > 0 ) {
2840
- ; removeLast joinPoint.children
2841
- ; chCnt = chCnt - 1
2842
- ;}
2843
-
2844
- ;ctx.setCurrentClass( cl )
2845
- ;for copy_of_body.children ch:CodeNode i {
2846
- ;push origBody.children ch
2847
- ; this.WalkCollectMethods( ch ctx wr )
2848
- ;}
2849
- }
2850
- }
2851
- for serializedClasses cl:RangerAppClassDesc i {
2852
- cl.is_serialized = true
2853
- def ser:RangerSerializeClass (new RangerSerializeClass())
2854
- def extWr:CodeWriter (new CodeWriter())
2855
- ser.createJSONSerializerFn( cl (unwrap cl.ctx) extWr )
2856
- def theCode:string (extWr.getCode())
2857
- def code:SourceCode (new SourceCode ( theCode))
2858
- code.filename = "extension " + (ctx.currentClass.name)
2859
- def parser:RangerLispParser (new RangerLispParser (code))
2860
- parser.parse()
2861
- def rn@(lives):CodeNode (unwrap parser.rootNode)
2862
- this.WalkCollectMethods( rn (unwrap cl.ctx) wr)
2863
- push walkAlso rn
2864
- }
2865
-
2866
- for immutableClasses cl:RangerAppClassDesc i {
2867
- def ser (new RangerImmutableExtension)
2868
- def extWr (new CodeWriter())
2869
- ser.createImmutableExtension( cl (unwrap cl.ctx) extWr )
2870
- def theCode (extWr.getCode())
2871
- def code (new SourceCode ( theCode ))
2872
- code.filename = "extension " + (cl.name)
2873
- def parser (new RangerLispParser (code))
2874
- parser.parse()
2875
- def rn@(lives):CodeNode (unwrap parser.rootNode)
2876
- this.WalkCollectMethods( rn (unwrap cl.ctx) wr)
2877
- push walkAlso rn
2878
- }
2879
- ; ctx.hadValidType( (unwrap v.nameNode) )
2880
- for ctx.definedClassList cname:string i {
2881
- def c (unwrap (get ctx.definedClasses cname))
2882
- if( c.is_system || c.is_interface || c.is_template || c.is_trait) {
2883
- continue
2884
- }
2885
- for c.variables p:RangerAppParamDesc i {
2886
- ctx.hadValidType( (unwrap p.nameNode) )
2887
- }
2888
- }
2889
-
2890
- }
2891
-
2892
- fn defineFunctionParam( method:RangerAppFunctionDesc arg:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2893
- this.CheckTypeAnnotationOf( arg ctx wr )
2894
- def p@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
2895
- p.name = arg.vref
2896
- p.value_type = arg.value_type
2897
- p.node = arg
2898
- p.init_cnt = 1
2899
- p.nameNode = arg
2900
- p.refType = RangerNodeRefType.Weak
2901
- p.varType = RangerContextVarType.FunctionParameter
2902
- push method.params p
2903
- arg.hasParamDesc = true
2904
- arg.paramDesc = p
2905
- arg.eval_type = arg.value_type
2906
- arg.eval_type_name = arg.type_name
2907
- if (arg.hasFlag("strong")) {
2908
- p.changeStrength(1 1 (unwrap p.nameNode))
2909
- } {
2910
- arg.setFlag("lives")
2911
- p.changeStrength(0 1 (unwrap p.nameNode))
2912
- }
2913
- }
2914
-
2915
- fn WalkCollectMethods:void (node@(lives):CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
2916
- def find_more:boolean true
2917
-
2918
- if (node.isFirstVref("operator")) {
2919
-
2920
- def nameNode@(lives):CodeNode (node.getSecond())
2921
- def opClassName (nameNode.vref)
2922
-
2923
- if (nameNode.vref == "class") {
2924
- ; print "Found operator class " + nameNode.type_name
2925
- def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
2926
- new_class.name = nameNode.type_name
2927
- new_class.nameNode = nameNode
2928
- ; TODO: make this cleaner....
2929
- nameNode.vref = nameNode.type_name
2930
- ctx.addClass(nameNode.vref new_class)
2931
- new_class.is_system = true
2932
- nameNode.clDesc = new_class
2933
- }
2934
-
2935
- def b_is_void (nameNode.type_name == "void")
2936
- def opLang (itemAt node.children 2)
2937
- def opsList (itemAt node.children 3)
2938
-
2939
- ; def listOf:CodeNode (node.getSecond())
2940
- ; for listOf.children item@(lives):CodeNode i {
2941
- ; ctx.createOperator(item)
2942
- ; }
2943
-
2944
- for opsList.children op:CodeNode i {
2945
- def fc (op.getFirst())
2946
- if( fc.vref == "fn") {
2947
- def nn (op.getSecond())
2948
- def args (op.getThird())
2949
- def opCode (itemAt op.children 3)
2950
-
2951
- def opN@(lives) (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
2952
-
2953
- def opName (nn.copy())
2954
- ; def opName (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
2955
-
2956
- def opSig (nn.rebuildWithType( (new RangerArgMatch) false))
2957
- def opArgs (args.rebuildWithType( (new RangerArgMatch) false))
2958
-
2959
- def opTpls (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
2960
- opTpls.is_block_node = true
2961
-
2962
- def opTemplatesMain (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
2963
- def opTemplatesVRef (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
2964
- def opTemplatesList (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
2965
-
2966
- opTemplatesVRef.vref = "templates"
2967
- push opTemplatesMain.children opTemplatesVRef
2968
- push opTemplatesMain.children opTemplatesList
2969
- push opTpls.children opTemplatesMain
2970
-
2971
- push opN.children opName
2972
- ; opName.vref = nn.vref
2973
- if(nn.hasFlag("newcontext")) {
2974
- opName.setFlag("newcontext")
2975
- }
2976
- opSig.vref = nn.vref
2977
- push opN.children opSig
2978
-
2979
- ; op _:void ( this:myClass .... )
2980
- ; nameNode
2981
- def opThisNode (nameNode.rebuildWithType( (new RangerArgMatch) false))
2982
- opThisNode.vref = "self"
2983
- if(nameNode.hasFlag("mutates")) {
2984
- opThisNode.setFlag("mutates")
2985
- }
2986
- if(nameNode.hasFlag("immutable")) {
2987
- opThisNode.setFlag("immutable")
2988
- }
2989
-
2990
- if b_is_void {
2991
- ; --> basebones operator without the self argument
2992
- } {
2993
- insert opArgs.children 0 opThisNode
2994
- }
2995
-
2996
- push opN.children opArgs
2997
- push opN.children opTpls
2998
-
2999
- def opCodeNode (opCode.rebuildWithType( (new RangerArgMatch) false))
3000
- def actualCode (new CodeNode ( (unwrap opCode.code) op.sp op.ep ) )
3001
-
3002
- def opLangDef (opLang.rebuildWithType( (new RangerArgMatch) false))
3003
-
3004
- if(opLangDef.vref == "all") {
3005
- opLangDef.vref = "*"
3006
- }
3007
-
3008
- push actualCode.children opLangDef
3009
- push actualCode.children opCodeNode
3010
-
3011
- if(opLangDef.vref == "*") {
3012
- if(opCode.is_block_node == false) {
3013
- opSig.setFlag("macro")
3014
- }
3015
- }
3016
- if(nameNode.hasFlag("macro")) {
3017
- opSig.setFlag("macro")
3018
- }
3019
-
3020
- push opTemplatesList.children actualCode
3021
-
3022
- ctx.createOperator(opN)
3023
- }
3024
- }
3025
-
3026
- return
3027
-
3028
- def instances:CodeNode (node.getThird())
3029
- def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
3030
- new_class.name = nameNode.vref
3031
- new_class.nameNode = nameNode
3032
- ctx.addClass(nameNode.vref new_class)
3033
- new_class.is_system_union = true
3034
- for instances.children ch:CodeNode i {
3035
- push new_class.is_union_of ch.vref
3036
- }
3037
- nameNode.clDesc = new_class
3038
- return
3039
- }
3040
-
3041
- if (node.isFirstVref("union")) {
3042
- def nameNode@(lives):CodeNode (node.getSecond())
3043
- def instances:CodeNode (node.getThird())
3044
- def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
3045
- new_class.name = nameNode.vref
3046
- new_class.nameNode = nameNode
3047
- ctx.addClass(nameNode.vref new_class)
3048
- new_class.is_union = true
3049
- for instances.children ch:CodeNode i {
3050
- push new_class.is_union_of ch.vref
3051
- }
3052
- nameNode.clDesc = new_class
3053
- return
3054
- }
3055
-
3056
- if (node.isFirstVref("systemunion")) {
3057
- def nameNode@(lives):CodeNode (node.getSecond())
3058
- def instances:CodeNode (node.getThird())
3059
- def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
3060
- new_class.name = nameNode.vref
3061
- new_class.nameNode = nameNode
3062
- ctx.addClass(nameNode.vref new_class)
3063
- new_class.is_system_union = true
3064
- for instances.children ch:CodeNode i {
3065
- push new_class.is_union_of ch.vref
3066
- }
3067
- nameNode.clDesc = new_class
3068
- return
3069
- }
3070
- if (node.isFirstVref("systemclass")) {
3071
- def nameNode@(lives):CodeNode (node.getSecond())
3072
- def instances:CodeNode (node.getThird())
3073
- def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
3074
- new_class.name = nameNode.vref
3075
- new_class.nameNode = nameNode
3076
- ctx.addClass(nameNode.vref new_class)
3077
- new_class.is_system = true
3078
- for instances.children ch:CodeNode i {
3079
- def langName:CodeNode (ch.getFirst())
3080
- def langClassName:CodeNode (ch.getSecond())
3081
- set new_class.systemNames langName.vref langClassName.vref
3082
- }
3083
- nameNode.is_system_class = true
3084
- nameNode.clDesc = new_class
3085
- return
3086
- }
3087
- if (node.isFirstVref("extends")) {
3088
- if( ( array_length node.children ) > 1 ) {
3089
- def ee (node.getSecond())
3090
- def currC:RangerAppClassDesc ctx.currentClass
3091
- currC.addParentClass(ee.vref)
3092
- def ParentClass:RangerAppClassDesc (ctx.findClass(ee.vref))
3093
- ParentClass.is_inherited = true
3094
- }
3095
- find_more = false
3096
- }
3097
- if (node.isFirstVref("Extends")) {
3098
- def extList:CodeNode (itemAt node.children 1)
3099
- def currC:RangerAppClassDesc ctx.currentClass
3100
- for extList.children ee:CodeNode ii {
3101
- currC.addParentClass(ee.vref)
3102
- def ParentClass:RangerAppClassDesc (ctx.findClass(ee.vref))
3103
- ParentClass.is_inherited = true
3104
- }
3105
- }
3106
- if ( (node.isFirstVref("constructor")) || (node.isFirstVref("Constructor"))) {
3107
-
3108
- def currC:RangerAppClassDesc ctx.currentClass
3109
- def subCtx:RangerAppWriterContext (currC.ctx.fork())
3110
-
3111
- currC.has_constructor = true
3112
- currC.constructor_node = node
3113
- def m@(lives):RangerAppFunctionDesc (new RangerAppFunctionDesc ())
3114
- m.name = "Constructor"
3115
- m.node = node
3116
- m.nameNode = (itemAt node.children 0)
3117
- m.fnBody = (itemAt node.children 2)
3118
- m.fnCtx = subCtx
3119
-
3120
- def args:CodeNode (itemAt node.children 1)
3121
- for args.children arg@(lives):CodeNode ii {
3122
- def p:RangerAppParamDesc (new RangerAppParamDesc ())
3123
- p.name = arg.vref
3124
- p.value_type = arg.value_type
3125
- p.node = arg
3126
- p.nameNode = arg
3127
- p.refType = RangerNodeRefType.Weak
3128
- p.varType = RangerContextVarType.FunctionParameter
3129
-
3130
- push m.params p
3131
-
3132
- arg.hasParamDesc = true
3133
- arg.paramDesc = p
3134
- arg.eval_type = arg.value_type
3135
- arg.eval_type_name = arg.type_name
3136
-
3137
- subCtx.defineVariable(p.name p)
3138
-
3139
- }
3140
- currC.constructor_fn = m
3141
- find_more = false
3142
- }
3143
- if (node.isFirstVref("enum")) {
3144
- def fNameNode:CodeNode (itemAt node.children 1)
3145
- def enumList:CodeNode (itemAt node.children 2)
3146
- def new_enum:RangerAppEnum (new RangerAppEnum ())
3147
- for enumList.children item:CodeNode i {
3148
- def fc (item.getFirst())
3149
- new_enum.add(fc.vref)
3150
- }
3151
- set ctx.definedEnums fNameNode.vref new_enum
3152
- find_more = false
3153
- }
3154
- if (node.isFirstVref("Enum")) {
3155
- def fNameNode:CodeNode (itemAt node.children 1)
3156
- def enumList:CodeNode (itemAt node.children 2)
3157
- def new_enum:RangerAppEnum (new RangerAppEnum ())
3158
- for enumList.children item:CodeNode i {
3159
- new_enum.add(item.vref)
3160
- }
3161
- set ctx.definedEnums fNameNode.vref new_enum
3162
- find_more = false
3163
- }
3164
- if (node.isFirstVref("trait")) {
3165
- def s:string (node.getVRefAt(1))
3166
- def classNameNode@(lives):CodeNode (node.getSecond())
3167
- def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
3168
- new_class.name = s
3169
- def subCtx@(lives):RangerAppWriterContext (ctx.fork())
3170
- ctx.setCurrentClass(new_class)
3171
- subCtx.setCurrentClass(new_class)
3172
- new_class.ctx = subCtx
3173
- new_class.nameNode = classNameNode
3174
- ctx.addClass(s new_class)
3175
- new_class.classNode = node
3176
- new_class.node = node
3177
- new_class.is_trait = true
3178
- }
3179
-
3180
- if ((node.isFirstVref("CreateClass")) || (node.isFirstVref("class"))) {
3181
-
3182
- if( (array_length node.children) < 3) {
3183
- ctx.addError(node "Not enough arguments for creating a class")
3184
- return
3185
- }
3186
-
3187
- def s:string (node.getVRefAt(1))
3188
- def classNameNode@(lives):CodeNode (node.getSecond())
3189
- def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
3190
- new_class.name = s
3191
- def subCtx@(lives):RangerAppWriterContext (ctx.fork())
3192
- ctx.setCurrentClass(new_class)
3193
- subCtx.setCurrentClass(new_class)
3194
- new_class.ctx = subCtx
3195
- new_class.nameNode = classNameNode
3196
- ctx.addClass(s new_class)
3197
- new_class.classNode = node
3198
- new_class.node = node
3199
- if(node.hasBooleanProperty("trait")) {
3200
- new_class.is_trait = true
3201
- }
3202
- if(classNameNode.hasFlag("immutable")) {
3203
- push immutableClasses new_class
3204
- new_class.is_immutable = true
3205
- }
3206
- def third (node.getThird())
3207
- if(third.vref == "extends") {
3208
- if( (node.chlen()) >= 4 ) {
3209
- def extClass (itemAt node.children 3)
3210
- if( (strlen extClass.vref) > 0 ) {
3211
- ;
3212
- set extendedClasses s extClass.vref
3213
- } {
3214
- ctx.addError( node "Invalid classname given for the extends keyword")
3215
- }
3216
- }
3217
- }
3218
- ; check for the extends keyword
3219
- }
3220
-
3221
- if (node.isFirstVref("TemplateClass")) {
3222
- def s:string (node.getVRefAt(1))
3223
- ctx.addTemplateClass(s node)
3224
- find_more = false
3225
- }
3226
-
3227
- if((node.isFirstVref("Extends"))) {
3228
-
3229
- def list:CodeNode (itemAt node.children 1)
3230
- for list.children cname:CodeNode i {
3231
- def extC:RangerAppClassDesc (ctx.findClass(cname.vref))
3232
- for extC.variables vv@(lives):RangerAppParamDesc i {
3233
- def currC:RangerAppClassDesc ctx.currentClass
3234
- def subCtx:RangerAppWriterContext currC.ctx
3235
- subCtx.defineVariable(vv.name vv)
3236
- }
3237
- }
3238
- find_more = false
3239
- }
3240
-
3241
- if ((node.isFirstVref("def")) || (node.isFirstVref("let"))) {
3242
- def s:string (node.getVRefAt(1))
3243
- def vDef@(lives):CodeNode (itemAt node.children 1)
3244
- def p:RangerAppParamDesc (new RangerAppParamDesc ())
3245
-
3246
- ; TODO: check also for new...
3247
- ; TODO: may not work if trait has not been declared
3248
- if(vDef.has_type_annotation) {
3249
- this.CheckTypeAnnotationOf( vDef ctx wr )
3250
- }
3251
- if( s != ((ctx.transformWord(s)))) {
3252
- ; ctx.addError( node "Can not use reserved word " + s + " as class propery")
3253
- }
3254
- def currC:RangerAppClassDesc ctx.currentClass
3255
-
3256
- ; immutable classes have only weak properties
3257
- if currC.is_immutable {
3258
- vDef.setFlag("weak")
3259
- if( vDef.value_type == RangerNodeType.Array) {
3260
- def initNode (node.newExpressionNode())
3261
- initNode.push( (node.newVRefNode("new")) )
3262
- def tDef (node.newVRefNode("Vector"))
3263
-
3264
- ; Vector@(string)
3265
- def vAnn (node.newExpressionNode())
3266
- vAnn.push( (node.newVRefNode(vDef.array_type)))
3267
- tDef.has_vref_annotation = true
3268
- tDef.vref_annotation = vAnn
3269
- initNode.push(tDef)
3270
-
3271
- set node.children 2 (initNode)
3272
-
3273
- vDef.value_type = RangerNodeType.VRef
3274
- vDef.type_name = "Vector"
3275
- ; def obj:Vector@(string)
3276
- def tAnn (node.newExpressionNode())
3277
- tAnn.push( (node.newVRefNode(vDef.array_type)))
3278
- vDef.has_type_annotation = true
3279
- vDef.type_annotation = tAnn
3280
-
3281
- this.CheckTypeAnnotationOf( vDef ctx wr )
3282
- this.CheckVRefTypeAnnotationOf( tDef ctx wr )
3283
-
3284
- }
3285
- if( vDef.value_type == RangerNodeType.Hash) {
3286
- def initNode (node.newExpressionNode())
3287
- initNode.push( (node.newVRefNode("new")) )
3288
- def tDef (node.newVRefNode("Map"))
3289
-
3290
- ; Vector@(string)
3291
- def vAnn (node.newExpressionNode())
3292
- vAnn.push( (node.newVRefNode(vDef.key_type)))
3293
- vAnn.push( (node.newVRefNode(vDef.array_type)))
3294
- tDef.has_vref_annotation = true
3295
- tDef.vref_annotation = vAnn
3296
- initNode.push(tDef)
3297
- set node.children 2 (initNode)
3298
-
3299
- vDef.value_type = RangerNodeType.VRef
3300
- vDef.type_name = "Map"
3301
- ; def obj:Vector@(string)
3302
- def tAnn (node.newExpressionNode())
3303
- tAnn.push( (node.newVRefNode(vDef.key_type)))
3304
- tAnn.push( (node.newVRefNode(vDef.array_type)))
3305
- vDef.has_type_annotation = true
3306
- vDef.type_annotation = tAnn
3307
-
3308
- this.CheckTypeAnnotationOf( vDef ctx wr )
3309
- this.CheckVRefTypeAnnotationOf( tDef ctx wr )
3310
-
3311
- }
3312
- }
3313
-
3314
- ; transforming reserved words here
3315
- p.name = s
3316
- p.value_type = vDef.value_type
3317
- p.node = node
3318
- p.is_class_variable = true
3319
- p.varType = RangerContextVarType.Property
3320
- p.node = node
3321
- p.nameNode = vDef
3322
- vDef.hasParamDesc = true
3323
- vDef.ownParamDesc = p
3324
- vDef.paramDesc = p
3325
- node.hasParamDesc = true
3326
- node.paramDesc = p
3327
-
3328
- if (vDef.hasFlag("weak")) {
3329
- p.changeStrength(0 2 (unwrap p.nameNode))
3330
- } {
3331
- p.changeStrength(2 2 (unwrap p.nameNode))
3332
- }
3333
-
3334
- if ((array_length node.children) > 2) {
3335
- p.set_cnt = 1
3336
- p.init_cnt = 1
3337
- p.def_value = (itemAt node.children 2)
3338
- p.is_optional = false
3339
- if(p.def_value.value_type == RangerNodeType.String) {
3340
- vDef.type_name = "string"
3341
- }
3342
- if(p.def_value.value_type == RangerNodeType.Integer) {
3343
- vDef.type_name = "int"
3344
- }
3345
- if(p.def_value.value_type == RangerNodeType.Double) {
3346
- vDef.type_name = "double"
3347
- }
3348
- if(p.def_value.value_type == RangerNodeType.Boolean) {
3349
- vDef.type_name = "boolean"
3350
- }
3351
- def valueNode (itemAt node.children 2)
3352
- if( (array_length valueNode.children) > 0) {
3353
- def fc (valueNode.getFirst())
3354
- if(fc.vref == "new") {
3355
- def second (valueNode.getSecond())
3356
- this.CheckVRefTypeAnnotationOf( second ctx wr )
3357
- }
3358
- }
3359
- } {
3360
- p.is_optional = true
3361
- if (false == ((vDef.value_type == RangerNodeType.Array) || (vDef.value_type == RangerNodeType.Hash))) {
3362
- vDef.setFlag("optional")
3363
- }
3364
- }
3365
- currC.addVariable(p)
3366
-
3367
- def subCtx:RangerAppWriterContext currC.ctx
3368
- subCtx.defineVariable(p.name p)
3369
- p.is_class_variable = true
3370
-
3371
- find_more = false
3372
- }
3373
- if (node.isFirstVref("operators")) {
3374
- def listOf:CodeNode (node.getSecond())
3375
- for listOf.children item@(lives):CodeNode i {
3376
- ctx.createOperator(item)
3377
- }
3378
- find_more = false
3379
- }
3380
- if ((node.isFirstVref("Import")) || (node.isFirstVref("import"))) {
3381
- def fNameNode:CodeNode (itemAt node.children 1)
3382
- def import_file:string fNameNode.string_value
3383
- if (has ctx.already_imported import_file) {
3384
- return
3385
- } {
3386
- set ctx.already_imported import_file true
3387
- }
3388
-
3389
- def root_path "."
3390
- if hasRootPath {
3391
- root_path = rootPath
3392
- }
3393
- def rootCtx (ctx.getRoot())
3394
- def filePathIs (this.searchLib( rootCtx.libraryPaths import_file ))
3395
-
3396
- if( ( file_exists filePathIs import_file ) == false ) {
3397
- ctx.addError(node ("Could not import file " + import_file))
3398
- return
3399
- ;"
3400
- }
3401
- def c:string (read_file filePathIs import_file)
3402
- def code:SourceCode (new SourceCode ( (unwrap c)))
3403
- code.filename = import_file
3404
- def parser:RangerLispParser (new RangerLispParser (code))
3405
- parser.parse()
3406
- def rnode:CodeNode parser.rootNode
3407
- this.WalkCollectMethods( (unwrap rnode) ctx wr)
3408
- find_more = false
3409
- }
3410
- ; consumes_traits
3411
- if (node.isFirstVref("does")) {
3412
- def defName:CodeNode (node.getSecond())
3413
- def currC@(lives):RangerAppClassDesc ctx.currentClass
3414
- push currC.consumes_traits defName.vref
3415
- def joinPoint@(lives):ClassJoinPoint (new ClassJoinPoint())
3416
- joinPoint.class_def = currC
3417
- joinPoint.node = node
3418
- push classesWithTraits joinPoint
3419
- }
3420
-
3421
- def b_is_main false
3422
- if ( node.code.filename == (ctx.getRootFile()) ) {
3423
- b_is_main = true
3424
- }
3425
-
3426
- if ((node.isFirstVref("static")) ) {
3427
- ; static fn foo () {}
3428
- if( (node.chlen()) < 5 ) {
3429
- ctx.addError(node "Invalid static function declaration")
3430
- return
3431
- }
3432
- def s:string (node.getVRefAt(2))
3433
- if( s == "main" ) {
3434
- if b_is_main {
3435
- this.mainCnt = this.mainCnt + 1
3436
- if(this.mainCnt > 1) {
3437
- ctx.addError( node "main function can be declared only once")
3438
- }
3439
- }
3440
- }
3441
- def currC:RangerAppClassDesc ctx.currentClass
3442
- def m@(lives):RangerAppFunctionDesc (new RangerAppFunctionDesc ())
3443
- m.name = s
3444
- m.compiledName = (ctx.transformWord(s))
3445
- m.node = node
3446
- m.is_static = true
3447
- m.nameNode = (itemAt node.children 2)
3448
- m.nameNode.ifNoTypeSetToVoid()
3449
- def args:CodeNode (itemAt node.children 3)
3450
- m.fnBody = (itemAt node.children 4)
3451
- ; m.fnCtx = (ctx.fork())
3452
- this.CheckTypeAnnotationOf( (unwrap m.nameNode) ctx wr )
3453
- args.children.forEach({
3454
- this.defineFunctionParam( m item ctx wr)
3455
- })
3456
- currC.addStaticMethod(m)
3457
- find_more = false
3458
- }
3459
- if ((node.isFirstVref("StaticMethod")) || (node.isFirstVref("sfn"))) {
3460
- def s:string (node.getVRefAt(1))
3461
- def currC:RangerAppClassDesc ctx.currentClass
3462
- def m@(lives):RangerAppFunctionDesc (new RangerAppFunctionDesc ())
3463
- m.name = s
3464
- m.compiledName = (ctx.transformWord(s))
3465
- m.node = node
3466
- m.is_static = true
3467
- m.nameNode = (itemAt node.children 1)
3468
- m.nameNode.ifNoTypeSetToVoid()
3469
- def args:CodeNode (itemAt node.children 2)
3470
- m.fnBody = (itemAt node.children 3)
3471
- ; m.fnCtx = (ctx.fork())
3472
- this.CheckTypeAnnotationOf( (unwrap m.nameNode) ctx wr )
3473
- args.children.forEach({
3474
- this.defineFunctionParam( m item ctx wr)
3475
- })
3476
- currC.addStaticMethod(m)
3477
- find_more = false
3478
-
3479
- if( m.nameNode.hasFlag("main") ) {
3480
- if b_is_main {
3481
- this.mainCnt = this.mainCnt + 1
3482
- if(this.mainCnt > 1) {
3483
- ctx.addError( node "main function can be declared only once")
3484
- }
3485
- }
3486
- }
3487
-
3488
- }
3489
- if (node.isFirstVref("extension")) {
3490
- def s:string (node.getVRefAt(1))
3491
- def old_class@(lives):RangerAppClassDesc (ctx.findClass(s))
3492
- ctx.setCurrentClass( old_class )
3493
- ; print "extension for " + s
3494
- }
3495
-
3496
- if ((node.isFirstVref("PublicMethod")) || (node.isFirstVref("fn"))) {
3497
- def cn:CodeNode (node.getSecond())
3498
- def s:string (node.getVRefAt(1))
3499
- cn.ifNoTypeSetToVoid()
3500
-
3501
- def currC:RangerAppClassDesc ctx.currentClass
3502
- if( (currC.hasOwnMethod(s)) && (false == (cn.hasFlag("override"))) ) {
3503
- ctx.addError( node "Error: method of same name declared earlier. Overriding function declarations is not currently allowed!")
3504
- return
3505
- }
3506
- if(cn.hasFlag("main")) {
3507
- ctx.addError( node "Error: dynamic method declared as @(main). Use static 'sfn' instead of 'fn'.")
3508
- return
3509
- }
3510
- def m@(lives):RangerAppFunctionDesc (new RangerAppFunctionDesc ())
3511
- m.name = s
3512
- m.compiledName = (ctx.transformWord(s))
3513
-
3514
- m.node = node
3515
- m.nameNode = (itemAt node.children 1)
3516
- if (node.hasBooleanProperty("strong")) {
3517
- m.refType = RangerNodeRefType.Strong
3518
- } {
3519
- m.refType = RangerNodeRefType.Weak
3520
- }
3521
- def subCtx:RangerAppWriterContext (currC.ctx.fork())
3522
- subCtx.is_function = true
3523
- subCtx.currentMethod = m
3524
- m.fnCtx = subCtx
3525
- if (cn.hasFlag("weak")) {
3526
- m.changeStrength(0 1 node)
3527
- } {
3528
- m.changeStrength(1 1 node)
3529
- }
3530
- def args:CodeNode (itemAt node.children 2)
3531
- m.fnBody = (itemAt node.children 3)
3532
-
3533
- this.CheckTypeAnnotationOf( (unwrap m.nameNode) ctx wr )
3534
-
3535
- for args.children arg@(lives):CodeNode ii {
3536
-
3537
- this.CheckTypeAnnotationOf( arg subCtx wr )
3538
-
3539
- def p2@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
3540
- p2.name = arg.vref
3541
- p2.value_type = arg.value_type
3542
- p2.node = arg
3543
- p2.nameNode = arg
3544
- p2.init_cnt = 1
3545
- p2.refType = RangerNodeRefType.Weak
3546
- p2.initRefType = RangerNodeRefType.Weak
3547
- p2.debugString = "--> collected "
3548
- if (args.hasBooleanProperty("strong")) {
3549
- p2.debugString = "--> collected as STRONG"
3550
- ctx.log(node "memory5" "strong param should move local ownership to call ***")
3551
- p2.refType = RangerNodeRefType.Strong
3552
- p2.initRefType = RangerNodeRefType.Strong
3553
- }
3554
- p2.varType = RangerContextVarType.FunctionParameter
3555
- push m.params p2
3556
- arg.hasParamDesc = true
3557
- arg.paramDesc = p2
3558
- arg.eval_type = arg.value_type
3559
- arg.eval_type_name = arg.type_name
3560
- if (arg.hasFlag("strong")) {
3561
- p2.changeStrength(1 1 (unwrap p2.nameNode))
3562
- } {
3563
- arg.setFlag("lives")
3564
- p2.changeStrength(0 1 (unwrap p2.nameNode))
3565
- }
3566
- ; subCtx.hadValidType(p2.nameNode)
3567
- subCtx.defineVariable(p2.name p2)
3568
- }
3569
- currC.addMethod(m)
3570
- find_more = false
3571
- }
3572
- if find_more {
3573
- for node.children item:CodeNode i {
3574
- this.WalkCollectMethods(item ctx wr)
3575
- }
3576
- }
3577
- ; serialize should be at end when all extensions have been added
3578
-
3579
- if(node.hasBooleanProperty("serialize")) {
3580
- push serializedClasses (unwrap ctx.currentClass)
3581
- }
3582
-
3583
- }
3584
- fn FindWeakRefs:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
3585
- def list:[RangerAppClassDesc] (ctx.getClasses())
3586
- for list classDesc:RangerAppClassDesc i {
3587
- for classDesc.variables varD:RangerAppParamDesc i2 {
3588
- if (varD.refType == RangerNodeRefType.Weak) {
3589
- if (varD.isArray()) {
3590
- def nn:CodeNode varD.nameNode
3591
- }
3592
- if (varD.isHash()) {
3593
- def nn:CodeNode varD.nameNode
3594
- }
3595
- if (varD.isObject()) {
3596
- def nn:CodeNode varD.nameNode
3597
- }
3598
- }
3599
- }
3600
- }
3601
- }
3602
- fn findFunctionDesc@(weak optional):RangerAppFunctionDesc (obj:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
3603
- def varDesc:RangerAppParamDesc
3604
- def varFnDesc:RangerAppFunctionDesc
3605
-
3606
- if (obj.vref != (this.getThisName())) {
3607
- if ((array_length obj.ns) > 1) {
3608
- def cnt:int (array_length obj.ns)
3609
- def classRefDesc:RangerAppParamDesc
3610
- def classDesc:RangerAppClassDesc
3611
- for obj.ns strname:string i {
3612
- if (i == 0) {
3613
-
3614
- if (strname == (this.getThisName())) {
3615
- classDesc = (ctx.getCurrentClass())
3616
- } {
3617
- if (ctx.isDefinedClass(strname)) {
3618
- classDesc = (ctx.findClass(strname))
3619
- continue _
3620
- }
3621
- classRefDesc = (ctx.getVariableDef(strname))
3622
- if ( (null? classRefDesc) || (null? classRefDesc.nameNode) ) {
3623
- ctx.addError(obj ("Error, no description for called object: " + strname))
3624
- break _
3625
- }
3626
- classRefDesc.ref_cnt = (1 + classRefDesc.ref_cnt)
3627
- classDesc = (ctx.findClass(classRefDesc.nameNode.type_name))
3628
- if(null? classDesc) {
3629
- return varFnDesc
3630
- }
3631
- }
3632
- } {
3633
-
3634
- if(null? classDesc) {
3635
- return varFnDesc
3636
- }
3637
- if (i < (cnt - 1)) {
3638
- varDesc = (classDesc.findVariable(strname))
3639
- if (null? varDesc) {
3640
- ctx.addError(obj ("Error, no description for refenced obj: " + strname))
3641
- }
3642
- def subClass:string (varDesc.getTypeName())
3643
- classDesc = (ctx.findClass(subClass))
3644
- continue _
3645
- }
3646
- if (!null? classDesc) {
3647
- varFnDesc = (classDesc.findMethod(strname))
3648
- if (null? varFnDesc) {
3649
- varFnDesc = (classDesc.findStaticMethod(strname))
3650
- if (null? varFnDesc) {
3651
- ctx.addError(obj (" function variable not found " + strname))
3652
- }
3653
- }
3654
- }
3655
- }
3656
- }
3657
- return varFnDesc
3658
- }
3659
-
3660
- def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
3661
- def currClass:RangerAppClassDesc (unwrap udesc)
3662
-
3663
- varFnDesc = (currClass.findMethod(obj.vref))
3664
- if (!null? varFnDesc.nameNode) {
3665
- } {
3666
- ctx.addError(obj ("Error, no description for called function: " + obj.vref))
3667
- }
3668
- return varFnDesc
3669
- }
3670
- ctx.addError(obj "Can not call 'this' like function")
3671
- varFnDesc = (new RangerAppFunctionDesc ())
3672
- return varFnDesc
3673
- }
3674
- fn findParamDesc@(weak optional):RangerAppParamDesc (obj:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
3675
-
3676
- def varDesc@(lives):RangerAppParamDesc
3677
- def set_nsp:boolean false
3678
- def classDesc@(lives):RangerAppClassDesc
3679
- if (0 == (array_length obj.nsp)) {
3680
- set_nsp = true
3681
- }
3682
- if (obj.vref != (this.getThisName())) {
3683
- if ((array_length obj.ns) > 1) {
3684
- def cnt:int (array_length obj.ns)
3685
- def classRefDesc@(lives):RangerAppParamDesc
3686
- for obj.ns strname:string i {
3687
- if (i == 0) {
3688
-
3689
- if (strname == (this.getThisName())) {
3690
-
3691
- classDesc = (ctx.getCurrentClass())
3692
-
3693
- if set_nsp {
3694
- push obj.nsp (unwrap classDesc)
3695
- }
3696
- } {
3697
- if (ctx.isDefinedClass(strname)) {
3698
- classDesc = (ctx.findClass(strname))
3699
- if set_nsp {
3700
- push obj.nsp (unwrap classDesc)
3701
- }
3702
- continue _
3703
- }
3704
- classRefDesc = (ctx.getVariableDef(strname))
3705
- if (null? classRefDesc) {
3706
- ctx.addError(obj ("Error, no description for called object: " + strname))
3707
- break _
3708
- }
3709
- if set_nsp {
3710
- push obj.nsp (unwrap classRefDesc)
3711
- }
3712
- classRefDesc.ref_cnt = (1 + classRefDesc.ref_cnt)
3713
- classDesc = (ctx.findClass(classRefDesc.nameNode.type_name))
3714
- }
3715
- } {
3716
- if (i < (cnt - 1)) {
3717
- varDesc = (classDesc.findVariable(strname))
3718
- if (null? varDesc) {
3719
- ctx.addError(obj ("Error, no description for refenced obj: " + strname))
3720
- }
3721
- def subClass:string (varDesc.getTypeName())
3722
- classDesc = (ctx.findClass(subClass))
3723
- if set_nsp {
3724
- push obj.nsp (unwrap varDesc)
3725
- }
3726
- continue _
3727
- }
3728
- if (!null? classDesc) {
3729
- varDesc = (classDesc.findVariable(strname))
3730
- if (null? varDesc) {
3731
- def classMethod@(lives optional):RangerAppFunctionDesc (classDesc.findMethod(strname))
3732
- if (null? classMethod) {
3733
- classMethod = (classDesc.findStaticMethod(strname))
3734
- if (null? classMethod) {
3735
- ctx.addError(obj ("variable not found " + strname))
3736
- }
3737
- }
3738
- if (!null? classMethod) {
3739
- if set_nsp {
3740
- push obj.nsp (unwrap classMethod)
3741
- }
3742
- return classMethod
3743
- }
3744
- }
3745
- if set_nsp {
3746
- push obj.nsp (unwrap varDesc)
3747
- }
3748
- }
3749
- }
3750
- }
3751
- return varDesc
3752
- }
3753
- varDesc = (ctx.getVariableDef(obj.vref))
3754
- if (!null? varDesc.nameNode) {
3755
- } {
3756
- print ("findParamDesc : description not found for " + obj.vref)
3757
- if (!null? varDesc) {
3758
- print ("Vardesc was found though..." + varDesc.name)
3759
- }
3760
- ctx.addError(obj ("Error, no description for called object: " + obj.vref))
3761
- }
3762
- return varDesc
3763
- }
3764
- def cc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
3765
- return cc
3766
- }
3767
-
3768
- fn convertToUnion( unionName:string node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
3769
-
3770
- if( (ctx.isDefinedClass(unionName)) ) {
3771
- def c1:RangerAppClassDesc (ctx.findClass(unionName))
3772
- if( c1.is_union ) {
3773
- if( (node.type_name != c1.name) && (node.eval_type_name != c1.name ) ) {
3774
- def toEx (node.newExpressionNode())
3775
- def toVref (node.newVRefNode("to"))
3776
- def argType (node.newVRefNode("_"))
3777
- def targetNode (node.copy())
3778
- argType.type_name = unionName
3779
- toEx.push( toVref )
3780
- toEx.push( argType )
3781
- toEx.push( targetNode )
3782
- node.expression = true
3783
- node.flow_done = false
3784
- node.value_type = RangerNodeType.NoType
3785
- node.getChildrenFrom( toEx )
3786
- def wr (new CodeWriter)
3787
- this.WalkNode( node ctx wr )
3788
- }
3789
- }
3790
- }
3791
- }
3792
- fn areEqualTypes:boolean (n1:CodeNode n2:CodeNode ctx:RangerAppWriterContext) {
3793
-
3794
- if(n1.eval_type == RangerNodeType.ExpressionType) {
3795
-
3796
- def n1Expr@(weak) (n1.expression_value)
3797
- def n2Expr@(weak) (n2.expression_value)
3798
-
3799
- if(null? n1Expr) {
3800
- if(n1.hasParamDesc && (!null? n1.paramDesc.nameNode)) {
3801
- n1Expr = n1.paramDesc.nameNode.expression_value
3802
- }
3803
- }
3804
- if(null? n2Expr) {
3805
- if(n2.hasParamDesc && (!null? n2.paramDesc.nameNode)) {
3806
- n2Expr = n2.paramDesc.nameNode.expression_value
3807
- }
3808
- }
3809
- if( (!null? n1Expr) && (!null? n2Expr) ) {
3810
- return (this.matchLambdaArgs( (unwrap n1Expr) (unwrap n2Expr) ctx (new CodeWriter)))
3811
- }
3812
- ctx.addError(n2 "Was not able to evaluate lambda expression types")
3813
- return false
3814
- }
3815
-
3816
- if ((n1.eval_type != RangerNodeType.NoType) && (n2.eval_type != RangerNodeType.NoType) && ((strlen n1.eval_type_name) > 0) && ((strlen n2.eval_type_name) > 0)) {
3817
- if (n1.eval_type_name == n2.eval_type_name) {
3818
- } {
3819
- def b_ok:boolean false
3820
- if ((ctx.isEnumDefined(n1.eval_type_name)) && (n2.eval_type_name == "int")) {
3821
- b_ok = true
3822
- }
3823
- if ((ctx.isEnumDefined(n2.eval_type_name)) && (n1.eval_type_name == "int")) {
3824
- b_ok = true
3825
- }
3826
- if ((n1.eval_type_name == "char") && (n2.eval_type_name == "int")) {
3827
- b_ok = true
3828
- }
3829
- if ((n1.eval_type_name == "int") && (n2.eval_type_name == "char")) {
3830
- b_ok = true
3831
- }
3832
-
3833
- if( (ctx.isDefinedClass(n1.eval_type_name)) && (ctx.isDefinedClass (n2.eval_type_name))) {
3834
-
3835
- def c1:RangerAppClassDesc (ctx.findClass(n1.eval_type_name))
3836
- def c2:RangerAppClassDesc (ctx.findClass(n2.eval_type_name))
3837
-
3838
- if( c1.is_union ) {
3839
- if( c2.is_union == false ) {
3840
-
3841
- this.convertToUnion( n1.eval_type_name n2 ctx (new CodeWriter))
3842
- if(n2.eval_type_name == n1.eval_type_name) {
3843
- return true
3844
- } {
3845
- return false
3846
- }
3847
- }
3848
- }
3849
-
3850
- if( (c2.is_union != c1.is_union ) ) {
3851
- ctx.addError( n1 ("Can not convert union to type "))
3852
- return false
3853
- }
3854
-
3855
- if( (c2.is_union == true) && (c1.is_union == true)) {
3856
- ctx.addError( n1 ("Union types must be the same => " + n1.eval_type_name + " <> " + n2.eval_type_name))
3857
- return false
3858
- }
3859
-
3860
- if ( c1.isSameOrParentClass (n2.eval_type_name ctx)) {
3861
- return true
3862
- }
3863
- if ( c2.isSameOrParentClass (n1.eval_type_name ctx)) {
3864
- return true
3865
- }
3866
- }
3867
-
3868
- if (b_ok == false) {
3869
- return false
3870
- }
3871
- }
3872
- }
3873
- return true
3874
- }
3875
- fn shouldBeEqualTypes:void (n1:CodeNode n2:CodeNode ctx@(weak):RangerAppWriterContext msg:string) {
3876
-
3877
- if ((n1.eval_type != RangerNodeType.NoType) && (n2.eval_type != RangerNodeType.NoType) && ((strlen n1.eval_type_name) > 0) && ((strlen n2.eval_type_name) > 0)) {
3878
- if (n1.eval_type_name == n2.eval_type_name) {
3879
- } {
3880
- def b_ok:boolean false
3881
- if ((ctx.isEnumDefined(n1.eval_type_name)) && (n2.eval_type_name == "int")) {
3882
- b_ok = true
3883
- }
3884
- if ((ctx.isEnumDefined(n2.eval_type_name)) && (n1.eval_type_name == "int")) {
3885
- b_ok = true
3886
- }
3887
- if (ctx.isDefinedClass(n2.eval_type_name)) {
3888
- def cc:RangerAppClassDesc (ctx.findClass(n2.eval_type_name))
3889
- if (cc.isSameOrParentClass(n1.eval_type_name ctx)) {
3890
- b_ok = true
3891
- }
3892
- }
3893
- if ((n1.eval_type_name == "char") && (n2.eval_type_name == "int")) {
3894
- b_ok = true
3895
- }
3896
- if ((n1.eval_type_name == "int") && (n2.eval_type_name == "char")) {
3897
- b_ok = true
3898
- }
3899
- if (b_ok == false) {
3900
- ctx.addError(n1 ("Type mismatch " + n2.eval_type_name + " <> " + n1.eval_type_name + ". " + msg))
3901
- }
3902
- }
3903
- }
3904
- }
3905
- fn shouldBeExpression:void (n1:CodeNode ctx:RangerAppWriterContext msg:string) {
3906
- if (n1.expression == false) {
3907
- ctx.addError(n1 (msg))
3908
- }
3909
- }
3910
- fn shouldHaveChildCnt:void (cnt:int n1:CodeNode ctx:RangerAppWriterContext msg:string) {
3911
- if ((array_length n1.children) != cnt) {
3912
- ctx.addError(n1 (msg))
3913
- }
3914
- }
3915
- fn shouldBeNumeric:void (n1:CodeNode ctx:RangerAppWriterContext msg:string) {
3916
- if ((n1.eval_type != RangerNodeType.NoType) && ((strlen n1.eval_type_name) > 0)) {
3917
- if (false == ((n1.eval_type_name == "double") || (n1.eval_type_name == "int"))) {
3918
- ctx.addError(n1 ("Not numeric: " + n1.eval_type_name + ". " + msg))
3919
- }
3920
- }
3921
- }
3922
- fn shouldBeArray:void (n1:CodeNode ctx:RangerAppWriterContext msg:string) {
3923
- if (n1.eval_type != RangerNodeType.Array) {
3924
- ctx.addError(n1 ("Expecting array. " + msg))
3925
- }
3926
- }
3927
- fn shouldBeType:void (type_name:string n1:CodeNode ctx:RangerAppWriterContext msg:string) {
3928
- if ((n1.eval_type != RangerNodeType.NoType) && ((strlen n1.eval_type_name) > 0)) {
3929
- if (n1.eval_type_name == type_name) {
3930
- } {
3931
- def b_ok:boolean false
3932
- if ((ctx.isEnumDefined(n1.eval_type_name)) && (type_name == "int")) {
3933
- b_ok = true
3934
- }
3935
- if ((ctx.isEnumDefined(type_name)) && (n1.eval_type_name == "int")) {
3936
- b_ok = true
3937
- }
3938
- if ((n1.eval_type_name == "char") && (type_name == "int")) {
3939
- b_ok = true
3940
- }
3941
- if ((n1.eval_type_name == "int") && (type_name == "char")) {
3942
- b_ok = true
3943
- }
3944
- if (b_ok == false) {
3945
- ctx.addError(n1 ("Type mismatch " + type_name + " <> " + n1.eval_type_name + ". " + msg))
3946
- }
3947
- }
3948
- }
3949
- }
3950
- }
3951
-