ranger-compiler 2.1.69 → 3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +103 -0
- package/README.md +991 -96
- package/{compiler/Lang.clj → dist/Lang.rgr} +2345 -75
- package/dist/README.md +116 -0
- package/dist/{bin/api.d.ts → api.d.ts} +430 -154
- package/dist/api.js +34345 -0
- package/{lib/Ajax.clj → dist/lib/Ajax.rgr} +1 -1
- package/{lib/CmdParams.clj → dist/lib/CmdParams.rgr} +72 -72
- package/{lib/Crypto.clj → dist/lib/Crypto.rgr} +1 -1
- package/{lib/DOMLib.clj → dist/lib/DOMLib.rgr} +2 -2
- package/{lib/Engine3D.clj → dist/lib/Engine3D.rgr} +1 -1
- package/{lib/ImmutableVector.clj → dist/lib/ImmutableVector.rgr} +364 -364
- package/{lib/IndexedDB.clj → dist/lib/IndexedDB.rgr} +1 -1
- package/{lib/JSON.clj → dist/lib/JSON.rgr} +105 -2
- package/{lib/JinxProcess.clj → dist/lib/JinxProcess.rgr} +3 -3
- package/{lib/Storage.clj → dist/lib/Storage.rgr} +1 -1
- package/{lib/Timers.clj → dist/lib/Timers.rgr} +176 -170
- package/{lib/ViewLib.clj → dist/lib/ViewLib.rgr} +1 -1
- package/dist/lib/lib/ACEEditor.rgr +5 -0
- package/dist/lib/lib/Ajax.rgr +196 -0
- package/dist/lib/lib/CmdParams.rgr +72 -0
- package/dist/lib/lib/Crypto.rgr +90 -0
- package/dist/lib/lib/DOMLib.rgr +307 -0
- package/{examples/3D/Engine3D.clj → dist/lib/lib/Engine3D.rgr} +870 -857
- package/dist/lib/lib/ImmutableVector.rgr +364 -0
- package/dist/lib/lib/IndexedDB.rgr +32 -0
- package/{compiler/JSON.clj → dist/lib/lib/JSON.rgr} +106 -3
- package/dist/lib/lib/JinxProcess.rgr +838 -0
- package/dist/lib/lib/SQL.rgr +44 -0
- package/dist/lib/lib/ServiceLib.rgr +9 -0
- package/dist/lib/lib/Storage.rgr +89 -0
- package/dist/lib/lib/Time.rgr +75 -0
- package/dist/lib/lib/Timers.rgr +176 -0
- package/dist/lib/lib/TypedArrays.rgr +14 -0
- package/dist/lib/lib/ViewLib.rgr +851 -0
- package/dist/lib/lib/WebLib.rgr +47 -0
- package/dist/lib/lib/WebServerLib.rgr +137 -0
- package/{lib/ranger-dir.clj → dist/lib/lib/ranger-dir.rgr} +1 -1
- package/{compiler/stdlib.clj → dist/lib/lib/stdlib.rgr} +42 -19
- package/{lib/stdops.clj → dist/lib/lib/stdops.rgr} +1 -1
- package/dist/lib/ranger-dir.rgr +175 -0
- package/{lib/stdlib.clj → dist/lib/stdlib.rgr} +2 -2
- package/dist/lib/stdops.rgr +168 -0
- package/dist/package.json +47 -0
- package/{bin/output.js → dist/rgrc.js} +15377 -7935
- package/dist/stdops.rgr +168 -0
- package/package.json +196 -38
- package/adventofcode/day1/bin/LambdaSignature1.java +0 -3
- package/adventofcode/day1/bin/LambdaSignature2.java +0 -3
- package/adventofcode/day1/bin/LambdaSignature3.java +0 -3
- package/adventofcode/day1/bin/day1.cpp +0 -124
- package/adventofcode/day1/bin/day1.go +0 -75
- package/adventofcode/day1/bin/day1.js +0 -45
- package/adventofcode/day1/bin/day1.php +0 -46
- package/adventofcode/day1/bin/day1.scala +0 -48
- package/adventofcode/day1/bin/day1.swift +0 -48
- package/adventofcode/day1/bin/day1_part2.cpp +0 -180
- package/adventofcode/day1/bin/day1_part2.go +0 -123
- package/adventofcode/day1/bin/day1_part2.js +0 -76
- package/adventofcode/day1/bin/day1_part2.php +0 -88
- package/adventofcode/day1/bin/day1_part2.scala +0 -81
- package/adventofcode/day1/bin/day1_part2.swift +0 -91
- package/adventofcode/day1/bin/day_one.java +0 -38
- package/adventofcode/day1/bin/day_one_part_two.java +0 -57
- package/adventofcode/day1/bin/operatorsOf.java +0 -37
- package/adventofcode/day1/bin/operatorsOf_5.java +0 -10
- package/adventofcode/day1/bin/operatorsOfboolean_5.java +0 -10
- package/adventofcode/day1/bin/variant.hpp +0 -2416
- package/adventofcode/day1/compile.bat +0 -7
- package/adventofcode/day1/compile2.bat +0 -7
- package/adventofcode/day1/day1.clj +0 -19
- package/adventofcode/day1/day1_part2.clj +0 -43
- package/adventofcode/day1/input1.txt +0 -1
- package/adventofcode/day2/bin/LambdaSignature1.class +0 -0
- package/adventofcode/day2/bin/LambdaSignature1.java +0 -3
- package/adventofcode/day2/bin/LambdaSignature2.class +0 -0
- package/adventofcode/day2/bin/LambdaSignature2.java +0 -3
- package/adventofcode/day2/bin/day2.cpp +0 -133
- package/adventofcode/day2/bin/day2.go +0 -85
- package/adventofcode/day2/bin/day2.js +0 -45
- package/adventofcode/day2/bin/day2.php +0 -59
- package/adventofcode/day2/bin/day2.scala +0 -54
- package/adventofcode/day2/bin/day2.swift +0 -62
- package/adventofcode/day2/bin/day2_part2.cpp +0 -150
- package/adventofcode/day2/bin/day2_part2.go +0 -101
- package/adventofcode/day2/bin/day2_part2.js +0 -54
- package/adventofcode/day2/bin/day2_part2.php +0 -80
- package/adventofcode/day2/bin/day2_part2.scala +0 -68
- package/adventofcode/day2/bin/day2_part2.swift +0 -82
- package/adventofcode/day2/bin/day_two.java +0 -61
- package/adventofcode/day2/bin/day_two_part_two$1$1$1.class +0 -0
- package/adventofcode/day2/bin/day_two_part_two$1$1.class +0 -0
- package/adventofcode/day2/bin/day_two_part_two$1.class +0 -0
- package/adventofcode/day2/bin/day_two_part_two.class +0 -0
- package/adventofcode/day2/bin/day_two_part_two.java +0 -80
- package/adventofcode/day2/bin/operatorsOf.class +0 -0
- package/adventofcode/day2/bin/operatorsOf.java +0 -18
- package/adventofcode/day2/bin/variant.hpp +0 -2416
- package/adventofcode/day2/compile.bat +0 -7
- package/adventofcode/day2/compile2.bat +0 -7
- package/adventofcode/day2/day2.clj +0 -60
- package/adventofcode/day2/day2_part2.clj +0 -69
- package/adventofcode/day2/input1.txt +0 -1
- package/adventofcode/day3/bin/Grid.java +0 -92
- package/adventofcode/day3/bin/GridRow.java +0 -5
- package/adventofcode/day3/bin/LambdaSignature1.java +0 -3
- package/adventofcode/day3/bin/LambdaSignature2.java +0 -3
- package/adventofcode/day3/bin/LambdaSignature3.java +0 -3
- package/adventofcode/day3/bin/day3.cpp +0 -64
- package/adventofcode/day3/bin/day3.go +0 -55
- package/adventofcode/day3/bin/day3.js +0 -42
- package/adventofcode/day3/bin/day3.php +0 -41
- package/adventofcode/day3/bin/day3.scala +0 -52
- package/adventofcode/day3/bin/day3.swift +0 -43
- package/adventofcode/day3/bin/day3_part2.cpp +0 -216
- package/adventofcode/day3/bin/day3_part2.go +0 -188
- package/adventofcode/day3/bin/day3_part2.js +0 -123
- package/adventofcode/day3/bin/day3_part2.php +0 -135
- package/adventofcode/day3/bin/day3_part2.swift +0 -131
- package/adventofcode/day3/bin/day_three_part_two.java +0 -43
- package/adventofcode/day3/bin/day_two.java +0 -42
- package/adventofcode/day3/bin/operatorsOf.java +0 -14
- package/adventofcode/day3/bin/variant.hpp +0 -2416
- package/adventofcode/day3/compile.bat +0 -7
- package/adventofcode/day3/compile2.bat +0 -7
- package/adventofcode/day3/day3.clj +0 -42
- package/adventofcode/day3/day3_part2.clj +0 -112
- package/adventofcode/day4/bin/LambdaSignature1.java +0 -3
- package/adventofcode/day4/bin/day4.cpp +0 -118
- package/adventofcode/day4/bin/day4.go +0 -75
- package/adventofcode/day4/bin/day4.js +0 -40
- package/adventofcode/day4/bin/day4.php +0 -52
- package/adventofcode/day4/bin/day4.scala +0 -47
- package/adventofcode/day4/bin/day4.swift +0 -56
- package/adventofcode/day4/bin/day4_part2.go +0 -129
- package/adventofcode/day4/bin/day4_part2.js +0 -72
- package/adventofcode/day4/bin/day_four.java +0 -41
- package/adventofcode/day4/bin/inputData.java +0 -7
- package/adventofcode/day4/bin/operatorsOf.java +0 -11
- package/adventofcode/day4/bin/variant.hpp +0 -2416
- package/adventofcode/day4/compile.bat +0 -7
- package/adventofcode/day4/compile2.bat +0 -7
- package/adventofcode/day4/day4.clj +0 -32
- package/adventofcode/day4/day4_part2.clj +0 -44
- package/adventofcode/day4/input.clj +0 -519
- package/adventofcode/day4/input.txt +0 -512
- package/bin/api.ts +0 -24471
- package/bin/compiler.ts +0 -24482
- package/compiler/ColorConsole.clj +0 -22
- package/compiler/ContextOperators.clj +0 -75
- package/compiler/FlowEnterVarDef.clj +0 -223
- package/compiler/InputFileSystem.clj +0 -276
- package/compiler/RangerDocs.clj +0 -7
- package/compiler/TFactory.clj +0 -146
- package/compiler/TFiles.clj +0 -23
- package/compiler/TFlow.clj +0 -39
- package/compiler/TNodeFactory.clj +0 -84
- package/compiler/TTypes.clj +0 -188
- package/compiler/VirtualCompiler.clj +0 -800
- package/compiler/bin/ng_Compiler.js +0 -23779
- package/compiler/commonmark_plugin.clj +0 -359
- package/compiler/feat2.bat +0 -2
- package/compiler/feats.bat +0 -9
- package/compiler/feature_tests.clj +0 -192
- package/compiler/index.js +0 -2
- package/compiler/issue_57.clj +0 -25
- package/compiler/makefile_plugin.clj +0 -135
- package/compiler/markdown_plugin.clj +0 -386
- package/compiler/maven_plugin.clj +0 -162
- package/compiler/ng_AndroidPageWriter.clj +0 -299
- package/compiler/ng_CodeNode.clj +0 -756
- package/compiler/ng_CodeNodeCompilerExtensions.clj +0 -839
- package/compiler/ng_Compiler.clj +0 -49
- package/compiler/ng_CompilerGeneric.clj +0 -260
- package/compiler/ng_CompilerOrig.clj +0 -854
- package/compiler/ng_DictNode.clj +0 -346
- package/compiler/ng_DictNode2.clj +0 -316
- package/compiler/ng_Execute.clj +0 -138
- package/compiler/ng_Execute1.clj +0 -129
- package/compiler/ng_FlowWork.clj +0 -3951
- package/compiler/ng_LiveCompiler.clj +0 -1109
- package/compiler/ng_RagnerJavaScriptClassWriter.clj +0 -402
- package/compiler/ng_RangerActiveOperators.clj +0 -86
- package/compiler/ng_RangerAppClassDesc.clj +0 -400
- package/compiler/ng_RangerAppEnums.clj +0 -86
- package/compiler/ng_RangerAppFunctionDesc.clj +0 -127
- package/compiler/ng_RangerAppMessages.clj +0 -15
- package/compiler/ng_RangerAppOperatorDesc.clj +0 -20
- package/compiler/ng_RangerAppParamDesc.clj +0 -388
- package/compiler/ng_RangerAppWriterContext.clj +0 -1793
- package/compiler/ng_RangerArgMatch.clj +0 -638
- package/compiler/ng_RangerCSharpClassWriter.clj +0 -484
- package/compiler/ng_RangerCppClassWriter.clj +0 -1023
- package/compiler/ng_RangerDocGenerator.clj +0 -305
- package/compiler/ng_RangerFlowParser.clj +0 -4992
- package/compiler/ng_RangerFlowParserOrig.clj +0 -4002
- package/compiler/ng_RangerGenericClassWriter.clj +0 -573
- package/compiler/ng_RangerGolangClassWriter.clj +0 -1766
- package/compiler/ng_RangerImmutableExtension.clj +0 -77
- package/compiler/ng_RangerJava7ClassWriter.clj +0 -961
- package/compiler/ng_RangerJavaScriptClassWriter.clj +0 -1042
- package/compiler/ng_RangerKotlinClassWriter.clj +0 -372
- package/compiler/ng_RangerLanguageWriters.clj +0 -14
- package/compiler/ng_RangerLispParser.clj +0 -873
- package/compiler/ng_RangerPHPClassWriter.clj +0 -643
- package/compiler/ng_RangerPlugin.clj +0 -41
- package/compiler/ng_RangerRangerClassWriter.clj +0 -357
- package/compiler/ng_RangerRustClassWriter.clj +0 -420
- package/compiler/ng_RangerScalaClassWriter.clj +0 -818
- package/compiler/ng_RangerSerializeClass.clj +0 -502
- package/compiler/ng_RangerServiceBuilder.clj +0 -63
- package/compiler/ng_RangerSwift3ClassWriter.clj +0 -809
- package/compiler/ng_RangerSwiftClassWriter.clj +0 -0
- package/compiler/ng_RangerTypeClass.clj +0 -45
- package/compiler/ng_SourceParser.clj +0 -241
- package/compiler/ng_SourceParser2.clj +0 -214
- package/compiler/ng_WebPageWriter.clj +0 -39
- package/compiler/ng_jsonParser.clj +0 -340
- package/compiler/ng_p_test.clj +0 -1711
- package/compiler/ng_parser.clj +0 -911
- package/compiler/ng_parser2.clj +0 -735
- package/compiler/ng_parser2_backup.clj +0 -1679
- package/compiler/ng_parser_backup.clj +0 -886
- package/compiler/ng_parser_ok.clj +0 -1718
- package/compiler/ng_parser_ok2.clj +0 -1717
- package/compiler/ng_parser_std_match.clj +0 -687
- package/compiler/ng_parser_std_match2.clj +0 -1012
- package/compiler/ng_parser_v2.clj +0 -1251
- package/compiler/ng_ui.clj +0 -403
- package/compiler/ng_ui_test.clj +0 -18
- package/compiler/ng_writer.clj +0 -338
- package/compiler/ng_xmlParser.clj +0 -472
- package/compiler/ng_xmlParser2.clj +0 -317
- package/compiler/ng_xmlParser3.clj +0 -251
- package/compiler/opdoc.bat +0 -4
- package/compiler/operators.md +0 -290
- package/compiler/p.bat +0 -4
- package/compiler/package.json +0 -10
- package/compiler/pcmd.bat +0 -4
- package/compiler/pcmd2.bat +0 -3
- package/compiler/plaintext_plugin.clj +0 -69
- package/compiler/plugin.bat +0 -19
- package/compiler/plugin2.bat +0 -4
- package/compiler/plugin_app.bat +0 -3
- package/compiler/plugin_apps.clj +0 -27
- package/compiler/plugins.bat +0 -10
- package/compiler/reveal_plugin.clj +0 -409
- package/compiler/simplePlugin.clj +0 -780
- package/compiler/t.bat +0 -3
- package/compiler/test_any.clj +0 -43
- package/compiler/test_call.clj +0 -141
- package/compiler/test_chain.clj +0 -79
- package/compiler/test_json.clj +0 -10
- package/compiler/test_lambda.clj +0 -153
- package/compiler/test_pcmd.clj +0 -32
- package/compiler/test_pcmd2.clj +0 -29
- package/compiler/test_plugin.clj +0 -237
- package/compiler/test_readfile.clj +0 -13
- package/compiler/test_reveal.clj +0 -19
- package/compiler/test_slides.clj +0 -312
- package/compiler/test_types.clj +0 -143
- package/compiler/test_types2.clj +0 -49
- package/compiler/test_types3.clj +0 -53
- package/compiler/test_var.clj +0 -40
- package/compiler/tonpm.bat +0 -14
- package/compiler/tonpm2.bat +0 -12
- package/compiler/ui_plugin.clj +0 -507
- package/compiler/ui_plugin2.clj +0 -427
- package/compiler/update-git.bat +0 -3
- package/compiler/vcomp.bat +0 -4
- package/compiler/viewbuilder_Android.clj +0 -176
- package/compiler/viewbuilder_Web.clj +0 -105
- package/dist/bin/api.js +0 -32422
- package/dist/bin/api.js.map +0 -1
- package/dist/bin/compiler.d.ts +0 -1638
- package/dist/bin/compiler.js +0 -32444
- package/dist/bin/compiler.js.map +0 -1
- package/examples/3D/bin/test_3d.js +0 -329
- package/examples/3D/test_3d.clj +0 -385
- package/examples/EVGColor/EVGColor.clj +0 -310
- package/examples/EVGColor/EVGColorContext.clj +0 -176
- package/examples/EVGColor/bin/EVGColor.js +0 -286
- package/examples/EVGColor/bin/minimized.js +0 -286
- package/examples/SVGPath/SVGPath.clj +0 -625
- package/examples/SVGPath/Vec2.clj +0 -103
- package/examples/SVGPath/bin/SVGPath.cpp +0 -887
- package/examples/SVGPath/bin/SVGPath.js +0 -682
- package/examples/SVGPath/bin/minimized.js +0 -578
- package/examples/SVGPath/bin/variant.hpp +0 -2416
- package/examples/minification/Vec2.clj +0 -103
- package/examples/minification/bin/minified.js +0 -44
- package/examples/minification/bin/test.js +0 -117
- package/examples/minification/test.clj +0 -13
- package/fiddle/VirtualCompiler.js +0 -23495
- package/fiddle/browser_editor.js +0 -13240
- package/fiddle/compileEnv.js +0 -1
- package/fiddle/compileEnv.json +0 -1
- package/fiddle/lang_data.js +0 -1
- package/index.html +0 -18
- package/native/httpd/HttpTester.clj +0 -33
- package/native/httpd/RangerWebService.clj +0 -81
- package/operators.md +0 -290
- package/tsconfig.json +0 -29
- package/versions/cpp/compiler.cpp +0 -15032
- package/versions/es6/compiler.js +0 -12860
- package/versions/go/compiler.go +0 -21338
- package/versions/java/AfterCodeNode.java +0 -4
- package/versions/java/ClassJoinPoint.java +0 -6
- package/versions/java/CodeFile.java +0 -42
- package/versions/java/CodeFileSystem.java +0 -72
- package/versions/java/CodeNode.java +0 -807
- package/versions/java/CodeSlice.java +0 -13
- package/versions/java/CodeWriter.java +0 -185
- package/versions/java/ColorConsole.java +0 -8
- package/versions/java/CompilerInterface.java +0 -213
- package/versions/java/DictNode.java +0 -353
- package/versions/java/LiveCompiler.java +0 -772
- package/versions/java/NodeEvalState.java +0 -24
- package/versions/java/OpFindResult.java +0 -6
- package/versions/java/RangerAppArrayValue.java +0 -7
- package/versions/java/RangerAppClassDesc.java +0 -217
- package/versions/java/RangerAppEnum.java +0 -14
- package/versions/java/RangerAppFunctionDesc.java +0 -20
- package/versions/java/RangerAppHashValue.java +0 -11
- package/versions/java/RangerAppInterfaceImpl.java +0 -6
- package/versions/java/RangerAppMethodVariants.java +0 -6
- package/versions/java/RangerAppParamDesc.java +0 -321
- package/versions/java/RangerAppTodo.java +0 -6
- package/versions/java/RangerAppValue.java +0 -10
- package/versions/java/RangerAppWriterContext.java +0 -800
- package/versions/java/RangerArgMatch.java +0 -317
- package/versions/java/RangerBackReference.java +0 -7
- package/versions/java/RangerCSharpClassWriter.java +0 -287
- package/versions/java/RangerCompilerMessage.java +0 -9
- package/versions/java/RangerCppClassWriter.java +0 -725
- package/versions/java/RangerFlowParser.java +0 -2142
- package/versions/java/RangerGenericClassWriter.java +0 -367
- package/versions/java/RangerGolangClassWriter.java +0 -1379
- package/versions/java/RangerJava7ClassWriter.java +0 -652
- package/versions/java/RangerJavaScriptClassWriter.java +0 -305
- package/versions/java/RangerKotlinClassWriter.java +0 -380
- package/versions/java/RangerLispParser.java +0 -845
- package/versions/java/RangerNodeValue.java +0 -9
- package/versions/java/RangerPHPClassWriter.java +0 -527
- package/versions/java/RangerParamEventHandler.java +0 -6
- package/versions/java/RangerParamEventList.java +0 -5
- package/versions/java/RangerParamEventMap.java +0 -27
- package/versions/java/RangerRangerClassWriter.java +0 -268
- package/versions/java/RangerRefForce.java +0 -7
- package/versions/java/RangerScalaClassWriter.java +0 -365
- package/versions/java/RangerSerializeClass.java +0 -148
- package/versions/java/RangerSwift3ClassWriter.java +0 -548
- package/versions/java/RangerTypeClass.java +0 -17
- package/versions/java/SourceCode.java +0 -65
- package/versions/php/compiler.php +0 -13830
- package/versions/swift3/compiler.swift +0 -12542
- /package/{lib/ACEEditor.clj → dist/lib/ACEEditor.rgr} +0 -0
- /package/{lib/SQL.clj → dist/lib/SQL.rgr} +0 -0
- /package/{lib/ServiceLib.clj → dist/lib/ServiceLib.rgr} +0 -0
- /package/{lib/Time.clj → dist/lib/Time.rgr} +0 -0
- /package/{lib/TypedArrays.clj → dist/lib/TypedArrays.rgr} +0 -0
- /package/{lib/WebLib.clj → dist/lib/WebLib.rgr} +0 -0
- /package/{lib/WebServerLib.clj → dist/lib/WebServerLib.rgr} +0 -0
|
@@ -1,4992 +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
|
-
Import "ng_RangerServiceBuilder.clj"
|
|
17
|
-
Import "ng_RangerAppOperatorDesc.clj"
|
|
18
|
-
|
|
19
|
-
Import "TFiles.clj"
|
|
20
|
-
Import "TTypes.clj"
|
|
21
|
-
|
|
22
|
-
Import "FlowEnterVarDef.clj"
|
|
23
|
-
|
|
24
|
-
; -------- developer documentation part comes over here --------------
|
|
25
|
-
|
|
26
|
-
plugin.md "developer.md" {
|
|
27
|
-
h1 Flow Parser Developer Docs
|
|
28
|
-
|
|
29
|
-
h2 'Overview of the parsing'
|
|
30
|
-
|
|
31
|
-
p 'The parsing process has broadly following stages'
|
|
32
|
-
|
|
33
|
-
ul {
|
|
34
|
-
li 'Parse the root document using RangerLispParser'
|
|
35
|
-
li 'Create root context'
|
|
36
|
-
li 'Parse basic operators and initialize active `operators` from Lang.clj in the context'
|
|
37
|
-
li 'Merge imported documents into the main AST'
|
|
38
|
-
li 'Call plugins generate_ast method for additional declarations'
|
|
39
|
-
li 'Collect operators, classes, methods, extensions, unions, system classes from files'
|
|
40
|
-
li 'Do static analysis of the code using ' (b 'RangerFlowParser')
|
|
41
|
-
li 'Call preprocess plugins'
|
|
42
|
-
li 'Compile the source code into virtual filesystem'
|
|
43
|
-
li 'Call postprocess plugins'
|
|
44
|
-
li 'If no errors, save the results into real filesystem'
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
operator type:void all {
|
|
49
|
-
fn r.func:RangerAppFunctionDesc ( node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter ) {
|
|
50
|
-
def parser (new RangerFlowParser)
|
|
51
|
-
return (parser.CreateFunctionObject(node ctx wr))
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
class ClassJoinPoint {
|
|
56
|
-
def class_def:RangerAppClassDesc
|
|
57
|
-
def node@(weak):CodeNode
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
class WalkLater {
|
|
61
|
-
def arg@(weak):CodeNode
|
|
62
|
-
def callArg@(weak):CodeNode
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
class RangerFlowParser {
|
|
66
|
-
|
|
67
|
-
def hasRootPath false
|
|
68
|
-
def rootPath:string ""
|
|
69
|
-
def _debug false
|
|
70
|
-
; def is_chaining false
|
|
71
|
-
; def chainRoot:CodeNode
|
|
72
|
-
|
|
73
|
-
def stdCommands@(optional):CodeNode
|
|
74
|
-
def lastProcessedNode@(weak):CodeNode
|
|
75
|
-
def collectWalkAtEnd:[CodeNode]
|
|
76
|
-
def walkAlso@(weak):[CodeNode]
|
|
77
|
-
def serializedClasses@(weak):[RangerAppClassDesc]
|
|
78
|
-
def immutableClasses@(weak):[RangerAppClassDesc]
|
|
79
|
-
def classesWithTraits:[ClassJoinPoint]
|
|
80
|
-
def collectedIntefaces:[RangerAppClassDesc]
|
|
81
|
-
def definedInterfaces:[string:boolean]
|
|
82
|
-
|
|
83
|
-
def signatureCnt 0
|
|
84
|
-
def argSignatureCnt 0
|
|
85
|
-
def mainCnt 0
|
|
86
|
-
def isDefinedSignature:[string:int]
|
|
87
|
-
def isDefinedArgSignature:[string:int]
|
|
88
|
-
|
|
89
|
-
def extendedClasses:[string:string]
|
|
90
|
-
|
|
91
|
-
def allNewRNodes:[CodeNode]
|
|
92
|
-
|
|
93
|
-
fn WalkNodeChildren:void (node@(lives):CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
94
|
-
if (node.hasStringProperty("todo")) {
|
|
95
|
-
ctx.addTodo(node (node.getStringProperty("todo")))
|
|
96
|
-
}
|
|
97
|
-
if node.expression {
|
|
98
|
-
def is_chaining false
|
|
99
|
-
def last_is_assign false
|
|
100
|
-
def chainRoot@(weak):CodeNode
|
|
101
|
-
def innerNode@(weak):CodeNode
|
|
102
|
-
def assignNode@(weak):CodeNode
|
|
103
|
-
def newNode:CodeNode
|
|
104
|
-
|
|
105
|
-
def ch_len (size node.children)
|
|
106
|
-
for node.children item:CodeNode i {
|
|
107
|
-
def did_find false
|
|
108
|
-
if(has item.children) {
|
|
109
|
-
def fc (item.getFirst())
|
|
110
|
-
def name (fc.vref)
|
|
111
|
-
|
|
112
|
-
if( ( (strlen name) > 0 ) && ( ( charAt name 0) == (charcode ".")) ) {
|
|
113
|
-
did_find = true
|
|
114
|
-
if(i>0) {
|
|
115
|
-
def last_line (at node.children (i - 1))
|
|
116
|
-
if (is_chaining == false ) {
|
|
117
|
-
last_line.createChainTarget()
|
|
118
|
-
is_chaining = true
|
|
119
|
-
if(!null? last_line.chainTarget) {
|
|
120
|
-
chainRoot = last_line.chainTarget
|
|
121
|
-
innerNode = last_line.chainTarget
|
|
122
|
-
assignNode = last_line
|
|
123
|
-
last_is_assign = true
|
|
124
|
-
} {
|
|
125
|
-
chainRoot = last_line
|
|
126
|
-
innerNode = last_line
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
def method_name (substring name 1 (strlen name))
|
|
130
|
-
def mArgs (item.getSecond())
|
|
131
|
-
if(last_is_assign) {
|
|
132
|
-
push assignNode.children (fc.copy())
|
|
133
|
-
push assignNode.children (mArgs.copy())
|
|
134
|
-
} {
|
|
135
|
-
newNode = (node.newExpressionNode())
|
|
136
|
-
newNode.add( (node.newVRefNode("call") ) )
|
|
137
|
-
newNode.add( (innerNode.copy() ) )
|
|
138
|
-
newNode.add( (node.newVRefNode(method_name)) )
|
|
139
|
-
newNode.add( (mArgs.copy()) )
|
|
140
|
-
innerNode = newNode
|
|
141
|
-
}
|
|
142
|
-
item.is_part_of_chain = true
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if(did_find == false || (i == (ch_len - 1) ) ) {
|
|
147
|
-
if( is_chaining && (last_is_assign == false)) {
|
|
148
|
-
chainRoot.getChildrenFrom( (unwrap innerNode ) )
|
|
149
|
-
chainRoot.tag = "chainroot"
|
|
150
|
-
}
|
|
151
|
-
is_chaining = false
|
|
152
|
-
last_is_assign = false
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
for node.children item@(lives):CodeNode i {
|
|
156
|
-
|
|
157
|
-
if( (ctx.expressionLevel()) == 0 ) {
|
|
158
|
-
ctx.lastBlockOp = item
|
|
159
|
-
}
|
|
160
|
-
item.parent = node
|
|
161
|
-
this.WalkNode(item ctx wr)
|
|
162
|
-
node.copyEvalResFrom(item)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
fn WalkNode:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
168
|
-
|
|
169
|
-
def line_index:int (node.getLine())
|
|
170
|
-
if node.flow_done {
|
|
171
|
-
return true
|
|
172
|
-
}
|
|
173
|
-
if( ctx.isPluginOp(node)) {
|
|
174
|
-
return true
|
|
175
|
-
}
|
|
176
|
-
node.flow_ctx = ctx
|
|
177
|
-
node.flow_done = true
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
this.lastProcessedNode = node
|
|
181
|
-
if (node.hasStringProperty("todo")) {
|
|
182
|
-
ctx.addTodo(node (node.getStringProperty("todo")))
|
|
183
|
-
}
|
|
184
|
-
; currently skip...
|
|
185
|
-
if(node.is_part_of_chain) {
|
|
186
|
-
return true
|
|
187
|
-
}
|
|
188
|
-
if (node.isPrimitive()) {
|
|
189
|
-
if ((ctx.expressionLevel()) == 0) {
|
|
190
|
-
if! (ctx.hasCompilerFlag('voidexpr')) {
|
|
191
|
-
ctx.addError( node "Primitive element at top level!")
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
this.WriteScalarValue(node ctx wr)
|
|
195
|
-
return true
|
|
196
|
-
}
|
|
197
|
-
if (node.value_type == RangerNodeType.VRef || node.value_type == RangerNodeType.Hash || node.value_type == RangerNodeType.Array) {
|
|
198
|
-
this.WriteVRef(node ctx wr)
|
|
199
|
-
return true
|
|
200
|
-
}
|
|
201
|
-
if (node.value_type == RangerNodeType.Comment) {
|
|
202
|
-
return true
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
; if node is defined from register, get the value from the register...
|
|
206
|
-
if( (has node.register_name)) {
|
|
207
|
-
if( ctx.isVarDefined( node.register_name )) {
|
|
208
|
-
def regInfo (ctx.getVariableDef(node.register_name))
|
|
209
|
-
if(!null? regInfo.nameNode ) {
|
|
210
|
-
node.copyEvalResFrom( (unwrap regInfo.nameNode) )
|
|
211
|
-
return true
|
|
212
|
-
} {
|
|
213
|
-
; ctx.addError( node ('compiler error: could not find temporary register ' + node.register_name) )
|
|
214
|
-
}
|
|
215
|
-
} {
|
|
216
|
-
; ctx.addError( node ('compiler error: could not find temporary register ' + node.register_name) )
|
|
217
|
-
}
|
|
218
|
-
return true
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
; if(node.expression && ((size node.children) > 0)) {
|
|
222
|
-
if(node.value_type == RangerNodeType.XMLNode) {
|
|
223
|
-
|
|
224
|
-
def fc node
|
|
225
|
-
|
|
226
|
-
if(fc.value_type == RangerNodeType.XMLNode) {
|
|
227
|
-
|
|
228
|
-
; operator function...
|
|
229
|
-
def opBody (r.block)
|
|
230
|
-
def opTpl (r.expression (r.vref 'defn') (r.vref 'tmp_create') (r.expression) )
|
|
231
|
-
|
|
232
|
-
def currCnt 1
|
|
233
|
-
|
|
234
|
-
def walk_xml (fn:void (xmlNode:CodeNode regName:string) {
|
|
235
|
-
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
walk_xml = (fn:void (xmlNode:CodeNode regName:string) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
def rootClassDef (ctx.findClass(xmlNode.vref))
|
|
242
|
-
|
|
243
|
-
if rootClassDef.is_system {
|
|
244
|
-
push opBody.children (r.expression (r.vref 'def') (r.vref regName) (r.expression (r.vref 'create') (r.vref xmlNode.vref)))
|
|
245
|
-
xmlNode.attrs.forEach({
|
|
246
|
-
if( (size item.children) > 0) {
|
|
247
|
-
def fc (at item.children 0)
|
|
248
|
-
; print " - attr expression for " + item.vref + " " + (fc.getCode())
|
|
249
|
-
push opBody.children (r.expression (r.vref 'attr') (r.vref regName) (r.vref item.vref) (fc.copy()) )
|
|
250
|
-
return
|
|
251
|
-
}
|
|
252
|
-
if(has item.string_value) {
|
|
253
|
-
push opBody.children (r.expression (r.vref 'attr') (r.vref regName) (r.vref item.vref) (r.value item.string_value) )
|
|
254
|
-
}
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
; -- walk the children...
|
|
258
|
-
xmlNode.children.forEach({
|
|
259
|
-
if(item.value_type != RangerNodeType.XMLNode) {
|
|
260
|
-
if( item.expression ) {
|
|
261
|
-
; for example maps
|
|
262
|
-
def itemCopy (item.copy())
|
|
263
|
-
def theNode item
|
|
264
|
-
ctx.setTestCompile()
|
|
265
|
-
this.WalkNode( itemCopy ctx wr )
|
|
266
|
-
ctx.unsetTestCompile()
|
|
267
|
-
if(ctx.hasClass(itemCopy.eval_array_type)) {
|
|
268
|
-
def paramClassDef (ctx.findClass(itemCopy.eval_array_type))
|
|
269
|
-
def chNode item
|
|
270
|
-
def t (r.vref 'tmp')
|
|
271
|
-
t.setFlag('temp')
|
|
272
|
-
push opBody.children (r.expression (r.vref 'forEach' ) (theNode.copy())
|
|
273
|
-
(r.block
|
|
274
|
-
(r.expression (r.vref 'def') t (r.vref 'item') )
|
|
275
|
-
(r.expression (r.vref 'push') (r.vref regName) (r.vref 'tmp'))
|
|
276
|
-
)
|
|
277
|
-
)
|
|
278
|
-
} {
|
|
279
|
-
if(ctx.hasClass(itemCopy.eval_type_name)) {
|
|
280
|
-
push opBody.children (r.expression (r.vref 'push') (r.vref regName) (theNode.copy()))
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
} {
|
|
284
|
-
; print "--> not expression, vref --> " + (item.vref)
|
|
285
|
-
; if(ctx.hasClass(itemCopy.eval_type)) {
|
|
286
|
-
; push opBody.children (r.expression (r.vref 'push') (r.vref regName) (item.copy()))
|
|
287
|
-
; }
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
if(item.value_type == RangerNodeType.XMLNode) {
|
|
291
|
-
if(ctx.hasClass(item.vref)) {
|
|
292
|
-
def paramClassDef (ctx.findClass(item.vref))
|
|
293
|
-
def chNode item
|
|
294
|
-
currCnt = currCnt + 1
|
|
295
|
-
def regN ('r' + currCnt)
|
|
296
|
-
walk_xml ( chNode regN )
|
|
297
|
-
push opBody.children (r.expression (r.vref 'push') (r.vref regName) (r.vref regN) )
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
})
|
|
301
|
-
; ***** system class ends ****
|
|
302
|
-
} {
|
|
303
|
-
|
|
304
|
-
def match (new RangerArgMatch)
|
|
305
|
-
; fn areEqualATypes:boolean (type1:string type2:string ctx:RangerAppWriterContext) {
|
|
306
|
-
|
|
307
|
-
; areEqualATypes
|
|
308
|
-
|
|
309
|
-
push opBody.children (r.expression (r.vref 'def') (r.vref regName) (r.expression (r.vref 'new') (r.vref xmlNode.vref)))
|
|
310
|
-
; print "XML node " + xmlNode.vref
|
|
311
|
-
xmlNode.attrs.forEach({
|
|
312
|
-
; print "attr " + item.vref + " str val -> " + item.string_value
|
|
313
|
-
if( (size item.children) > 0) {
|
|
314
|
-
def fc (at item.children 0)
|
|
315
|
-
; print " - attr expression for " + item.vref + " " + (fc.getCode())
|
|
316
|
-
push opBody.children (r.expression (r.vref '=') (r.vref (regName + '.' + item.vref)) (fc.copy()) )
|
|
317
|
-
return
|
|
318
|
-
}
|
|
319
|
-
if(has item.string_value) {
|
|
320
|
-
push opBody.children (r.expression (r.vref '=') (r.vref (regName + '.' + item.vref)) (r.value item.string_value) )
|
|
321
|
-
}
|
|
322
|
-
if(item.parsed_type == RangerNodeType.Integer) {
|
|
323
|
-
push opBody.children (r.expression (r.vref '=') (r.vref (regName + '.' + item.vref)) (r.value item.int_value) )
|
|
324
|
-
}
|
|
325
|
-
})
|
|
326
|
-
; -- walk the children...
|
|
327
|
-
xmlNode.children.forEach({
|
|
328
|
-
if(item.value_type != RangerNodeType.XMLNode) {
|
|
329
|
-
|
|
330
|
-
if( item.expression ) {
|
|
331
|
-
; for example maps
|
|
332
|
-
def itemCopy (item.copy())
|
|
333
|
-
def theNode item
|
|
334
|
-
|
|
335
|
-
ctx.setTestCompile()
|
|
336
|
-
this.WalkNode( itemCopy ctx wr )
|
|
337
|
-
ctx.unsetTestCompile()
|
|
338
|
-
|
|
339
|
-
if(ctx.hasClass(itemCopy.eval_array_type)) {
|
|
340
|
-
def paramClassDef (ctx.findClass(itemCopy.eval_array_type))
|
|
341
|
-
def chNode item
|
|
342
|
-
rootClassDef.variables.forEach({
|
|
343
|
-
; --> comparing, are the same class ??
|
|
344
|
-
if( match.areEqualATypes(item.nameNode.array_type itemCopy.eval_array_type ctx)) { ; if(item.nameNode.array_type == itemCopy.eval_array_type) {
|
|
345
|
-
def t (r.vref 'tmp')
|
|
346
|
-
t.setFlag('temp')
|
|
347
|
-
push opBody.children (r.expression (r.vref 'forEach' ) (theNode.copy())
|
|
348
|
-
(r.block
|
|
349
|
-
(r.expression (r.vref 'def') t (r.vref 'item') )
|
|
350
|
-
(r.expression (r.vref 'push') (r.vref (regName +'.' +item.name)) (r.vref 'tmp'))
|
|
351
|
-
)
|
|
352
|
-
)
|
|
353
|
-
}
|
|
354
|
-
})
|
|
355
|
-
} {
|
|
356
|
-
print "could not find class" + itemCopy.eval_array_type
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if(item.value_type == RangerNodeType.XMLNode) {
|
|
361
|
-
if(ctx.hasClass(item.vref)) {
|
|
362
|
-
def paramClassDef (ctx.findClass(item.vref))
|
|
363
|
-
def chNode item
|
|
364
|
-
; find the variable which has this class as array...
|
|
365
|
-
rootClassDef.variables.forEach({
|
|
366
|
-
if( match.areEqualATypes(item.nameNode.array_type chNode.vref ctx)) {
|
|
367
|
-
; if(item.nameNode.array_type == itemCopy.eval_array_type) {
|
|
368
|
-
; if(item.nameNode.array_type == chNode.vref) {
|
|
369
|
-
; found the variable...
|
|
370
|
-
currCnt = currCnt + 1
|
|
371
|
-
def regN ('r' + currCnt)
|
|
372
|
-
walk_xml ( chNode regN )
|
|
373
|
-
if paramClassDef.is_immutable {
|
|
374
|
-
; if Immutable should first walk the children and only after that add..
|
|
375
|
-
; r1_5 = (r1_5).set_children(operatorsOfVector.push_3(r1_5.children, (r7_1)));
|
|
376
|
-
|
|
377
|
-
push opBody.children (r.expression (r.vref '=')
|
|
378
|
-
(r.vref (regName +'.' +item.name))
|
|
379
|
-
(r.expression (r.vref 'push')
|
|
380
|
-
(r.vref (regName +'.' +item.name)) (r.vref regN) ) )
|
|
381
|
-
|
|
382
|
-
} {
|
|
383
|
-
push opBody.children (r.expression (r.vref 'push') (r.vref (regName +'.' +item.name)) (r.vref regN) )
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
})
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
})
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
})
|
|
393
|
-
|
|
394
|
-
walk_xml( fc 'r1' )
|
|
395
|
-
|
|
396
|
-
push opBody.children (r.expression (r.vref 'ret') (r.vref 'r1'))
|
|
397
|
-
push opTpl.children opBody
|
|
398
|
-
|
|
399
|
-
node.value_type = RangerNodeType.NoType
|
|
400
|
-
node.getChildrenFrom( (r.expression (r.vref 'tmp_create')))
|
|
401
|
-
|
|
402
|
-
node.value_type = RangerNodeType.NoType
|
|
403
|
-
node.expression = true
|
|
404
|
-
|
|
405
|
-
this.TransformOpFn( ([] opTpl) node ctx wr)
|
|
406
|
-
return true
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if( (size node.children) > 0) {
|
|
413
|
-
def fc (node.getFirst())
|
|
414
|
-
if( (size fc.ns) > 1) {
|
|
415
|
-
if( (at fc.ns 0) == "plugin" ) {
|
|
416
|
-
if(node.is_plugin) {
|
|
417
|
-
return true
|
|
418
|
-
}
|
|
419
|
-
node.is_plugin = true
|
|
420
|
-
def pName (at fc.ns 1)
|
|
421
|
-
ctx.addPluginNode( pName node )
|
|
422
|
-
return true
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
if( (size node.children) == 1 ) {
|
|
428
|
-
def fc (first node.children)
|
|
429
|
-
if( ctx.isVarDefined( fc.vref )) {
|
|
430
|
-
fc.parent = node
|
|
431
|
-
if(!null? fc.evalCtx) {
|
|
432
|
-
this.WalkNode(fc (unwrap fc.evalCtx) wr)
|
|
433
|
-
} {
|
|
434
|
-
this.WalkNode(fc ctx wr)
|
|
435
|
-
}
|
|
436
|
-
node.copyEvalResFrom(fc)
|
|
437
|
-
return true
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
def skip_if ([] "Extends" "operator" "extends" "operators" "systemclass" "systemunion" "union" "flag" "trait" "enum" "Import")
|
|
442
|
-
if( has node.children ) {
|
|
443
|
-
|
|
444
|
-
def fc (first node.children)
|
|
445
|
-
if( (indexOf skip_if fc.vref ) >= 0) {
|
|
446
|
-
return true
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
; _1 _2 _3 _4 _5 _6
|
|
450
|
-
|
|
451
|
-
; createNewOpFnName
|
|
452
|
-
; ("" + (_ * 10))
|
|
453
|
-
; (=> "" + (_ * 10))
|
|
454
|
-
; defn tmp_anon1 (v1) ("" + (v1 * 10))
|
|
455
|
-
; (=> "" + (_ * 10)) --> tmp_anon1
|
|
456
|
-
; map items (# print '' + _)
|
|
457
|
-
|
|
458
|
-
; (# _ > 10) item
|
|
459
|
-
|
|
460
|
-
if(fc.vref == '#') {
|
|
461
|
-
|
|
462
|
-
; print "--> arrow op " + (node.getCode()) + " err cnt " + (ctx.errCnt())
|
|
463
|
-
|
|
464
|
-
def fnCtx (ctx.findFunctionCtx())
|
|
465
|
-
this.DefineArrowOpFn( node fnCtx wr)
|
|
466
|
-
|
|
467
|
-
node.value_type = RangerNodeType.VRef
|
|
468
|
-
node.expression = false
|
|
469
|
-
node.is_block_node = false
|
|
470
|
-
; node.vref = ''
|
|
471
|
-
clear node.ns
|
|
472
|
-
push node.ns node.vref
|
|
473
|
-
|
|
474
|
-
clear node.children
|
|
475
|
-
nullify node.paramDesc
|
|
476
|
-
node.hasParamDesc = false
|
|
477
|
-
return true
|
|
478
|
-
} {
|
|
479
|
-
if(fc.expression && (has fc.children)) {
|
|
480
|
-
def exprFc (first fc.children)
|
|
481
|
-
if(exprFc.vref == '#') {
|
|
482
|
-
; def opFnName ( ctx.createNewOpFnName() )
|
|
483
|
-
this.DefineArrowOpFn( fc ctx wr)
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
def b_found true
|
|
490
|
-
def opFn (ctx.getOpFns(fc.vref))
|
|
491
|
-
if(has opFn) {
|
|
492
|
-
this.TransformOpFn( opFn node ctx wr)
|
|
493
|
-
return true
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
switch fc.vref {
|
|
497
|
-
case 'page' {
|
|
498
|
-
def sc (node.getSecond())
|
|
499
|
-
ctx.addPage( sc.vref node )
|
|
500
|
-
}
|
|
501
|
-
case 'def' {
|
|
502
|
-
EnterVarDef this node ctx wr
|
|
503
|
-
}
|
|
504
|
-
case 'var' {
|
|
505
|
-
EnterVarDef this node ctx wr
|
|
506
|
-
}
|
|
507
|
-
case 'let' {
|
|
508
|
-
EnterVarDef this node ctx wr
|
|
509
|
-
}
|
|
510
|
-
case 'property' {
|
|
511
|
-
this.GetProperty(node ctx wr)
|
|
512
|
-
}
|
|
513
|
-
case 'CreateClass' {
|
|
514
|
-
this.EnterClass(node ctx wr)
|
|
515
|
-
}
|
|
516
|
-
case 'class' {
|
|
517
|
-
this.EnterClass(node ctx wr)
|
|
518
|
-
}
|
|
519
|
-
case 'defn' {
|
|
520
|
-
this.DefineOpFn(node ctx wr)
|
|
521
|
-
}
|
|
522
|
-
case 'fn' {
|
|
523
|
-
if(ctx.isInMethod()) {
|
|
524
|
-
this.EnterLambdaMethod( node ctx wr )
|
|
525
|
-
} {
|
|
526
|
-
this.EnterMethod(node ctx wr)
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
case 'sfn' {
|
|
530
|
-
this.EnterStaticMethod(node ctx wr)
|
|
531
|
-
}
|
|
532
|
-
case 'static' {
|
|
533
|
-
this.EnterStaticMethod(node ctx wr)
|
|
534
|
-
}
|
|
535
|
-
case '=' {
|
|
536
|
-
this.cmdAssign(node ctx wr)
|
|
537
|
-
}
|
|
538
|
-
case 'constructor' {
|
|
539
|
-
this.Constructor(node ctx wr)
|
|
540
|
-
}
|
|
541
|
-
case 'Constructor' {
|
|
542
|
-
this.Constructor(node ctx wr)
|
|
543
|
-
}
|
|
544
|
-
case 'new' {
|
|
545
|
-
this.cmdNew(node ctx wr)
|
|
546
|
-
}
|
|
547
|
-
case '[]' {
|
|
548
|
-
this.cmdArray( node ctx wr )
|
|
549
|
-
}
|
|
550
|
-
case 'call' {
|
|
551
|
-
this.cmdCall( node ctx wr )
|
|
552
|
-
}
|
|
553
|
-
case 'fun' {
|
|
554
|
-
this.EnterLambdaMethod( node ctx wr )
|
|
555
|
-
}
|
|
556
|
-
case 'extension' {
|
|
557
|
-
this.EnterClass(node ctx wr)
|
|
558
|
-
}
|
|
559
|
-
case 'service' {
|
|
560
|
-
try {
|
|
561
|
-
def sc (node.getSecond())
|
|
562
|
-
def params (node.getThird())
|
|
563
|
-
ctx.addService( sc.vref node )
|
|
564
|
-
def paramClass (params.getFirst())
|
|
565
|
-
def rvClassDef (ctx.findClass(sc.type_name))
|
|
566
|
-
def paramClassDef (ctx.findClass(paramClass.type_name))
|
|
567
|
-
node.appGUID = sc.vref+"_"+(sha256 ( (rvClassDef.node.getCode()) + (paramClassDef.node.getCode()) ) )
|
|
568
|
-
|
|
569
|
-
} {
|
|
570
|
-
ctx.addError(node "invalid service definition")
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
default {
|
|
574
|
-
b_found = false
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
if b_found {
|
|
578
|
-
return true
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
if (this.matchNode(node ctx wr)) {
|
|
583
|
-
return true
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
if ((size node.children) > 0) {
|
|
587
|
-
|
|
588
|
-
def fc:CodeNode (at node.children 0)
|
|
589
|
-
|
|
590
|
-
; ( (someObject) '.someProperty' )
|
|
591
|
-
if( fc.expression && ( ( size node.children ) == 2) ) {
|
|
592
|
-
def sec (node.getSecond())
|
|
593
|
-
if( (has sec.vref) && (first sec.vref) == '.' ) {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
; TODO: implement also pure property access...
|
|
597
|
-
; print "Possible property access " + (node.getCode()) + " : " + (substring sec.vref 1)
|
|
598
|
-
; print "--> Walking "
|
|
599
|
-
this.WalkNode( fc ctx wr )
|
|
600
|
-
; print "<-- returned from walk of Possible property access " + (node.getCode()) + " : " + (substring sec.vref 1)
|
|
601
|
-
; print "<-- type == " + fc.eval_type_name
|
|
602
|
-
|
|
603
|
-
if( (has fc.eval_type_name) && (ctx.isDefinedClass(fc.eval_type_name)) ) {
|
|
604
|
-
|
|
605
|
-
def parts (strsplit (substring sec.vref 1) ".")
|
|
606
|
-
def method_name (first parts)
|
|
607
|
-
def classDesc (ctx.findClass(fc.eval_type_name))
|
|
608
|
-
|
|
609
|
-
def objExpr (fc.copy())
|
|
610
|
-
def calledItem (r.expression
|
|
611
|
-
(r.vref 'property')
|
|
612
|
-
(fc.copy())
|
|
613
|
-
(r.vref method_name)
|
|
614
|
-
)
|
|
615
|
-
parts.forEach({
|
|
616
|
-
if(index > 0) {
|
|
617
|
-
try {
|
|
618
|
-
def p (classDesc.findVariable(method_name))
|
|
619
|
-
classDesc = (ctx.findClass(p.nameNode.type_name))
|
|
620
|
-
calledItem = (r.expression
|
|
621
|
-
(r.vref 'property')
|
|
622
|
-
(calledItem.copy())
|
|
623
|
-
(r.vref item)
|
|
624
|
-
)
|
|
625
|
-
method_name = item
|
|
626
|
-
} {
|
|
627
|
-
ctx.addError(sec ('invalid property'))
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
})
|
|
631
|
-
|
|
632
|
-
def m (classDesc.findVariable(method_name))
|
|
633
|
-
if (!null? m) {
|
|
634
|
-
node.getChildrenFrom( calledItem )
|
|
635
|
-
node.flow_done = false
|
|
636
|
-
this.WalkNode( node ctx wr)
|
|
637
|
-
return true
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
def m (classDesc.findMethod(method_name))
|
|
641
|
-
if (!null? m) {
|
|
642
|
-
; ( (<something>) .someMethod )
|
|
643
|
-
node.getChildrenFrom( calledItem )
|
|
644
|
-
node.flow_done = false
|
|
645
|
-
this.transformMethodToLambda( node (unwrap m) ctx wr )
|
|
646
|
-
return true
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
; ( (someObject) '.methodName' (<arguments>) )
|
|
653
|
-
if( fc.expression && ( ( size node.children ) == 3) ) {
|
|
654
|
-
|
|
655
|
-
; print ""
|
|
656
|
-
; print ""
|
|
657
|
-
|
|
658
|
-
def sec (node.getSecond())
|
|
659
|
-
def third (node.getThird())
|
|
660
|
-
if( (has sec.vref) && (first sec.vref) == '.' ) {
|
|
661
|
-
|
|
662
|
-
this.WalkNode( fc ctx wr )
|
|
663
|
-
def parts (strsplit (substring sec.vref 1) ".")
|
|
664
|
-
def method_name (last parts)
|
|
665
|
-
def classDesc (ctx.findClass(fc.eval_type_name))
|
|
666
|
-
def objExpr (fc.copy())
|
|
667
|
-
def calledItem (fc.copy())
|
|
668
|
-
|
|
669
|
-
parts.forEach({
|
|
670
|
-
if(index < ((size parts) - 1) ) {
|
|
671
|
-
try {
|
|
672
|
-
calledItem = (r.expression
|
|
673
|
-
(r.vref 'property')
|
|
674
|
-
(calledItem.copy())
|
|
675
|
-
(r.vref item)
|
|
676
|
-
)
|
|
677
|
-
def p (classDesc.findVariable(item))
|
|
678
|
-
classDesc = (ctx.findClass(p.nameNode.type_name))
|
|
679
|
-
} {
|
|
680
|
-
ctx.addError(sec ('invalid property ' + item ))
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
})
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
def calledItem (r.expression
|
|
687
|
-
(r.vref 'call')
|
|
688
|
-
calledItem
|
|
689
|
-
(r.vref method_name)
|
|
690
|
-
(third.copy())
|
|
691
|
-
)
|
|
692
|
-
node.getChildrenFrom( calledItem )
|
|
693
|
-
node.flow_done = false
|
|
694
|
-
this.WalkNode( node ctx wr)
|
|
695
|
-
return true
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
if (fc.value_type == RangerNodeType.VRef) {
|
|
700
|
-
def was_called:boolean true
|
|
701
|
-
switch fc.vref {
|
|
702
|
-
case "Enum" {
|
|
703
|
-
; this.cmdEnum(node ctx wr)
|
|
704
|
-
was_called = true
|
|
705
|
-
}
|
|
706
|
-
default {
|
|
707
|
-
was_called = false
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
if was_called {
|
|
711
|
-
return true
|
|
712
|
-
}
|
|
713
|
-
if ((size node.children) > 1) {
|
|
714
|
-
if (this.cmdLocalCall(node ctx wr)) {
|
|
715
|
-
return true
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
if node.expression {
|
|
721
|
-
for node.children item@(lives):CodeNode i {
|
|
722
|
-
|
|
723
|
-
if( (ctx.expressionLevel()) == 0 ) {
|
|
724
|
-
ctx.lastBlockOp = item
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
item.parent = node
|
|
728
|
-
if(!null? item.evalCtx) {
|
|
729
|
-
this.WalkNode(item (unwrap item.evalCtx) wr)
|
|
730
|
-
} {
|
|
731
|
-
this.WalkNode(item ctx wr)
|
|
732
|
-
}
|
|
733
|
-
node.copyEvalResFrom(item)
|
|
734
|
-
|
|
735
|
-
if( (i == 0) && ( (size node.children ) == 2) ) {
|
|
736
|
-
|
|
737
|
-
if(item.eval_type == RangerNodeType.Method && (!null? item.paramDesc) ) {
|
|
738
|
-
|
|
739
|
-
def mDesc (unwrap item.paramDesc)
|
|
740
|
-
;def mDesc (cast pDesc to:RangerAppFunctionDesc)
|
|
741
|
-
|
|
742
|
-
node.eval_type = mDesc.nameNode.value_type
|
|
743
|
-
node.eval_type_name = mDesc.nameNode.type_name
|
|
744
|
-
node.eval_array_type = mDesc.nameNode.array_type
|
|
745
|
-
node.eval_key_type = mDesc.nameNode.eval_key_type
|
|
746
|
-
|
|
747
|
-
node.is_direct_method_call = true
|
|
748
|
-
return true
|
|
749
|
-
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
; the first node could be lambda expression, which transforms to lambda call ...
|
|
754
|
-
if( (!null? item.expression_value) || item.value_type == RangerNodeType.ExpressionType || item.eval_type == RangerNodeType.ExpressionType ) {
|
|
755
|
-
|
|
756
|
-
; localLambdaCall
|
|
757
|
-
if( (i == 0) && ( (size node.children ) == 2) ) {
|
|
758
|
-
|
|
759
|
-
node.has_lambda_call = true
|
|
760
|
-
def second ( at node.children 1)
|
|
761
|
-
ctx.setInExpr()
|
|
762
|
-
this.WalkNode( second ctx wr)
|
|
763
|
-
ctx.unsetInExpr()
|
|
764
|
-
|
|
765
|
-
; set the lambda expression return value as the value of the current node...
|
|
766
|
-
if(!null? item.expression_value) {
|
|
767
|
-
def lambdaNode (unwrap item.expression_value)
|
|
768
|
-
|
|
769
|
-
def nn:CodeNode (at lambdaNode.children 0)
|
|
770
|
-
node.eval_type = (nn.typeNameAsType(ctx))
|
|
771
|
-
node.eval_type_name = nn.type_name
|
|
772
|
-
node.eval_array_type = nn.array_type
|
|
773
|
-
node.eval_key_type = nn.key_type
|
|
774
|
-
if(node.eval_type == RangerNodeType.ExpressionType) {
|
|
775
|
-
node.expression_value = (nn.expression_value.copy())
|
|
776
|
-
}
|
|
777
|
-
if(nn.hasFlag("optional")) {
|
|
778
|
-
node.setFlag("optional")
|
|
779
|
-
}
|
|
780
|
-
this.testLambdaCallArgs( lambdaNode second ctx wr )
|
|
781
|
-
}
|
|
782
|
-
break
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
; ctx.addError(node "Could not understand this part")
|
|
787
|
-
return true
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
ctx.addError(node "Could not understand this part")
|
|
791
|
-
|
|
792
|
-
return true
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
fn getVoidNameSignature:string () {
|
|
798
|
-
def s "void"
|
|
799
|
-
if(has isDefinedSignature s) {
|
|
800
|
-
def cc (unwrap (get isDefinedSignature s))
|
|
801
|
-
return ("void_" + cc)
|
|
802
|
-
}
|
|
803
|
-
signatureCnt = signatureCnt + 1
|
|
804
|
-
set isDefinedSignature s signatureCnt
|
|
805
|
-
return ( "void_" + signatureCnt )
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
fn getNameSignature:string (node:CodeNode) {
|
|
809
|
-
def s ( (node.type_name) + (node.buildTypeSignature()) )
|
|
810
|
-
if(has isDefinedSignature s) {
|
|
811
|
-
def cc (unwrap (get isDefinedSignature s))
|
|
812
|
-
if(cc == 1) {
|
|
813
|
-
return node.type_name
|
|
814
|
-
}
|
|
815
|
-
return ("_" + cc)
|
|
816
|
-
}
|
|
817
|
-
signatureCnt = signatureCnt + 1
|
|
818
|
-
set isDefinedSignature s signatureCnt
|
|
819
|
-
if(signatureCnt == 1) {
|
|
820
|
-
return node.type_name
|
|
821
|
-
}
|
|
822
|
-
return ( node.type_name + "_" + signatureCnt )
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
fn getArgsSignature:string (node:CodeNode) {
|
|
826
|
-
def exp_s ""
|
|
827
|
-
for node.children arg:CodeNode i {
|
|
828
|
-
exp_s = exp_s + (arg.buildTypeSignature())
|
|
829
|
-
exp_s = exp_s + ","
|
|
830
|
-
}
|
|
831
|
-
if(has isDefinedArgSignature exp_s) {
|
|
832
|
-
def cc (unwrap (get isDefinedArgSignature exp_s))
|
|
833
|
-
if(cc == 1) {
|
|
834
|
-
return ""
|
|
835
|
-
}
|
|
836
|
-
return ("_" + cc)
|
|
837
|
-
}
|
|
838
|
-
signatureCnt = signatureCnt + 1
|
|
839
|
-
set isDefinedArgSignature exp_s signatureCnt
|
|
840
|
-
if(signatureCnt == 1) {
|
|
841
|
-
return ""
|
|
842
|
-
}
|
|
843
|
-
return ( "_" + signatureCnt )
|
|
844
|
-
}
|
|
845
|
-
fn getThisName:string () {
|
|
846
|
-
return "this"
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
; (property obj someProperty)
|
|
850
|
-
; (property obj x)
|
|
851
|
-
fn GetProperty:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
852
|
-
if( (size node.children ) != 3) {
|
|
853
|
-
ctx.addError(node 'Invalid property descriptor')
|
|
854
|
-
return
|
|
855
|
-
}
|
|
856
|
-
def obj (node.getSecond())
|
|
857
|
-
def prop (node.getThird())
|
|
858
|
-
this.WalkNode( obj ctx wr )
|
|
859
|
-
|
|
860
|
-
if( ctx.isDefinedClass(obj.eval_type_name) ) {
|
|
861
|
-
try {
|
|
862
|
-
def currC ( ctx.findClass(obj.eval_type_name) )
|
|
863
|
-
def varDef (currC.findVariable(prop.vref))
|
|
864
|
-
if(!null? varDef) {
|
|
865
|
-
|
|
866
|
-
prop.flow_done = true
|
|
867
|
-
prop.eval_type = RangerNodeType.VRef
|
|
868
|
-
|
|
869
|
-
node.hasParamDesc = true
|
|
870
|
-
node.ownParamDesc = varDef
|
|
871
|
-
node.paramDesc = varDef
|
|
872
|
-
varDef.ref_cnt = (1 + varDef.ref_cnt)
|
|
873
|
-
def vNameNode:CodeNode varDef.nameNode
|
|
874
|
-
if (!null? vNameNode) {
|
|
875
|
-
if (vNameNode.hasFlag("optional")) {
|
|
876
|
-
node.setFlag("optional")
|
|
877
|
-
}
|
|
878
|
-
node.eval_type = (vNameNode.typeNameAsType(ctx))
|
|
879
|
-
node.eval_type_name = vNameNode.type_name
|
|
880
|
-
if (vNameNode.value_type == RangerNodeType.Array) {
|
|
881
|
-
node.eval_type = RangerNodeType.Array
|
|
882
|
-
node.eval_array_type = vNameNode.array_type
|
|
883
|
-
}
|
|
884
|
-
if (vNameNode.value_type == RangerNodeType.Hash) {
|
|
885
|
-
node.eval_type = RangerNodeType.Hash
|
|
886
|
-
node.eval_key_type = vNameNode.key_type
|
|
887
|
-
node.eval_array_type = vNameNode.array_type
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
return
|
|
891
|
-
}
|
|
892
|
-
def mDef (currC.findMethod(prop.vref))
|
|
893
|
-
if(!null? mDef) {
|
|
894
|
-
; node.flow_done = true
|
|
895
|
-
node.eval_type = RangerNodeType.Method
|
|
896
|
-
node.hasParamDesc = true
|
|
897
|
-
node.ownParamDesc = mDef
|
|
898
|
-
node.paramDesc = mDef
|
|
899
|
-
mDef.ref_cnt = (1 + mDef.ref_cnt)
|
|
900
|
-
return
|
|
901
|
-
}
|
|
902
|
-
ctx.addError(node ('Did not find property from class ' + currC.name))
|
|
903
|
-
} {
|
|
904
|
-
ctx.addError(node 'Not valid property access')
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
} {
|
|
908
|
-
ctx.addError(obj 'Can not access property of a non-class value')
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
fn WriteVRef:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
914
|
-
if (node.vref == "_") {
|
|
915
|
-
return
|
|
916
|
-
}
|
|
917
|
-
if (node.vref == "#") {
|
|
918
|
-
return
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
def rootObjName:string (at node.ns 0)
|
|
922
|
-
if (ctx.isInStatic()) {
|
|
923
|
-
if(rootObjName == "this") {
|
|
924
|
-
ctx.addError(node "This can not be used in static context")
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
if (ctx.isEnumDefined(rootObjName)) {
|
|
928
|
-
def enumName:string (at node.ns 1)
|
|
929
|
-
def ee@(optional):RangerAppEnum (ctx.getEnum(rootObjName))
|
|
930
|
-
def e:RangerAppEnum (unwrap ee)
|
|
931
|
-
if (has e.values enumName) {
|
|
932
|
-
node.eval_type = RangerNodeType.Enum
|
|
933
|
-
node.eval_type_name = rootObjName
|
|
934
|
-
node.int_value = (unwrap (get e.values enumName))
|
|
935
|
-
} {
|
|
936
|
-
ctx.addError(node ('Undefined Enum ' + rootObjName + '.' + enumName))
|
|
937
|
-
node.eval_type = RangerNodeType.InvalidType
|
|
938
|
-
}
|
|
939
|
-
return
|
|
940
|
-
}
|
|
941
|
-
if (node.vref == (this.getThisName())) {
|
|
942
|
-
def cd@(optional):RangerAppClassDesc (ctx.getCurrentClass())
|
|
943
|
-
def thisClassDesc:RangerAppClassDesc cd
|
|
944
|
-
node.eval_type = RangerNodeType.Object
|
|
945
|
-
node.eval_type_name = thisClassDesc.name
|
|
946
|
-
node.ref_type = RangerNodeRefType.StrongImmutable
|
|
947
|
-
; def ts:RangerTypeClass (thisClassDesc.nameNode.createTypeSignature(ctx))
|
|
948
|
-
;node.typeClass = ts
|
|
949
|
-
return
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
if( ctx.isCapturing()) {
|
|
953
|
-
if( (ctx.isVarDefined(rootObjName)) ) {
|
|
954
|
-
if ( (ctx.isLocalToCapture(rootObjName)) == false ) {
|
|
955
|
-
; is_captured
|
|
956
|
-
def captDef@(lives):RangerAppParamDesc (ctx.getVariableDef(rootObjName))
|
|
957
|
-
def cd@(optional):RangerAppClassDesc (ctx.getCurrentClass())
|
|
958
|
-
; capturedLocals
|
|
959
|
-
push cd.capturedLocals captDef
|
|
960
|
-
|
|
961
|
-
captDef.is_captured = true
|
|
962
|
-
ctx.addCapturedVariable( rootObjName)
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
if ( rootObjName == "this" || (ctx.isVarDefined(rootObjName)) ) {
|
|
967
|
-
|
|
968
|
-
def vDef2:RangerAppParamDesc (ctx.getVariableDef(rootObjName))
|
|
969
|
-
def activeFn:RangerAppFunctionDesc (ctx.getCurrentMethod())
|
|
970
|
-
def vDef@(optional):RangerAppParamDesc (this.findParamDesc(node ctx wr))
|
|
971
|
-
|
|
972
|
-
if(!null? vDef) {
|
|
973
|
-
node.hasParamDesc = true
|
|
974
|
-
node.ownParamDesc = vDef
|
|
975
|
-
node.paramDesc = vDef
|
|
976
|
-
vDef.ref_cnt = (1 + vDef.ref_cnt)
|
|
977
|
-
def vNameNode:CodeNode vDef.nameNode
|
|
978
|
-
|
|
979
|
-
if( ctx.isDefinedClass( node.type_name)) {
|
|
980
|
-
def m (ctx.getCurrentMethod())
|
|
981
|
-
m.addClassUsage( (ctx.findClass(node.type_name)) ctx)
|
|
982
|
-
}
|
|
983
|
-
if( ctx.isDefinedClass( node.eval_type_name)) {
|
|
984
|
-
def m (ctx.getCurrentMethod())
|
|
985
|
-
m.addClassUsage( (ctx.findClass(node.eval_type_name)) ctx)
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
if (!null? vNameNode) {
|
|
989
|
-
if (vNameNode.hasFlag("optional")) {
|
|
990
|
-
node.setFlag("optional")
|
|
991
|
-
}
|
|
992
|
-
;def ts:RangerTypeClass (vNameNode.createTypeSignature(ctx))
|
|
993
|
-
;node.typeClass = ts
|
|
994
|
-
node.eval_type = (vNameNode.typeNameAsType(ctx))
|
|
995
|
-
node.eval_type_name = vNameNode.type_name
|
|
996
|
-
if (vNameNode.value_type == RangerNodeType.Array) {
|
|
997
|
-
node.eval_type = RangerNodeType.Array
|
|
998
|
-
node.eval_array_type = vNameNode.array_type
|
|
999
|
-
}
|
|
1000
|
-
if (vNameNode.value_type == RangerNodeType.Hash) {
|
|
1001
|
-
node.eval_type = RangerNodeType.Hash
|
|
1002
|
-
node.eval_key_type = vNameNode.key_type
|
|
1003
|
-
node.eval_array_type = vNameNode.array_type
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
} {
|
|
1007
|
-
ctx.addError( node 'Undefined variable')
|
|
1008
|
-
}
|
|
1009
|
-
} {
|
|
1010
|
-
def class_or_this:boolean (rootObjName == (this.getThisName()))
|
|
1011
|
-
if (ctx.isDefinedClass(rootObjName)) {
|
|
1012
|
-
class_or_this = true
|
|
1013
|
-
node.eval_type = RangerNodeType.Class
|
|
1014
|
-
node.eval_type_name = rootObjName
|
|
1015
|
-
def m (ctx.getCurrentMethod())
|
|
1016
|
-
m.addClassUsage( (ctx.findClass(rootObjName)) ctx)
|
|
1017
|
-
}
|
|
1018
|
-
if (ctx.hasTemplateNode(rootObjName)) {
|
|
1019
|
-
class_or_this = true
|
|
1020
|
-
}
|
|
1021
|
-
if (false == class_or_this) {
|
|
1022
|
-
def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
|
|
1023
|
-
def desc:RangerAppClassDesc (unwrap udesc)
|
|
1024
|
-
|
|
1025
|
-
def opList (ctx.getOpFns(node.vref))
|
|
1026
|
-
; if {
|
|
1027
|
-
|
|
1028
|
-
if( (has opList) || node.vref == "fun" || node.vref == "fn" || (node.hasFlag('keyword'))) {
|
|
1029
|
-
; print "TODO: fix the 'fun'"
|
|
1030
|
-
} {
|
|
1031
|
-
|
|
1032
|
-
ctx.addError(node ('WriteVREF -> Undefined variable ' + node.vref + ' in class ' + desc.name + ' node : ' + (node.getCode())))
|
|
1033
|
-
ctx.addError(node ('WriteVREF -> Undefined variable ' + rootObjName + ' in class ' + desc.name + ' node : ' + (node.parent.getCode())))
|
|
1034
|
-
if(!null? node.parent.parent) {
|
|
1035
|
-
ctx.addError(node ('WriteVREF -> Undefined variable ' + rootObjName + ' in class ' + desc.name + ' node : ' + (node.parent.parent.getCode())))
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
}
|
|
1041
|
-
return
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
fn EnterFn (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter
|
|
1046
|
-
callback:(fn:void ( node:CodeNode
|
|
1047
|
-
ctx:RangerAppWriterContext
|
|
1048
|
-
wr:CodeWriter
|
|
1049
|
-
nameNode:CodeNode ; node defining the function name
|
|
1050
|
-
fnArgs:CodeNode ; arguments list
|
|
1051
|
-
fnBody:CodeNode ; function body
|
|
1052
|
-
desc:RangerAppClassDesc ; class description
|
|
1053
|
-
))) {
|
|
1054
|
-
|
|
1055
|
-
try {
|
|
1056
|
-
if( (size node.children ) < 4) {
|
|
1057
|
-
ctx.addError( node 'Function has too few arguments')
|
|
1058
|
-
return
|
|
1059
|
-
}
|
|
1060
|
-
def nameNode:CodeNode
|
|
1061
|
-
def idx 0
|
|
1062
|
-
node.children.forEach({
|
|
1063
|
-
if(item.vref == 'static') {
|
|
1064
|
-
idx = idx + 1
|
|
1065
|
-
}
|
|
1066
|
-
})
|
|
1067
|
-
def currClass (ctx.getCurrentClass())
|
|
1068
|
-
if(null? currClass) {
|
|
1069
|
-
ctx.addError( node 'Current class was not defined when entering method')
|
|
1070
|
-
return
|
|
1071
|
-
}
|
|
1072
|
-
callback( node ctx wr
|
|
1073
|
-
(at node.children (idx + 1))
|
|
1074
|
-
(at node.children (idx + 2))
|
|
1075
|
-
(at node.children (idx + 3))
|
|
1076
|
-
(unwrap currClass)
|
|
1077
|
-
)
|
|
1078
|
-
} {
|
|
1079
|
-
ctx.addError( node ('Error parsing function ' + (error_msg)))
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
|
|
1083
|
-
fn Constructor:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
1084
|
-
this.shouldHaveChildCnt(3 node ctx "Method expexts four arguments")
|
|
1085
|
-
def cn:CodeNode (at node.children 1)
|
|
1086
|
-
def fnBody:CodeNode (at node.children 2)
|
|
1087
|
-
def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
|
|
1088
|
-
def desc:RangerAppClassDesc (unwrap udesc)
|
|
1089
|
-
def m@(lives):RangerAppFunctionDesc desc.constructor_fn
|
|
1090
|
-
def subCtx:RangerAppWriterContext (unwrap m.fnCtx)
|
|
1091
|
-
|
|
1092
|
-
subCtx.is_function = true
|
|
1093
|
-
subCtx.currentMethod = m
|
|
1094
|
-
subCtx.setInMethod()
|
|
1095
|
-
for m.params v@(lives):RangerAppParamDesc i {
|
|
1096
|
-
subCtx.defineVariable(v.name v)
|
|
1097
|
-
}
|
|
1098
|
-
this.WalkNodeChildren(fnBody subCtx wr)
|
|
1099
|
-
subCtx.unsetInMethod()
|
|
1100
|
-
if (fnBody.didReturnAtIndex >= 0) {
|
|
1101
|
-
ctx.addError(node "constructor should not return any values!")
|
|
1102
|
-
}
|
|
1103
|
-
for subCtx.localVarNames n:string i {
|
|
1104
|
-
def p:RangerAppParamDesc (get subCtx.localVariables n)
|
|
1105
|
-
if (p.set_cnt > 0) {
|
|
1106
|
-
if(p.is_immutable) {
|
|
1107
|
-
ctx.addError( node "Immutable variable was assigned a value")
|
|
1108
|
-
}
|
|
1109
|
-
def defNode:CodeNode p.node
|
|
1110
|
-
defNode.setFlag("mutable")
|
|
1111
|
-
def nNode:CodeNode p.nameNode
|
|
1112
|
-
nNode.setFlag("mutable")
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
fn WriteScalarValue:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
1117
|
-
TTypes.baseTypeAsEval( node ctx wr )
|
|
1118
|
-
node.evalTypeClass = (TFactory.new_scalar_signature( node ctx wr ))
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
fn cmdNew:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
1122
|
-
if ((size node.children) < 2) {
|
|
1123
|
-
ctx.addError(node "the new operator expects at lest two arguments")
|
|
1124
|
-
return
|
|
1125
|
-
}
|
|
1126
|
-
if ((size node.children) < 3) {
|
|
1127
|
-
def expr (new CodeNode ( (unwrap node.code) node.sp node.ep))
|
|
1128
|
-
expr.expression = true
|
|
1129
|
-
push node.children expr
|
|
1130
|
-
; ctx.addError(node "the new operator expects at lest two arguments")
|
|
1131
|
-
; return
|
|
1132
|
-
}
|
|
1133
|
-
def obj:CodeNode (node.getSecond())
|
|
1134
|
-
def params:CodeNode (node.getThird())
|
|
1135
|
-
def currC@(lives):RangerAppClassDesc
|
|
1136
|
-
def b_template:boolean false
|
|
1137
|
-
|
|
1138
|
-
def expects_error:boolean false
|
|
1139
|
-
def err_cnt:int (ctx.getErrorCount())
|
|
1140
|
-
if( node.hasBooleanProperty("error")) {
|
|
1141
|
-
expects_error = true
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
; transform generic trait into a class if necessary
|
|
1145
|
-
if(obj.has_vref_annotation) {
|
|
1146
|
-
this.CheckVRefTypeAnnotationOf( obj ctx wr )
|
|
1147
|
-
}
|
|
1148
|
-
this.WalkNode(obj ctx wr)
|
|
1149
|
-
for params.children arg:CodeNode i {
|
|
1150
|
-
ctx.setInExpr()
|
|
1151
|
-
this.WalkNode(arg ctx wr)
|
|
1152
|
-
ctx.unsetInExpr()
|
|
1153
|
-
}
|
|
1154
|
-
node.eval_type = RangerNodeType.Object
|
|
1155
|
-
node.eval_type_name = obj.vref
|
|
1156
|
-
if (b_template == false) {
|
|
1157
|
-
currC = (ctx.findClass(obj.vref))
|
|
1158
|
-
def currM (ctx.getCurrentMethod())
|
|
1159
|
-
currM.addClassUsage( (unwrap currC) ctx )
|
|
1160
|
-
}
|
|
1161
|
-
node.hasNewOper = true
|
|
1162
|
-
node.clDesc = currC
|
|
1163
|
-
def fnDescr:RangerAppFunctionDesc currC.constructor_fn
|
|
1164
|
-
if (!null? fnDescr) {
|
|
1165
|
-
if( (size fnDescr.params) > (size params.children)) {
|
|
1166
|
-
ctx.addError(node 'Not enough arguments for class constructor ' + (fnDescr.node.getLineAsString()))
|
|
1167
|
-
return
|
|
1168
|
-
}
|
|
1169
|
-
for fnDescr.params param:RangerAppParamDesc i {
|
|
1170
|
-
def has_default:boolean false
|
|
1171
|
-
if (param.nameNode.hasFlag('default')) {
|
|
1172
|
-
has_default = true
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
if( param.nameNode.hasFlag('keyword')) {
|
|
1176
|
-
continue
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
if( (size params.children) <= i) {
|
|
1180
|
-
if has_default {
|
|
1181
|
-
continue _
|
|
1182
|
-
}
|
|
1183
|
-
ctx.addError(node 'Missing arguments for function')
|
|
1184
|
-
ctx.addError( (unwrap param.nameNode) 'To fix the previous error: Check original function declaration')
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
def argNode:CodeNode (at params.children i)
|
|
1188
|
-
|
|
1189
|
-
if (false == (this.areEqualTypes( (unwrap param.nameNode) argNode ctx wr))) {
|
|
1190
|
-
ctx.addError(argNode ('ERROR, invalid argument type for ' + currC.name + ' constructor '))
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
def pNode:CodeNode (unwrap param.nameNode)
|
|
1194
|
-
if( pNode.hasFlag("optional")) {
|
|
1195
|
-
if ( false == (argNode.hasFlag("optional")) ) {
|
|
1196
|
-
ctx.addError(node ( 'new parameter optionality does not match, expected optional parameter' + (argNode.getCode())) )
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
if( argNode.hasFlag('optional')) {
|
|
1200
|
-
if ( false == (pNode.hasFlag('optional')) ) {
|
|
1201
|
-
ctx.addError(node ( 'new parameter optionality does not match, expected non-optional, optional given' + (argNode.getCode())) )
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
if(expects_error) {
|
|
1208
|
-
def cnt_now:int (ctx.getErrorCount())
|
|
1209
|
-
if (cnt_now == err_cnt) {
|
|
1210
|
-
ctx.addParserError( node "LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt + " : " +cnt_now)
|
|
1211
|
-
}
|
|
1212
|
-
} {
|
|
1213
|
-
def cnt_now:int (ctx.getErrorCount())
|
|
1214
|
-
if (cnt_now > err_cnt) {
|
|
1215
|
-
ctx.addParserError( node "LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt + " : " +cnt_now)
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
fn transformParams:[CodeNode] ( list:[CodeNode] fnArgs:[RangerAppParamDesc] ctx:RangerAppWriterContext) {
|
|
1221
|
-
def res:[CodeNode]
|
|
1222
|
-
for list item:CodeNode i {
|
|
1223
|
-
if(item.is_block_node) {
|
|
1224
|
-
def newNode:CodeNode (new CodeNode ( (unwrap item.code) item.sp item.ep))
|
|
1225
|
-
def fnArg:RangerAppParamDesc (at fnArgs i)
|
|
1226
|
-
def nn:CodeNode (fnArg.nameNode)
|
|
1227
|
-
if(null? nn.expression_value) {
|
|
1228
|
-
ctx.addError( item "Parameter is not lambda expression")
|
|
1229
|
-
break
|
|
1230
|
-
}
|
|
1231
|
-
def fnDef:CodeNode (unwrap nn.expression_value)
|
|
1232
|
-
def match:RangerArgMatch (new RangerArgMatch ())
|
|
1233
|
-
def copyOf:CodeNode (fnDef.rebuildWithType( match false ))
|
|
1234
|
-
; example:
|
|
1235
|
-
; fn mapToStrings:[string] ( callback:( f:string (item:T)) ) {
|
|
1236
|
-
def fc:CodeNode (at copyOf.children 0)
|
|
1237
|
-
fc.vref = "fun"
|
|
1238
|
-
; then add the block as the last children
|
|
1239
|
-
def itemCopy:CodeNode (item.rebuildWithType (match false))
|
|
1240
|
-
push copyOf.children itemCopy
|
|
1241
|
-
def cnt:int ( size item.children )
|
|
1242
|
-
while( cnt > 0) {
|
|
1243
|
-
removeLast item.children
|
|
1244
|
-
cnt = cnt - 1
|
|
1245
|
-
}
|
|
1246
|
-
for copyOf.children ch@(lives):CodeNode i {
|
|
1247
|
-
; ch.flow_done = false
|
|
1248
|
-
push item.children ch
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
push res item
|
|
1252
|
-
}
|
|
1253
|
-
return res
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
fn transformParams2:[CodeNode] ( list:[CodeNode] fnArgs:[CodeNode] ctx:RangerAppWriterContext) {
|
|
1257
|
-
def res:[CodeNode]
|
|
1258
|
-
for list item:CodeNode i {
|
|
1259
|
-
if(item.is_block_node) {
|
|
1260
|
-
print "Transforming --> " + (item.getCode())
|
|
1261
|
-
def newNode:CodeNode (new CodeNode ( (unwrap item.code) item.sp item.ep))
|
|
1262
|
-
def nn:CodeNode (at fnArgs i)
|
|
1263
|
-
if(null? nn.expression_value) {
|
|
1264
|
-
ctx.addError( item "Parameter is not lambda expression")
|
|
1265
|
-
break
|
|
1266
|
-
}
|
|
1267
|
-
def fnDef:CodeNode (unwrap nn.expression_value)
|
|
1268
|
-
def match:RangerArgMatch (new RangerArgMatch ())
|
|
1269
|
-
def copyOf:CodeNode (fnDef.rebuildWithType( match false ))
|
|
1270
|
-
; example:
|
|
1271
|
-
; fn mapToStrings:[string] ( callback:( f:string (item:T)) ) {
|
|
1272
|
-
def fc:CodeNode (at copyOf.children 0)
|
|
1273
|
-
fc.vref = "fun"
|
|
1274
|
-
; then add the block as the last children
|
|
1275
|
-
def itemCopy:CodeNode (item.rebuildWithType (match false))
|
|
1276
|
-
push copyOf.children itemCopy
|
|
1277
|
-
def cnt:int ( size item.children )
|
|
1278
|
-
while( cnt > 0) {
|
|
1279
|
-
removeLast item.children
|
|
1280
|
-
cnt = cnt - 1
|
|
1281
|
-
}
|
|
1282
|
-
for copyOf.children ch@(lives):CodeNode i {
|
|
1283
|
-
; ch.flow_done = false
|
|
1284
|
-
push item.children ch
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
push res item
|
|
1288
|
-
}
|
|
1289
|
-
return res
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
; compile time type information
|
|
1293
|
-
fn CreateCTTI (node:CodeNode ctx:RangerAppWriterContext orig_wr:CodeWriter) {
|
|
1294
|
-
def root (ctx.getRoot())
|
|
1295
|
-
def wr (new CodeWriter)
|
|
1296
|
-
|
|
1297
|
-
root.definedClasses.forEach({
|
|
1298
|
-
if(item.isNormalClass()) {
|
|
1299
|
-
wr.raw(`
|
|
1300
|
-
operators {
|
|
1301
|
-
class_name _:string ( ` + item.name + `@(keyword) ) {
|
|
1302
|
-
templates {
|
|
1303
|
-
* ( '\"` + item.name + `\"' )
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
` , true)
|
|
1308
|
-
}
|
|
1309
|
-
})
|
|
1310
|
-
root.pushAndCollectCode( (wr.getCode()) orig_wr )
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
; run-time type information ...
|
|
1314
|
-
fn CreateRTTI (node:CodeNode ctx:RangerAppWriterContext orig_wr:CodeWriter) {
|
|
1315
|
-
|
|
1316
|
-
def root (ctx.getRoot())
|
|
1317
|
-
def wr (new CodeWriter)
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
wr.out('operator type:void all {' true)
|
|
1322
|
-
wr.indent(1)
|
|
1323
|
-
wr.out('fn rtti_get_classes:[string] () {' true)
|
|
1324
|
-
wr.indent(1)
|
|
1325
|
-
wr.out('return ([] ' false)
|
|
1326
|
-
root.definedClasses.forEach({
|
|
1327
|
-
if(item.isNormalClass()) {
|
|
1328
|
-
wr.out( `'` + item.name + `' ` , false )
|
|
1329
|
-
}
|
|
1330
|
-
})
|
|
1331
|
-
wr.out(')' true)
|
|
1332
|
-
wr.indent(-1)
|
|
1333
|
-
wr.out('}' true)
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
wr.out('fn rtti_get_fields:[RTTIClassField] (className:string) {' true)
|
|
1337
|
-
wr.indent(1)
|
|
1338
|
-
wr.out(`def fields:[RTTIClassField]` true)
|
|
1339
|
-
root.definedClasses.forEach({
|
|
1340
|
-
if(item.isNormalClass()) {
|
|
1341
|
-
wr.out(`if(className == '` + item.name +`') {` , true)
|
|
1342
|
-
wr.indent(1)
|
|
1343
|
-
item.variables.forEach({
|
|
1344
|
-
wr.out('def f (new RTTIClassField)' true)
|
|
1345
|
-
wr.out('f.name = `' + item.compiledName + '`' , true)
|
|
1346
|
-
wr.out('f.type_name = `' + item.nameNode.type_name + '`' , true)
|
|
1347
|
-
wr.out('push fields f' true)
|
|
1348
|
-
})
|
|
1349
|
-
; -->
|
|
1350
|
-
wr.indent(-1)
|
|
1351
|
-
wr.out(`}` true)
|
|
1352
|
-
}
|
|
1353
|
-
})
|
|
1354
|
-
wr.out('return fields' true)
|
|
1355
|
-
wr.indent(-1)
|
|
1356
|
-
wr.out('}' true)
|
|
1357
|
-
wr.indent(-1)
|
|
1358
|
-
wr.out('}' true)
|
|
1359
|
-
|
|
1360
|
-
; print (wr.getCode())
|
|
1361
|
-
|
|
1362
|
-
root.pushAndCollectCode( (wr.getCode()) orig_wr )
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
fn SolveAsyncFuncs (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
1367
|
-
|
|
1368
|
-
def root (ctx.getRoot())
|
|
1369
|
-
root.definedClasses.forEach({
|
|
1370
|
-
|
|
1371
|
-
item.static_methods.forEach({
|
|
1372
|
-
|
|
1373
|
-
def thisFn (item)
|
|
1374
|
-
def set_async (fn:void (f:RangerAppFunctionDesc) {
|
|
1375
|
-
|
|
1376
|
-
})
|
|
1377
|
-
def visited@(weak):[RangerAppFunctionDesc]
|
|
1378
|
-
|
|
1379
|
-
;thisFn.params.forEach({
|
|
1380
|
-
; item.nameNode.setFlag('async')
|
|
1381
|
-
;})
|
|
1382
|
-
|
|
1383
|
-
set_async = (fn:void (f:RangerAppFunctionDesc) {
|
|
1384
|
-
if( (indexOf visited f ) >= 0 ) {
|
|
1385
|
-
return
|
|
1386
|
-
}
|
|
1387
|
-
push visited f
|
|
1388
|
-
if( (!null? f.nameNode) ) {
|
|
1389
|
-
f.nameNode.setFlag('async')
|
|
1390
|
-
}
|
|
1391
|
-
f.isCalledBy.forEach({
|
|
1392
|
-
set_async( item )
|
|
1393
|
-
})
|
|
1394
|
-
if( !null? f.insideFn) {
|
|
1395
|
-
set_async( (unwrap f.insideFn ))
|
|
1396
|
-
}
|
|
1397
|
-
})
|
|
1398
|
-
if( (!null? item.nameNode) ) {
|
|
1399
|
-
if(item.nameNode.hasFlag("async")) {
|
|
1400
|
-
item.isCalledBy.forEach({
|
|
1401
|
-
set_async( item )
|
|
1402
|
-
})
|
|
1403
|
-
item.forOtherVersions( ctx {
|
|
1404
|
-
set_async(item)
|
|
1405
|
-
})
|
|
1406
|
-
if( !null? item.insideFn) {
|
|
1407
|
-
set_async( (unwrap item.insideFn ))
|
|
1408
|
-
}
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
item.myLambdas.forEach({
|
|
1412
|
-
if( (!null? item.nameNode) ) {
|
|
1413
|
-
if(item.nameNode.hasFlag("async")) {
|
|
1414
|
-
item.isCalledBy.forEach({
|
|
1415
|
-
set_async( item )
|
|
1416
|
-
})
|
|
1417
|
-
if( !null? item.insideFn) {
|
|
1418
|
-
set_async( (unwrap item.insideFn ))
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
})
|
|
1423
|
-
})
|
|
1424
|
-
|
|
1425
|
-
item.method_variants.forEach({
|
|
1426
|
-
item.variants.forEach({
|
|
1427
|
-
|
|
1428
|
-
def thisFn (item)
|
|
1429
|
-
def set_async (fn:void (f:RangerAppFunctionDesc) {
|
|
1430
|
-
|
|
1431
|
-
})
|
|
1432
|
-
def visited@(weak):[RangerAppFunctionDesc]
|
|
1433
|
-
|
|
1434
|
-
;thisFn.params.forEach({
|
|
1435
|
-
; item.nameNode.setFlag('async')
|
|
1436
|
-
;})
|
|
1437
|
-
|
|
1438
|
-
set_async = (fn:void (f:RangerAppFunctionDesc) {
|
|
1439
|
-
if( (indexOf visited f ) >= 0 ) {
|
|
1440
|
-
return
|
|
1441
|
-
}
|
|
1442
|
-
push visited f
|
|
1443
|
-
; TODO: must also iterate all the inherited class functions...
|
|
1444
|
-
if( (!null? f.nameNode) ) {
|
|
1445
|
-
f.nameNode.setFlag('async')
|
|
1446
|
-
}
|
|
1447
|
-
f.forOtherVersions( ctx {
|
|
1448
|
-
set_async(item)
|
|
1449
|
-
})
|
|
1450
|
-
f.isCalledBy.forEach({
|
|
1451
|
-
set_async( item )
|
|
1452
|
-
})
|
|
1453
|
-
if( !null? f.insideFn) {
|
|
1454
|
-
set_async( (unwrap f.insideFn ))
|
|
1455
|
-
}
|
|
1456
|
-
})
|
|
1457
|
-
if( (!null? item.nameNode) ) {
|
|
1458
|
-
if(item.nameNode.hasFlag("async")) {
|
|
1459
|
-
item.isCalledBy.forEach({
|
|
1460
|
-
set_async( item )
|
|
1461
|
-
})
|
|
1462
|
-
item.forOtherVersions( ctx {
|
|
1463
|
-
set_async(item)
|
|
1464
|
-
})
|
|
1465
|
-
if( !null? item.insideFn) {
|
|
1466
|
-
set_async( (unwrap item.insideFn ))
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
item.myLambdas.forEach({
|
|
1471
|
-
if( (!null? item.nameNode) ) {
|
|
1472
|
-
if(item.nameNode.hasFlag("async")) {
|
|
1473
|
-
item.isCalledBy.forEach({
|
|
1474
|
-
set_async( item )
|
|
1475
|
-
})
|
|
1476
|
-
if( !null? item.insideFn) {
|
|
1477
|
-
set_async( (unwrap item.insideFn ))
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
})
|
|
1482
|
-
})
|
|
1483
|
-
})
|
|
1484
|
-
})
|
|
1485
|
-
|
|
1486
|
-
def notUsedFunctionCnt 0
|
|
1487
|
-
|
|
1488
|
-
root.definedClasses.forEach({
|
|
1489
|
-
item.method_variants.forEach({
|
|
1490
|
-
item.variants.forEach({
|
|
1491
|
-
if( (size item.isCalledBy ) == 0 ) {
|
|
1492
|
-
if( !null? item.container_class) {
|
|
1493
|
-
def cc (unwrap item.container_class)
|
|
1494
|
-
if( (has cc.extends_classes ) || cc.is_inherited ) {
|
|
1495
|
-
def eC (at cc.extends_classes 0)
|
|
1496
|
-
ctx.findClass( eC )
|
|
1497
|
-
; not sure if this function is necessary or not...
|
|
1498
|
-
} {
|
|
1499
|
-
; print " unused function " + item.name + " in class " + item.container_class.name
|
|
1500
|
-
notUsedFunctionCnt = notUsedFunctionCnt + 1
|
|
1501
|
-
item.is_unsed = true
|
|
1502
|
-
}
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
})
|
|
1506
|
-
})
|
|
1507
|
-
})
|
|
1508
|
-
|
|
1509
|
-
def add_dce_fn (fn:void (theFn:RangerAppFunctionDesc) {
|
|
1510
|
-
def set_called (fn:void (f:RangerAppFunctionDesc) {
|
|
1511
|
-
|
|
1512
|
-
})
|
|
1513
|
-
set_called = (fn:void (f:RangerAppFunctionDesc) {
|
|
1514
|
-
if(f.is_called_from_main) {
|
|
1515
|
-
return
|
|
1516
|
-
}
|
|
1517
|
-
f.is_called_from_main = true
|
|
1518
|
-
f.isUsingClasses.forEach({
|
|
1519
|
-
item.is_used_by_main = true
|
|
1520
|
-
if(!null? item.constructor_fn) {
|
|
1521
|
-
set_called( (unwrap item.constructor_fn))
|
|
1522
|
-
}
|
|
1523
|
-
})
|
|
1524
|
-
f.forOtherVersions( ctx {
|
|
1525
|
-
set_called(item)
|
|
1526
|
-
})
|
|
1527
|
-
f.isCalling.forEach({
|
|
1528
|
-
set_called( item )
|
|
1529
|
-
})
|
|
1530
|
-
f.myLambdas.forEach({
|
|
1531
|
-
set_called( item )
|
|
1532
|
-
})
|
|
1533
|
-
if( !null? f.container_class) {
|
|
1534
|
-
if(!null? f.container_class.constructor_fn) {
|
|
1535
|
-
set_called( (unwrap f.container_class.constructor_fn))
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
})
|
|
1539
|
-
set_called(theFn)
|
|
1540
|
-
})
|
|
1541
|
-
|
|
1542
|
-
def use_dce false
|
|
1543
|
-
if(ctx.hasCompilerFlag('dead4main')) {
|
|
1544
|
-
def mainFn:RangerAppFunctionDesc
|
|
1545
|
-
root.definedClasses.forEach({
|
|
1546
|
-
def cl item
|
|
1547
|
-
for cl.static_methods variant@(lives):RangerAppFunctionDesc i {
|
|
1548
|
-
ctx.disableCurrentClass()
|
|
1549
|
-
if ( (variant.nameNode.hasFlag("main")) && (variant.nameNode.code.filename == (ctx.getRootFile()))) {
|
|
1550
|
-
mainFn = variant
|
|
1551
|
-
mainFn.addClassUsage( cl ctx )
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
})
|
|
1555
|
-
if(!null? mainFn) {
|
|
1556
|
-
add_dce_fn( (unwrap mainFn))
|
|
1557
|
-
use_dce = true
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
if(ctx.hasCompilerSetting('dceclass')) {
|
|
1561
|
-
def dc (ctx.getCompilerSetting('dceclass'))
|
|
1562
|
-
print "DCE : " + dc
|
|
1563
|
-
root.definedClasses.forEach({
|
|
1564
|
-
def cl item
|
|
1565
|
-
if(cl.name == dc) {
|
|
1566
|
-
use_dce = true
|
|
1567
|
-
cl.is_used_by_main = true
|
|
1568
|
-
for cl.static_methods variant@(lives):RangerAppFunctionDesc i {
|
|
1569
|
-
add_dce_fn( variant )
|
|
1570
|
-
}
|
|
1571
|
-
item.method_variants.forEach({
|
|
1572
|
-
item.variants.forEach({
|
|
1573
|
-
add_dce_fn(item)
|
|
1574
|
-
})
|
|
1575
|
-
})
|
|
1576
|
-
}
|
|
1577
|
-
})
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1580
|
-
if use_dce {
|
|
1581
|
-
def verbose (ctx.hasCompilerFlag('verbose'))
|
|
1582
|
-
root.definedClasses.forEach({
|
|
1583
|
-
if( item.is_used_by_main == false && verbose ) {
|
|
1584
|
-
print "class not used by main : " + item.name
|
|
1585
|
-
}
|
|
1586
|
-
item.static_methods = (filter item.static_methods {
|
|
1587
|
-
def cc (unwrap item.container_class)
|
|
1588
|
-
if( item.is_called_from_main == false ) {
|
|
1589
|
-
if verbose {
|
|
1590
|
-
print "removing as dead " + item.name + " from " + cc.name
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
return item.is_called_from_main
|
|
1594
|
-
})
|
|
1595
|
-
item.method_variants.forEach({
|
|
1596
|
-
item.variants = (filter item.variants {
|
|
1597
|
-
def cc (unwrap item.container_class)
|
|
1598
|
-
if( item.is_called_from_main == false ) {
|
|
1599
|
-
if verbose {
|
|
1600
|
-
print "removing as dead " + item.name + " from " + cc.name
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
return item.is_called_from_main
|
|
1604
|
-
})
|
|
1605
|
-
})
|
|
1606
|
-
})
|
|
1607
|
-
}
|
|
1608
|
-
|
|
1609
|
-
if(ctx.hasCompilerFlag('deadcode')) {
|
|
1610
|
-
root.definedClasses.forEach({
|
|
1611
|
-
item.method_variants.forEach({
|
|
1612
|
-
item.variants = (filter item.variants {
|
|
1613
|
-
return (item.is_unsed == false)
|
|
1614
|
-
})
|
|
1615
|
-
})
|
|
1616
|
-
})
|
|
1617
|
-
}
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
fn cmdCall:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
1621
|
-
|
|
1622
|
-
def obj (node.getSecond())
|
|
1623
|
-
def method (node.getThird())
|
|
1624
|
-
def callArgs (at node.children 3)
|
|
1625
|
-
|
|
1626
|
-
; print "PARAMS : " + (callArgs.getCode())
|
|
1627
|
-
; this.ModernSyntax( callArgs ctx wr true)
|
|
1628
|
-
; print "AFTER WALK : " + (callArgs.getCode())
|
|
1629
|
-
; this.WalkNode( callParams subCtx wr)
|
|
1630
|
-
|
|
1631
|
-
; test if the method could be operator
|
|
1632
|
-
; (call 4 + (5))
|
|
1633
|
-
def possible_cmd method.vref
|
|
1634
|
-
; def op_list (ctx.getOperators(possible_cmd))
|
|
1635
|
-
; for op_list cmd:CodeNode i {
|
|
1636
|
-
|
|
1637
|
-
def altVersion ( node.newExpressionNode() )
|
|
1638
|
-
def origCopy ( node.copy() )
|
|
1639
|
-
|
|
1640
|
-
altVersion.add( (node.newVRefNode( possible_cmd)) )
|
|
1641
|
-
altVersion.add( (obj.copy()) )
|
|
1642
|
-
for callArgs.children ca:CodeNode i {
|
|
1643
|
-
altVersion.add( (ca.copy()) )
|
|
1644
|
-
}
|
|
1645
|
-
altVersion.parent = node
|
|
1646
|
-
node.getChildrenFrom( altVersion )
|
|
1647
|
-
if ( this.stdParamMatch(node ctx wr false) ) {
|
|
1648
|
-
return true
|
|
1649
|
-
} {
|
|
1650
|
-
; no match
|
|
1651
|
-
node.getChildrenFrom( origCopy )
|
|
1652
|
-
}
|
|
1653
|
-
; }
|
|
1654
|
-
|
|
1655
|
-
; refresh the variables...
|
|
1656
|
-
def obj (node.getSecond())
|
|
1657
|
-
def method (node.getThird())
|
|
1658
|
-
def callArgs (at node.children 3)
|
|
1659
|
-
|
|
1660
|
-
this.WalkNode( obj ctx wr )
|
|
1661
|
-
|
|
1662
|
-
if(ctx.isDefinedClass(obj.eval_type_name)) {
|
|
1663
|
-
def cl (ctx.findClass(obj.eval_type_name))
|
|
1664
|
-
def m (cl.findMethod(method.vref))
|
|
1665
|
-
if(!null? m) {
|
|
1666
|
-
node.has_call = true
|
|
1667
|
-
|
|
1668
|
-
def currM (ctx.getCurrentMethod())
|
|
1669
|
-
currM.addCallTo( (unwrap m) )
|
|
1670
|
-
|
|
1671
|
-
ctx.setInExpr()
|
|
1672
|
-
for callArgs.children callArg:CodeNode i {
|
|
1673
|
-
this.WalkNode( callArg ctx wr)
|
|
1674
|
-
}
|
|
1675
|
-
ctx.unsetInExpr()
|
|
1676
|
-
def nn:CodeNode m.nameNode
|
|
1677
|
-
node.eval_type = (nn.typeNameAsType(ctx))
|
|
1678
|
-
node.eval_type_name = nn.type_name
|
|
1679
|
-
node.eval_array_type = nn.array_type
|
|
1680
|
-
node.eval_key_type = nn.key_type
|
|
1681
|
-
if(m.nameNode.hasFlag("throws")) {
|
|
1682
|
-
if(false == (ctx.isTryBlock()) ) {
|
|
1683
|
-
ctx.addError(obj ('The method ' + m.name + " potentially throws an exception, try { } block is required"))
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
if(nn.value_type == RangerNodeType.ExpressionType) {
|
|
1687
|
-
node.expression_value = (nn.expression_value.copy())
|
|
1688
|
-
}
|
|
1689
|
-
if(nn.hasFlag("optional")) {
|
|
1690
|
-
node.setFlag("optional")
|
|
1691
|
-
}
|
|
1692
|
-
return true
|
|
1693
|
-
} {
|
|
1694
|
-
ctx.addError(node ('Class ' + obj.eval_type_name + ' does not have method ' + method.vref))
|
|
1695
|
-
return false
|
|
1696
|
-
}
|
|
1697
|
-
} {
|
|
1698
|
-
ctx.addError( node ('can not call non-class type'))
|
|
1699
|
-
}
|
|
1700
|
-
return true
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
; getAnon:(_:string ( n:string )) ()
|
|
1704
|
-
; (fn:string (nn:string) {
|
|
1705
|
-
fn matchLambdaArgs:boolean (n1:CodeNode n2:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
1706
|
-
def chLen1 (size n1.children)
|
|
1707
|
-
def chLen2 (size n2.children)
|
|
1708
|
-
if(chLen1 < 2) {
|
|
1709
|
-
ctx.addError(n1 "Invalid Lambda definition, missing args or return value")
|
|
1710
|
-
ctx.addError(n2 "^ Invalid Lambda definition, missing args or return value")
|
|
1711
|
-
return false
|
|
1712
|
-
}
|
|
1713
|
-
if(chLen2 < 2) {
|
|
1714
|
-
ctx.addError(n1 "Invalid Lambda definition, missing args or return value")
|
|
1715
|
-
ctx.addError(n2 "^ Invalid Lambda definition, missing args or return value")
|
|
1716
|
-
; print "--> error " + (n1.getCode()) + ", " + (n2.getCode())
|
|
1717
|
-
return false
|
|
1718
|
-
}
|
|
1719
|
-
; create copies, just in case...
|
|
1720
|
-
def rv1 (n1.getFirst())
|
|
1721
|
-
def args1 (n1.getSecond())
|
|
1722
|
-
def rv2 (n2.getFirst())
|
|
1723
|
-
def args2 (n2.getSecond())
|
|
1724
|
-
|
|
1725
|
-
def rvExpr1 (n1.newExpressionNode())
|
|
1726
|
-
rvExpr1.push( (rv1.copy()) )
|
|
1727
|
-
def rvExpr2 (n2.newExpressionNode())
|
|
1728
|
-
rvExpr2.push( (rv2.copy()) )
|
|
1729
|
-
|
|
1730
|
-
def argsExpr1 (args1.copy())
|
|
1731
|
-
def argsExpr2 (args2.copy())
|
|
1732
|
-
|
|
1733
|
-
def all_matched true
|
|
1734
|
-
|
|
1735
|
-
; to work around typescript bug
|
|
1736
|
-
if(ctx.hasCompilerFlag('notreallyexistingflag')) {
|
|
1737
|
-
all_matched = false
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
if( (size argsExpr1.children) != (size argsExpr2.children) ) {
|
|
1741
|
-
ctx.addError(n2 "Invalid parameter count for the lambda expression")
|
|
1742
|
-
return false
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
argsExpr1.children.forEach({
|
|
1746
|
-
def item2 (at argsExpr2.children index)
|
|
1747
|
-
if ( item2.value_type != item.value_type ) {
|
|
1748
|
-
all_matched = false
|
|
1749
|
-
}
|
|
1750
|
-
if ( item2.type_name != item.type_name ) {
|
|
1751
|
-
all_matched = false
|
|
1752
|
-
}
|
|
1753
|
-
if ( item2.array_type != item.array_type ) {
|
|
1754
|
-
all_matched = false
|
|
1755
|
-
}
|
|
1756
|
-
if ( item2.key_type != item.key_type ) {
|
|
1757
|
-
all_matched = false
|
|
1758
|
-
}
|
|
1759
|
-
if ( all_matched && item.value_type == RangerNodeType.ExpressionType ) {
|
|
1760
|
-
if( false == (this.matchLambdaArgs( (unwrap item.expression_value) (unwrap item2.expression_value) ctx wr) ) ) {
|
|
1761
|
-
all_matched = false
|
|
1762
|
-
}
|
|
1763
|
-
}
|
|
1764
|
-
})
|
|
1765
|
-
if( all_matched == false) {
|
|
1766
|
-
ctx.addError(n2 "Invalid lambda argument types")
|
|
1767
|
-
return false
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
rvExpr1.children.forEach({
|
|
1771
|
-
def item2 (at rvExpr2.children index)
|
|
1772
|
-
if ( item2.value_type != item.value_type ) {
|
|
1773
|
-
all_matched = false
|
|
1774
|
-
}
|
|
1775
|
-
if ( item2.type_name != item.type_name ) {
|
|
1776
|
-
all_matched = false
|
|
1777
|
-
}
|
|
1778
|
-
if ( item2.array_type != item.array_type ) {
|
|
1779
|
-
all_matched = false
|
|
1780
|
-
}
|
|
1781
|
-
if ( item2.key_type != item.key_type ) {
|
|
1782
|
-
all_matched = false
|
|
1783
|
-
}
|
|
1784
|
-
if ( all_matched && item.value_type == RangerNodeType.ExpressionType ) {
|
|
1785
|
-
if( false == (this.matchLambdaArgs( (unwrap item.expression_value) (unwrap item2.expression_value) ctx wr) ) ) {
|
|
1786
|
-
all_matched = false
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
})
|
|
1790
|
-
|
|
1791
|
-
if(ctx.hasCompilerFlag('notreallyexistingflag')) {
|
|
1792
|
-
all_matched = false
|
|
1793
|
-
}
|
|
1794
|
-
if( all_matched == false) {
|
|
1795
|
-
ctx.addError(n2 "Invalid lambda return value type")
|
|
1796
|
-
return false
|
|
1797
|
-
}
|
|
1798
|
-
return true
|
|
1799
|
-
}
|
|
1800
|
-
|
|
1801
|
-
fn testLambdaCallArgs:boolean ( lambda_expression:CodeNode callParams:CodeNode ctx:RangerAppWriterContext wr:CodeWriter ) {
|
|
1802
|
-
def lambdaDef (at lambda_expression.children 0)
|
|
1803
|
-
def lambdaArgs (at lambda_expression.children 1)
|
|
1804
|
-
def all_matched true
|
|
1805
|
-
if( (size callParams.children) != (size lambdaArgs.children) ) {
|
|
1806
|
-
ctx.addError(callParams "Invalid parameter count for the lambda expression " )
|
|
1807
|
-
ctx.addError(callParams (' ^ expected : ' + (lambdaArgs.getCode()) ) )
|
|
1808
|
-
; ctx.addError(node (' ^ definition : ' + (d.nameNode.getParsedString()) ) )
|
|
1809
|
-
all_matched = false
|
|
1810
|
-
}
|
|
1811
|
-
lambdaArgs.children.forEach({
|
|
1812
|
-
def item2 (at callParams.children index)
|
|
1813
|
-
if ( item2.eval_type_name != item.type_name ) {
|
|
1814
|
-
; missing: union types handling
|
|
1815
|
-
if( item.type_name != 'Any' ) {
|
|
1816
|
-
ctx.addError( item2 ( 'Argument of wrong type given for the lambda parameter ' + index))
|
|
1817
|
-
all_matched = false
|
|
1818
|
-
}
|
|
1819
|
-
}
|
|
1820
|
-
if ( item2.eval_array_type != item.array_type ) {
|
|
1821
|
-
ctx.addError( item2 ( 'Argument of wrong type given for the lambda parameter ' + index))
|
|
1822
|
-
all_matched = false
|
|
1823
|
-
}
|
|
1824
|
-
if ( item2.eval_key_type != item.key_type ) {
|
|
1825
|
-
ctx.addError( item2 ( 'Argument of wrong type given for the lambda parameter ' + index))
|
|
1826
|
-
all_matched = false
|
|
1827
|
-
}
|
|
1828
|
-
})
|
|
1829
|
-
if( all_matched == false) {
|
|
1830
|
-
ctx.addError(callParams "Invalid types for lambda call")
|
|
1831
|
-
}
|
|
1832
|
-
return all_matched
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1835
|
-
fn cmdLocalCall:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
1836
|
-
def fnNode@(lives):CodeNode (node.getFirst())
|
|
1837
|
-
def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
|
|
1838
|
-
def desc:RangerAppClassDesc (unwrap udesc)
|
|
1839
|
-
def expects_error:boolean false
|
|
1840
|
-
def err_cnt:int (ctx.getErrorCount())
|
|
1841
|
-
if( node.hasBooleanProperty("error")) {
|
|
1842
|
-
expects_error = true
|
|
1843
|
-
}
|
|
1844
|
-
; print "childnode count : " + (size node.children)
|
|
1845
|
-
; collect also the chain here..
|
|
1846
|
-
|
|
1847
|
-
; obj.foo() .bar() .foor2()
|
|
1848
|
-
; --> obj.foo() will be the innerNode...
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
def chlen (size node.children)
|
|
1852
|
-
|
|
1853
|
-
if( chlen > 2) {
|
|
1854
|
-
def i 2
|
|
1855
|
-
def chainRoot:CodeNode (node)
|
|
1856
|
-
def innerNode@(weak):CodeNode
|
|
1857
|
-
def newNode (node.newExpressionNode())
|
|
1858
|
-
def sc (node.getSecond())
|
|
1859
|
-
newNode.add( (fnNode.copy()) )
|
|
1860
|
-
newNode.add( (sc.copy()) )
|
|
1861
|
-
innerNode = newNode
|
|
1862
|
-
|
|
1863
|
-
; print "Chaining " + (node.getCode())
|
|
1864
|
-
|
|
1865
|
-
def chain_cnt 0
|
|
1866
|
-
def b_valid true
|
|
1867
|
-
; push the first into bottom of stack
|
|
1868
|
-
; obj.foo.something ()
|
|
1869
|
-
while ( i < (chlen - 1) ) {
|
|
1870
|
-
def fc (at node.children i)
|
|
1871
|
-
def args@(lives) (at node.children (i + 1))
|
|
1872
|
-
def name (fc.vref)
|
|
1873
|
-
if( ( (strlen name) > 0 ) && ( ( charAt name 0) == (charcode ".")) ) {
|
|
1874
|
-
def method_name (substring name 1 (strlen name))
|
|
1875
|
-
def newNode (node.newExpressionNode())
|
|
1876
|
-
newNode.add( (node.newVRefNode("call") ) )
|
|
1877
|
-
newNode.add( (innerNode.copy() ) )
|
|
1878
|
-
newNode.add( (node.newVRefNode(method_name)) )
|
|
1879
|
-
newNode.add( (args.copy()))
|
|
1880
|
-
innerNode = newNode
|
|
1881
|
-
chain_cnt = chain_cnt + 1
|
|
1882
|
-
} {
|
|
1883
|
-
b_valid = false
|
|
1884
|
-
; ctx.addError(node "Invalid chaining op")
|
|
1885
|
-
}
|
|
1886
|
-
i = i + 2
|
|
1887
|
-
}
|
|
1888
|
-
if ( b_valid && (chain_cnt > 0 ) ) {
|
|
1889
|
-
node.getChildrenFrom( (unwrap innerNode ) )
|
|
1890
|
-
node.tag = "chainroot"
|
|
1891
|
-
node.flow_done = false
|
|
1892
|
-
this.WalkNode( node ctx wr)
|
|
1893
|
-
return true
|
|
1894
|
-
}
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
if ((size fnNode.ns) > 1) {
|
|
1898
|
-
|
|
1899
|
-
def rootName (at fnNode.ns 0)
|
|
1900
|
-
def vDef2 (ctx.getVariableDef(rootName))
|
|
1901
|
-
if( (rootName != "this") && (vDef2.init_cnt == 0) && (vDef2.set_cnt == 0) ) {
|
|
1902
|
-
if( (vDef2.is_class_variable == false ) && ( (ctx.isDefinedClass(rootName)) == false ) ) {
|
|
1903
|
-
ctx.addError( node ('Call to uninitialized object ' + rootName) )
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
def vFnDef@(optional):RangerAppFunctionDesc (this.findFunctionDesc(fnNode ctx wr))
|
|
1907
|
-
|
|
1908
|
-
if (!null? vFnDef) {
|
|
1909
|
-
|
|
1910
|
-
if(vFnDef.nameNode.hasFlag("throws")) {
|
|
1911
|
-
if(false == (ctx.isTryBlock()) ) {
|
|
1912
|
-
ctx.addError(node ('The method ' + vFnDef.name + " potentially throws an exception, try { } block is required"))
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
def currM@(lives) (ctx.getCurrentMethod())
|
|
1917
|
-
currM.addCallTo( (unwrap vFnDef) )
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
vFnDef.ref_cnt = (vFnDef.ref_cnt + 1)
|
|
1921
|
-
def subCtx:RangerAppWriterContext (ctx.fork())
|
|
1922
|
-
node.hasFnCall = true
|
|
1923
|
-
node.fnDesc = vFnDef
|
|
1924
|
-
def p@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
|
|
1925
|
-
p.name = fnNode.vref
|
|
1926
|
-
p.value_type = fnNode.value_type
|
|
1927
|
-
p.node = fnNode
|
|
1928
|
-
p.nameNode = fnNode
|
|
1929
|
-
p.varType = RangerContextVarType.Function
|
|
1930
|
-
subCtx.defineVariable(p.name p)
|
|
1931
|
-
this.WalkNode(fnNode subCtx wr)
|
|
1932
|
-
def callParams:CodeNode (at node.children 1)
|
|
1933
|
-
def keyword_cnt 0
|
|
1934
|
-
vFnDef.params.forEach({
|
|
1935
|
-
if(item.nameNode.hasFlag('keyword')) {
|
|
1936
|
-
keyword_cnt = keyword_cnt + 1
|
|
1937
|
-
( (at callParams.children index) .setFlag('keyword'))
|
|
1938
|
-
}
|
|
1939
|
-
})
|
|
1940
|
-
def nodeList:[CodeNode] (this.transformParams( callParams.children vFnDef.params subCtx))
|
|
1941
|
-
if(ctx.hasCompilerFlag('dbg')) {
|
|
1942
|
-
print "Local: " + vFnDef.name
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
|
-
for nodeList arg:CodeNode i {
|
|
1946
|
-
; expression as parameter is a lambda
|
|
1947
|
-
ctx.setInExpr()
|
|
1948
|
-
def was_lambda false
|
|
1949
|
-
if(arg.isFirstVref("fun")) {
|
|
1950
|
-
arg.flow_done = false
|
|
1951
|
-
arg.forTree({
|
|
1952
|
-
item.flow_done = false
|
|
1953
|
-
})
|
|
1954
|
-
was_lambda = true
|
|
1955
|
-
}
|
|
1956
|
-
this.WalkNode(arg subCtx wr)
|
|
1957
|
-
|
|
1958
|
-
if was_lambda {
|
|
1959
|
-
def currM@(lives) (ctx.getCurrentMethod())
|
|
1960
|
-
if(!null? arg.lambdaFnDesc) {
|
|
1961
|
-
vFnDef.addCallTo( (unwrap arg.lambdaFnDesc))
|
|
1962
|
-
currM.addCallTo( (unwrap vFnDef ) )
|
|
1963
|
-
push currM.myLambdas (unwrap arg.lambdaFnDesc)
|
|
1964
|
-
push vFnDef.myLambdas (unwrap arg.lambdaFnDesc)
|
|
1965
|
-
}
|
|
1966
|
-
arg.forTree({
|
|
1967
|
-
if(!null? item.lambdaFnDesc) {
|
|
1968
|
-
item.lambdaFnDesc.insideFn = currM
|
|
1969
|
-
}
|
|
1970
|
-
if(!null? item.fnDesc) {
|
|
1971
|
-
if(!null? arg.lambdaFnDesc) {
|
|
1972
|
-
arg.lambdaFnDesc.addCallTo( (unwrap item.fnDesc) )
|
|
1973
|
-
}
|
|
1974
|
-
vFnDef.addCallTo( (unwrap item.fnDesc ) )
|
|
1975
|
-
}
|
|
1976
|
-
})
|
|
1977
|
-
}
|
|
1978
|
-
ctx.unsetInExpr()
|
|
1979
|
-
if( (size vFnDef.params) > i) {
|
|
1980
|
-
def fnArg:RangerAppParamDesc (at vFnDef.params i)
|
|
1981
|
-
def callArgP:RangerAppParamDesc arg.paramDesc
|
|
1982
|
-
if (!null? callArgP) {
|
|
1983
|
-
callArgP.moveRefTo(node fnArg ctx)
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
def cp_len:int ( (size callParams.children) - keyword_cnt )
|
|
1988
|
-
if( cp_len > ( size vFnDef.params )) {
|
|
1989
|
-
def lastCallParam:CodeNode (at callParams.children (cp_len - 1))
|
|
1990
|
-
ctx.addError( lastCallParam "Too many arguments for function")
|
|
1991
|
-
ctx.addError( (unwrap vFnDef.nameNode) "NOTE: To fix the previous error: Check original function declaration which was")
|
|
1992
|
-
}
|
|
1993
|
-
for vFnDef.params param:RangerAppParamDesc i {
|
|
1994
|
-
if( (size callParams.children) <= i) {
|
|
1995
|
-
if (param.nameNode.hasFlag("default")) {
|
|
1996
|
-
continue
|
|
1997
|
-
}
|
|
1998
|
-
ctx.addError(node "Missing arguments for function")
|
|
1999
|
-
ctx.addError( (unwrap param.nameNode) "NOTE: To fix the previous error: Check original function declaration which was")
|
|
2000
|
-
break
|
|
2001
|
-
}
|
|
2002
|
-
if( param.nameNode.hasFlag('keyword')) {
|
|
2003
|
-
continue
|
|
2004
|
-
}
|
|
2005
|
-
def argNode:CodeNode (at callParams.children i)
|
|
2006
|
-
if (false == (this.areEqualTypes( (unwrap param.nameNode) argNode ctx wr))) {
|
|
2007
|
-
ctx.addError(argNode ('ERROR, invalid argument type for method ' + vFnDef.name))
|
|
2008
|
-
}
|
|
2009
|
-
def pNode:CodeNode (unwrap param.nameNode)
|
|
2010
|
-
if( pNode.hasFlag('optional')) {
|
|
2011
|
-
if ( false == (argNode.hasFlag('optional')) ) {
|
|
2012
|
-
ctx.addError(node ( 'function parameter optionality does not match, consider making parameter optional ' + (argNode.getCode())) )
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
if( argNode.hasFlag('optional')) {
|
|
2016
|
-
if ( false == (pNode.hasFlag('optional')) ) {
|
|
2017
|
-
ctx.addError(node ( 'function parameter optionality does not match, consider unwrapping ' + (argNode.getCode())) )
|
|
2018
|
-
}
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
def nn:CodeNode vFnDef.nameNode
|
|
2022
|
-
node.eval_type = (nn.typeNameAsType(ctx))
|
|
2023
|
-
node.eval_type_name = nn.type_name
|
|
2024
|
-
node.eval_array_type = nn.array_type
|
|
2025
|
-
node.eval_key_type = nn.key_type
|
|
2026
|
-
|
|
2027
|
-
if(node.eval_type == RangerNodeType.ExpressionType) {
|
|
2028
|
-
node.expression_value = (nn.expression_value.copy())
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
|
-
if(nn.hasFlag("optional")) {
|
|
2032
|
-
node.setFlag("optional")
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
if(expects_error) {
|
|
2036
|
-
def cnt_now:int (ctx.getErrorCount())
|
|
2037
|
-
if (cnt_now == err_cnt) {
|
|
2038
|
-
ctx.addParserError( node "LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt + " : " +cnt_now)
|
|
2039
|
-
}
|
|
2040
|
-
} {
|
|
2041
|
-
def cnt_now:int (ctx.getErrorCount())
|
|
2042
|
-
if (cnt_now > err_cnt) {
|
|
2043
|
-
ctx.addParserError( node "LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt + " : " +cnt_now)
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
return true
|
|
2047
|
-
} {
|
|
2048
|
-
ctx.addError(node "Called Object or Property was not defined")
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
if (desc.hasMethod(fnNode.vref)) {
|
|
2052
|
-
def fnDescr@(optional):RangerAppFunctionDesc (desc.findMethod(fnNode.vref))
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
if(fnDescr.nameNode.hasFlag("throws")) {
|
|
2056
|
-
if(false == (ctx.isTryBlock()) ) {
|
|
2057
|
-
ctx.addError(node ('The method ' + fnDescr.name + " potentially throws an exception, try { } block is required"))
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
|
|
2061
|
-
def currM (ctx.getCurrentMethod())
|
|
2062
|
-
currM.addCallTo( (unwrap fnDescr) )
|
|
2063
|
-
|
|
2064
|
-
if(ctx.hasCompilerFlag('dbg')) {
|
|
2065
|
-
print "Local 2 : " + fnDescr.name
|
|
2066
|
-
}
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
def subCtx:RangerAppWriterContext (ctx.fork())
|
|
2070
|
-
node.hasFnCall = true
|
|
2071
|
-
node.fnDesc = fnDescr
|
|
2072
|
-
def p@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
|
|
2073
|
-
p.name = fnNode.vref
|
|
2074
|
-
p.value_type = fnNode.value_type
|
|
2075
|
-
p.node = fnNode
|
|
2076
|
-
p.nameNode = fnNode
|
|
2077
|
-
p.varType = RangerContextVarType.Function
|
|
2078
|
-
subCtx.defineVariable(p.name p)
|
|
2079
|
-
this.WalkNode(fnNode subCtx wr)
|
|
2080
|
-
for node.children arg:CodeNode i {
|
|
2081
|
-
if (i < 1) {
|
|
2082
|
-
continue _
|
|
2083
|
-
}
|
|
2084
|
-
ctx.setInExpr()
|
|
2085
|
-
this.WalkNode(arg subCtx wr)
|
|
2086
|
-
ctx.unsetInExpr()
|
|
2087
|
-
}
|
|
2088
|
-
for fnDescr.params param:RangerAppParamDesc i {
|
|
2089
|
-
if( (size node.children) <= (i + 1)) {
|
|
2090
|
-
ctx.addError(node "Argument was not defined")
|
|
2091
|
-
break
|
|
2092
|
-
}
|
|
2093
|
-
|
|
2094
|
-
def argNode:CodeNode (at node.children (i + 1))
|
|
2095
|
-
if (false == (this.areEqualTypes( (unwrap param.nameNode) argNode ctx wr))) {
|
|
2096
|
-
ctx.addError(argNode ('ERROR, invalid argument type for ' + desc.name + ' method ' + fnDescr.name))
|
|
2097
|
-
}
|
|
2098
|
-
}
|
|
2099
|
-
def nn:CodeNode fnDescr.nameNode
|
|
2100
|
-
nn.defineNodeTypeTo(node ctx)
|
|
2101
|
-
if(expects_error) {
|
|
2102
|
-
def cnt_now:int (ctx.getErrorCount())
|
|
2103
|
-
if (cnt_now == err_cnt) {
|
|
2104
|
-
ctx.addParserError( node "LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt + " : " +cnt_now)
|
|
2105
|
-
}
|
|
2106
|
-
} {
|
|
2107
|
-
def cnt_now:int (ctx.getErrorCount())
|
|
2108
|
-
if (cnt_now > err_cnt) {
|
|
2109
|
-
ctx.addParserError( node "LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt + " : " +cnt_now)
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2112
|
-
return true
|
|
2113
|
-
}
|
|
2114
|
-
|
|
2115
|
-
; TODO: first lambda call check comes here... continue to other variants later
|
|
2116
|
-
if (ctx.isVarDefined(fnNode.vref)) {
|
|
2117
|
-
def d (ctx.getVariableDef(fnNode.vref))
|
|
2118
|
-
|
|
2119
|
-
d.ref_cnt = (1 + d.ref_cnt)
|
|
2120
|
-
|
|
2121
|
-
if( d.nameNode.hasFlag('optional')) {
|
|
2122
|
-
ctx.addError( node 'Can not call optional lambda function, unwrap the function first!')
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
if(d.nameNode.value_type == RangerNodeType.ExpressionType) {
|
|
2126
|
-
|
|
2127
|
-
def cnNode1 (at node.children 0)
|
|
2128
|
-
this.WalkNode(cnNode1 ctx wr)
|
|
2129
|
-
|
|
2130
|
-
def lambdaDefArgs (at d.nameNode.expression_value.children 1)
|
|
2131
|
-
def callParams:CodeNode (at node.children 1)
|
|
2132
|
-
|
|
2133
|
-
for callParams.children arg:CodeNode i {
|
|
2134
|
-
ctx.setInExpr()
|
|
2135
|
-
this.WalkNode(arg ctx wr)
|
|
2136
|
-
ctx.unsetInExpr()
|
|
2137
|
-
}
|
|
2138
|
-
|
|
2139
|
-
this.testLambdaCallArgs( (unwrap d.nameNode.expression_value) callParams ctx wr)
|
|
2140
|
-
|
|
2141
|
-
def lambdaDef (at d.nameNode.expression_value.children 0)
|
|
2142
|
-
node.has_lambda_call = true
|
|
2143
|
-
node.eval_type = (lambdaDef.typeNameAsType(ctx))
|
|
2144
|
-
node.eval_type_name = lambdaDef.type_name
|
|
2145
|
-
node.eval_array_type = lambdaDef.array_type
|
|
2146
|
-
node.eval_key_type = lambdaDef.key_type
|
|
2147
|
-
|
|
2148
|
-
if(node.eval_type == RangerNodeType.ExpressionType) {
|
|
2149
|
-
if(!null? lambdaDef.expression_value) {
|
|
2150
|
-
node.expression_value = (lambdaDef.expression_value.copy())
|
|
2151
|
-
}
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
return true
|
|
2155
|
-
})
|
|
2156
|
-
}
|
|
2157
|
-
return false
|
|
2158
|
-
; -------------------------------------------------
|
|
2159
|
-
ctx.addError(node ('ERROR, could not find class ' + desc.name + ' method ' + fnNode.vref))
|
|
2160
|
-
ctx.addError(node ('definition : ' + (node.getCode())))
|
|
2161
|
-
if(expects_error) {
|
|
2162
|
-
def cnt_now:int (ctx.getErrorCount())
|
|
2163
|
-
if (cnt_now == err_cnt) {
|
|
2164
|
-
ctx.addParserError( node "LANGUAGE_PARSER_ERROR: expected generated error, err counts : " + err_cnt + " : " +cnt_now)
|
|
2165
|
-
}
|
|
2166
|
-
} {
|
|
2167
|
-
def cnt_now:int (ctx.getErrorCount())
|
|
2168
|
-
if (cnt_now > err_cnt) {
|
|
2169
|
-
ctx.addParserError( node "LANGUAGE_PARSER_ERROR: did not expect generated error, err counts : " + err_cnt + " : " +cnt_now)
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2172
|
-
return false
|
|
2173
|
-
}
|
|
2174
|
-
|
|
2175
|
-
; obj.firstChild.name = "name of firstChild"
|
|
2176
|
-
; obj = (call obj set_firstChild ( (call obj.firstChild set_name ("name of firstChild")) ))
|
|
2177
|
-
fn transformImmutableAssigment:CodeNode (node:CodeNode) {
|
|
2178
|
-
|
|
2179
|
-
def target (node.getSecond()) ; obj.firstChild.name
|
|
2180
|
-
def assign_value (node.getThird()) ; "name of firstChild"
|
|
2181
|
-
def root (node.newExpressionNode())
|
|
2182
|
-
|
|
2183
|
-
root.add( (node.newVRefNode("=")))
|
|
2184
|
-
root.add( (node.newVRefNode( (at target.ns 0) ))) ; obj
|
|
2185
|
-
|
|
2186
|
-
def i 1
|
|
2187
|
-
def cnt (size target.ns)
|
|
2188
|
-
def valueExpression (node.newExpressionNode())
|
|
2189
|
-
def obj_ref (at target.ns 0)
|
|
2190
|
-
def currentParent@(weak temp) root
|
|
2191
|
-
while( i < cnt ) {
|
|
2192
|
-
def callExpr@(lives) (node.newExpressionNode())
|
|
2193
|
-
callExpr.add( (node.newVRefNode("call")))
|
|
2194
|
-
callExpr.add( (node.newVRefNode(obj_ref)))
|
|
2195
|
-
def next_ref (at target.ns (i))
|
|
2196
|
-
def set_ref ("set_" + next_ref )
|
|
2197
|
-
callExpr.add( (node.newVRefNode(set_ref)))
|
|
2198
|
-
i = i + 1
|
|
2199
|
-
if( i < cnt ) {
|
|
2200
|
-
obj_ref = obj_ref + "." + next_ref
|
|
2201
|
-
def paramsNode (node.newExpressionNode())
|
|
2202
|
-
paramsNode.add(callExpr)
|
|
2203
|
-
currentParent.add( paramsNode )
|
|
2204
|
-
currentParent = callExpr
|
|
2205
|
-
} {
|
|
2206
|
-
def callParams (node.newExpressionNode())
|
|
2207
|
-
callParams.add((assign_value.copy()))
|
|
2208
|
-
callExpr.add( callParams )
|
|
2209
|
-
def paramsNode (node.newExpressionNode())
|
|
2210
|
-
paramsNode.add( (callExpr.copy()) )
|
|
2211
|
-
currentParent.add( paramsNode )
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
return root
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2217
|
-
fn cmdAssign:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
2218
|
-
|
|
2219
|
-
def target:CodeNode (node.getSecond())
|
|
2220
|
-
this.WalkNode(target ctx wr)
|
|
2221
|
-
|
|
2222
|
-
; immutable check which denies assigent operation
|
|
2223
|
-
if(target.hasParamDesc) {
|
|
2224
|
-
if( !null? target.paramDesc.propertyClass) {
|
|
2225
|
-
def nn (unwrap target.paramDesc.propertyClass.nameNode)
|
|
2226
|
-
if(nn.hasFlag("immutable")) {
|
|
2227
|
-
|
|
2228
|
-
def do_transform false
|
|
2229
|
-
def propC (target.paramDesc.propertyClass)
|
|
2230
|
-
def currC (ctx.getCurrentClass())
|
|
2231
|
-
if( (unwrap currC) == (unwrap propC) ) {
|
|
2232
|
-
if( (at target.ns 0) == "this" ) {
|
|
2233
|
-
; ctx.addError( node "Assigment to immutable class this variable")
|
|
2234
|
-
do_transform = true
|
|
2235
|
-
}
|
|
2236
|
-
} {
|
|
2237
|
-
; ctx.addError( node "Assigment to immutable class node")
|
|
2238
|
-
do_transform = true
|
|
2239
|
-
}
|
|
2240
|
-
|
|
2241
|
-
if do_transform {
|
|
2242
|
-
|
|
2243
|
-
def n1:CodeNode (node.getSecond())
|
|
2244
|
-
def n2:CodeNode (node.getThird())
|
|
2245
|
-
this.WalkNode(n1 ctx wr)
|
|
2246
|
-
ctx.setInExpr()
|
|
2247
|
-
this.WalkNode(n2 ctx wr)
|
|
2248
|
-
ctx.unsetInExpr()
|
|
2249
|
-
|
|
2250
|
-
this.convertToUnion( n1.eval_type_name n2 ctx wr)
|
|
2251
|
-
; --> should test here
|
|
2252
|
-
this.shouldBeEqualTypes( n1 n2 ctx "Can not assign variable.")
|
|
2253
|
-
|
|
2254
|
-
def immAss (this.transformImmutableAssigment(node))
|
|
2255
|
-
; print "immutable assigment => " + (immAss.getCode())
|
|
2256
|
-
node.getChildrenFrom( immAss )
|
|
2257
|
-
; print "eventual assigment => " + (node.getCode())
|
|
2258
|
-
this.cmdAssign( node ctx wr)
|
|
2259
|
-
return
|
|
2260
|
-
}
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
|
|
2265
|
-
def chlen (size node.children)
|
|
2266
|
-
wr.newline()
|
|
2267
|
-
def n1:CodeNode (node.getSecond())
|
|
2268
|
-
def n2:CodeNode (node.getThird())
|
|
2269
|
-
this.WalkNode(n1 ctx wr)
|
|
2270
|
-
ctx.setInExpr()
|
|
2271
|
-
this.WalkNode(n2 ctx wr)
|
|
2272
|
-
ctx.unsetInExpr()
|
|
2273
|
-
if n1.hasParamDesc {
|
|
2274
|
-
n1.paramDesc.ref_cnt = (n1.paramDesc.ref_cnt + 1)
|
|
2275
|
-
n1.paramDesc.set_cnt = (n1.paramDesc.set_cnt + 1)
|
|
2276
|
-
}
|
|
2277
|
-
if n2.hasParamDesc {
|
|
2278
|
-
n2.paramDesc.ref_cnt = (n2.paramDesc.ref_cnt + 1)
|
|
2279
|
-
}
|
|
2280
|
-
if (n2.hasFlag("optional")) {
|
|
2281
|
-
if (false == (n1.hasFlag("optional"))) {
|
|
2282
|
-
ctx.addError(node "Can not assign optional to non-optional type")
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
this.stdParamMatch(node ctx wr true)
|
|
2286
|
-
this.convertToUnion( n1.eval_type_name n2 ctx wr)
|
|
2287
|
-
this.shouldBeEqualTypes( n1 n2 ctx "Can not assign variable.")
|
|
2288
|
-
}
|
|
2289
|
-
fn EnterTemplateClass:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
2290
|
-
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
|
-
fn EnterClass:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
2294
|
-
def body_index ( (node.chlen()) - 1)
|
|
2295
|
-
if( (size node.children) != 3) {
|
|
2296
|
-
if( (node.chlen()) == 5 ) {
|
|
2297
|
-
|
|
2298
|
-
} {
|
|
2299
|
-
ctx.addError(node "Invalid class declaration")
|
|
2300
|
-
return
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
if(node.hasBooleanProperty("trait")) {
|
|
2304
|
-
return
|
|
2305
|
-
}
|
|
2306
|
-
def cn:CodeNode (at node.children 1)
|
|
2307
|
-
def cBody:CodeNode (at node.children body_index)
|
|
2308
|
-
def desc@(lives):RangerAppClassDesc (ctx.findClass(cn.vref))
|
|
2309
|
-
def subCtx:RangerAppWriterContext (unwrap desc.ctx)
|
|
2310
|
-
|
|
2311
|
-
subCtx.setCurrentClass(desc)
|
|
2312
|
-
subCtx.class_level_context = true
|
|
2313
|
-
for desc.variables p:RangerAppParamDesc i {
|
|
2314
|
-
def vNode:CodeNode p.node
|
|
2315
|
-
if ((size vNode.children) > 2) {
|
|
2316
|
-
def value:CodeNode (at vNode.children 2)
|
|
2317
|
-
ctx.setInExpr()
|
|
2318
|
-
this.WalkNode(value ctx wr)
|
|
2319
|
-
ctx.unsetInExpr()
|
|
2320
|
-
}
|
|
2321
|
-
p.is_class_variable = true
|
|
2322
|
-
p.nameNode.eval_type = (p.nameNode.typeNameAsType(ctx))
|
|
2323
|
-
p.nameNode.eval_type_name = p.nameNode.type_name
|
|
2324
|
-
}
|
|
2325
|
-
|
|
2326
|
-
for cBody.children fNode:CodeNode i {
|
|
2327
|
-
if ((fNode.isFirstVref("fn")) || (fNode.isFirstVref("constructor")) || (fNode.isFirstVref("Constructor"))) {
|
|
2328
|
-
this.WalkNode(fNode subCtx wr)
|
|
2329
|
-
}
|
|
2330
|
-
}
|
|
2331
|
-
for cBody.children fNode:CodeNode i {
|
|
2332
|
-
if ((fNode.isFirstVref("fn")) || (fNode.isFirstVref("PublicMethod"))) {
|
|
2333
|
-
this.WalkNode(fNode subCtx wr)
|
|
2334
|
-
}
|
|
2335
|
-
}
|
|
2336
|
-
def staticCtx:RangerAppWriterContext (ctx.fork())
|
|
2337
|
-
staticCtx.setCurrentClass(desc)
|
|
2338
|
-
for cBody.children fNode:CodeNode i {
|
|
2339
|
-
if ((fNode.isFirstVref("sfn")) || (fNode.isFirstVref("StaticMethod")) || (fNode.isFirstVref("static"))) {
|
|
2340
|
-
this.WalkNode(fNode staticCtx wr)
|
|
2341
|
-
}
|
|
2342
|
-
}
|
|
2343
|
-
|
|
2344
|
-
cBody.children.forEach({
|
|
2345
|
-
try {
|
|
2346
|
-
if( item.isFirstVref('doc')) {
|
|
2347
|
-
def sc (item.getSecond())
|
|
2348
|
-
def fndesc (desc.findMethod(sc.vref))
|
|
2349
|
-
if (fndesc) {
|
|
2350
|
-
def third (item.getThird())
|
|
2351
|
-
fndesc.git_doc = third.string_value
|
|
2352
|
-
}
|
|
2353
|
-
}
|
|
2354
|
-
} {
|
|
2355
|
-
|
|
2356
|
-
}
|
|
2357
|
-
})
|
|
2358
|
-
node.hasClassDescription = true
|
|
2359
|
-
node.clDesc = desc
|
|
2360
|
-
desc.classNode = node
|
|
2361
|
-
}
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
fn walkFunctionBody (m@(lives):RangerAppFunctionDesc fnBody:CodeNode ctx:RangerAppWriterContext subCtx:RangerAppWriterContext wr:CodeWriter) {
|
|
2365
|
-
def prev_fnc subCtx.function_level_context
|
|
2366
|
-
def prev_isfn subCtx.is_function
|
|
2367
|
-
subCtx.function_level_context = true
|
|
2368
|
-
subCtx.is_function = true
|
|
2369
|
-
subCtx.currentMethod = m
|
|
2370
|
-
for m.params v@(lives):RangerAppParamDesc i {
|
|
2371
|
-
if( false == (subCtx.isVarDefined(v.name)) ) {
|
|
2372
|
-
subCtx.defineVariable(v.name v)
|
|
2373
|
-
}
|
|
2374
|
-
v.nameNode.eval_type = (v.nameNode.typeNameAsType(subCtx))
|
|
2375
|
-
v.nameNode.eval_type_name = v.nameNode.type_name
|
|
2376
|
-
ctx.hadValidType( (unwrap v.nameNode) )
|
|
2377
|
-
|
|
2378
|
-
if( (ctx.isDefinedClass(v.nameNode.type_name)) ) {
|
|
2379
|
-
def cl (ctx.findClass(v.nameNode.type_name))
|
|
2380
|
-
m.addClassUsage( cl ctx )
|
|
2381
|
-
}
|
|
2382
|
-
if( (ctx.isDefinedClass(v.nameNode.array_type)) ) {
|
|
2383
|
-
def cl (ctx.findClass(v.nameNode.array_type))
|
|
2384
|
-
m.addClassUsage( cl ctx )
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
subCtx.setInMethod()
|
|
2388
|
-
this.WalkNodeChildren(fnBody subCtx wr)
|
|
2389
|
-
subCtx.unsetInMethod()
|
|
2390
|
-
if (fnBody.didReturnAtIndex == -1) {
|
|
2391
|
-
if (m.nameNode.type_name != "void") {
|
|
2392
|
-
if( false == (ctx.getFlag("in_task")) ) {
|
|
2393
|
-
ctx.addError( (unwrap m.nameNode) "Function does not return any values!")
|
|
2394
|
-
}
|
|
2395
|
-
}
|
|
2396
|
-
} {
|
|
2397
|
-
if( (m.nameNode.type_name == "void") || ( (has m.nameNode.type_name) == false ) && ( (has m.nameNode.array_type) == false ) ) {
|
|
2398
|
-
if( false == (ctx.getFlag("in_task")) ) {
|
|
2399
|
-
def rvNode ( at fnBody.children fnBody.didReturnAtIndex)
|
|
2400
|
-
if( (size rvNode.children ) > 1) {
|
|
2401
|
-
ctx.addError( (unwrap m.nameNode) "No return value type defined for a function which returns value")
|
|
2402
|
-
ctx.addError( rvNode "Returning value from a function without set return value")
|
|
2403
|
-
}
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
}
|
|
2407
|
-
for subCtx.localVarNames n:string i {
|
|
2408
|
-
def p:RangerAppParamDesc (get subCtx.localVariables n)
|
|
2409
|
-
if (p.set_cnt > 0) {
|
|
2410
|
-
if(p.is_immutable) {
|
|
2411
|
-
ctx.addError( (unwrap p.nameNode) "Immutable variable was assigned a value")
|
|
2412
|
-
}
|
|
2413
|
-
def defNode:CodeNode p.node
|
|
2414
|
-
defNode.setFlag("mutable")
|
|
2415
|
-
def nNode:CodeNode p.nameNode
|
|
2416
|
-
nNode.setFlag("mutable")
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
|
-
; subCtx.function_level_context = prev_fnc
|
|
2420
|
-
; subCtx.is_function = prev_isfn
|
|
2421
|
-
}
|
|
2422
|
-
|
|
2423
|
-
fn EnterMethod:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
2424
|
-
this.EnterFn(node ctx wr {
|
|
2425
|
-
def m@(lives) (unwrap (desc.findMethod(nameNode.vref)))
|
|
2426
|
-
def subCtx:RangerAppWriterContext (unwrap m.fnCtx)
|
|
2427
|
-
this.walkFunctionBody( m fnBody ctx subCtx wr)
|
|
2428
|
-
})
|
|
2429
|
-
}
|
|
2430
|
-
fn EnterStaticMethod:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
2431
|
-
this.EnterFn(node ctx wr {
|
|
2432
|
-
def m@(lives) (unwrap (desc.findStaticMethod(nameNode.vref)))
|
|
2433
|
-
def subCtx (ctx.fork())
|
|
2434
|
-
m.fnCtx = subCtx
|
|
2435
|
-
subCtx.in_static_method = true
|
|
2436
|
-
this.walkFunctionBody( m fnBody ctx subCtx wr)
|
|
2437
|
-
subCtx.in_static_method = false
|
|
2438
|
-
})
|
|
2439
|
-
}
|
|
2440
|
-
|
|
2441
|
-
; (=> _ * 10)
|
|
2442
|
-
; (=> _1 + _2 * 10)
|
|
2443
|
-
; (=> () )
|
|
2444
|
-
; --->?
|
|
2445
|
-
|
|
2446
|
-
fn DefineArrowOpFn:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
2447
|
-
|
|
2448
|
-
; (# print '' + _1)
|
|
2449
|
-
def myName (ctx.createNewOpFnName())
|
|
2450
|
-
def argsNode (r.expression)
|
|
2451
|
-
def fBody (node.copy())
|
|
2452
|
-
remove fBody.children 0
|
|
2453
|
-
def opNode@(lives) (r.expression (r.vref 'defn') (r.vref myName ) argsNode fBody )
|
|
2454
|
-
|
|
2455
|
-
; (_arg1 _arg2)
|
|
2456
|
-
def setArg (fn:void (idx:int) {
|
|
2457
|
-
def i (size argsNode.children )
|
|
2458
|
-
while( i <= idx ) {
|
|
2459
|
-
push argsNode.children (r.vref (myName + '_arg' + i) )
|
|
2460
|
-
i = i + 1
|
|
2461
|
-
}
|
|
2462
|
-
})
|
|
2463
|
-
fBody.forTree({
|
|
2464
|
-
|
|
2465
|
-
; note: should be recursive...
|
|
2466
|
-
item.attrs.forEach({
|
|
2467
|
-
item.forTree({
|
|
2468
|
-
if(has item.vref) {
|
|
2469
|
-
if(item.vref == '_') {
|
|
2470
|
-
setArg(0)
|
|
2471
|
-
item.vref = (myName + '_arg0')
|
|
2472
|
-
}
|
|
2473
|
-
def parts (strsplit item.vref '_')
|
|
2474
|
-
if( (size parts) == 2) {
|
|
2475
|
-
def rest (at parts 1)
|
|
2476
|
-
def nbr (to_int rest)
|
|
2477
|
-
if(!null? nbr) {
|
|
2478
|
-
def n (unwrap nbr)
|
|
2479
|
-
setArg( (n - 1))
|
|
2480
|
-
item.vref = (myName + '_arg' + (n - 1))
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
}
|
|
2484
|
-
})
|
|
2485
|
-
}))
|
|
2486
|
-
|
|
2487
|
-
if(has item.vref) {
|
|
2488
|
-
if(item.vref == '_') {
|
|
2489
|
-
setArg(0)
|
|
2490
|
-
item.vref = (myName + '_arg0')
|
|
2491
|
-
}
|
|
2492
|
-
def parts (strsplit item.vref '_')
|
|
2493
|
-
if( (size parts) == 2) {
|
|
2494
|
-
def rest (at parts 1)
|
|
2495
|
-
def nbr (to_int rest)
|
|
2496
|
-
if(!null? nbr) {
|
|
2497
|
-
def n (unwrap nbr)
|
|
2498
|
-
setArg( (n - 1))
|
|
2499
|
-
item.vref = (myName + '_arg' + (n - 1))
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
}
|
|
2503
|
-
})
|
|
2504
|
-
ctx.addOpFn( myName opNode )
|
|
2505
|
-
clear node.children
|
|
2506
|
-
node.vref = myName
|
|
2507
|
-
node.expression = false
|
|
2508
|
-
}
|
|
2509
|
-
|
|
2510
|
-
fn DefineOpFn:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
2511
|
-
; defn inc (x) (x + 1)
|
|
2512
|
-
if( (size node.children ) < 4) {
|
|
2513
|
-
ctx.addError(node 'invalid operator function')
|
|
2514
|
-
return
|
|
2515
|
-
}
|
|
2516
|
-
def fnName (at node.children 1)
|
|
2517
|
-
if(! (has fnName.vref)) {
|
|
2518
|
-
ctx.addError(node 'operator function has no name')
|
|
2519
|
-
return
|
|
2520
|
-
}
|
|
2521
|
-
; print "OP -> " + (node.getCode())
|
|
2522
|
-
ctx.addOpFn( fnName.vref node )
|
|
2523
|
-
; set ctx.opFns fnName.vref node
|
|
2524
|
-
node.disabled_node = true
|
|
2525
|
-
node.flow_done = true
|
|
2526
|
-
}
|
|
2527
|
-
|
|
2528
|
-
; returns the evaluated codenodes for the parameters in this compilation...
|
|
2529
|
-
fn testCompile@(weak):[string:CodeNode] (opFn:CodeNode node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
2530
|
-
|
|
2531
|
-
def ok false
|
|
2532
|
-
def rootCtx (ctx.getRoot())
|
|
2533
|
-
def errCnt (size rootCtx.compilerErrors)
|
|
2534
|
-
|
|
2535
|
-
def opParams (at opFn.children 2)
|
|
2536
|
-
def opBody (at opFn.children 3)
|
|
2537
|
-
def xValue (node.copy())
|
|
2538
|
-
remove xValue.children 0 ; (inc 1) -> (1)
|
|
2539
|
-
|
|
2540
|
-
; collect the actual function parameters so that they can be placed
|
|
2541
|
-
; into registers...
|
|
2542
|
-
def regToArg@(weak lives):[string:CodeNode]
|
|
2543
|
-
def am@(lives) (new RangerArgMatch)
|
|
2544
|
-
opParams.parallelTree( xValue {
|
|
2545
|
-
if( (!null? left) && (!null? right) ) {
|
|
2546
|
-
if(has left.vref) {
|
|
2547
|
-
def v (unwrap right)
|
|
2548
|
-
if v.expression {
|
|
2549
|
-
set regToArg left.vref (unwrap right)
|
|
2550
|
-
}
|
|
2551
|
-
set am.nodes left.vref (unwrap right)
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2554
|
-
})
|
|
2555
|
-
|
|
2556
|
-
; print "xValue " + (xValue.getCode())
|
|
2557
|
-
; print "params " + (opParams.getCode())
|
|
2558
|
-
def opParamSet:[string:boolean]
|
|
2559
|
-
def regParams:[string:boolean]
|
|
2560
|
-
def regNames:[string:string]
|
|
2561
|
-
; IMPORTANT: do not process if this node has already been made to register
|
|
2562
|
-
if(! ( has node.register_name ) ) {
|
|
2563
|
-
opBody.forTree({
|
|
2564
|
-
if(has regToArg item.vref) {
|
|
2565
|
-
if(has opParamSet item.vref) {
|
|
2566
|
-
if(! (has regParams item.vref) ) {
|
|
2567
|
-
def realArg (unwrap (get regToArg item.vref))
|
|
2568
|
-
if( has realArg.register_name ) {
|
|
2569
|
-
|
|
2570
|
-
} {
|
|
2571
|
-
def regName = (ctx.createNewRegName())
|
|
2572
|
-
set regNames item.vref regName
|
|
2573
|
-
def argCopy (realArg.copy())
|
|
2574
|
-
def regExpr (r.expression (r.vref 'def') (r.vref regName) argCopy)
|
|
2575
|
-
this.WalkNode( regExpr ctx wr )
|
|
2576
|
-
def regArg (at regExpr.children 1)
|
|
2577
|
-
def realRegName ( (at regExpr.children 1) .paramDesc.compiledName )
|
|
2578
|
-
regArg.paramDesc.set_cnt = 1
|
|
2579
|
-
regArg.paramDesc.ref_cnt = 1
|
|
2580
|
-
|
|
2581
|
-
def BlockOP (ctx.getLastBlockOp())
|
|
2582
|
-
BlockOP.register_expressions.push( regExpr )
|
|
2583
|
-
|
|
2584
|
-
; realArg.register_expressions.push( regExpr )
|
|
2585
|
-
realArg.register_name = regName
|
|
2586
|
-
realArg.reg_compiled_name = realRegName
|
|
2587
|
-
}
|
|
2588
|
-
|
|
2589
|
-
}
|
|
2590
|
-
set regParams item.vref true
|
|
2591
|
-
}
|
|
2592
|
-
set opParamSet item.vref true
|
|
2593
|
-
}
|
|
2594
|
-
})
|
|
2595
|
-
}
|
|
2596
|
-
|
|
2597
|
-
def bodyCopy (opBody.copy())
|
|
2598
|
-
|
|
2599
|
-
def newNode (opBody.rebuildWithType(am true))
|
|
2600
|
-
|
|
2601
|
-
clear node.children
|
|
2602
|
-
forEach newNode.children {
|
|
2603
|
-
def tmp@(lives) item
|
|
2604
|
-
push node.children tmp
|
|
2605
|
-
}
|
|
2606
|
-
; node.getChildrenFrom( newNode )
|
|
2607
|
-
node.flow_done = false
|
|
2608
|
-
|
|
2609
|
-
if(opBody.is_block_node) {
|
|
2610
|
-
print "Block -> " + (opBody.getCode())
|
|
2611
|
-
def blockCtx (ctx.fork())
|
|
2612
|
-
blockCtx.newBlock()
|
|
2613
|
-
this.WalkNode( node blockCtx wr )
|
|
2614
|
-
} {
|
|
2615
|
-
this.WalkNode( node ctx wr )
|
|
2616
|
-
}
|
|
2617
|
-
|
|
2618
|
-
;; -- test compile cutted part was here
|
|
2619
|
-
|
|
2620
|
-
; am.nodes.forEach({
|
|
2621
|
-
; print " - " + index + " --> " + item.eval_type
|
|
2622
|
-
; })
|
|
2623
|
-
|
|
2624
|
-
return am.builtNodes
|
|
2625
|
-
}
|
|
2626
|
-
|
|
2627
|
-
; transforms a node
|
|
2628
|
-
; origNode has the syntax (opname x y z)
|
|
2629
|
-
; against given operator definition nodes in opFnList in format
|
|
2630
|
-
; defn someOp (x) (x + 1)
|
|
2631
|
-
;
|
|
2632
|
-
def infinite_recursion false
|
|
2633
|
-
def match_types:[string:string]
|
|
2634
|
-
|
|
2635
|
-
fn TransformOpFn:void (opFnList:[CodeNode] origNode:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
2636
|
-
|
|
2637
|
-
if infinite_recursion {
|
|
2638
|
-
return
|
|
2639
|
-
}
|
|
2640
|
-
def ok false
|
|
2641
|
-
def rootCtx (ctx.getRoot())
|
|
2642
|
-
def errCnt (size rootCtx.compilerErrors)
|
|
2643
|
-
|
|
2644
|
-
def use_delta true
|
|
2645
|
-
|
|
2646
|
-
def least_err_cnt 99999
|
|
2647
|
-
def least_errs:[RangerCompilerMessage]
|
|
2648
|
-
|
|
2649
|
-
def depth (transaction_depth 'TransformOpFn' ctx)
|
|
2650
|
-
|
|
2651
|
-
if( depth > 20 ) {
|
|
2652
|
-
ctx.addError( origNode 'Error: recursive operator function detected')
|
|
2653
|
-
infinite_recursion = true
|
|
2654
|
-
return
|
|
2655
|
-
}
|
|
2656
|
-
|
|
2657
|
-
; print "Depth : " + (transaction_depth 'TransformOpFn' ctx)
|
|
2658
|
-
|
|
2659
|
-
if( has origNode.register_name ) {
|
|
2660
|
-
if( ctx.isVarDefined( origNode.register_name )) {
|
|
2661
|
-
def regInfo (ctx.getVariableDef(origNode.register_name))
|
|
2662
|
-
if(!null? regInfo.nameNode ) {
|
|
2663
|
-
origNode.copyEvalResFrom( (unwrap regInfo.nameNode) )
|
|
2664
|
-
return
|
|
2665
|
-
} {
|
|
2666
|
-
; ctx.addError( origNode ('compiler error: could not find temporary register ' + origNode.register_name) )
|
|
2667
|
-
}
|
|
2668
|
-
} {
|
|
2669
|
-
; ctx.addError( origNode ('compiler error: could not find temporary register ' + origNode.register_name) )
|
|
2670
|
-
}
|
|
2671
|
-
; return
|
|
2672
|
-
}
|
|
2673
|
-
|
|
2674
|
-
def fc (at origNode.children 0)
|
|
2675
|
-
; print "--> " + fc.vref + ", depth : " + (transaction_depth 'TransformOpFn' ctx)
|
|
2676
|
-
; print (origNode.getCode())
|
|
2677
|
-
def myT (start_transaction 'TransformOpFn' fc.vref ctx)
|
|
2678
|
-
|
|
2679
|
-
def newOps:[CodeNode]
|
|
2680
|
-
|
|
2681
|
-
def tryTypes ([] 'string' 'int' 'double' 'boolean')
|
|
2682
|
-
|
|
2683
|
-
def codeStrHash (origNode.getSource())
|
|
2684
|
-
if( has match_types codeStrHash) {
|
|
2685
|
-
insert tryTypes 0 (unwrap (get match_types codeStrHash))
|
|
2686
|
-
}
|
|
2687
|
-
|
|
2688
|
-
def cList (reverse ( (ctx.getRoot()) .getClasses()))
|
|
2689
|
-
cList.forEach({
|
|
2690
|
-
if( (item.isNormalClass()) || (item.is_system) ) {
|
|
2691
|
-
if( (indexOf codeStrHash item.name) >= 0) {
|
|
2692
|
-
insert tryTypes 0 item.name
|
|
2693
|
-
} {
|
|
2694
|
-
push tryTypes item.name
|
|
2695
|
-
}
|
|
2696
|
-
}
|
|
2697
|
-
})
|
|
2698
|
-
|
|
2699
|
-
; print codeStrHash
|
|
2700
|
-
; print "try order : " + (join tryTypes ",")
|
|
2701
|
-
|
|
2702
|
-
opFnList.forEach({
|
|
2703
|
-
def had_v false
|
|
2704
|
-
item.forTree({
|
|
2705
|
-
if(item.array_type == '?' || item.key_type == '?' || item.type_name == '?') {
|
|
2706
|
-
had_v = true
|
|
2707
|
-
}
|
|
2708
|
-
})
|
|
2709
|
-
if had_v {
|
|
2710
|
-
|
|
2711
|
-
def opFn (item.copy())
|
|
2712
|
-
def opParams (at opFn.children 2)
|
|
2713
|
-
def opBody (at opFn.children 3)
|
|
2714
|
-
|
|
2715
|
-
def typeName ""
|
|
2716
|
-
tryTypes.forEach({
|
|
2717
|
-
def copyOfFn (opFn.copy())
|
|
2718
|
-
typeName = item
|
|
2719
|
-
copyOfFn.forTree({
|
|
2720
|
-
if(item.array_type == '?') {
|
|
2721
|
-
item.array_type = typeName
|
|
2722
|
-
}
|
|
2723
|
-
if(item.key_type == '?') {
|
|
2724
|
-
item.key_type = typeName
|
|
2725
|
-
}
|
|
2726
|
-
if(item.type_name == '?') {
|
|
2727
|
-
item.type_name = typeName
|
|
2728
|
-
}
|
|
2729
|
-
})
|
|
2730
|
-
copyOfFn.matched_type = typeName
|
|
2731
|
-
push newOps copyOfFn
|
|
2732
|
-
})
|
|
2733
|
-
}
|
|
2734
|
-
|
|
2735
|
-
})
|
|
2736
|
-
|
|
2737
|
-
if( (size newOps) > 0) {
|
|
2738
|
-
; print "now has " + (size newOps) + " variants "
|
|
2739
|
-
forEach newOps {
|
|
2740
|
-
def tmp@(temp) item
|
|
2741
|
-
push opFnList item
|
|
2742
|
-
}
|
|
2743
|
-
}
|
|
2744
|
-
|
|
2745
|
-
def oNodeParams (size origNode.children)
|
|
2746
|
-
filter opFnList {
|
|
2747
|
-
def opParams (at item.children 2)
|
|
2748
|
-
return (oNodeParams == ( (size opParams.children) - 1) )
|
|
2749
|
-
}
|
|
2750
|
-
|
|
2751
|
-
opFnList.forEach({
|
|
2752
|
-
if ok {
|
|
2753
|
-
return
|
|
2754
|
-
} {
|
|
2755
|
-
; if last round did not work, try again...
|
|
2756
|
-
def currentErrCnt (size rootCtx.compilerErrors)
|
|
2757
|
-
def errDelta ( currentErrCnt - errCnt )
|
|
2758
|
-
if( errDelta > 0) {
|
|
2759
|
-
if( errDelta < least_err_cnt ) {
|
|
2760
|
-
least_err_cnt = errDelta
|
|
2761
|
-
def i errCnt
|
|
2762
|
-
clear least_errs
|
|
2763
|
-
while( i < currentErrCnt) {
|
|
2764
|
-
def tmp@(temp) (at rootCtx.compilerErrors i)
|
|
2765
|
-
push least_errs tmp
|
|
2766
|
-
i = i + 1
|
|
2767
|
-
}
|
|
2768
|
-
}
|
|
2769
|
-
def i errCnt
|
|
2770
|
-
while( i < currentErrCnt) {
|
|
2771
|
-
removeLast rootCtx.compilerErrors
|
|
2772
|
-
i = i + 1
|
|
2773
|
-
}
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
|
|
2777
|
-
def originalOpFn item
|
|
2778
|
-
def node (origNode.copy())
|
|
2779
|
-
def opFn item
|
|
2780
|
-
def opParams (at opFn.children 2)
|
|
2781
|
-
def opBody (at opFn.children 3)
|
|
2782
|
-
def xValue (node.copy())
|
|
2783
|
-
remove xValue.children 0 ; (inc 1) -> (1)
|
|
2784
|
-
|
|
2785
|
-
opBody.forTree({
|
|
2786
|
-
if(item.vref == 'return') {
|
|
2787
|
-
; ctx.addError( item 'Return keyword is not allowed in defn macros')
|
|
2788
|
-
}
|
|
2789
|
-
})
|
|
2790
|
-
|
|
2791
|
-
; collect the actual function parameters so that they can be placed
|
|
2792
|
-
; into registers...
|
|
2793
|
-
def regToArg@(weak):[string:CodeNode]
|
|
2794
|
-
def am@(lives) (new RangerArgMatch)
|
|
2795
|
-
opParams.parallelTree( xValue {
|
|
2796
|
-
if( (!null? left) && (!null? right) ) {
|
|
2797
|
-
if(has left.vref) {
|
|
2798
|
-
def v (unwrap right)
|
|
2799
|
-
if v.expression {
|
|
2800
|
-
set regToArg left.vref (unwrap right)
|
|
2801
|
-
}
|
|
2802
|
-
set am.nodes left.vref (unwrap right)
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
})
|
|
2806
|
-
|
|
2807
|
-
; print "xValue " + (xValue.getCode())
|
|
2808
|
-
; print "params " + (opParams.getCode())
|
|
2809
|
-
def opParamSet:[string:boolean]
|
|
2810
|
-
def regParams:[string:boolean]
|
|
2811
|
-
def regNames:[string:string]
|
|
2812
|
-
|
|
2813
|
-
def BlockOP (ctx.getLastBlockOp())
|
|
2814
|
-
def newDefNodes:[CodeNode]
|
|
2815
|
-
def newRNodes:[CodeNode]
|
|
2816
|
-
|
|
2817
|
-
; IMPORTANT: do not process if this node has already been made to register
|
|
2818
|
-
if(! ( has node.register_name ) ) {
|
|
2819
|
-
opBody.forTree({
|
|
2820
|
-
if(has regToArg item.vref) {
|
|
2821
|
-
if(has opParamSet item.vref) {
|
|
2822
|
-
if(! (has regParams item.vref) ) {
|
|
2823
|
-
def realArg (unwrap (get regToArg item.vref))
|
|
2824
|
-
if( has realArg.register_name ) {
|
|
2825
|
-
|
|
2826
|
-
} {
|
|
2827
|
-
|
|
2828
|
-
def regName = (ctx.createNewRegName())
|
|
2829
|
-
set regNames item.vref regName
|
|
2830
|
-
def argCopy (realArg.copy())
|
|
2831
|
-
def regExpr@(temp lives) (r.expression (r.vref 'def') (r.vref regName) argCopy)
|
|
2832
|
-
|
|
2833
|
-
; *** Walk the Def and move expressions which are dynamically created into newRNodes
|
|
2834
|
-
; list so that we can decide if this compilation was a test run prevent those lines
|
|
2835
|
-
; to be added
|
|
2836
|
-
def cnt (size BlockOP.register_expressions)
|
|
2837
|
-
; ctx.setTestCompile()
|
|
2838
|
-
|
|
2839
|
-
this.WalkNode( regExpr ctx wr )
|
|
2840
|
-
; ctx.unsetTestCompile()
|
|
2841
|
-
def opCntDelta ((size BlockOP.register_expressions) - cnt)
|
|
2842
|
-
|
|
2843
|
-
if(use_delta && opCntDelta > 0 ) {
|
|
2844
|
-
def opCnt (size BlockOP.register_expressions)
|
|
2845
|
-
def i cnt
|
|
2846
|
-
while( i < opCnt ) {
|
|
2847
|
-
def tmp@(temp) (at BlockOP.register_expressions i)
|
|
2848
|
-
push newRNodes tmp
|
|
2849
|
-
i = i + 1
|
|
2850
|
-
}
|
|
2851
|
-
i = cnt
|
|
2852
|
-
while( i < opCnt ) {
|
|
2853
|
-
removeLast BlockOP.register_expressions
|
|
2854
|
-
i = i + 1
|
|
2855
|
-
}
|
|
2856
|
-
}
|
|
2857
|
-
|
|
2858
|
-
def regArg (at regExpr.children 1)
|
|
2859
|
-
def realRegName ( (at regExpr.children 1) .paramDesc.compiledName )
|
|
2860
|
-
regArg.paramDesc.set_cnt = 1
|
|
2861
|
-
regArg.paramDesc.ref_cnt = 1
|
|
2862
|
-
|
|
2863
|
-
if use_delta {
|
|
2864
|
-
push newRNodes regExpr
|
|
2865
|
-
} {
|
|
2866
|
-
def BlockOP (ctx.getLastBlockOp())
|
|
2867
|
-
BlockOP.register_expressions.push( regExpr )
|
|
2868
|
-
}
|
|
2869
|
-
realArg.register_name = regName
|
|
2870
|
-
realArg.reg_compiled_name = realRegName
|
|
2871
|
-
}
|
|
2872
|
-
|
|
2873
|
-
}
|
|
2874
|
-
set regParams item.vref true
|
|
2875
|
-
}
|
|
2876
|
-
set opParamSet item.vref true
|
|
2877
|
-
}
|
|
2878
|
-
})
|
|
2879
|
-
}
|
|
2880
|
-
|
|
2881
|
-
def newNode (opBody.rebuildWithType(am true))
|
|
2882
|
-
node.getChildrenFrom( newNode )
|
|
2883
|
-
node.flow_done = false
|
|
2884
|
-
|
|
2885
|
-
; if( (size xValue.children ) != (size opParams.children) ) {
|
|
2886
|
-
; ctx.addError( origNode 'Invalid arg count')
|
|
2887
|
-
;}
|
|
2888
|
-
|
|
2889
|
-
ctx.setTestCompile()
|
|
2890
|
-
|
|
2891
|
-
if(opBody.is_block_node) {
|
|
2892
|
-
; print "Block -> " + (opBody.getCode())
|
|
2893
|
-
def blockCtx (ctx.fork())
|
|
2894
|
-
blockCtx.newBlock()
|
|
2895
|
-
this.WalkNode( node blockCtx wr )
|
|
2896
|
-
} {
|
|
2897
|
-
this.WalkNode( node ctx wr )
|
|
2898
|
-
}
|
|
2899
|
-
|
|
2900
|
-
if( errCnt == (size rootCtx.compilerErrors) ) {
|
|
2901
|
-
ctx.unsetTestCompile()
|
|
2902
|
-
|
|
2903
|
-
if(has originalOpFn.matched_type) {
|
|
2904
|
-
set match_types codeStrHash originalOpFn.matched_type
|
|
2905
|
-
; print "--> had matched type " + originalOpFn.matched_type
|
|
2906
|
-
; origNode.matched_type = originalOpFn.matched_type
|
|
2907
|
-
}
|
|
2908
|
-
|
|
2909
|
-
; matched_type
|
|
2910
|
-
|
|
2911
|
-
if(! (ctx.isTestCompile() ) ) {
|
|
2912
|
-
forEach newDefNodes {
|
|
2913
|
-
def tmp@(temp) item
|
|
2914
|
-
push BlockOP.register_expressions tmp
|
|
2915
|
-
}
|
|
2916
|
-
forEach newRNodes {
|
|
2917
|
-
def tmp@(temp) item
|
|
2918
|
-
push BlockOP.register_expressions tmp
|
|
2919
|
-
}
|
|
2920
|
-
}
|
|
2921
|
-
|
|
2922
|
-
ok = true
|
|
2923
|
-
def newNode (opBody.rebuildWithType(am true))
|
|
2924
|
-
origNode.getChildrenFrom( newNode )
|
|
2925
|
-
origNode.flow_done = false
|
|
2926
|
-
if(opBody.is_block_node) {
|
|
2927
|
-
def blockCtx (ctx.fork())
|
|
2928
|
-
blockCtx.newBlock()
|
|
2929
|
-
this.WalkNode( origNode blockCtx wr )
|
|
2930
|
-
def lastLine (last origNode.children)
|
|
2931
|
-
|
|
2932
|
-
if( (lastLine.isFirstVref('ret')) || (has lastLine.eval_array_type ) || ( (has lastLine.eval_type_name) && (lastLine.eval_type_name != 'void') ) ) {
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
def argVal (at lastLine.children 1)
|
|
2936
|
-
|
|
2937
|
-
this.WalkNode( argVal blockCtx wr )
|
|
2938
|
-
|
|
2939
|
-
; print "arg val --> " + (argVal.getCode()) + " reg " + argVal.register_name
|
|
2940
|
-
origNode.copyEvalResFrom( argVal )
|
|
2941
|
-
|
|
2942
|
-
def regName = (ctx.createNewRegName())
|
|
2943
|
-
set regNames item.vref regName
|
|
2944
|
-
def argCopy (argVal.copy())
|
|
2945
|
-
def nameNode (r.vref regName)
|
|
2946
|
-
|
|
2947
|
-
nameNode.value_type = origNode.eval_type
|
|
2948
|
-
nameNode.type_name = origNode.eval_type_name
|
|
2949
|
-
nameNode.array_type = origNode.eval_array_type
|
|
2950
|
-
nameNode.key_type = origNode.eval_key_type
|
|
2951
|
-
|
|
2952
|
-
if(argVal.eval_type == RangerNodeType.ExpressionType) {
|
|
2953
|
-
if(!null? argVal.expression_value) {
|
|
2954
|
-
nameNode.expression_value = (argVal.expression_value.copy())
|
|
2955
|
-
} {
|
|
2956
|
-
nameNode.expression_value = (argVal.copy())
|
|
2957
|
-
}
|
|
2958
|
-
}
|
|
2959
|
-
;if(!null? argVal.expression_value) {
|
|
2960
|
-
; nameNode.expression_value = (argVal.expression_value.copy())
|
|
2961
|
-
;}
|
|
2962
|
-
|
|
2963
|
-
; note: must set this flag to force unwrap, otherwise the node will be optional
|
|
2964
|
-
nameNode.setFlag('unwrap')
|
|
2965
|
-
|
|
2966
|
-
def regExpr (r.expression (r.vref 'def') nameNode)
|
|
2967
|
-
|
|
2968
|
-
; print "Defining " + (regExpr.getCode()) + " <- " + regName
|
|
2969
|
-
; print "Depth : " + (transaction_depth 'TransformOpFn' ctx)
|
|
2970
|
-
|
|
2971
|
-
this.WalkNode( regExpr ctx wr )
|
|
2972
|
-
def regArg (at regExpr.children 1)
|
|
2973
|
-
def realRegName ( (at regExpr.children 1) .paramDesc.compiledName )
|
|
2974
|
-
regArg.paramDesc.set_cnt = 1
|
|
2975
|
-
regArg.paramDesc.ref_cnt = 1
|
|
2976
|
-
|
|
2977
|
-
def BlockOP (ctx.getLastBlockOp())
|
|
2978
|
-
if(! (ctx.isTestCompile() ) ) {
|
|
2979
|
-
; print "adding regExpr to block " + (BlockOP.getCode())
|
|
2980
|
-
}
|
|
2981
|
-
|
|
2982
|
-
; realArg.register_expressions.push( regExpr )
|
|
2983
|
-
origNode.register_name = regName
|
|
2984
|
-
origNode.reg_compiled_name = realRegName
|
|
2985
|
-
|
|
2986
|
-
lastLine.flow_done = false
|
|
2987
|
-
clear lastLine.children
|
|
2988
|
-
lastLine.getChildrenFrom( (r.expression (r.vref '=') (r.vref regName) argCopy ) )
|
|
2989
|
-
|
|
2990
|
-
def regE (at regExpr.children 1)
|
|
2991
|
-
; print "Defining 'lastline' -> " + (lastLine.getCode()) + " <- " + regName
|
|
2992
|
-
|
|
2993
|
-
this.WalkNode( lastLine blockCtx wr)
|
|
2994
|
-
|
|
2995
|
-
;; def nn (blockCtx.getVariableDef(regName))
|
|
2996
|
-
|
|
2997
|
-
;; print "regname --> " + (nn.getCode())
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
def myBlock (r.expression)
|
|
3001
|
-
myBlock.getChildrenFrom( origNode )
|
|
3002
|
-
if(! (ctx.isTestCompile() ) ) {
|
|
3003
|
-
insert myBlock.children 0 regExpr
|
|
3004
|
-
; push myBlock.register_expressions regExpr
|
|
3005
|
-
push BlockOP.register_expressions myBlock
|
|
3006
|
-
}
|
|
3007
|
-
clear origNode.children
|
|
3008
|
-
origNode.flow_done = true
|
|
3009
|
-
}
|
|
3010
|
-
} {
|
|
3011
|
-
this.WalkNode( origNode ctx wr )
|
|
3012
|
-
origNode.flow_done = true
|
|
3013
|
-
}
|
|
3014
|
-
} {
|
|
3015
|
-
ctx.unsetTestCompile()
|
|
3016
|
-
}
|
|
3017
|
-
|
|
3018
|
-
})
|
|
3019
|
-
|
|
3020
|
-
def depth (transaction_depth 'TransformOpFn' ctx)
|
|
3021
|
-
|
|
3022
|
-
def errDelta ( (size rootCtx.compilerErrors) - errCnt )
|
|
3023
|
-
def currentErrCnt (size rootCtx.compilerErrors)
|
|
3024
|
-
def errDelta ( currentErrCnt - errCnt )
|
|
3025
|
-
if( errDelta > 0 ) {
|
|
3026
|
-
if( errDelta < least_err_cnt ) {
|
|
3027
|
-
def i errCnt
|
|
3028
|
-
clear least_errs
|
|
3029
|
-
while( i < currentErrCnt) {
|
|
3030
|
-
def tmp@(temp) (at rootCtx.compilerErrors i)
|
|
3031
|
-
push least_errs tmp
|
|
3032
|
-
i = i + 1
|
|
3033
|
-
}
|
|
3034
|
-
}
|
|
3035
|
-
def i errCnt
|
|
3036
|
-
while( i < currentErrCnt) {
|
|
3037
|
-
removeLast rootCtx.compilerErrors
|
|
3038
|
-
i = i + 1
|
|
3039
|
-
}
|
|
3040
|
-
}
|
|
3041
|
-
|
|
3042
|
-
if(errDelta > 0 ) {
|
|
3043
|
-
least_errs.forEach({
|
|
3044
|
-
def tmp@(temp) item
|
|
3045
|
-
push rootCtx.compilerErrors tmp
|
|
3046
|
-
})
|
|
3047
|
-
print "^ had errors..."
|
|
3048
|
-
ctx.addError( origNode 'Could not find suitable match for the operator node' )
|
|
3049
|
-
}
|
|
3050
|
-
|
|
3051
|
-
if infinite_recursion {
|
|
3052
|
-
ctx.addError( origNode 'Error: max recursiion depth of > 20 for inline operators detected')
|
|
3053
|
-
}
|
|
3054
|
-
|
|
3055
|
-
end_transaction myT
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
}
|
|
3059
|
-
|
|
3060
|
-
fn cmdArray:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3061
|
-
|
|
3062
|
-
; ([] _:int (2 3 4 5))
|
|
3063
|
-
if( (size node.children ) == 3 ) {
|
|
3064
|
-
def sc (node.getSecond())
|
|
3065
|
-
if( ( (strlen sc.vref) > 0 ) && ( (strlen sc.type_name ) > 0 ) ) {
|
|
3066
|
-
node.eval_array_type = sc.type_name
|
|
3067
|
-
node.eval_type = RangerNodeType.Array
|
|
3068
|
-
def items (node.getThird())
|
|
3069
|
-
def b_union false
|
|
3070
|
-
def union_types@(weak temp):[string]
|
|
3071
|
-
if( ctx.isDefinedClass( sc.type_name)) {
|
|
3072
|
-
def cl (ctx.findClass( sc.type_name))
|
|
3073
|
-
if(cl.is_union) {
|
|
3074
|
-
b_union = true
|
|
3075
|
-
union_types = cl.is_union_of
|
|
3076
|
-
}
|
|
3077
|
-
}
|
|
3078
|
-
def arrayItems (node.newExpressionNode())
|
|
3079
|
-
for items.children it:CodeNode i {
|
|
3080
|
-
def itemCopy (it.copy())
|
|
3081
|
-
this.WalkNode( itemCopy ctx wr )
|
|
3082
|
-
if( itemCopy.eval_type_name != sc.type_name ) {
|
|
3083
|
-
if( b_union ) {
|
|
3084
|
-
if( (indexOf union_types itemCopy.eval_type_name) >= 0 ) {
|
|
3085
|
-
; OK
|
|
3086
|
-
} {
|
|
3087
|
-
ctx.addError( it ( itemCopy.eval_type_name + " is Not part of union " + sc.type_name ) )
|
|
3088
|
-
break
|
|
3089
|
-
}
|
|
3090
|
-
} {
|
|
3091
|
-
ctx.addError( it ( 'The array type should be ' + sc.type_name ) )
|
|
3092
|
-
break
|
|
3093
|
-
}
|
|
3094
|
-
}
|
|
3095
|
-
push arrayItems.children itemCopy
|
|
3096
|
-
}
|
|
3097
|
-
node.getChildrenFrom( arrayItems )
|
|
3098
|
-
node.is_array_literal = true
|
|
3099
|
-
return
|
|
3100
|
-
}
|
|
3101
|
-
}
|
|
3102
|
-
|
|
3103
|
-
def arrayItems (node.newExpressionNode())
|
|
3104
|
-
def types:[string]
|
|
3105
|
-
for node.children it:CodeNode i {
|
|
3106
|
-
if( i == 0 ) {
|
|
3107
|
-
continue
|
|
3108
|
-
}
|
|
3109
|
-
def itemCopy (it.copy())
|
|
3110
|
-
this.WalkNode( itemCopy ctx wr )
|
|
3111
|
-
|
|
3112
|
-
if( (indexOf types itemCopy.eval_type_name) < 0 ) {
|
|
3113
|
-
push types itemCopy.eval_type_name
|
|
3114
|
-
}
|
|
3115
|
-
push arrayItems.children itemCopy
|
|
3116
|
-
}
|
|
3117
|
-
def typeCnt ( size types )
|
|
3118
|
-
if( typeCnt == 0 ) {
|
|
3119
|
-
ctx.addError( node "Invalid array types")
|
|
3120
|
-
return
|
|
3121
|
-
}
|
|
3122
|
-
node.eval_type = RangerNodeType.Array
|
|
3123
|
-
if( ( size types ) > 1 ) {
|
|
3124
|
-
node.eval_array_type = "Any"
|
|
3125
|
-
} {
|
|
3126
|
-
node.eval_array_type = (at types 0)
|
|
3127
|
-
}
|
|
3128
|
-
node.is_array_literal = true
|
|
3129
|
-
node.getChildrenFrom( arrayItems )
|
|
3130
|
-
}
|
|
3131
|
-
|
|
3132
|
-
fn EnterLambdaMethod:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3133
|
-
|
|
3134
|
-
def args:CodeNode (at node.children 1)
|
|
3135
|
-
def body@(lives):CodeNode (at node.children 2)
|
|
3136
|
-
def subCtx:RangerAppWriterContext (ctx.fork())
|
|
3137
|
-
|
|
3138
|
-
if(! args.expression ) {
|
|
3139
|
-
ctx.addError(node 'Invalid anonymous function: second param should be an expression')
|
|
3140
|
-
}
|
|
3141
|
-
|
|
3142
|
-
ctx.incLambdaCnt()
|
|
3143
|
-
subCtx.is_capturing = true
|
|
3144
|
-
|
|
3145
|
-
node.evalTypeClass = (TFactory.new_lambda_signature(node ctx wr))
|
|
3146
|
-
|
|
3147
|
-
def currM@(lives) (ctx.getCurrentMethod())
|
|
3148
|
-
|
|
3149
|
-
def cn:CodeNode (at node.children 0)
|
|
3150
|
-
def m@(lives):RangerAppFunctionDesc (new RangerAppFunctionDesc ())
|
|
3151
|
-
m.name = "lambda"
|
|
3152
|
-
m.node = node
|
|
3153
|
-
m.is_lambda = true
|
|
3154
|
-
m.nameNode = (at node.children 0)
|
|
3155
|
-
m.insideFn = currM
|
|
3156
|
-
|
|
3157
|
-
subCtx.newBlock()
|
|
3158
|
-
currM.myLambdas.push( m )
|
|
3159
|
-
|
|
3160
|
-
subCtx.is_function = true
|
|
3161
|
-
subCtx.currentMethod = m
|
|
3162
|
-
; m.fnCtx = subCtx
|
|
3163
|
-
if (cn.hasFlag("weak")) {
|
|
3164
|
-
m.changeStrength(0 1 node)
|
|
3165
|
-
} {
|
|
3166
|
-
m.changeStrength(1 1 node)
|
|
3167
|
-
}
|
|
3168
|
-
m.fnBody = (at node.children 2)
|
|
3169
|
-
for args.children arg@(lives):CodeNode ii {
|
|
3170
|
-
|
|
3171
|
-
this.CheckTypeAnnotationOf( arg subCtx wr )
|
|
3172
|
-
|
|
3173
|
-
def p2@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
|
|
3174
|
-
|
|
3175
|
-
p2.name = arg.vref
|
|
3176
|
-
p2.value_type = arg.value_type
|
|
3177
|
-
p2.node = arg
|
|
3178
|
-
p2.nameNode = arg
|
|
3179
|
-
p2.init_cnt = 1
|
|
3180
|
-
p2.refType = RangerNodeRefType.Weak
|
|
3181
|
-
p2.initRefType = RangerNodeRefType.Weak
|
|
3182
|
-
if (args.hasBooleanProperty("strong")) {
|
|
3183
|
-
p2.refType = RangerNodeRefType.Strong
|
|
3184
|
-
p2.initRefType = RangerNodeRefType.Strong
|
|
3185
|
-
}
|
|
3186
|
-
p2.varType = RangerContextVarType.FunctionParameter
|
|
3187
|
-
push m.params p2
|
|
3188
|
-
arg.hasParamDesc = true
|
|
3189
|
-
arg.paramDesc = p2
|
|
3190
|
-
arg.eval_type = arg.value_type
|
|
3191
|
-
arg.eval_type_name = arg.type_name
|
|
3192
|
-
if (arg.hasFlag("strong")) {
|
|
3193
|
-
p2.changeStrength(1 1 (unwrap p2.nameNode))
|
|
3194
|
-
} {
|
|
3195
|
-
arg.setFlag("lives")
|
|
3196
|
-
p2.changeStrength(0 1 (unwrap p2.nameNode))
|
|
3197
|
-
}
|
|
3198
|
-
; subCtx.hadValidType(p2.nameNode)
|
|
3199
|
-
subCtx.defineVariable(p2.name p2)
|
|
3200
|
-
}
|
|
3201
|
-
|
|
3202
|
-
def cnt:int ( size body.children )
|
|
3203
|
-
; def activeFn:RangerAppFunctionDesc (ctx.getCurrentMethod())
|
|
3204
|
-
|
|
3205
|
-
for body.children item:CodeNode i {
|
|
3206
|
-
def tmp@(lives) item
|
|
3207
|
-
subCtx.lastBlockOp = tmp
|
|
3208
|
-
this.WalkNode(item subCtx wr)
|
|
3209
|
-
if( i == ( (size body.children ) - 1) ) {
|
|
3210
|
-
if( (size item.children ) > 0) {
|
|
3211
|
-
def fc (item.getFirst())
|
|
3212
|
-
if(fc.vref != "return") {
|
|
3213
|
-
cn.type_name = "void"
|
|
3214
|
-
}
|
|
3215
|
-
}
|
|
3216
|
-
}
|
|
3217
|
-
}
|
|
3218
|
-
node.has_lambda = true
|
|
3219
|
-
node.lambda_ctx = subCtx
|
|
3220
|
-
node.eval_type = RangerNodeType.ExpressionType
|
|
3221
|
-
node.eval_function = node
|
|
3222
|
-
node.expression_value = (node.copy())
|
|
3223
|
-
node.lambdaFnDesc = m
|
|
3224
|
-
; capture 2nd tier
|
|
3225
|
-
if((ctx.isCapturing())) {
|
|
3226
|
-
node.lambda_ctx.captured_variables.forEach({
|
|
3227
|
-
if( (ctx.isVarDefined(item)) ) {
|
|
3228
|
-
if ( (ctx.isLocalToCapture(item)) == false ) {
|
|
3229
|
-
ctx.addCapturedVariable( item )
|
|
3230
|
-
}
|
|
3231
|
-
}
|
|
3232
|
-
})
|
|
3233
|
-
}
|
|
3234
|
-
}
|
|
3235
|
-
|
|
3236
|
-
; myClass@(xxx)
|
|
3237
|
-
fn CheckVRefTypeAnnotationOf:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3238
|
-
if(node.has_vref_annotation) {
|
|
3239
|
-
def tAnn (node.vref_annotation)
|
|
3240
|
-
if(false == (ctx.isDefinedClass(node.vref))) {
|
|
3241
|
-
ctx.addError(node ('Trait class ' + node.vref + ' is not defined'))
|
|
3242
|
-
} {
|
|
3243
|
-
def testC (ctx.findClass(node.vref))
|
|
3244
|
-
if(testC.is_trait) {
|
|
3245
|
-
if (testC.node.hasExpressionProperty("params")) {
|
|
3246
|
-
def params (testC.node.getExpressionProperty("params"))
|
|
3247
|
-
|
|
3248
|
-
def cnt (size tAnn.children)
|
|
3249
|
-
def tstr ""
|
|
3250
|
-
for tAnn.children ch:CodeNode i {
|
|
3251
|
-
this.CheckVRefTypeAnnotationOf( ch ctx wr )
|
|
3252
|
-
tstr = tstr + "_" + ch.vref
|
|
3253
|
-
}
|
|
3254
|
-
def my_class_name ( testC.name + tstr)
|
|
3255
|
-
def ann (unwrap tAnn)
|
|
3256
|
-
ctx.createTraitInstanceClass( testC.name my_class_name ann this wr )
|
|
3257
|
-
node.vref = my_class_name
|
|
3258
|
-
node.has_vref_annotation = false
|
|
3259
|
-
return true
|
|
3260
|
-
}
|
|
3261
|
-
}
|
|
3262
|
-
}
|
|
3263
|
-
}
|
|
3264
|
-
return false
|
|
3265
|
-
}
|
|
3266
|
-
|
|
3267
|
-
; def xxx:vectorOf@(int)
|
|
3268
|
-
fn CheckTypeAnnotationOf:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3269
|
-
if(node.has_type_annotation) {
|
|
3270
|
-
def tAnn (node.type_annotation)
|
|
3271
|
-
if(false == (ctx.isDefinedClass(node.type_name))) {
|
|
3272
|
-
ctx.addError(node ('Trait class ' + node.type_name + ' is not defined'))
|
|
3273
|
-
} {
|
|
3274
|
-
def testC (ctx.findClass(node.type_name))
|
|
3275
|
-
if(testC.is_trait) {
|
|
3276
|
-
if (testC.node.hasExpressionProperty("params")) {
|
|
3277
|
-
def params (testC.node.getExpressionProperty("params"))
|
|
3278
|
-
|
|
3279
|
-
def cnt (size tAnn.children)
|
|
3280
|
-
def tstr ""
|
|
3281
|
-
for tAnn.children ch:CodeNode i {
|
|
3282
|
-
this.CheckVRefTypeAnnotationOf( ch ctx wr )
|
|
3283
|
-
tstr = tstr + "_" + ch.vref
|
|
3284
|
-
}
|
|
3285
|
-
def my_class_name ( testC.name + tstr)
|
|
3286
|
-
def ann (unwrap tAnn)
|
|
3287
|
-
ctx.createTraitInstanceClass( testC.name my_class_name ann this wr )
|
|
3288
|
-
node.type_name = my_class_name
|
|
3289
|
-
node.has_type_annotation = false
|
|
3290
|
-
return true
|
|
3291
|
-
}
|
|
3292
|
-
}
|
|
3293
|
-
}
|
|
3294
|
-
}
|
|
3295
|
-
return false
|
|
3296
|
-
}
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
fn matchNode:boolean (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3300
|
-
if (0 == (size node.children)) {
|
|
3301
|
-
return false
|
|
3302
|
-
}
|
|
3303
|
-
def fc:CodeNode (node.getFirst())
|
|
3304
|
-
stdCommands = (ctx.getStdCommands())
|
|
3305
|
-
def op_list (ctx.getOperators(fc.vref))
|
|
3306
|
-
for op_list cmd:CodeNode i {
|
|
3307
|
-
def cmdName:CodeNode (cmd.getFirst())
|
|
3308
|
-
if (cmdName.vref == fc.vref && (! (ctx.isVarDefined(cmdName.vref)))) {
|
|
3309
|
-
this.stdParamMatch(node ctx wr true)
|
|
3310
|
-
if (!null? node.parent) {
|
|
3311
|
-
; node.parent.copyEvalResFrom(node)
|
|
3312
|
-
}
|
|
3313
|
-
return true
|
|
3314
|
-
}
|
|
3315
|
-
}
|
|
3316
|
-
; convert into a call because it handles the lambda functions correctly
|
|
3317
|
-
if( ( (size fc.ns) > 1 ) && ( ( size node.children) > 1) ) {
|
|
3318
|
-
def possible_cmd (last fc.ns)
|
|
3319
|
-
def op_list (ctx.getOperators(possible_cmd))
|
|
3320
|
-
|
|
3321
|
-
if( (has op_list) ) {
|
|
3322
|
-
; for op_list cmd:CodeNode i {
|
|
3323
|
-
|
|
3324
|
-
;def m (new RangerArgMatch)
|
|
3325
|
-
;def altVersion ( node.rebuildWithType (m false) )
|
|
3326
|
-
;def origCopy ( node.rebuildWithType (m false) )
|
|
3327
|
-
|
|
3328
|
-
def args (node.getSecond())
|
|
3329
|
-
def nn (fc.copy())
|
|
3330
|
-
removeLast nn.ns
|
|
3331
|
-
|
|
3332
|
-
def objName (join nn.ns ".")
|
|
3333
|
-
|
|
3334
|
-
def newNode (node.newExpressionNode())
|
|
3335
|
-
newNode.add( ( node.newVRefNode("call")) )
|
|
3336
|
-
newNode.add( ( node.newVRefNode(objName)) )
|
|
3337
|
-
newNode.add( ( node.newVRefNode(possible_cmd)))
|
|
3338
|
-
newNode.add( ( args.copy()))
|
|
3339
|
-
node.getChildrenFrom( newNode )
|
|
3340
|
-
|
|
3341
|
-
if( ( (ctx.expressionLevel()) == 0 ) ) {
|
|
3342
|
-
ctx.lastBlockOp = node
|
|
3343
|
-
}
|
|
3344
|
-
|
|
3345
|
-
node.flow_done = false
|
|
3346
|
-
this.WalkNode( node ctx wr)
|
|
3347
|
-
return true
|
|
3348
|
-
}
|
|
3349
|
-
}
|
|
3350
|
-
|
|
3351
|
-
return false
|
|
3352
|
-
}
|
|
3353
|
-
fn StartWalk:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3354
|
-
; walkAlso
|
|
3355
|
-
this.WalkNode(node ctx wr)
|
|
3356
|
-
for walkAlso ch:CodeNode i {
|
|
3357
|
-
this.WalkNode(ch ctx wr)
|
|
3358
|
-
}
|
|
3359
|
-
}
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
fn clearImports:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3363
|
-
|
|
3364
|
-
if (node.isFirstVref("Import")) {
|
|
3365
|
-
node.expression = true
|
|
3366
|
-
node.vref = ""
|
|
3367
|
-
removeLast node.children
|
|
3368
|
-
removeLast node.children
|
|
3369
|
-
} {
|
|
3370
|
-
for node.children item:CodeNode i {
|
|
3371
|
-
this.clearImports(item ctx wr)
|
|
3372
|
-
}
|
|
3373
|
-
}
|
|
3374
|
-
}
|
|
3375
|
-
|
|
3376
|
-
fn mergeImports:void (node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3377
|
-
|
|
3378
|
-
def envOpt (ctx.getEnv())
|
|
3379
|
-
if(null? envOpt) {
|
|
3380
|
-
ctx.addError( node 'Environment not defined')
|
|
3381
|
-
return
|
|
3382
|
-
}
|
|
3383
|
-
def env (unwrap envOpt)
|
|
3384
|
-
|
|
3385
|
-
if (node.isFirstVref("Import")) {
|
|
3386
|
-
def fNameNode:CodeNode (at node.children 1)
|
|
3387
|
-
def import_file:string fNameNode.string_value
|
|
3388
|
-
|
|
3389
|
-
if (has ctx.already_imported import_file) {
|
|
3390
|
-
return
|
|
3391
|
-
}
|
|
3392
|
-
|
|
3393
|
-
def source_code ""
|
|
3394
|
-
|
|
3395
|
-
if_javascript {
|
|
3396
|
-
def ppList (ctx.findPluginsFor("import_loader"))
|
|
3397
|
-
if( has ppList ) {
|
|
3398
|
-
try {
|
|
3399
|
-
ppList.forEach({
|
|
3400
|
-
def plugin (load_compiler_plugin item)
|
|
3401
|
-
def ss ( call_plugin plugin "import_loader" node ctx wr )
|
|
3402
|
-
case ss str:string {
|
|
3403
|
-
print "--> import " + str
|
|
3404
|
-
source_code = str
|
|
3405
|
-
}
|
|
3406
|
-
})
|
|
3407
|
-
} {
|
|
3408
|
-
|
|
3409
|
-
}
|
|
3410
|
-
}
|
|
3411
|
-
}
|
|
3412
|
-
set ctx.already_imported import_file true
|
|
3413
|
-
def rootCtx (ctx.getRoot())
|
|
3414
|
-
|
|
3415
|
-
if( (strlen source_code) == 0 ) {
|
|
3416
|
-
def filePathIs (TFiles.searchEnv( env rootCtx.libraryPaths import_file ))
|
|
3417
|
-
if( ( file_exists env filePathIs import_file ) == false ) {
|
|
3418
|
-
if(ctx.hasCompilerFlag("verbose")) {
|
|
3419
|
-
print "import did not find the file: " + import_file
|
|
3420
|
-
}
|
|
3421
|
-
ctx.addError(node ('Could not import file ' + import_file))
|
|
3422
|
-
return
|
|
3423
|
-
}
|
|
3424
|
-
if(ctx.hasCompilerFlag("verbose")) {
|
|
3425
|
-
print "importing " + import_file
|
|
3426
|
-
}
|
|
3427
|
-
def c:string (read_file env filePathIs import_file)
|
|
3428
|
-
source_code = (unwrap c)
|
|
3429
|
-
}
|
|
3430
|
-
def code:SourceCode (new SourceCode ( source_code ))
|
|
3431
|
-
code.filename = import_file
|
|
3432
|
-
def parser:RangerLispParser (new RangerLispParser (code))
|
|
3433
|
-
parser.parse((ctx.hasCompilerFlag("no-op-transform")))
|
|
3434
|
-
node.expression = true
|
|
3435
|
-
node.vref = ""
|
|
3436
|
-
removeLast node.children
|
|
3437
|
-
removeLast node.children
|
|
3438
|
-
|
|
3439
|
-
if(ctx.hasCompilerFlag("copysrc")) {
|
|
3440
|
-
print "--> copying " + (import_file)
|
|
3441
|
-
def fileWr (wr.getFileWriter("." import_file))
|
|
3442
|
-
fileWr.raw( source_code false)
|
|
3443
|
-
}
|
|
3444
|
-
|
|
3445
|
-
def rn:CodeNode (unwrap parser.rootNode)
|
|
3446
|
-
this.mergeImports( rn ctx wr)
|
|
3447
|
-
push node.children rn
|
|
3448
|
-
} {
|
|
3449
|
-
for node.children item:CodeNode i {
|
|
3450
|
-
this.mergeImports(item ctx wr)
|
|
3451
|
-
}
|
|
3452
|
-
}
|
|
3453
|
-
}
|
|
3454
|
-
|
|
3455
|
-
; this.CollectMethods( (unwrap parser.rootNode ) ctx wr)
|
|
3456
|
-
fn CollectMethods:void (node@(lives):CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3457
|
-
|
|
3458
|
-
this.WalkCollectMethods(node ctx wr)
|
|
3459
|
-
def allTypes:[string]
|
|
3460
|
-
|
|
3461
|
-
def serviceBuilder (new RangerServiceBuilder)
|
|
3462
|
-
serviceBuilder.CreateServices( this ctx wr )
|
|
3463
|
-
|
|
3464
|
-
extendedClasses.forEach({
|
|
3465
|
-
def ch (ctx.findClass(index))
|
|
3466
|
-
def parent (ctx.findClass(item))
|
|
3467
|
-
ch.addParentClass(item)
|
|
3468
|
-
parent.is_inherited = true
|
|
3469
|
-
|
|
3470
|
-
parent.variables.forEach({
|
|
3471
|
-
ch.ctx.defineVariable(item.name item)
|
|
3472
|
-
})
|
|
3473
|
-
})
|
|
3474
|
-
|
|
3475
|
-
for classesWithTraits point:ClassJoinPoint i {
|
|
3476
|
-
def cl:RangerAppClassDesc (unwrap point.class_def)
|
|
3477
|
-
def joinPoint:CodeNode (unwrap point.node)
|
|
3478
|
-
def traitClassDef@(lives):CodeNode (at point.node.children 1)
|
|
3479
|
-
def name:string (traitClassDef.vref)
|
|
3480
|
-
; print "trait " + name + " to class " + cl.name
|
|
3481
|
-
def t:RangerAppClassDesc (ctx.findClass(name))
|
|
3482
|
-
if( (size t.extends_classes) > 0 ) {
|
|
3483
|
-
ctx.addError( (unwrap point.node) ('Can not join class ' + name + ' because it is inherited. Currently on base classes can be used as traits.' ))
|
|
3484
|
-
continue
|
|
3485
|
-
}
|
|
3486
|
-
if(t.has_constructor) {
|
|
3487
|
-
ctx.addError( (unwrap point.node) ('Can not join class ' + name + ' because it has a constructor function' ))
|
|
3488
|
-
} {
|
|
3489
|
-
; def clBody:CodeNode (at t.node.children 2)
|
|
3490
|
-
def origBody:CodeNode (at cl.node.children 2)
|
|
3491
|
-
def match:RangerArgMatch (new RangerArgMatch ())
|
|
3492
|
-
def params (t.node.getExpressionProperty("params"))
|
|
3493
|
-
def initParams (point.node.getExpressionProperty("params"))
|
|
3494
|
-
def traitParams (new RangerTraitParams)
|
|
3495
|
-
|
|
3496
|
-
; print "building trait for class " + cl.name
|
|
3497
|
-
if( (!null? params) && (!null? initParams) ) {
|
|
3498
|
-
for params.children typeName:CodeNode i {
|
|
3499
|
-
def pArg (at initParams.children i)
|
|
3500
|
-
if ( 0 == (strlen pArg.vref) ) {
|
|
3501
|
-
match.addNode( typeName.vref pArg)
|
|
3502
|
-
} {
|
|
3503
|
-
match.add(typeName.vref pArg.vref ctx)
|
|
3504
|
-
; print "- add " + typeName.vref + " => " +pArg.vref
|
|
3505
|
-
}
|
|
3506
|
-
push traitParams.param_names typeName.vref
|
|
3507
|
-
set traitParams.values typeName.vref pArg.vref
|
|
3508
|
-
}
|
|
3509
|
-
set cl.trait_params name traitParams
|
|
3510
|
-
} {
|
|
3511
|
-
match.add("T" cl.name ctx)
|
|
3512
|
-
}
|
|
3513
|
-
|
|
3514
|
-
; print "traitparam values == " + (keys traitParams.values)
|
|
3515
|
-
|
|
3516
|
-
ctx.setCurrentClass( cl )
|
|
3517
|
-
|
|
3518
|
-
def traitClass (ctx.findClass(traitClassDef.vref))
|
|
3519
|
-
for traitClass.variables pvar:RangerAppParamDesc i {
|
|
3520
|
-
def ccopy:CodeNode (pvar.node.rebuildWithType(match true))
|
|
3521
|
-
this.WalkCollectMethods( ccopy ctx wr )
|
|
3522
|
-
push origBody.children ccopy
|
|
3523
|
-
}
|
|
3524
|
-
for traitClass.defined_variants fnVar:string i {
|
|
3525
|
-
def mVs:RangerAppMethodVariants (get traitClass.method_variants fnVar)
|
|
3526
|
-
for mVs.variants variant:RangerAppFunctionDesc i {
|
|
3527
|
-
def ccopy:CodeNode (variant.node.rebuildWithType(match true))
|
|
3528
|
-
this.WalkCollectMethods( ccopy ctx wr )
|
|
3529
|
-
push origBody.children ccopy
|
|
3530
|
-
}
|
|
3531
|
-
}
|
|
3532
|
-
for traitClass.static_methods variant:RangerAppFunctionDesc i {
|
|
3533
|
-
def ccopy:CodeNode (variant.node.rebuildWithType(match true))
|
|
3534
|
-
this.WalkCollectMethods( ccopy ctx wr )
|
|
3535
|
-
push origBody.children ccopy
|
|
3536
|
-
}
|
|
3537
|
-
|
|
3538
|
-
; def copy_of_body:CodeNode (clBody.rebuildWithType(match true))
|
|
3539
|
-
;joinPoint.vref = "does"
|
|
3540
|
-
;joinPoint.value_type = RangerNodeType.NoType
|
|
3541
|
-
;joinPoint.expression = true
|
|
3542
|
-
;def chCnt:int (size joinPoint.children)
|
|
3543
|
-
;while( chCnt > 0 ) {
|
|
3544
|
-
; removeLast joinPoint.children
|
|
3545
|
-
; chCnt = chCnt - 1
|
|
3546
|
-
;}
|
|
3547
|
-
|
|
3548
|
-
;ctx.setCurrentClass( cl )
|
|
3549
|
-
;for copy_of_body.children ch:CodeNode i {
|
|
3550
|
-
;push origBody.children ch
|
|
3551
|
-
; this.WalkCollectMethods( ch ctx wr )
|
|
3552
|
-
;}
|
|
3553
|
-
}
|
|
3554
|
-
}
|
|
3555
|
-
|
|
3556
|
-
def cClassList (sort serializedClasses {
|
|
3557
|
-
def left_had false
|
|
3558
|
-
def right_had false
|
|
3559
|
-
forEach left.variables {
|
|
3560
|
-
if(item.nameNode.type_name == right.name || item.nameNode.array_type == right.name) {
|
|
3561
|
-
left_had = true
|
|
3562
|
-
}
|
|
3563
|
-
}
|
|
3564
|
-
forEach right.variables {
|
|
3565
|
-
if(item.nameNode.type_name == left.name || item.nameNode.array_type == left.name) {
|
|
3566
|
-
right_had = true
|
|
3567
|
-
}
|
|
3568
|
-
}
|
|
3569
|
-
if(left_had) {
|
|
3570
|
-
return 1
|
|
3571
|
-
}
|
|
3572
|
-
if(right_had) {
|
|
3573
|
-
return -1
|
|
3574
|
-
}
|
|
3575
|
-
return 0
|
|
3576
|
-
})
|
|
3577
|
-
|
|
3578
|
-
for cClassList cl:RangerAppClassDesc i {
|
|
3579
|
-
cl.is_serialized = true
|
|
3580
|
-
def ser:RangerSerializeClass (new RangerSerializeClass())
|
|
3581
|
-
def extWr:CodeWriter (new CodeWriter())
|
|
3582
|
-
; ser.createJSONSerializerFn( cl (unwrap cl.ctx) extWr )
|
|
3583
|
-
ser.createJSONSerializerFn2( cl (unwrap cl.ctx) extWr )
|
|
3584
|
-
def theCode:string (extWr.getCode())
|
|
3585
|
-
def code:SourceCode (new SourceCode ( theCode))
|
|
3586
|
-
code.filename = "extension " + (ctx.currentClass.name)
|
|
3587
|
-
def parser:RangerLispParser (new RangerLispParser (code))
|
|
3588
|
-
parser.parse((ctx.hasCompilerFlag("no-op-transform")))
|
|
3589
|
-
def rn@(lives):CodeNode (unwrap parser.rootNode)
|
|
3590
|
-
this.WalkCollectMethods( rn (unwrap cl.ctx) wr)
|
|
3591
|
-
push walkAlso rn
|
|
3592
|
-
}
|
|
3593
|
-
|
|
3594
|
-
for immutableClasses cl:RangerAppClassDesc i {
|
|
3595
|
-
def ser (new RangerImmutableExtension)
|
|
3596
|
-
def extWr (new CodeWriter())
|
|
3597
|
-
ser.createImmutableExtension( cl (unwrap cl.ctx) extWr )
|
|
3598
|
-
def theCode (extWr.getCode())
|
|
3599
|
-
def code (new SourceCode ( theCode ))
|
|
3600
|
-
code.filename = "extension " + (cl.name)
|
|
3601
|
-
def parser (new RangerLispParser (code))
|
|
3602
|
-
parser.parse((ctx.hasCompilerFlag("no-op-transform")))
|
|
3603
|
-
def rn@(lives):CodeNode (unwrap parser.rootNode)
|
|
3604
|
-
this.WalkCollectMethods( rn (unwrap cl.ctx) wr)
|
|
3605
|
-
push walkAlso rn
|
|
3606
|
-
}
|
|
3607
|
-
; ctx.hadValidType( (unwrap v.nameNode) )
|
|
3608
|
-
for ctx.definedClassList cname:string i {
|
|
3609
|
-
push allTypes cname
|
|
3610
|
-
def c (unwrap (get ctx.definedClasses cname))
|
|
3611
|
-
if( c.is_system || c.is_interface || c.is_template || c.is_trait) {
|
|
3612
|
-
continue
|
|
3613
|
-
}
|
|
3614
|
-
def varNames:[string:boolean]
|
|
3615
|
-
for c.variables p:RangerAppParamDesc i {
|
|
3616
|
-
ctx.hadValidType( (unwrap p.nameNode) )
|
|
3617
|
-
set varNames p.name true
|
|
3618
|
-
}
|
|
3619
|
-
c.method_variants.forEach({
|
|
3620
|
-
item.variants.forEach({
|
|
3621
|
-
if(has varNames item.name) {
|
|
3622
|
-
ctx.addError( (unwrap item.nameNode) 'Class has defined method and variable of the same name.')
|
|
3623
|
-
}
|
|
3624
|
-
})
|
|
3625
|
-
})
|
|
3626
|
-
; check that no double variables..
|
|
3627
|
-
|
|
3628
|
-
}
|
|
3629
|
-
|
|
3630
|
-
for ctx.definedClassList cname:string i {
|
|
3631
|
-
push allTypes cname
|
|
3632
|
-
}
|
|
3633
|
-
|
|
3634
|
-
push allTypes "int"
|
|
3635
|
-
push allTypes "string"
|
|
3636
|
-
push allTypes "boolean"
|
|
3637
|
-
push allTypes "double"
|
|
3638
|
-
|
|
3639
|
-
def Anynn@(lives) (node.newVRefNode("Any"))
|
|
3640
|
-
|
|
3641
|
-
def rootCtx (ctx.getRoot())
|
|
3642
|
-
|
|
3643
|
-
def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
|
|
3644
|
-
new_class.name = "Any"
|
|
3645
|
-
new_class.nameNode = Anynn
|
|
3646
|
-
rootCtx.addClass("Any" new_class)
|
|
3647
|
-
new_class.is_union = true
|
|
3648
|
-
def did_push:[string:boolean]
|
|
3649
|
-
for allTypes typeName:string i {
|
|
3650
|
-
if( has did_push typeName) {
|
|
3651
|
-
continue
|
|
3652
|
-
}
|
|
3653
|
-
push new_class.is_union_of typeName
|
|
3654
|
-
set did_push typeName true
|
|
3655
|
-
}
|
|
3656
|
-
Anynn.clDesc = new_class
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
; initialize the operator root
|
|
3660
|
-
}
|
|
3661
|
-
|
|
3662
|
-
fn defineFunctionParam( method:RangerAppFunctionDesc arg:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3663
|
-
this.CheckTypeAnnotationOf( arg ctx wr )
|
|
3664
|
-
def p@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
|
|
3665
|
-
p.name = arg.vref
|
|
3666
|
-
p.value_type = arg.value_type
|
|
3667
|
-
p.node = arg
|
|
3668
|
-
p.init_cnt = 1
|
|
3669
|
-
p.nameNode = arg
|
|
3670
|
-
p.refType = RangerNodeRefType.Weak
|
|
3671
|
-
p.varType = RangerContextVarType.FunctionParameter
|
|
3672
|
-
push method.params p
|
|
3673
|
-
arg.hasParamDesc = true
|
|
3674
|
-
arg.paramDesc = p
|
|
3675
|
-
arg.eval_type = arg.value_type
|
|
3676
|
-
arg.eval_type_name = arg.type_name
|
|
3677
|
-
if (arg.hasFlag("strong")) {
|
|
3678
|
-
p.changeStrength(1 1 (unwrap p.nameNode))
|
|
3679
|
-
} {
|
|
3680
|
-
arg.setFlag("lives")
|
|
3681
|
-
p.changeStrength(0 1 (unwrap p.nameNode))
|
|
3682
|
-
}
|
|
3683
|
-
}
|
|
3684
|
-
|
|
3685
|
-
fn spliceFunctionBody:CodeNode ( startIndex:int node@(temp lives):CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3686
|
-
def block_index startIndex ; fn foo () {}
|
|
3687
|
-
def ch_len ( ( size node.children ) - 1)
|
|
3688
|
-
if( ch_len == startIndex ) {
|
|
3689
|
-
return node
|
|
3690
|
-
}
|
|
3691
|
-
for node.children cb:CodeNode i {
|
|
3692
|
-
if( i > startIndex ) {
|
|
3693
|
-
if( (strlen cb.vref) > 0 ) {
|
|
3694
|
-
if( ( ctx.hasCompilerFlag(cb.vref) ) && ( i < ch_len ) ) {
|
|
3695
|
-
block_index = i + 1
|
|
3696
|
-
}
|
|
3697
|
-
}
|
|
3698
|
-
}
|
|
3699
|
-
}
|
|
3700
|
-
def copyOf (node.copy())
|
|
3701
|
-
while( (size node.children) > (startIndex + 1) ) {
|
|
3702
|
-
removeLast node.children
|
|
3703
|
-
}
|
|
3704
|
-
if( block_index > startIndex ) {
|
|
3705
|
-
def replacer (at copyOf.children block_index)
|
|
3706
|
-
removeLast node.children
|
|
3707
|
-
push node.children (replacer.copy())
|
|
3708
|
-
}
|
|
3709
|
-
return node
|
|
3710
|
-
}
|
|
3711
|
-
|
|
3712
|
-
fn CreateFunctionObject:RangerAppFunctionDesc (orig_node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3713
|
-
|
|
3714
|
-
plugin.md "developer.md" {
|
|
3715
|
-
h2 Creating new function objects
|
|
3716
|
-
p 'Implemented a new, perhaps shorter way for creating new ' (b 'RangerAppFunctionDesc') 'Objects'
|
|
3717
|
-
code 'RangerFlowParser::CreateFunctionObject(orig_node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter)'
|
|
3718
|
-
}
|
|
3719
|
-
|
|
3720
|
-
def subCtx (ctx.fork())
|
|
3721
|
-
def node (this.spliceFunctionBody( 3 orig_node subCtx wr ))
|
|
3722
|
-
def cn:CodeNode (node.getSecond())
|
|
3723
|
-
def s:string (node.getVRefAt(1))
|
|
3724
|
-
cn.ifNoTypeSetToVoid()
|
|
3725
|
-
|
|
3726
|
-
; not automatically assigned to some class
|
|
3727
|
-
; def currC:RangerAppClassDesc ctx.currentClass
|
|
3728
|
-
; if( (currC.hasOwnMethod(s)) && (false == (cn.hasFlag("override"))) ) {
|
|
3729
|
-
; ctx.addError( node "Error: method of same name declared earlier. Overriding function declarations is not currently allowed!")
|
|
3730
|
-
; return
|
|
3731
|
-
; }
|
|
3732
|
-
; if(cn.hasFlag("main")) {
|
|
3733
|
-
; ctx.addError( node "Error: dynamic method declared as @(main). Use static 'sfn' instead of 'fn'.")
|
|
3734
|
-
; return
|
|
3735
|
-
; }
|
|
3736
|
-
|
|
3737
|
-
def m@(lives) (r.funcdesc node ctx)
|
|
3738
|
-
subCtx.is_function = true
|
|
3739
|
-
subCtx.currentMethod = m
|
|
3740
|
-
m.fnCtx = subCtx
|
|
3741
|
-
if (cn.hasFlag("weak")) {
|
|
3742
|
-
m.changeStrength(0 1 node)
|
|
3743
|
-
} {
|
|
3744
|
-
m.changeStrength(1 1 node)
|
|
3745
|
-
}
|
|
3746
|
-
def args:CodeNode (at node.children 2)
|
|
3747
|
-
m.fnBody = (at node.children 3)
|
|
3748
|
-
|
|
3749
|
-
this.CheckTypeAnnotationOf( (unwrap m.nameNode) ctx wr )
|
|
3750
|
-
|
|
3751
|
-
for args.children arg@(lives):CodeNode ii {
|
|
3752
|
-
|
|
3753
|
-
this.CheckTypeAnnotationOf( arg subCtx wr )
|
|
3754
|
-
|
|
3755
|
-
def p2@(lives):RangerAppParamDesc (new RangerAppParamDesc ())
|
|
3756
|
-
p2.name = arg.vref
|
|
3757
|
-
p2.value_type = arg.value_type
|
|
3758
|
-
p2.node = arg
|
|
3759
|
-
p2.nameNode = arg
|
|
3760
|
-
p2.init_cnt = 1
|
|
3761
|
-
p2.refType = RangerNodeRefType.Weak
|
|
3762
|
-
p2.initRefType = RangerNodeRefType.Weak
|
|
3763
|
-
p2.debugString = "--> collected "
|
|
3764
|
-
if (args.hasBooleanProperty("strong")) {
|
|
3765
|
-
p2.refType = RangerNodeRefType.Strong
|
|
3766
|
-
p2.initRefType = RangerNodeRefType.Strong
|
|
3767
|
-
}
|
|
3768
|
-
p2.varType = RangerContextVarType.FunctionParameter
|
|
3769
|
-
push m.params p2
|
|
3770
|
-
arg.hasParamDesc = true
|
|
3771
|
-
arg.paramDesc = p2
|
|
3772
|
-
arg.eval_type = arg.value_type
|
|
3773
|
-
arg.eval_type_name = arg.type_name
|
|
3774
|
-
if (arg.hasFlag("strong")) {
|
|
3775
|
-
p2.changeStrength(1 1 (unwrap p2.nameNode))
|
|
3776
|
-
} {
|
|
3777
|
-
arg.setFlag("lives")
|
|
3778
|
-
p2.changeStrength(0 1 (unwrap p2.nameNode))
|
|
3779
|
-
}
|
|
3780
|
-
; subCtx.hadValidType(p2.nameNode)
|
|
3781
|
-
subCtx.defineVariable(p2.name p2)
|
|
3782
|
-
}
|
|
3783
|
-
return m
|
|
3784
|
-
}
|
|
3785
|
-
|
|
3786
|
-
fn WalkCollectMethods:void (node@(lives):CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
3787
|
-
def find_more:boolean true
|
|
3788
|
-
|
|
3789
|
-
if( (size node.children) > 0) {
|
|
3790
|
-
def fc (node.getFirst())
|
|
3791
|
-
if( (size fc.ns) > 1) {
|
|
3792
|
-
if( (at fc.ns 0) == "plugin" ) {
|
|
3793
|
-
if(node.is_plugin) {
|
|
3794
|
-
return
|
|
3795
|
-
}
|
|
3796
|
-
node.is_plugin = true
|
|
3797
|
-
def pName (at fc.ns 1)
|
|
3798
|
-
ctx.addPluginNode( pName node )
|
|
3799
|
-
return
|
|
3800
|
-
}
|
|
3801
|
-
}
|
|
3802
|
-
}
|
|
3803
|
-
if (node.isFirstVref("defn")) {
|
|
3804
|
-
return
|
|
3805
|
-
}
|
|
3806
|
-
if (node.isFirstVref("flag")) {
|
|
3807
|
-
return
|
|
3808
|
-
}
|
|
3809
|
-
if (node.isFirstVref("page")) {
|
|
3810
|
-
return
|
|
3811
|
-
}
|
|
3812
|
-
if (node.isFirstVref("service")) {
|
|
3813
|
-
return
|
|
3814
|
-
}
|
|
3815
|
-
|
|
3816
|
-
if (node.isFirstVref("operator")) {
|
|
3817
|
-
|
|
3818
|
-
def opRef (at node.children 0)
|
|
3819
|
-
def nameNode@(lives):CodeNode (node.getSecond())
|
|
3820
|
-
def opClassName (nameNode.vref)
|
|
3821
|
-
|
|
3822
|
-
if (nameNode.vref == "class") {
|
|
3823
|
-
def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
|
|
3824
|
-
new_class.name = nameNode.type_name
|
|
3825
|
-
new_class.nameNode = nameNode
|
|
3826
|
-
nameNode.vref = nameNode.type_name
|
|
3827
|
-
ctx.addClass(nameNode.vref new_class)
|
|
3828
|
-
|
|
3829
|
-
; TODO: this may be dangerous assumbtion, the 'class' type def could be removed
|
|
3830
|
-
def cSig (TFactory.new_class_signature(nameNode ctx wr))
|
|
3831
|
-
cSig.is_system = true
|
|
3832
|
-
|
|
3833
|
-
new_class.is_system = true
|
|
3834
|
-
nameNode.clDesc = new_class
|
|
3835
|
-
}
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
def b_is_void ((nameNode.type_name == "void") || nameNode.is_block_node )
|
|
3839
|
-
def langRef (r.vref (ctx.getTargetLang()))
|
|
3840
|
-
if( has opRef.type_name ) {
|
|
3841
|
-
langRef.vref = opRef.type_name
|
|
3842
|
-
print 'OP type ' + opRef.type_name
|
|
3843
|
-
}
|
|
3844
|
-
def opLang (? ( (size node.children) > 2) (at node.children 2) langRef )
|
|
3845
|
-
def opsList (last node.children )
|
|
3846
|
-
|
|
3847
|
-
; def listOf:CodeNode (node.getSecond())
|
|
3848
|
-
; for listOf.children item@(lives):CodeNode i {
|
|
3849
|
-
; ctx.createOperator(item)
|
|
3850
|
-
; }
|
|
3851
|
-
|
|
3852
|
-
for opsList.children op:CodeNode i {
|
|
3853
|
-
def fc (op.getFirst())
|
|
3854
|
-
if( fc.vref == "fn") {
|
|
3855
|
-
def nn (op.getSecond())
|
|
3856
|
-
def args (op.getThird())
|
|
3857
|
-
def opCode (at op.children 3)
|
|
3858
|
-
|
|
3859
|
-
; print ":: op :: " + nn.vref
|
|
3860
|
-
|
|
3861
|
-
def opN@(lives) (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
|
|
3862
|
-
|
|
3863
|
-
def opName (nn.copy())
|
|
3864
|
-
; def opName (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
|
|
3865
|
-
|
|
3866
|
-
def opSig (nn.rebuildWithType( (new RangerArgMatch) false))
|
|
3867
|
-
def opArgs (args.rebuildWithType( (new RangerArgMatch) false))
|
|
3868
|
-
|
|
3869
|
-
def opTpls (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
|
|
3870
|
-
opTpls.is_block_node = true
|
|
3871
|
-
|
|
3872
|
-
def opTemplatesMain (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
|
|
3873
|
-
def opTemplatesVRef (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
|
|
3874
|
-
def opTemplatesList (new CodeNode ( (unwrap op.code) op.sp op.ep ) )
|
|
3875
|
-
|
|
3876
|
-
opTemplatesVRef.vref = "templates"
|
|
3877
|
-
push opTemplatesMain.children opTemplatesVRef
|
|
3878
|
-
push opTemplatesMain.children opTemplatesList
|
|
3879
|
-
push opTpls.children opTemplatesMain
|
|
3880
|
-
|
|
3881
|
-
push opN.children opName
|
|
3882
|
-
; opName.vref = nn.vref
|
|
3883
|
-
if(nn.hasFlag("newcontext")) {
|
|
3884
|
-
opName.setFlag("newcontext")
|
|
3885
|
-
}
|
|
3886
|
-
opSig.vref = nn.vref
|
|
3887
|
-
push opN.children opSig
|
|
3888
|
-
|
|
3889
|
-
; op _:void ( this:myClass .... )
|
|
3890
|
-
; nameNode
|
|
3891
|
-
def opThisNode (nameNode.rebuildWithType( (new RangerArgMatch) false))
|
|
3892
|
-
opThisNode.vref = "self"
|
|
3893
|
-
if(nameNode.hasFlag("mutates")) {
|
|
3894
|
-
opThisNode.setFlag("mutates")
|
|
3895
|
-
}
|
|
3896
|
-
if(nameNode.hasFlag("immutable")) {
|
|
3897
|
-
opThisNode.setFlag("immutable")
|
|
3898
|
-
}
|
|
3899
|
-
|
|
3900
|
-
if b_is_void {
|
|
3901
|
-
; --> basebones operator without the self argument
|
|
3902
|
-
} {
|
|
3903
|
-
insert opArgs.children 0 opThisNode
|
|
3904
|
-
}
|
|
3905
|
-
|
|
3906
|
-
push opN.children opArgs
|
|
3907
|
-
push opN.children opTpls
|
|
3908
|
-
|
|
3909
|
-
if( op.hasStringProperty("doc") ) {
|
|
3910
|
-
opN.setStringProperty( "doc" (op.getStringProperty("doc")) )
|
|
3911
|
-
}
|
|
3912
|
-
|
|
3913
|
-
def opCodeNode (opCode.rebuildWithType( (new RangerArgMatch) false))
|
|
3914
|
-
def actualCode (new CodeNode ( (unwrap opCode.code) op.sp op.ep ) )
|
|
3915
|
-
def opLangDef (opLang.rebuildWithType( (new RangerArgMatch) false))
|
|
3916
|
-
|
|
3917
|
-
if(opLangDef.vref == "all") {
|
|
3918
|
-
opLangDef.vref = "*"
|
|
3919
|
-
}
|
|
3920
|
-
|
|
3921
|
-
push actualCode.children opLangDef
|
|
3922
|
-
push actualCode.children opCodeNode
|
|
3923
|
-
if(opLangDef.vref == "*") {
|
|
3924
|
-
if(opCode.is_block_node == false) {
|
|
3925
|
-
opSig.setFlag("macro")
|
|
3926
|
-
}
|
|
3927
|
-
}
|
|
3928
|
-
if(nameNode.hasFlag("macro")) {
|
|
3929
|
-
opSig.setFlag("macro")
|
|
3930
|
-
}
|
|
3931
|
-
if(nn.hasFlag("pure")) {
|
|
3932
|
-
opSig.setFlag("pure")
|
|
3933
|
-
}
|
|
3934
|
-
push opTemplatesList.children actualCode
|
|
3935
|
-
ctx.createOperator(opN)
|
|
3936
|
-
}
|
|
3937
|
-
}
|
|
3938
|
-
|
|
3939
|
-
return
|
|
3940
|
-
|
|
3941
|
-
def instances:CodeNode (node.getThird())
|
|
3942
|
-
def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
|
|
3943
|
-
new_class.name = nameNode.vref
|
|
3944
|
-
new_class.nameNode = nameNode
|
|
3945
|
-
ctx.addClass(nameNode.vref new_class)
|
|
3946
|
-
new_class.is_system_union = true
|
|
3947
|
-
for instances.children ch:CodeNode i {
|
|
3948
|
-
push new_class.is_union_of ch.vref
|
|
3949
|
-
}
|
|
3950
|
-
nameNode.clDesc = new_class
|
|
3951
|
-
return
|
|
3952
|
-
}
|
|
3953
|
-
|
|
3954
|
-
if (node.isFirstVref("union")) {
|
|
3955
|
-
def nameNode@(lives):CodeNode (node.getSecond())
|
|
3956
|
-
def instances:CodeNode (node.getThird())
|
|
3957
|
-
def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
|
|
3958
|
-
new_class.name = nameNode.vref
|
|
3959
|
-
new_class.nameNode = nameNode
|
|
3960
|
-
ctx.addClass(nameNode.vref new_class)
|
|
3961
|
-
new_class.is_union = true
|
|
3962
|
-
for instances.children ch:CodeNode i {
|
|
3963
|
-
push new_class.is_union_of ch.vref
|
|
3964
|
-
}
|
|
3965
|
-
nameNode.clDesc = new_class
|
|
3966
|
-
return
|
|
3967
|
-
}
|
|
3968
|
-
|
|
3969
|
-
if (node.isFirstVref("systemunion")) {
|
|
3970
|
-
|
|
3971
|
-
def nameNode@(lives):CodeNode (node.getSecond())
|
|
3972
|
-
if(ctx.isDefinedClass(nameNode.vref)) {
|
|
3973
|
-
def cl (ctx.findClass(nameNode.vref))
|
|
3974
|
-
if( cl.is_system == false ) {
|
|
3975
|
-
ctx.addError(node "Only system classes can be systemunions")
|
|
3976
|
-
}
|
|
3977
|
-
cl.is_system_union = true
|
|
3978
|
-
def instances:CodeNode (node.getThird())
|
|
3979
|
-
for instances.children ch:CodeNode i {
|
|
3980
|
-
push cl.is_union_of ch.vref
|
|
3981
|
-
}
|
|
3982
|
-
return
|
|
3983
|
-
}
|
|
3984
|
-
|
|
3985
|
-
def nameNode@(lives):CodeNode (node.getSecond())
|
|
3986
|
-
def instances:CodeNode (node.getThird())
|
|
3987
|
-
def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
|
|
3988
|
-
new_class.name = nameNode.vref
|
|
3989
|
-
new_class.nameNode = nameNode
|
|
3990
|
-
ctx.addClass(nameNode.vref new_class)
|
|
3991
|
-
new_class.is_system_union = true
|
|
3992
|
-
for instances.children ch:CodeNode i {
|
|
3993
|
-
push new_class.is_union_of ch.vref
|
|
3994
|
-
}
|
|
3995
|
-
nameNode.clDesc = new_class
|
|
3996
|
-
return
|
|
3997
|
-
}
|
|
3998
|
-
if (node.isFirstVref("systemclass")) {
|
|
3999
|
-
def nameNode@(lives):CodeNode (node.getSecond())
|
|
4000
|
-
if(ctx.isDefinedClass(nameNode.vref)) {
|
|
4001
|
-
def cl (ctx.findClass(nameNode.vref))
|
|
4002
|
-
if( cl.is_system_union == false ) {
|
|
4003
|
-
ctx.addError(node "Class already defined and it was not a systemunion.")
|
|
4004
|
-
}
|
|
4005
|
-
cl.is_system = true
|
|
4006
|
-
def instances:CodeNode (node.getThird())
|
|
4007
|
-
for instances.children ch@(lives):CodeNode i {
|
|
4008
|
-
def langName:CodeNode (ch.getFirst())
|
|
4009
|
-
def langClassName:CodeNode (ch.getSecond())
|
|
4010
|
-
set cl.systemNodes langName.vref ch
|
|
4011
|
-
if( (strlen langClassName.vref ) > 0 ) {
|
|
4012
|
-
set cl.systemNames langName.vref langClassName.vref
|
|
4013
|
-
}
|
|
4014
|
-
if( (strlen langClassName.string_value ) > 0 ) {
|
|
4015
|
-
set cl.systemNames langName.vref langClassName.string_value
|
|
4016
|
-
}
|
|
4017
|
-
}
|
|
4018
|
-
return
|
|
4019
|
-
}
|
|
4020
|
-
def instances:CodeNode (node.getThird())
|
|
4021
|
-
def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
|
|
4022
|
-
new_class.name = nameNode.vref
|
|
4023
|
-
new_class.nameNode = nameNode
|
|
4024
|
-
ctx.addClass(nameNode.vref new_class)
|
|
4025
|
-
new_class.is_system = true
|
|
4026
|
-
for instances.children ch@(lives):CodeNode i {
|
|
4027
|
-
def langName:CodeNode (ch.getFirst())
|
|
4028
|
-
def langClassName:CodeNode (ch.getSecond())
|
|
4029
|
-
set new_class.systemNodes langName.vref ch
|
|
4030
|
-
; set new_class.systemNames langName.vref langClassName.vref
|
|
4031
|
-
if( (strlen langClassName.vref ) > 0 ) {
|
|
4032
|
-
set new_class.systemNames langName.vref langClassName.vref
|
|
4033
|
-
}
|
|
4034
|
-
if( (strlen langClassName.string_value ) > 0 ) {
|
|
4035
|
-
set new_class.systemNames langName.vref langClassName.string_value
|
|
4036
|
-
}
|
|
4037
|
-
|
|
4038
|
-
}
|
|
4039
|
-
nameNode.is_system_class = true
|
|
4040
|
-
nameNode.clDesc = new_class
|
|
4041
|
-
return
|
|
4042
|
-
}
|
|
4043
|
-
if (node.isFirstVref("extends")) {
|
|
4044
|
-
if( ( size node.children ) > 1 ) {
|
|
4045
|
-
def ee (node.getSecond())
|
|
4046
|
-
def currC:RangerAppClassDesc ctx.currentClass
|
|
4047
|
-
currC.addParentClass(ee.vref)
|
|
4048
|
-
def ParentClass:RangerAppClassDesc (ctx.findClass(ee.vref))
|
|
4049
|
-
ParentClass.is_inherited = true
|
|
4050
|
-
}
|
|
4051
|
-
find_more = false
|
|
4052
|
-
}
|
|
4053
|
-
if (node.isFirstVref("Extends")) {
|
|
4054
|
-
def extList:CodeNode (at node.children 1)
|
|
4055
|
-
def currC:RangerAppClassDesc ctx.currentClass
|
|
4056
|
-
for extList.children ee:CodeNode ii {
|
|
4057
|
-
currC.addParentClass(ee.vref)
|
|
4058
|
-
def ParentClass:RangerAppClassDesc (ctx.findClass(ee.vref))
|
|
4059
|
-
ParentClass.is_inherited = true
|
|
4060
|
-
}
|
|
4061
|
-
}
|
|
4062
|
-
if ( (node.isFirstVref("constructor")) || (node.isFirstVref("Constructor"))) {
|
|
4063
|
-
|
|
4064
|
-
def currC:RangerAppClassDesc ctx.currentClass
|
|
4065
|
-
def subCtx:RangerAppWriterContext (currC.ctx.fork())
|
|
4066
|
-
|
|
4067
|
-
currC.has_constructor = true
|
|
4068
|
-
currC.constructor_node = node
|
|
4069
|
-
def m@(lives):RangerAppFunctionDesc (new RangerAppFunctionDesc ())
|
|
4070
|
-
m.name = "Constructor"
|
|
4071
|
-
m.node = node
|
|
4072
|
-
m.nameNode = (at node.children 0)
|
|
4073
|
-
m.fnBody = (at node.children 2)
|
|
4074
|
-
m.fnCtx = subCtx
|
|
4075
|
-
|
|
4076
|
-
def args:CodeNode (at node.children 1)
|
|
4077
|
-
for args.children arg@(lives):CodeNode ii {
|
|
4078
|
-
def p:RangerAppParamDesc (new RangerAppParamDesc ())
|
|
4079
|
-
p.name = arg.vref
|
|
4080
|
-
p.value_type = arg.value_type
|
|
4081
|
-
p.node = arg
|
|
4082
|
-
p.nameNode = arg
|
|
4083
|
-
p.refType = RangerNodeRefType.Weak
|
|
4084
|
-
p.varType = RangerContextVarType.FunctionParameter
|
|
4085
|
-
|
|
4086
|
-
push m.params p
|
|
4087
|
-
|
|
4088
|
-
arg.hasParamDesc = true
|
|
4089
|
-
arg.paramDesc = p
|
|
4090
|
-
arg.eval_type = arg.value_type
|
|
4091
|
-
arg.eval_type_name = arg.type_name
|
|
4092
|
-
|
|
4093
|
-
subCtx.defineVariable(p.name p)
|
|
4094
|
-
|
|
4095
|
-
}
|
|
4096
|
-
currC.constructor_fn = m
|
|
4097
|
-
find_more = false
|
|
4098
|
-
}
|
|
4099
|
-
if (node.isFirstVref("enum")) {
|
|
4100
|
-
def fNameNode:CodeNode (at node.children 1)
|
|
4101
|
-
def enumList:CodeNode (at node.children 2)
|
|
4102
|
-
def new_enum:RangerAppEnum (new RangerAppEnum ())
|
|
4103
|
-
for enumList.children item:CodeNode i {
|
|
4104
|
-
def fc (item.getFirst())
|
|
4105
|
-
new_enum.add(fc.vref)
|
|
4106
|
-
}
|
|
4107
|
-
set ctx.definedEnums fNameNode.vref new_enum
|
|
4108
|
-
find_more = false
|
|
4109
|
-
}
|
|
4110
|
-
if (node.isFirstVref("Enum")) {
|
|
4111
|
-
def fNameNode:CodeNode (at node.children 1)
|
|
4112
|
-
def enumList:CodeNode (at node.children 2)
|
|
4113
|
-
def new_enum:RangerAppEnum (new RangerAppEnum ())
|
|
4114
|
-
for enumList.children item:CodeNode i {
|
|
4115
|
-
new_enum.add(item.vref)
|
|
4116
|
-
}
|
|
4117
|
-
set ctx.definedEnums fNameNode.vref new_enum
|
|
4118
|
-
find_more = false
|
|
4119
|
-
}
|
|
4120
|
-
if (node.isFirstVref("trait")) {
|
|
4121
|
-
def s:string (node.getVRefAt(1))
|
|
4122
|
-
def classNameNode@(lives):CodeNode (node.getSecond())
|
|
4123
|
-
def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
|
|
4124
|
-
new_class.name = s
|
|
4125
|
-
def subCtx@(lives):RangerAppWriterContext (ctx.fork())
|
|
4126
|
-
ctx.setCurrentClass(new_class)
|
|
4127
|
-
subCtx.setCurrentClass(new_class)
|
|
4128
|
-
new_class.ctx = subCtx
|
|
4129
|
-
new_class.nameNode = classNameNode
|
|
4130
|
-
ctx.addClass(s new_class)
|
|
4131
|
-
new_class.classNode = node
|
|
4132
|
-
new_class.node = node
|
|
4133
|
-
new_class.is_trait = true
|
|
4134
|
-
}
|
|
4135
|
-
|
|
4136
|
-
if ((node.isFirstVref("CreateClass")) || (node.isFirstVref("class"))) {
|
|
4137
|
-
|
|
4138
|
-
if( (size node.children) < 3) {
|
|
4139
|
-
ctx.addError(node "Not enough arguments for creating a class")
|
|
4140
|
-
return
|
|
4141
|
-
}
|
|
4142
|
-
|
|
4143
|
-
def s:string (node.getVRefAt(1))
|
|
4144
|
-
def classNameNode@(lives):CodeNode (node.getSecond())
|
|
4145
|
-
def new_class@(lives):RangerAppClassDesc (new RangerAppClassDesc ())
|
|
4146
|
-
new_class.name = s
|
|
4147
|
-
new_class.compiledName = s
|
|
4148
|
-
|
|
4149
|
-
classNameNode.evalTypeClass = (TFactory.new_class_signature(classNameNode ctx wr))
|
|
4150
|
-
def notOkNames ([] 'main')
|
|
4151
|
-
if( (indexOf notOkNames s) >= 0) {
|
|
4152
|
-
ctx.addError(classNameNode ( 'Unfortunately this class name not allowed: ' + s) )
|
|
4153
|
-
}
|
|
4154
|
-
|
|
4155
|
-
; illegal name check
|
|
4156
|
-
switch s {
|
|
4157
|
-
case "_" {
|
|
4158
|
-
new_class.compiledName = 'utiltyClass'
|
|
4159
|
-
}
|
|
4160
|
-
}
|
|
4161
|
-
|
|
4162
|
-
def subCtx@(lives):RangerAppWriterContext (ctx.fork())
|
|
4163
|
-
ctx.setCurrentClass(new_class)
|
|
4164
|
-
subCtx.setCurrentClass(new_class)
|
|
4165
|
-
new_class.ctx = subCtx
|
|
4166
|
-
new_class.nameNode = classNameNode
|
|
4167
|
-
ctx.addClass(s new_class)
|
|
4168
|
-
new_class.classNode = node
|
|
4169
|
-
new_class.node = node
|
|
4170
|
-
if(node.hasBooleanProperty("trait")) {
|
|
4171
|
-
new_class.is_trait = true
|
|
4172
|
-
}
|
|
4173
|
-
if(classNameNode.hasFlag("immutable")) {
|
|
4174
|
-
push immutableClasses new_class
|
|
4175
|
-
new_class.is_immutable = true
|
|
4176
|
-
}
|
|
4177
|
-
def third (node.getThird())
|
|
4178
|
-
if(third.vref == "extends") {
|
|
4179
|
-
if( (node.chlen()) >= 4 ) {
|
|
4180
|
-
def extClass (at node.children 3)
|
|
4181
|
-
if( (strlen extClass.vref) > 0 ) {
|
|
4182
|
-
;
|
|
4183
|
-
set extendedClasses s extClass.vref
|
|
4184
|
-
} {
|
|
4185
|
-
ctx.addError( node "Invalid classname given for the extends keyword")
|
|
4186
|
-
}
|
|
4187
|
-
}
|
|
4188
|
-
}
|
|
4189
|
-
; check for the extends keyword
|
|
4190
|
-
}
|
|
4191
|
-
|
|
4192
|
-
if (node.isFirstVref("TemplateClass")) {
|
|
4193
|
-
def s:string (node.getVRefAt(1))
|
|
4194
|
-
ctx.addTemplateClass(s node)
|
|
4195
|
-
find_more = false
|
|
4196
|
-
}
|
|
4197
|
-
|
|
4198
|
-
if((node.isFirstVref("Extends"))) {
|
|
4199
|
-
|
|
4200
|
-
def list:CodeNode (at node.children 1)
|
|
4201
|
-
for list.children cname:CodeNode i {
|
|
4202
|
-
def extC:RangerAppClassDesc (ctx.findClass(cname.vref))
|
|
4203
|
-
for extC.variables vv@(lives):RangerAppParamDesc i {
|
|
4204
|
-
def currC:RangerAppClassDesc ctx.currentClass
|
|
4205
|
-
def subCtx:RangerAppWriterContext currC.ctx
|
|
4206
|
-
subCtx.defineVariable(vv.name vv)
|
|
4207
|
-
}
|
|
4208
|
-
}
|
|
4209
|
-
find_more = false
|
|
4210
|
-
}
|
|
4211
|
-
|
|
4212
|
-
if ((node.isFirstVref("def")) || (node.isFirstVref("let"))) {
|
|
4213
|
-
def s:string (node.getVRefAt(1))
|
|
4214
|
-
def vDef@(lives):CodeNode (at node.children 1)
|
|
4215
|
-
def p:RangerAppParamDesc (new RangerAppParamDesc ())
|
|
4216
|
-
|
|
4217
|
-
; TODO: check also for new...
|
|
4218
|
-
; TODO: may not work if trait has not been declared
|
|
4219
|
-
if(vDef.has_type_annotation) {
|
|
4220
|
-
this.CheckTypeAnnotationOf( vDef ctx wr )
|
|
4221
|
-
}
|
|
4222
|
-
if( s != ((ctx.transformWord(s)))) {
|
|
4223
|
-
; ctx.addError( node "Can not use reserved word " + s + " as class propery")
|
|
4224
|
-
}
|
|
4225
|
-
def currC:RangerAppClassDesc ctx.currentClass
|
|
4226
|
-
|
|
4227
|
-
; immutable classes have only weak properties
|
|
4228
|
-
if currC.is_immutable {
|
|
4229
|
-
vDef.setFlag("weak")
|
|
4230
|
-
if( vDef.value_type == RangerNodeType.Array) {
|
|
4231
|
-
def initNode (node.newExpressionNode())
|
|
4232
|
-
initNode.push( (node.newVRefNode("new")) )
|
|
4233
|
-
def tDef (node.newVRefNode("Vector"))
|
|
4234
|
-
|
|
4235
|
-
; Vector@(string)
|
|
4236
|
-
def vAnn (node.newExpressionNode())
|
|
4237
|
-
vAnn.push( (node.newVRefNode(vDef.array_type)))
|
|
4238
|
-
tDef.has_vref_annotation = true
|
|
4239
|
-
tDef.vref_annotation = vAnn
|
|
4240
|
-
initNode.push(tDef)
|
|
4241
|
-
|
|
4242
|
-
set node.children 2 (initNode)
|
|
4243
|
-
|
|
4244
|
-
vDef.value_type = RangerNodeType.VRef
|
|
4245
|
-
vDef.type_name = "Vector"
|
|
4246
|
-
; def obj:Vector@(string)
|
|
4247
|
-
def tAnn (node.newExpressionNode())
|
|
4248
|
-
tAnn.push( (node.newVRefNode(vDef.array_type)))
|
|
4249
|
-
vDef.has_type_annotation = true
|
|
4250
|
-
vDef.type_annotation = tAnn
|
|
4251
|
-
|
|
4252
|
-
this.CheckTypeAnnotationOf( vDef ctx wr )
|
|
4253
|
-
this.CheckVRefTypeAnnotationOf( tDef ctx wr )
|
|
4254
|
-
|
|
4255
|
-
}
|
|
4256
|
-
if( vDef.value_type == RangerNodeType.Hash) {
|
|
4257
|
-
def initNode (node.newExpressionNode())
|
|
4258
|
-
initNode.push( (node.newVRefNode("new")) )
|
|
4259
|
-
def tDef (node.newVRefNode("Map"))
|
|
4260
|
-
|
|
4261
|
-
; Vector@(string)
|
|
4262
|
-
def vAnn (node.newExpressionNode())
|
|
4263
|
-
vAnn.push( (node.newVRefNode(vDef.key_type)))
|
|
4264
|
-
vAnn.push( (node.newVRefNode(vDef.array_type)))
|
|
4265
|
-
tDef.has_vref_annotation = true
|
|
4266
|
-
tDef.vref_annotation = vAnn
|
|
4267
|
-
initNode.push(tDef)
|
|
4268
|
-
set node.children 2 (initNode)
|
|
4269
|
-
|
|
4270
|
-
vDef.value_type = RangerNodeType.VRef
|
|
4271
|
-
vDef.type_name = "Map"
|
|
4272
|
-
; def obj:Vector@(string)
|
|
4273
|
-
def tAnn (node.newExpressionNode())
|
|
4274
|
-
tAnn.push( (node.newVRefNode(vDef.key_type)))
|
|
4275
|
-
tAnn.push( (node.newVRefNode(vDef.array_type)))
|
|
4276
|
-
vDef.has_type_annotation = true
|
|
4277
|
-
vDef.type_annotation = tAnn
|
|
4278
|
-
|
|
4279
|
-
this.CheckTypeAnnotationOf( vDef ctx wr )
|
|
4280
|
-
this.CheckVRefTypeAnnotationOf( tDef ctx wr )
|
|
4281
|
-
|
|
4282
|
-
}
|
|
4283
|
-
}
|
|
4284
|
-
|
|
4285
|
-
; transforming reserved words here
|
|
4286
|
-
p.name = s
|
|
4287
|
-
p.value_type = vDef.value_type
|
|
4288
|
-
p.node = node
|
|
4289
|
-
p.is_class_variable = true
|
|
4290
|
-
p.varType = RangerContextVarType.Property
|
|
4291
|
-
p.node = node
|
|
4292
|
-
p.nameNode = vDef
|
|
4293
|
-
vDef.hasParamDesc = true
|
|
4294
|
-
vDef.ownParamDesc = p
|
|
4295
|
-
vDef.paramDesc = p
|
|
4296
|
-
node.hasParamDesc = true
|
|
4297
|
-
node.paramDesc = p
|
|
4298
|
-
|
|
4299
|
-
if (vDef.hasFlag("weak")) {
|
|
4300
|
-
p.changeStrength(0 2 (unwrap p.nameNode))
|
|
4301
|
-
} {
|
|
4302
|
-
p.changeStrength(2 2 (unwrap p.nameNode))
|
|
4303
|
-
}
|
|
4304
|
-
|
|
4305
|
-
if ((size node.children) > 2) {
|
|
4306
|
-
p.set_cnt = 1
|
|
4307
|
-
p.init_cnt = 1
|
|
4308
|
-
p.def_value = (at node.children 2)
|
|
4309
|
-
p.is_optional = false
|
|
4310
|
-
if(p.def_value.value_type == RangerNodeType.String) {
|
|
4311
|
-
vDef.type_name = "string"
|
|
4312
|
-
}
|
|
4313
|
-
if(p.def_value.value_type == RangerNodeType.Integer) {
|
|
4314
|
-
vDef.type_name = "int"
|
|
4315
|
-
}
|
|
4316
|
-
if(p.def_value.value_type == RangerNodeType.Double) {
|
|
4317
|
-
vDef.type_name = "double"
|
|
4318
|
-
}
|
|
4319
|
-
if(p.def_value.value_type == RangerNodeType.Boolean) {
|
|
4320
|
-
vDef.type_name = "boolean"
|
|
4321
|
-
}
|
|
4322
|
-
def valueNode (at node.children 2)
|
|
4323
|
-
if( (size valueNode.children) > 0) {
|
|
4324
|
-
def fc (valueNode.getFirst())
|
|
4325
|
-
if(fc.vref == "new") {
|
|
4326
|
-
def second (valueNode.getSecond())
|
|
4327
|
-
this.CheckVRefTypeAnnotationOf( second ctx wr )
|
|
4328
|
-
}
|
|
4329
|
-
}
|
|
4330
|
-
} {
|
|
4331
|
-
p.is_optional = true
|
|
4332
|
-
if (false == ((vDef.value_type == RangerNodeType.Array) || (vDef.value_type == RangerNodeType.Hash))) {
|
|
4333
|
-
vDef.setFlag("optional")
|
|
4334
|
-
}
|
|
4335
|
-
}
|
|
4336
|
-
currC.addVariable(p)
|
|
4337
|
-
|
|
4338
|
-
def subCtx:RangerAppWriterContext currC.ctx
|
|
4339
|
-
subCtx.defineVariable(p.name p)
|
|
4340
|
-
p.is_class_variable = true
|
|
4341
|
-
|
|
4342
|
-
find_more = false
|
|
4343
|
-
}
|
|
4344
|
-
if (node.isFirstVref("operators")) {
|
|
4345
|
-
def listOf:CodeNode (node.getSecond())
|
|
4346
|
-
for listOf.children item@(lives):CodeNode i {
|
|
4347
|
-
ctx.createOperator(item)
|
|
4348
|
-
}
|
|
4349
|
-
find_more = false
|
|
4350
|
-
}
|
|
4351
|
-
if ((node.isFirstVref("Import")) || (node.isFirstVref("import"))) {
|
|
4352
|
-
def fNameNode:CodeNode (at node.children 1)
|
|
4353
|
-
def import_file:string fNameNode.string_value
|
|
4354
|
-
if (has ctx.already_imported import_file) {
|
|
4355
|
-
return
|
|
4356
|
-
} {
|
|
4357
|
-
set ctx.already_imported import_file true
|
|
4358
|
-
}
|
|
4359
|
-
def envOpt (ctx.getEnv())
|
|
4360
|
-
if(null? envOpt) {
|
|
4361
|
-
ctx.addError( node 'Environment not defined')
|
|
4362
|
-
return
|
|
4363
|
-
}
|
|
4364
|
-
def env (unwrap envOpt)
|
|
4365
|
-
def rootCtx (ctx.getRoot())
|
|
4366
|
-
def filePathIs (TFiles.searchEnv( env rootCtx.libraryPaths import_file ))
|
|
4367
|
-
|
|
4368
|
-
if( ( file_exists env filePathIs import_file ) == false ) {
|
|
4369
|
-
ctx.addError(node ('Could not import file ' + import_file))
|
|
4370
|
-
return
|
|
4371
|
-
}
|
|
4372
|
-
def c:string (read_file env filePathIs import_file)
|
|
4373
|
-
def code:SourceCode (new SourceCode ( (unwrap c)))
|
|
4374
|
-
code.filename = import_file
|
|
4375
|
-
def parser:RangerLispParser (new RangerLispParser (code))
|
|
4376
|
-
parser.parse((ctx.hasCompilerFlag("no-op-transform")))
|
|
4377
|
-
def rnode:CodeNode parser.rootNode
|
|
4378
|
-
this.WalkCollectMethods( (unwrap rnode) ctx wr)
|
|
4379
|
-
find_more = false
|
|
4380
|
-
}
|
|
4381
|
-
; consumes_traits
|
|
4382
|
-
if (node.isFirstVref("does")) {
|
|
4383
|
-
def defName:CodeNode (node.getSecond())
|
|
4384
|
-
def currC@(lives):RangerAppClassDesc ctx.currentClass
|
|
4385
|
-
push currC.consumes_traits defName.vref
|
|
4386
|
-
def joinPoint@(lives):ClassJoinPoint (new ClassJoinPoint())
|
|
4387
|
-
joinPoint.class_def = currC
|
|
4388
|
-
joinPoint.node = node
|
|
4389
|
-
push classesWithTraits joinPoint
|
|
4390
|
-
}
|
|
4391
|
-
|
|
4392
|
-
def b_is_main false
|
|
4393
|
-
if ( node.code.filename == (ctx.getRootFile()) ) {
|
|
4394
|
-
b_is_main = true
|
|
4395
|
-
}
|
|
4396
|
-
|
|
4397
|
-
if ((node.isFirstVref("static")) ) {
|
|
4398
|
-
; static fn foo () {}
|
|
4399
|
-
if( (node.chlen()) < 5 ) {
|
|
4400
|
-
ctx.addError(node "Invalid static function declaration")
|
|
4401
|
-
return
|
|
4402
|
-
}
|
|
4403
|
-
; static fn main () {}
|
|
4404
|
-
node = (this.spliceFunctionBody( 4 node ctx wr ))
|
|
4405
|
-
|
|
4406
|
-
def s:string (node.getVRefAt(2))
|
|
4407
|
-
if( s == "main" ) {
|
|
4408
|
-
if b_is_main {
|
|
4409
|
-
this.mainCnt = this.mainCnt + 1
|
|
4410
|
-
if(this.mainCnt > 1) {
|
|
4411
|
-
ctx.addError( node "main function can be declared only once")
|
|
4412
|
-
}
|
|
4413
|
-
}
|
|
4414
|
-
}
|
|
4415
|
-
def currC:RangerAppClassDesc ctx.currentClass
|
|
4416
|
-
def m@(lives):RangerAppFunctionDesc (new RangerAppFunctionDesc ())
|
|
4417
|
-
m.name = s
|
|
4418
|
-
m.compiledName = (ctx.transformWord(s))
|
|
4419
|
-
m.node = node
|
|
4420
|
-
m.is_static = true
|
|
4421
|
-
m.nameNode = (at node.children 2)
|
|
4422
|
-
m.nameNode.ifNoTypeSetToVoid()
|
|
4423
|
-
def args:CodeNode (at node.children 3)
|
|
4424
|
-
m.fnBody = (at node.children 4)
|
|
4425
|
-
; m.fnCtx = (ctx.fork())
|
|
4426
|
-
this.CheckTypeAnnotationOf( (unwrap m.nameNode) ctx wr )
|
|
4427
|
-
args.children.forEach({
|
|
4428
|
-
this.defineFunctionParam( m item ctx wr)
|
|
4429
|
-
})
|
|
4430
|
-
currC.addStaticMethod(m)
|
|
4431
|
-
find_more = false
|
|
4432
|
-
return
|
|
4433
|
-
}
|
|
4434
|
-
if ((node.isFirstVref("StaticMethod")) || (node.isFirstVref("sfn"))) {
|
|
4435
|
-
|
|
4436
|
-
; static fn main () {}
|
|
4437
|
-
node = (this.spliceFunctionBody( 3 node ctx wr ))
|
|
4438
|
-
|
|
4439
|
-
def s:string (node.getVRefAt(1))
|
|
4440
|
-
def currC:RangerAppClassDesc ctx.currentClass
|
|
4441
|
-
def m@(lives):RangerAppFunctionDesc (new RangerAppFunctionDesc ())
|
|
4442
|
-
m.name = s
|
|
4443
|
-
m.compiledName = (ctx.transformWord(s))
|
|
4444
|
-
m.node = node
|
|
4445
|
-
m.is_static = true
|
|
4446
|
-
m.nameNode = (at node.children 1)
|
|
4447
|
-
m.nameNode.ifNoTypeSetToVoid()
|
|
4448
|
-
def args:CodeNode (at node.children 2)
|
|
4449
|
-
m.fnBody = (at node.children 3)
|
|
4450
|
-
; m.fnCtx = (ctx.fork())
|
|
4451
|
-
this.CheckTypeAnnotationOf( (unwrap m.nameNode) ctx wr )
|
|
4452
|
-
args.children.forEach({
|
|
4453
|
-
this.defineFunctionParam( m item ctx wr)
|
|
4454
|
-
})
|
|
4455
|
-
currC.addStaticMethod(m)
|
|
4456
|
-
find_more = false
|
|
4457
|
-
|
|
4458
|
-
if( m.nameNode.hasFlag("main") ) {
|
|
4459
|
-
if b_is_main {
|
|
4460
|
-
this.mainCnt = this.mainCnt + 1
|
|
4461
|
-
if(this.mainCnt > 1) {
|
|
4462
|
-
ctx.addError( node "main function can be declared only once")
|
|
4463
|
-
}
|
|
4464
|
-
}
|
|
4465
|
-
}
|
|
4466
|
-
return
|
|
4467
|
-
}
|
|
4468
|
-
if (node.isFirstVref("extension")) {
|
|
4469
|
-
def s:string (node.getVRefAt(1))
|
|
4470
|
-
def old_class@(lives):RangerAppClassDesc (ctx.findClass(s))
|
|
4471
|
-
ctx.setCurrentClass( old_class )
|
|
4472
|
-
; print "extension for " + s
|
|
4473
|
-
}
|
|
4474
|
-
|
|
4475
|
-
if ((node.isFirstVref("PublicMethod")) || (node.isFirstVref("fn"))) {
|
|
4476
|
-
; --> new shortcut for function creators
|
|
4477
|
-
def currC:RangerAppClassDesc ctx.currentClass
|
|
4478
|
-
def fnObj@(lives) (r.func node (unwrap currC.ctx) wr)
|
|
4479
|
-
def cn (fnObj.nameNode)
|
|
4480
|
-
if( (currC.hasOwnMethod(fnObj.name)) && (false == (cn.hasFlag("override"))) ) {
|
|
4481
|
-
ctx.addError( node "Error: method of same name declared earlier. Overriding function declarations is not currently allowed!")
|
|
4482
|
-
return
|
|
4483
|
-
}
|
|
4484
|
-
if(cn.hasFlag("main")) {
|
|
4485
|
-
ctx.addError( node "Error: dynamic method declared as @(main). Use static 'sfn' instead of 'fn'.")
|
|
4486
|
-
return
|
|
4487
|
-
}
|
|
4488
|
-
currC.addMethod(fnObj)
|
|
4489
|
-
find_more = false
|
|
4490
|
-
return
|
|
4491
|
-
}
|
|
4492
|
-
if find_more {
|
|
4493
|
-
for node.children item:CodeNode i {
|
|
4494
|
-
this.WalkCollectMethods(item ctx wr)
|
|
4495
|
-
}
|
|
4496
|
-
}
|
|
4497
|
-
|
|
4498
|
-
if(node.hasBooleanProperty("serialize")) {
|
|
4499
|
-
push serializedClasses (unwrap ctx.currentClass)
|
|
4500
|
-
}
|
|
4501
|
-
|
|
4502
|
-
}
|
|
4503
|
-
|
|
4504
|
-
fn findFunctionDesc@(weak optional):RangerAppFunctionDesc (obj:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
4505
|
-
def varDesc:RangerAppParamDesc
|
|
4506
|
-
def varFnDesc:RangerAppFunctionDesc
|
|
4507
|
-
|
|
4508
|
-
if (obj.vref != (this.getThisName())) {
|
|
4509
|
-
if ((size obj.ns) > 1) {
|
|
4510
|
-
def cnt:int (size obj.ns)
|
|
4511
|
-
def classRefDesc:RangerAppParamDesc
|
|
4512
|
-
def classDesc:RangerAppClassDesc
|
|
4513
|
-
for obj.ns strname:string i {
|
|
4514
|
-
if (i == 0) {
|
|
4515
|
-
|
|
4516
|
-
if (strname == (this.getThisName())) {
|
|
4517
|
-
classDesc = (ctx.getCurrentClass())
|
|
4518
|
-
} {
|
|
4519
|
-
if (ctx.isDefinedClass(strname)) {
|
|
4520
|
-
classDesc = (ctx.findClass(strname))
|
|
4521
|
-
continue _
|
|
4522
|
-
}
|
|
4523
|
-
classRefDesc = (ctx.getVariableDef(strname))
|
|
4524
|
-
if ( (null? classRefDesc) || (null? classRefDesc.nameNode) ) {
|
|
4525
|
-
ctx.addError(obj ('Error, no description for called object: ' + strname))
|
|
4526
|
-
break _
|
|
4527
|
-
}
|
|
4528
|
-
classRefDesc.ref_cnt = (1 + classRefDesc.ref_cnt)
|
|
4529
|
-
classDesc = (ctx.findClass(classRefDesc.nameNode.type_name))
|
|
4530
|
-
if(null? classDesc) {
|
|
4531
|
-
return varFnDesc
|
|
4532
|
-
}
|
|
4533
|
-
}
|
|
4534
|
-
} {
|
|
4535
|
-
|
|
4536
|
-
if(null? classDesc) {
|
|
4537
|
-
return varFnDesc
|
|
4538
|
-
}
|
|
4539
|
-
if (i < (cnt - 1)) {
|
|
4540
|
-
varDesc = (classDesc.findVariable(strname))
|
|
4541
|
-
if (null? varDesc) {
|
|
4542
|
-
ctx.addError(obj ('Error, no description for refenced obj: ' + strname))
|
|
4543
|
-
}
|
|
4544
|
-
def subClass:string (varDesc.getTypeName())
|
|
4545
|
-
classDesc = (ctx.findClass(subClass))
|
|
4546
|
-
continue _
|
|
4547
|
-
}
|
|
4548
|
-
if (!null? classDesc) {
|
|
4549
|
-
varFnDesc = (classDesc.findMethod(strname))
|
|
4550
|
-
if (null? varFnDesc) {
|
|
4551
|
-
varFnDesc = (classDesc.findStaticMethod(strname))
|
|
4552
|
-
if (null? varFnDesc) {
|
|
4553
|
-
ctx.addError(obj (' function variable not found ' + strname))
|
|
4554
|
-
}
|
|
4555
|
-
}
|
|
4556
|
-
}
|
|
4557
|
-
}
|
|
4558
|
-
}
|
|
4559
|
-
return varFnDesc
|
|
4560
|
-
}
|
|
4561
|
-
|
|
4562
|
-
def udesc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
|
|
4563
|
-
def currClass:RangerAppClassDesc (unwrap udesc)
|
|
4564
|
-
|
|
4565
|
-
varFnDesc = (currClass.findMethod(obj.vref))
|
|
4566
|
-
if(!null? varFnDesc) {
|
|
4567
|
-
if (!null? varFnDesc.nameNode) {
|
|
4568
|
-
} {
|
|
4569
|
-
ctx.addError(obj ('Error, no description for called function: ' + obj.vref))
|
|
4570
|
-
}
|
|
4571
|
-
}
|
|
4572
|
-
return varFnDesc
|
|
4573
|
-
}
|
|
4574
|
-
return varFnDesc
|
|
4575
|
-
}
|
|
4576
|
-
fn findParamDesc@(weak optional):RangerAppParamDesc (obj:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
4577
|
-
|
|
4578
|
-
def varDesc@(lives):RangerAppParamDesc
|
|
4579
|
-
def set_nsp:boolean false
|
|
4580
|
-
def classDesc@(lives):RangerAppClassDesc
|
|
4581
|
-
if (0 == (size obj.nsp)) {
|
|
4582
|
-
set_nsp = true
|
|
4583
|
-
}
|
|
4584
|
-
if (obj.vref != (this.getThisName())) {
|
|
4585
|
-
if ((size obj.ns) > 1) {
|
|
4586
|
-
def cnt:int (size obj.ns)
|
|
4587
|
-
def classRefDesc@(lives):RangerAppParamDesc
|
|
4588
|
-
for obj.ns strname:string i {
|
|
4589
|
-
if (i == 0) {
|
|
4590
|
-
if (strname == (this.getThisName())) {
|
|
4591
|
-
classDesc = (ctx.getCurrentClass())
|
|
4592
|
-
if set_nsp {
|
|
4593
|
-
push obj.nsp (unwrap classDesc)
|
|
4594
|
-
}
|
|
4595
|
-
} {
|
|
4596
|
-
if (ctx.isDefinedClass(strname)) {
|
|
4597
|
-
classDesc = (ctx.findClass(strname))
|
|
4598
|
-
if set_nsp {
|
|
4599
|
-
push obj.nsp (unwrap classDesc)
|
|
4600
|
-
}
|
|
4601
|
-
continue _
|
|
4602
|
-
}
|
|
4603
|
-
classRefDesc = (ctx.getVariableDef(strname))
|
|
4604
|
-
if (null? classRefDesc) {
|
|
4605
|
-
ctx.addError(obj ('Error, no description for called object: ' + strname))
|
|
4606
|
-
break _
|
|
4607
|
-
}
|
|
4608
|
-
if set_nsp {
|
|
4609
|
-
push obj.nsp (unwrap classRefDesc)
|
|
4610
|
-
}
|
|
4611
|
-
|
|
4612
|
-
; --> if the call is optional
|
|
4613
|
-
;
|
|
4614
|
-
; o.foo.x --> optional always ...
|
|
4615
|
-
|
|
4616
|
-
if(classRefDesc.nameNode.hasFlag("optional")) {
|
|
4617
|
-
if(ctx.hasCompilerFlag('strict')) {
|
|
4618
|
-
if(false == (ctx.isTryBlock())) {
|
|
4619
|
-
ctx.addError( obj "Optional automatically unwrapped outside try block" )
|
|
4620
|
-
}
|
|
4621
|
-
}
|
|
4622
|
-
}
|
|
4623
|
-
|
|
4624
|
-
classRefDesc.ref_cnt = (1 + classRefDesc.ref_cnt)
|
|
4625
|
-
classDesc = (ctx.findClass(classRefDesc.nameNode.type_name))
|
|
4626
|
-
}
|
|
4627
|
-
} {
|
|
4628
|
-
if (i < (cnt - 1)) {
|
|
4629
|
-
varDesc = (classDesc.findVariable(strname))
|
|
4630
|
-
if( i > 0 ) {
|
|
4631
|
-
if(varDesc.nameNode.hasFlag("optional")) {
|
|
4632
|
-
if(ctx.hasCompilerFlag('strict')) {
|
|
4633
|
-
if(false == (ctx.isTryBlock())) {
|
|
4634
|
-
ctx.addError( obj "Optional automatically unwrapped outside try block" )
|
|
4635
|
-
}
|
|
4636
|
-
}
|
|
4637
|
-
}
|
|
4638
|
-
}
|
|
4639
|
-
if (null? varDesc) {
|
|
4640
|
-
ctx.addError(obj ('Error, no description for refenced obj: ' + strname))
|
|
4641
|
-
}
|
|
4642
|
-
def subClass:string (varDesc.getTypeName())
|
|
4643
|
-
classDesc = (ctx.findClass(subClass))
|
|
4644
|
-
if set_nsp {
|
|
4645
|
-
push obj.nsp (unwrap varDesc)
|
|
4646
|
-
}
|
|
4647
|
-
continue _
|
|
4648
|
-
}
|
|
4649
|
-
if (!null? classDesc) {
|
|
4650
|
-
varDesc = (classDesc.findVariable(strname))
|
|
4651
|
-
if (null? varDesc) {
|
|
4652
|
-
def classMethod@(lives optional):RangerAppFunctionDesc (classDesc.findMethod(strname))
|
|
4653
|
-
if (null? classMethod) {
|
|
4654
|
-
classMethod = (classDesc.findStaticMethod(strname))
|
|
4655
|
-
if (null? classMethod) {
|
|
4656
|
-
ctx.addError(obj ('variable not found ' + strname))
|
|
4657
|
-
}
|
|
4658
|
-
}
|
|
4659
|
-
if (!null? classMethod) {
|
|
4660
|
-
if set_nsp {
|
|
4661
|
-
push obj.nsp (unwrap classMethod)
|
|
4662
|
-
}
|
|
4663
|
-
return classMethod
|
|
4664
|
-
}
|
|
4665
|
-
}
|
|
4666
|
-
if set_nsp {
|
|
4667
|
-
push obj.nsp (unwrap varDesc)
|
|
4668
|
-
}
|
|
4669
|
-
}
|
|
4670
|
-
}
|
|
4671
|
-
}
|
|
4672
|
-
return varDesc
|
|
4673
|
-
}
|
|
4674
|
-
varDesc = (ctx.getVariableDef(obj.vref))
|
|
4675
|
-
if (!null? varDesc.nameNode) {
|
|
4676
|
-
} {
|
|
4677
|
-
|
|
4678
|
-
; print ('findParamDesc : description not found for ' + obj.vref)
|
|
4679
|
-
; if (!null? varDesc) {
|
|
4680
|
-
; print ('Vardesc was found though...' + varDesc.name)
|
|
4681
|
-
; }
|
|
4682
|
-
; ctx.addError(obj ('Error, no description for called object: ' + obj.vref))
|
|
4683
|
-
}
|
|
4684
|
-
return varDesc
|
|
4685
|
-
}
|
|
4686
|
-
def cc@(optional):RangerAppClassDesc (ctx.getCurrentClass())
|
|
4687
|
-
return cc
|
|
4688
|
-
}
|
|
4689
|
-
|
|
4690
|
-
fn convertToUnion( unionName:string node:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
4691
|
-
|
|
4692
|
-
if( (ctx.isDefinedClass(unionName)) ) {
|
|
4693
|
-
def c1:RangerAppClassDesc (ctx.findClass(unionName))
|
|
4694
|
-
if( c1.is_union ) {
|
|
4695
|
-
if( (node.type_name != c1.name) && (node.eval_type_name != c1.name ) ) {
|
|
4696
|
-
def toEx (node.newExpressionNode())
|
|
4697
|
-
def toVref (node.newVRefNode('to'))
|
|
4698
|
-
def argType (node.newVRefNode('_'))
|
|
4699
|
-
def targetNode (node.copy())
|
|
4700
|
-
argType.type_name = unionName
|
|
4701
|
-
toEx.push( toVref )
|
|
4702
|
-
toEx.push( argType )
|
|
4703
|
-
toEx.push( targetNode )
|
|
4704
|
-
node.expression = true
|
|
4705
|
-
node.flow_done = false
|
|
4706
|
-
node.value_type = RangerNodeType.NoType
|
|
4707
|
-
node.getChildrenFrom( toEx )
|
|
4708
|
-
def wr (new CodeWriter)
|
|
4709
|
-
this.WalkNode( node ctx wr )
|
|
4710
|
-
}
|
|
4711
|
-
}
|
|
4712
|
-
}
|
|
4713
|
-
}
|
|
4714
|
-
|
|
4715
|
-
fn transformMethodToLambda ( node:CodeNode vFnDef:RangerAppFunctionDesc ctx:RangerAppWriterContext wr:CodeWriter ) {
|
|
4716
|
-
|
|
4717
|
-
; node.
|
|
4718
|
-
; some.method -->
|
|
4719
|
-
|
|
4720
|
-
; def vFnDef@(optional):RangerAppFunctionDesc (this.findFunctionDesc(node ctx wr))
|
|
4721
|
-
; if (!null? vFnDef) {
|
|
4722
|
-
if(vFnDef.isFunction()) {
|
|
4723
|
-
; could transform here the n2 into expression...
|
|
4724
|
-
; fn myFn:int ()
|
|
4725
|
-
def args (map vFnDef.params {
|
|
4726
|
-
return (item.nameNode.copy())
|
|
4727
|
-
} to:[CodeNode])
|
|
4728
|
-
; (fn:rv () )
|
|
4729
|
-
def fnArg (vFnDef.nameNode.copy())
|
|
4730
|
-
fnArg.vref = "fn"
|
|
4731
|
-
def subNode (node.copy())
|
|
4732
|
-
subNode.flow_done = false
|
|
4733
|
-
def argsExpr (map args {
|
|
4734
|
-
return (item.copy())
|
|
4735
|
-
})
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
if( ( (has vFnDef.nameNode.type_name) && (vFnDef.nameNode.type_name != 'void') ) ||
|
|
4739
|
-
(has vFnDef.nameNode.array_type) ) {
|
|
4740
|
-
def staticLambda (r.expression
|
|
4741
|
-
fnArg
|
|
4742
|
-
(r.expression args )
|
|
4743
|
-
(r.block
|
|
4744
|
-
(r.expression
|
|
4745
|
-
(r.vref 'return')
|
|
4746
|
-
; call...
|
|
4747
|
-
(r.expression
|
|
4748
|
-
; (r.vref node.vref)
|
|
4749
|
-
subNode
|
|
4750
|
-
; parameters...
|
|
4751
|
-
(r.expression
|
|
4752
|
-
argsExpr
|
|
4753
|
-
)
|
|
4754
|
-
)
|
|
4755
|
-
)
|
|
4756
|
-
)
|
|
4757
|
-
)
|
|
4758
|
-
node.getChildrenFrom( staticLambda )
|
|
4759
|
-
|
|
4760
|
-
} {
|
|
4761
|
-
def staticLambda (r.expression
|
|
4762
|
-
fnArg
|
|
4763
|
-
(r.expression args )
|
|
4764
|
-
(r.block
|
|
4765
|
-
(r.expression
|
|
4766
|
-
; (r.vref node.vref)
|
|
4767
|
-
subNode
|
|
4768
|
-
; parameters...
|
|
4769
|
-
(r.expression
|
|
4770
|
-
argsExpr
|
|
4771
|
-
)
|
|
4772
|
-
)
|
|
4773
|
-
)
|
|
4774
|
-
)
|
|
4775
|
-
node.getChildrenFrom( staticLambda )
|
|
4776
|
-
}
|
|
4777
|
-
node.flow_done = false
|
|
4778
|
-
node.expression = true
|
|
4779
|
-
node.value_type = RangerNodeType.NoType
|
|
4780
|
-
node.vref = ""
|
|
4781
|
-
; node.hasParamDesc = false
|
|
4782
|
-
; nullify node.paramDesc
|
|
4783
|
-
this.WalkNode( node ctx wr)
|
|
4784
|
-
; }
|
|
4785
|
-
}
|
|
4786
|
-
}
|
|
4787
|
-
|
|
4788
|
-
fn areEqualTypes:boolean (n1:CodeNode n2:CodeNode ctx:RangerAppWriterContext wr:CodeWriter) {
|
|
4789
|
-
|
|
4790
|
-
if(n1.eval_type == RangerNodeType.ExpressionType) {
|
|
4791
|
-
|
|
4792
|
-
def n1Expr@(weak) (n1.expression_value)
|
|
4793
|
-
def n2Expr@(weak) (n2.expression_value)
|
|
4794
|
-
|
|
4795
|
-
if(null? n1Expr) {
|
|
4796
|
-
if(n1.hasParamDesc && (!null? n1.paramDesc.nameNode) && (!null? n1.paramDesc.nameNode.expression_value) ) {
|
|
4797
|
-
n1Expr = n1.paramDesc.nameNode.expression_value
|
|
4798
|
-
}
|
|
4799
|
-
}
|
|
4800
|
-
if(null? n2Expr) {
|
|
4801
|
-
if(n2.hasParamDesc && (!null? n2.paramDesc.nameNode) && (!null? n2.paramDesc.nameNode.expression_value) ) {
|
|
4802
|
-
n2Expr = n2.paramDesc.nameNode.expression_value
|
|
4803
|
-
}
|
|
4804
|
-
}
|
|
4805
|
-
if( (!null? n1Expr) && (!null? n2Expr) ) {
|
|
4806
|
-
; if two lambas have been given as argument...
|
|
4807
|
-
return (this.matchLambdaArgs( (unwrap n1Expr) (unwrap n2Expr) ctx (new CodeWriter)))
|
|
4808
|
-
}
|
|
4809
|
-
|
|
4810
|
-
if( (!null? n1Expr) ) {
|
|
4811
|
-
|
|
4812
|
-
; for example:
|
|
4813
|
-
; forEach list1 <operatorfn>
|
|
4814
|
-
;
|
|
4815
|
-
; this is transformed into corresponding lambda call like
|
|
4816
|
-
; (fn:void (item:int index:int) { <operator> item index })
|
|
4817
|
-
def opList (ctx.getOpFns(n2.vref))
|
|
4818
|
-
if(has opList) {
|
|
4819
|
-
|
|
4820
|
-
def newCall (r.expression (r.vref n2.vref))
|
|
4821
|
-
def newExpr (r.block )
|
|
4822
|
-
def proto (n1Expr.copy())
|
|
4823
|
-
|
|
4824
|
-
def fc (at proto.children 0)
|
|
4825
|
-
fc.vref = 'fn'
|
|
4826
|
-
def eParams (at n1Expr.children 1)
|
|
4827
|
-
eParams.children.forEach({
|
|
4828
|
-
push newCall.children (r.vref item.vref)
|
|
4829
|
-
})
|
|
4830
|
-
if(fc.type_name != 'void') {
|
|
4831
|
-
push newExpr.children (r.expression (r.vref 'return') newCall )
|
|
4832
|
-
} {
|
|
4833
|
-
push newExpr.children newCall
|
|
4834
|
-
}
|
|
4835
|
-
push proto.children newExpr
|
|
4836
|
-
|
|
4837
|
-
n2.value_type = RangerNodeType.NoType
|
|
4838
|
-
n2.expression_value = (proto.copy())
|
|
4839
|
-
n2.expression = true
|
|
4840
|
-
n2.flow_done = false
|
|
4841
|
-
n2.vref = ''
|
|
4842
|
-
clear n2.ns
|
|
4843
|
-
n2.getChildrenFrom( (proto.copy()) )
|
|
4844
|
-
|
|
4845
|
-
this.WalkNode(n2 ctx wr)
|
|
4846
|
-
n2.expression_value = proto
|
|
4847
|
-
return (this.areEqualTypes(n1 n2 ctx wr))
|
|
4848
|
-
}
|
|
4849
|
-
}
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
if( n2.eval_type == RangerNodeType.Method ) {
|
|
4853
|
-
def pDesc:RangerAppFunctionDesc (cast (unwrap n2.paramDesc) to:RangerAppFunctionDesc)
|
|
4854
|
-
; (cast pDesc to:RangerAppFunctionDesc)
|
|
4855
|
-
this.transformMethodToLambda( n2 pDesc ctx wr )
|
|
4856
|
-
return true
|
|
4857
|
-
}
|
|
4858
|
-
|
|
4859
|
-
def vFnDef@(optional):RangerAppFunctionDesc (this.findFunctionDesc(n2 ctx wr))
|
|
4860
|
-
if (!null? vFnDef) {
|
|
4861
|
-
; Static method is transformed here to lambda...
|
|
4862
|
-
; print "Transforming method to lambda " + (n2.getCode())
|
|
4863
|
-
this.transformMethodToLambda( n2 (unwrap vFnDef) ctx wr )
|
|
4864
|
-
return true
|
|
4865
|
-
}
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
ctx.addError(n2 "Was not able to evaluate lambda expression types!")
|
|
4870
|
-
if(!null? n1Expr) {
|
|
4871
|
-
ctx.addError(n1 ('^ ' + (n1Expr.getCode())) )
|
|
4872
|
-
} {
|
|
4873
|
-
ctx.addError(n1 "^ expression_value not found (1)" )
|
|
4874
|
-
}
|
|
4875
|
-
if(!null? n2Expr) {
|
|
4876
|
-
ctx.addError(n2 ('^ ' + (n2Expr.getCode())) )
|
|
4877
|
-
} {
|
|
4878
|
-
ctx.addError(n2 "^ expression_value not found (2)" )
|
|
4879
|
-
}
|
|
4880
|
-
return false
|
|
4881
|
-
}
|
|
4882
|
-
if ((n1.eval_type != RangerNodeType.NoType) && (n2.eval_type != RangerNodeType.NoType) && ((strlen n1.eval_type_name) > 0) && ((strlen n2.eval_type_name) > 0)) {
|
|
4883
|
-
if ( n1.eval_type_name == n2.eval_type_name) {
|
|
4884
|
-
} {
|
|
4885
|
-
def b_ok:boolean false
|
|
4886
|
-
if ((ctx.isEnumDefined(n1.eval_type_name)) && (n2.eval_type_name == "int")) {
|
|
4887
|
-
b_ok = true
|
|
4888
|
-
}
|
|
4889
|
-
if ((ctx.isEnumDefined(n2.eval_type_name)) && (n1.eval_type_name == "int")) {
|
|
4890
|
-
b_ok = true
|
|
4891
|
-
}
|
|
4892
|
-
if ((n1.eval_type_name == "char") && (n2.eval_type_name == "int")) {
|
|
4893
|
-
b_ok = true
|
|
4894
|
-
}
|
|
4895
|
-
if ((n1.eval_type_name == "int") && (n2.eval_type_name == "char")) {
|
|
4896
|
-
b_ok = true
|
|
4897
|
-
}
|
|
4898
|
-
|
|
4899
|
-
if( (ctx.isDefinedClass(n1.eval_type_name)) && (ctx.isDefinedClass (n2.eval_type_name))) {
|
|
4900
|
-
|
|
4901
|
-
def c1:RangerAppClassDesc (ctx.findClass(n1.eval_type_name))
|
|
4902
|
-
def c2:RangerAppClassDesc (ctx.findClass(n2.eval_type_name))
|
|
4903
|
-
|
|
4904
|
-
if( c1.is_union ) {
|
|
4905
|
-
if( c2.is_union == false ) {
|
|
4906
|
-
|
|
4907
|
-
this.convertToUnion( n1.eval_type_name n2 ctx (new CodeWriter))
|
|
4908
|
-
if(n2.eval_type_name == n1.eval_type_name) {
|
|
4909
|
-
return true
|
|
4910
|
-
} {
|
|
4911
|
-
return false
|
|
4912
|
-
}
|
|
4913
|
-
}
|
|
4914
|
-
}
|
|
4915
|
-
|
|
4916
|
-
if( (c2.is_union != c1.is_union ) ) {
|
|
4917
|
-
ctx.addError( n1 ('Can not convert union to type '))
|
|
4918
|
-
return false
|
|
4919
|
-
}
|
|
4920
|
-
|
|
4921
|
-
if( (c2.is_union == true) && (c1.is_union == true)) {
|
|
4922
|
-
ctx.addError( n1 ('Union types must be the same => ' + n1.eval_type_name + " <> " + n2.eval_type_name))
|
|
4923
|
-
return false
|
|
4924
|
-
}
|
|
4925
|
-
|
|
4926
|
-
if ( c1.isSameOrParentClass (n2.eval_type_name ctx)) {
|
|
4927
|
-
return true
|
|
4928
|
-
}
|
|
4929
|
-
if ( c2.isSameOrParentClass (n1.eval_type_name ctx)) {
|
|
4930
|
-
return true
|
|
4931
|
-
}
|
|
4932
|
-
}
|
|
4933
|
-
|
|
4934
|
-
if (b_ok == false) {
|
|
4935
|
-
if(n1.eval_type_name == 'Any') {
|
|
4936
|
-
this.convertToUnion( 'Any' n2 ctx (new CodeWriter))
|
|
4937
|
-
if(n2.eval_type_name == n1.eval_type_name) {
|
|
4938
|
-
; print "^ converted to union " + (n2.getCode())
|
|
4939
|
-
return true
|
|
4940
|
-
} {
|
|
4941
|
-
return false
|
|
4942
|
-
}
|
|
4943
|
-
}
|
|
4944
|
-
return false
|
|
4945
|
-
}
|
|
4946
|
-
}
|
|
4947
|
-
}
|
|
4948
|
-
return true
|
|
4949
|
-
}
|
|
4950
|
-
fn shouldBeEqualTypes:void (n1:CodeNode n2:CodeNode ctx@(weak):RangerAppWriterContext msg:string) {
|
|
4951
|
-
|
|
4952
|
-
if ((n1.eval_type != RangerNodeType.NoType) && (n2.eval_type != RangerNodeType.NoType) && ((strlen n1.eval_type_name) > 0) && ((strlen n2.eval_type_name) > 0)) {
|
|
4953
|
-
if (n1.eval_type_name == n2.eval_type_name) {
|
|
4954
|
-
} {
|
|
4955
|
-
def b_ok:boolean false
|
|
4956
|
-
if ((ctx.isEnumDefined(n1.eval_type_name)) && (n2.eval_type_name == "int")) {
|
|
4957
|
-
b_ok = true
|
|
4958
|
-
}
|
|
4959
|
-
if ((ctx.isEnumDefined(n2.eval_type_name)) && (n1.eval_type_name == "int")) {
|
|
4960
|
-
b_ok = true
|
|
4961
|
-
}
|
|
4962
|
-
if (ctx.isDefinedClass(n2.eval_type_name)) {
|
|
4963
|
-
def cc:RangerAppClassDesc (ctx.findClass(n2.eval_type_name))
|
|
4964
|
-
if (cc.isSameOrParentClass(n1.eval_type_name ctx)) {
|
|
4965
|
-
b_ok = true
|
|
4966
|
-
}
|
|
4967
|
-
}
|
|
4968
|
-
if ((n1.eval_type_name == "char") && (n2.eval_type_name == "int")) {
|
|
4969
|
-
b_ok = true
|
|
4970
|
-
}
|
|
4971
|
-
if ((n1.eval_type_name == "int") && (n2.eval_type_name == "char")) {
|
|
4972
|
-
b_ok = true
|
|
4973
|
-
}
|
|
4974
|
-
if (b_ok == false) {
|
|
4975
|
-
ctx.addError(n1 ('Type mismatch ' + n2.eval_type_name + ' <> ' + n1.eval_type_name + '. ' + msg))
|
|
4976
|
-
}
|
|
4977
|
-
}
|
|
4978
|
-
}
|
|
4979
|
-
}
|
|
4980
|
-
fn shouldBeExpression:void (n1:CodeNode ctx:RangerAppWriterContext msg:string) {
|
|
4981
|
-
if (n1.expression == false) {
|
|
4982
|
-
ctx.addError(n1 (msg))
|
|
4983
|
-
}
|
|
4984
|
-
}
|
|
4985
|
-
fn shouldHaveChildCnt:void (cnt:int n1:CodeNode ctx:RangerAppWriterContext msg:string) {
|
|
4986
|
-
if ((size n1.children) != cnt) {
|
|
4987
|
-
ctx.addError(n1 (msg))
|
|
4988
|
-
}
|
|
4989
|
-
}
|
|
4990
|
-
}
|
|
4991
|
-
|
|
4992
|
-
Import "ng_parser_std_match2.clj"
|