diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index 6430aaced..3b033793c 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -2005,14 +2005,14 @@ private void SetOutputPlatformOption(NETGenerator.CompilerOptions compilerOption } if (CompilerOptions.Only32Bit) compilerOptions.platformtarget = NETGenerator.CompilerOptions.PlatformTarget.x86; - - // целевой framework - if (this.compilerDirectives.TryGetValue(TreeConverter.compiler_string_consts.compiler_directive_targetframework, out compilerDirectivesList)) + } + if (compilerDirectives.TryGetValue(TreeConverter.compiler_string_consts.compiler_directive_targetframework, out compilerDirectivesList)) + { + compilerOptions.TargetFramework = compilerDirectivesList[0].directive; + if (!(new string[] { "net40", "net403", "net45", "net451", "net452", "net46", "net461", "net462", "net47", "net471", "net472", "net48", "net481" }) + .Contains(compilerOptions.TargetFramework)) { - compilerOptions.TargetFramework = compilerDirectivesList[0].directive; - if (!(new string[] { "net40", "net403", "net45", "net451", "net452", "net46", "net461", "net462", "net47", "net471", "net472", "net48", "net481" }) - .Contains(compilerOptions.TargetFramework)) - ErrorsList.Add(new UnsupportedTargetFramework(compilerOptions.TargetFramework, compilerDirectivesList[0].location)); + ErrorsList.Add(new UnsupportedTargetFramework(compilerOptions.TargetFramework, compilerDirectivesList[0].location)); } } } @@ -2329,7 +2329,7 @@ private void PrebuildMainSemanticTreeActions(out NETGenerator.CompilerOptions co compilerOptions = new NETGenerator.CompilerOptions(); - // выяснение целевой платформы + // выяснение TargetFramework и целевой платформы SetOutputPlatformOption(compilerOptions); // остальные директивы diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index b4f38d3d5..35db7addf 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "9"; public const string Build = "0"; - public const string Revision = "3417"; + public const string Revision = "3419"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index b8fe50267..1866a0792 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ %MINOR%=9 -%REVISION%=3417 +%REVISION%=3419 %COREVERSION%=0 %MAJOR%=3 diff --git a/Localization/DefaultLang.resources b/Localization/DefaultLang.resources index 814fc980c..48f76c2a1 100644 Binary files a/Localization/DefaultLang.resources and b/Localization/DefaultLang.resources differ diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index c574e9eee..a43dac2d6 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.9.0.3417 +3.9.0.3419 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index 88ab84c22..a038b53b0 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.9.0.3417' +!define VERSION '3.9.0.3419' diff --git a/SyntaxTreeConverters/StandardSyntaxConverter.cs b/SyntaxTreeConverters/StandardSyntaxConverter.cs index 011649493..f664df914 100644 --- a/SyntaxTreeConverters/StandardSyntaxConverter.cs +++ b/SyntaxTreeConverters/StandardSyntaxConverter.cs @@ -27,7 +27,7 @@ public syntax_tree_node Convert(syntax_tree_node root) // stat.ProcessNode(root); #endif // SSM 02.01.24 - LetExprVisitor.New.ProcessNode(root); + //LetExprVisitor.New.ProcessNode(root); // new range - до всего! До выноса выражения с лямбдой из foreach. 11.07 добавил поиск yields и присваивание pd.HasYield NewRangeDesugarAndFindHasYieldVisitor.New.ProcessNode(root); diff --git a/TestSuite/CompilationSamples/PABCSystem.pas b/TestSuite/CompilationSamples/PABCSystem.pas index ef7d0be43..25ba0910a 100644 --- a/TestSuite/CompilationSamples/PABCSystem.pas +++ b/TestSuite/CompilationSamples/PABCSystem.pas @@ -8882,17 +8882,15 @@ procedure Reverse(var s: string; index, count: integer); procedure Shuffle(a: array of T); begin - var n := a.Length; - for var i := 0 to n - 1 do - Swap(a[i], a[Random(n)]); + for var i := a.Length - 1 downto 1 do + Swap(a[i], a[Random(i + 1)]); end; procedure Shuffle(l: List); begin - var n := l.Count; - for var i := 0 to n - 1 do + for var i := l.Count - 1 downto 1 do begin - var ind := Random(n); + var ind := Random(i + 1); var v := l[i]; l[i] := l[ind]; l[ind] := v; @@ -10756,10 +10754,9 @@ function Indices(Self: List; cond: (T,integer) ->boolean): sequence of int /// Перемешивает элементы списка случайным образом function Shuffle(Self: List): List; extensionmethod; begin - var n := Self.Count; - for var i := 0 to n - 1 do + for var i := Self.Count - 1 downto 1 do begin - var r := Random(n); + var r := Random(i + 1); var v := Self[i]; Self[i] := Self[r]; Self[r] := v; @@ -11814,9 +11811,8 @@ function RandomElement(Self: array of T): T; extensionmethod; /// Перемешивает элементы массива случайным образом function Shuffle(Self: array of T): array of T; extensionmethod; begin - var n := Self.Length; - for var i := 0 to n - 1 do - Swap(Self[i], Self[Random(n)]); + for var i := Self.Length - 1 downto 1 do + Swap(Self[i], Self[Random(i + 1)]); Result := Self; end; diff --git a/TestSuite/CompilationSamples/Tasks1Loops.pas b/TestSuite/CompilationSamples/Tasks1Loops.pas index 91f79360c..2c5c7c786 100644 --- a/TestSuite/CompilationSamples/Tasks1Loops.pas +++ b/TestSuite/CompilationSamples/Tasks1Loops.pas @@ -528,7 +528,7 @@ procedure CheckTaskT(name: string); end; 'Min3': begin CheckData(InitialInput := |cRe|*3); - Generatetests(10,tRe(1,100)*2); + Generatetests(10,tRe(1,100)*3); CheckOutput(Min(Re(0),Re(1),Re(2))); end; 'SeriesMin2': begin diff --git a/TestSuite/CompilationSamples/TasksStr.pas b/TestSuite/CompilationSamples/TasksStr.pas index 805ca318d..a849171a0 100644 --- a/TestSuite/CompilationSamples/TasksStr.pas +++ b/TestSuite/CompilationSamples/TasksStr.pas @@ -282,7 +282,7 @@ procedure CheckTaskT(name: string); end; 'Insert2': begin CheckData(Input := Empty); - CheckOutput('Петр первый был великим русским императором'); + CheckOutput('Петр Первый был великим русским императором'); end; 'StrChange1': begin CheckData(Input := Empty); @@ -306,7 +306,7 @@ procedure CheckTaskT(name: string); end; 'StrSlice2': begin CheckData(Input := Empty); - CheckOutputSeq(Arr('клад зарыт на юго западе', 'клад зарыт на юго западе')); + CheckOutputSeq(Arr('клад зарыт на юго западе', 'зашифрованное сообщение')); end; 'StrSlice4': begin CheckData(Input := Empty); diff --git a/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs b/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs index 445b45afb..b3ddc5efb 100644 --- a/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs +++ b/TreeConverter/LambdaExpressions/Closure/CapturedVariablesTreeBuilder.cs @@ -95,6 +95,18 @@ public override void visit(var_def_statement varDefStmt) } } + + // SSM 2024.01.09 + public override void visit(let_var_expr letVarExpr) + { + ProcessNode(letVarExpr.ex); + + _visitor.ProcessNode(letVarExpr); + + SymbolInfo si = _visitor.context.find_first(letVarExpr.id.name); + _currentTreeNode.VariablesDefinedInScope.Add(new CapturedVariablesTreeNode.CapturedSymbolInfo(letVarExpr, si)); + } + public override void visit(statement_list stmtList) { if (stmtList.IsInternal) // просто обойти как продолжение объемлющего statement_list diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index e7bcfc734..130dbd26f 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -19809,6 +19809,36 @@ public override void visit(SyntaxTree.var_statement node) ret.reset(); // SSM 19.01.17 не возвращать семантическое значение т.к. ничего не нужно добавлять в текущий список операторов!! } + // создать словарик чтобы для одного _visitor.context.CurrentScope.ScopeNum и для одного letVarExpr + // мы заходили в этот visit один раз + private Dictionary> letDict = new Dictionary>(); + + // можно попробовать в одно ПИ не добавлять дважды - хранить словарь (let-переменная, номера ПИ в кот добавлена) + public override void visit(SyntaxTree.let_var_expr let_expr) + { + if (letDict.ContainsKey(let_expr) && letDict[let_expr].Contains(context.CurrentScope.ScopeNum)) + return; + + if (!letDict.ContainsKey(let_expr)) + letDict[let_expr] = new List(); + letDict[let_expr].Add(context.CurrentScope.ScopeNum); + + var exn = (expression_node)convert_strong(let_expr.ex); + var sav = new semantic_addr_value(exn); + var vds = new var_statement(let_expr.id, sav, let_expr.source_context); + if (let_expr.visit_var) + { + visit(vds.var_def); + //let_expr.visit_var = false; + } + else + { + + } + return_value(exn); + } + + public override void visit(SyntaxTree.expression_as_statement node) { return_value((statement_node)convert_strong(node.expr)); diff --git a/bin/Lib/CRT.pas b/bin/Lib/CRT.pas index 013f7c6f6..3ac48ff32 100644 --- a/bin/Lib/CRT.pas +++ b/bin/Lib/CRT.pas @@ -155,9 +155,9 @@ function ReadKey: char;// TODO продумать это var KeyInfo: ConsoleKeyInfo; begin - if NextKey <> Chr(0) then + if NextKey <> #0 then begin - ReadKey := nextkey; + ReadKey := NextKey; NextKey := #0; end else @@ -172,7 +172,7 @@ function ReadKey: char;// TODO продумать это function KeyPressed: boolean; begin - KeyPressed := Console.KeyAvailable; + KeyPressed := (NextKey <> #0) or Console.KeyAvailable; end; function WindowWidth: integer; @@ -300,4 +300,4 @@ procedure __InitModule__; begin //zdes oshibka ISConsoleApplication u nas nikogda ne inicializiruetsja __InitModule; -end. \ No newline at end of file +end. diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index ef7d0be43..25ba0910a 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -8882,17 +8882,15 @@ procedure Reverse(var s: string; index, count: integer); procedure Shuffle(a: array of T); begin - var n := a.Length; - for var i := 0 to n - 1 do - Swap(a[i], a[Random(n)]); + for var i := a.Length - 1 downto 1 do + Swap(a[i], a[Random(i + 1)]); end; procedure Shuffle(l: List); begin - var n := l.Count; - for var i := 0 to n - 1 do + for var i := l.Count - 1 downto 1 do begin - var ind := Random(n); + var ind := Random(i + 1); var v := l[i]; l[i] := l[ind]; l[ind] := v; @@ -10756,10 +10754,9 @@ function Indices(Self: List; cond: (T,integer) ->boolean): sequence of int /// Перемешивает элементы списка случайным образом function Shuffle(Self: List): List; extensionmethod; begin - var n := Self.Count; - for var i := 0 to n - 1 do + for var i := Self.Count - 1 downto 1 do begin - var r := Random(n); + var r := Random(i + 1); var v := Self[i]; Self[i] := Self[r]; Self[r] := v; @@ -11814,9 +11811,8 @@ function RandomElement(Self: array of T): T; extensionmethod; /// Перемешивает элементы массива случайным образом function Shuffle(Self: array of T): array of T; extensionmethod; begin - var n := Self.Length; - for var i := 0 to n - 1 do - Swap(Self[i], Self[Random(n)]); + for var i := Self.Length - 1 downto 1 do + Swap(Self[i], Self[Random(i + 1)]); Result := Self; end; diff --git a/bin/Lib/Tasks1Loops.pas b/bin/Lib/Tasks1Loops.pas index 91f79360c..2c5c7c786 100644 --- a/bin/Lib/Tasks1Loops.pas +++ b/bin/Lib/Tasks1Loops.pas @@ -528,7 +528,7 @@ procedure CheckTaskT(name: string); end; 'Min3': begin CheckData(InitialInput := |cRe|*3); - Generatetests(10,tRe(1,100)*2); + Generatetests(10,tRe(1,100)*3); CheckOutput(Min(Re(0),Re(1),Re(2))); end; 'SeriesMin2': begin diff --git a/bin/Lib/TasksStr.pas b/bin/Lib/TasksStr.pas index 805ca318d..a849171a0 100644 --- a/bin/Lib/TasksStr.pas +++ b/bin/Lib/TasksStr.pas @@ -282,7 +282,7 @@ procedure CheckTaskT(name: string); end; 'Insert2': begin CheckData(Input := Empty); - CheckOutput('Петр первый был великим русским императором'); + CheckOutput('Петр Первый был великим русским императором'); end; 'StrChange1': begin CheckData(Input := Empty); @@ -306,7 +306,7 @@ procedure CheckTaskT(name: string); end; 'StrSlice2': begin CheckData(Input := Empty); - CheckOutputSeq(Arr('клад зарыт на юго западе', 'клад зарыт на юго западе')); + CheckOutputSeq(Arr('клад зарыт на юго западе', 'зашифрованное сообщение')); end; 'StrSlice4': begin CheckData(Input := Empty);