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