From 04e17b7ba800f7f519b8237c902043b0d3e71b3f Mon Sep 17 00:00:00 2001 From: bormant Date: Mon, 22 Jan 2024 14:05:16 +0300 Subject: [PATCH 1/5] =?UTF-8?q?Use=20Fisher=E2=80=93Yates=20shuffle=20(#30?= =?UTF-8?q?30)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/Lib/PABCSystem.pas | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) 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; From 733c9e80e5871b4a733f65e6ca0544b988d00eba Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Mon, 22 Jan 2024 14:15:19 +0300 Subject: [PATCH 2/5] merge --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 4 +-- Localization/DefaultLang.resources | Bin 101625 -> 101832 bytes Release/pabcversion.txt | 2 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- .../StandardSyntaxConverter.cs | 2 +- TestSuite/CompilationSamples/Tasks1Loops.pas | 2 +- TestSuite/CompilationSamples/TasksStr.pas | 4 +-- .../Closure/CapturedVariablesTreeBuilder.cs | 12 +++++++ .../TreeConversion/syntax_tree_visitor.cs | 30 ++++++++++++++++++ bin/Lib/Tasks1Loops.pas | 2 +- bin/Lib/TasksStr.pas | 4 +-- 12 files changed, 54 insertions(+), 12 deletions(-) diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index b4f38d3d5..6fc89b8ce 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 = "3418"; 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..963a31e86 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%MINOR%=9 -%REVISION%=3417 %COREVERSION%=0 +%REVISION%=3418 +%MINOR%=9 %MAJOR%=3 diff --git a/Localization/DefaultLang.resources b/Localization/DefaultLang.resources index 69518271be235d38b8f23c1032064d091a96a724..5378709db2adaa507a72c023ad9fbc8c6a08ac3d 100644 GIT binary patch delta 218 zcmex4lkLQ8wh0dypKN>>=VzCio>^RyTI86Q;+&sXQk0()kW-qTnWvYMSi;Mt8W7~_ z<{6=C%gd#&9|TpZkeHXE098CWkWr#O$kp95IK(w5-qFt`-r3(TB*@<q!lU2s-@ShO j^sNFfmz#f(FQy5+Twn*4=9OgTrZ&6!Z+G=)++qs=)NNr- delta 23 fcmX>xo9*XJwh0dyMK?Z-^K0e{*v=QgxXTs*fjtSd diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index c574e9eee..3e1dca446 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.9.0.3417 +3.9.0.3418 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index 88ab84c22..db1338198 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.9.0.3417' +!define VERSION '3.9.0.3418' 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/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 14fead5d6..664c6e1bd 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -19807,6 +19807,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/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); From 087a00b6368a1628d30825f44b88c8f023431201 Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Mon, 22 Jan 2024 14:49:04 +0300 Subject: [PATCH 3/5] =?UTF-8?q?Shuffle=20-=20=D0=BE=D0=BF=D1=82=D0=B8?= =?UTF-8?q?=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D0=B5=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 4 ++-- Localization/DefaultLang.resources | Bin 101686 -> 101893 bytes Release/pabcversion.txt | 2 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- TestSuite/CompilationSamples/PABCSystem.pas | 20 ++++++++------------ 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 6fc89b8ce..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 = "3418"; + 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 963a31e86..1866a0792 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%COREVERSION%=0 -%REVISION%=3418 %MINOR%=9 +%REVISION%=3419 +%COREVERSION%=0 %MAJOR%=3 diff --git a/Localization/DefaultLang.resources b/Localization/DefaultLang.resources index 814fc980c385db790b948ed63d3cea77eb2d6cb0..48f76c2a172eadf797700b75c248595c3dde7e59 100644 GIT binary patch delta 219 zcmdlsi>-AI+k^*9ioF{j#roN$re_wHq!u~mr8wv3l@#UY1mu*aXXfdpB$n`UsRjhO zx_L&Z+VXPg>jy!VDkSEmC_oiY4rG+54{~+)3=VM(ig)yLiFfw*3kmY~i4X7zb@%j( z=jHNq^mVm8@aWUK4=(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; From 8b971136dc687b5363f1b0272aa988484a2f7758 Mon Sep 17 00:00:00 2001 From: samuraiGH Date: Mon, 29 Jan 2024 20:53:20 +0300 Subject: [PATCH 4/5] repair TargetFramework directive --- Compiler/Compiler.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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); // остальные директивы From e17dd66fd557b9bb8940af0856ab8b7371f73d09 Mon Sep 17 00:00:00 2001 From: bormant Date: Thu, 1 Feb 2024 22:08:40 +0300 Subject: [PATCH 5/5] Make KeyPressed act hand by hand with ReadKey (#3036) --- bin/Lib/CRT.pas | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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.