diff --git a/AOtp.pas b/AOtp.pas index 28d11d2c..a2ce1803 100644 --- a/AOtp.pas +++ b/AOtp.pas @@ -13,8 +13,7 @@ interface {$region Exception's} MessageException = class(Exception) - public constructor(text: string) := - inherited Create(text); + public constructor(text: string) := inherited Create(text); private constructor := raise new System.InvalidOperationException; end; ParentHaltException = class(Exception) @@ -406,11 +405,11 @@ procedure StartBgThread(p: ()->()); end; procedure Otp(line: OtpLine) := -if AsyncProcOtp.curr<>nil then - AsyncProcOtp.curr.Enq(line) else -if Logger.main=nil then - line.Println else - Logger.main.Otp(line); + if AsyncProcOtp.curr<>nil then + AsyncProcOtp.curr.Enq(line) else + if Logger.main=nil then + line.Println else + Logger.main.Otp(line); procedure Otp(line: string; kind: OtpKind) := Otp(new OtpLine(line, kind)); procedure Otp(line: string; kinds: array of string) := diff --git a/AQueue.pas b/AQueue.pas index 8eacfc3b..b6f8cec6 100644 --- a/AQueue.pas +++ b/AQueue.pas @@ -15,37 +15,33 @@ AsyncQueue = class(IEnumerable, IEnumerator) {$endif DEBUG} public constructor := - q := new Queue; + q := new Queue; public constructor(capacity: integer) := - q := new Queue(capacity); + q := new Queue(capacity); - public procedure Enq(o: T) := - lock q do + public procedure Enq(o: T) := lock q do begin if done then raise new System.InvalidOperationException($'ERROR: Попытка писать {TypeName(o)}[{_ObjectToString(o)}] в завершенную {TypeName(self)}'); q.Enqueue(o); ev.Set; end; public procedure EnqRange(sq: sequence of T) := - foreach var o in sq do Enq(o); + foreach var o in sq do Enq(o); - public procedure Finish; + public procedure Finish := lock q do begin - lock q do - begin - if done then raise new InvalidOperationException($'ERROR: Двойная попытка завершить {self.GetType}' - {$ifdef DEBUG} - +':'#10#10+ - done_trace + #10#10 + - System.Environment.StackTrace - {$endif DEBUG} - ); - done := true; + if done then raise new InvalidOperationException($'ERROR: Двойная попытка завершить {self.GetType}' {$ifdef DEBUG} - done_trace := System.Environment.StackTrace; + +':'#10#10+ + done_trace + #10#10 + + System.Environment.StackTrace {$endif DEBUG} - ev.Set; - end; + ); + done := true; + {$ifdef DEBUG} + done_trace := System.Environment.StackTrace; + {$endif DEBUG} + ev.Set; end; public function GetEnumerator: IEnumerator := self; diff --git a/ColoredStrings.pas b/ColoredStrings.pas index 002167d1..641d6c2f 100644 --- a/ColoredStrings.pas +++ b/ColoredStrings.pas @@ -109,17 +109,17 @@ ColoredStringPart = class {$region Append} public procedure Append(ch: char) := - if range.i2.IsInvalid then sb += ch else - raise new System.InvalidOperationException($'{TypeName(self)} is sealed'); + if range.i2.IsInvalid then sb += ch else + raise new System.InvalidOperationException($'{TypeName(self)} is sealed'); public procedure Append(ch: char; c: integer) := - loop c do Append(ch); + loop c do Append(ch); public procedure Append(s: string) := - for var i := 0 to s.Length-1 do Append(s[i]); + for var i := 0 to s.Length-1 do Append(s[i]); public procedure Append(s: StringSection) := - for var i := 0 to s.Length-1 do Append(s[i]); + for var i := 0 to s.Length-1 do Append(s[i]); public static procedure operator+=(b: ColoredStringBuilderBase; ch: char) := b.Append(ch); public static procedure operator+=(b: ColoredStringBuilderBase; s: string) := b.Append(s); @@ -179,7 +179,7 @@ ColoredStringPart = class Result[i] := parts[i].FinishAsPart; end; private function FinishAsPart := - new ColoredStringPart(self.key, self.GetFixedRange, FinishAllParts); + new ColoredStringPart(self.key, self.GetFixedRange, FinishAllParts); public function Finish: ColoredString; begin diff --git a/Parsing.pas b/Parsing.pas index c071fd9d..61f75021 100644 --- a/Parsing.pas +++ b/Parsing.pas @@ -27,9 +27,9 @@ StringIndex = record(IComparable) public static function operator=(ind1, ind2: StringIndex) := ind1.val=ind2.val; public static function operator=(ind1: StringIndex; ind2: integer) := - (ind1.val=ind2) and not ind1.IsInvalid; + (ind1.val=ind2) and not ind1.IsInvalid; public static function operator=(ind1: integer; ind2: StringIndex) := - (ind1=ind2.val) and not ind2.IsInvalid; + (ind1=ind2.val) and not ind2.IsInvalid; public static function operator<(ind1: StringIndex; ind2: integer) := integer(ind1)(ind1: StringIndex; ind2: integer) := integer(ind1)>ind2; @@ -53,20 +53,20 @@ StringIndex = record(IComparable) public static function operator>=(ind1, ind2: StringIndex) := not (ind1) end; public function ToString: string; override := - if self.IsInvalid then 'StringIndex.Invalid' else self.val.ToString; + if self.IsInvalid then 'StringIndex.Invalid' else self.val.ToString; public function Print: StringIndex; begin self.ToString.Print; @@ -171,9 +171,9 @@ StringSection = record public constructor := exit; public procedure ValidateInd(ind: StringIndex) := - if (ind >= StringIndex(Length)) then raise new System.IndexOutOfRangeException($'Index {ind} was >= {Length}'); + if (ind >= StringIndex(Length)) then raise new System.IndexOutOfRangeException($'Index {ind} was >= {Length}'); public procedure ValidateLen(len: StringIndex) := - if (len > StringIndex(Length)) then raise new System.IndexOutOfRangeException($'Length {len} was > {Length}'); + if (len > StringIndex(Length)) then raise new System.IndexOutOfRangeException($'Length {len} was > {Length}'); public static function operator in(ind: StringIndex; s: StringSection) := ind in s.range; @@ -267,13 +267,13 @@ StringSection = record end; end; public function TrimWhile(ch_validator: char->boolean) := self - .TrimFirstWhile(ch_validator) - .TrimLastWhile(ch_validator); + .TrimFirstWhile(ch_validator) + .TrimLastWhile(ch_validator); public function TakeFirstWhile(ch_validator: char->boolean) := - self.TakeFirst(0).NextWhile(self.I2, ch_validator); + self.TakeFirst(0).NextWhile(self.I2, ch_validator); public function TakeLastWhile(ch_validator: char->boolean) := - self.TakeLast(0).PrevWhile(self.I1, ch_validator); + self.TakeLast(0).PrevWhile(self.I1, ch_validator); public function TrimAfterFirst(ch: char): StringSection; begin @@ -514,7 +514,7 @@ StringSection = record end; public function IsEscaped(min_ind: StringIndex; escape_sym: char) := - self.TakeFirst(0).PrevWhile(min_ind, ch->ch=escape_sym).Length.IsOdd; + self.TakeFirst(0).PrevWhile(min_ind, ch->ch=escape_sym).Length.IsOdd; public procedure UnescapeTo(res: StringBuilder; escape_sym: char); begin @@ -578,7 +578,7 @@ StringSection = record end; public function ToString: string; override := - if self.IsInvalid then 'StringSection.Invalid' else range.ToString(text); + if self.IsInvalid then 'StringSection.Invalid' else range.ToString(text); public property AsString: string read ToString; end; diff --git a/Patterns.pas b/Patterns.pas index 7c9ce696..008f8693 100644 --- a/Patterns.pas +++ b/Patterns.pas @@ -40,7 +40,7 @@ PatternPath = record public n: TJumpNode; public constructor(n: TJumpNode) := self.n := n; public static function operator implicit(n: TJumpNode): PatternPath := - new PatternPath(n); + new PatternPath(n); public function Count: integer; begin @@ -65,7 +65,7 @@ PatternPath = record end; public function ToString: string; override := - self.ToArray(n->n).JoinToString(', '); + self.ToArray(n->n).JoinToString(', '); end; @@ -136,12 +136,12 @@ BasicPatternPointDummy = record(IPatternPoint) := self.ep = p.ep; public static function operator implicit(ep: TPointer): BasicPatternPointDummy := - new BasicPatternPointDummy(ep); + new BasicPatternPointDummy(ep); public property Edge: TPointer read ep; public function ToString: string; override := - $'{self.GetType.Name}(Edge={Edge})'; + $'{self.GetType.Name}(Edge={Edge})'; end; @@ -173,7 +173,7 @@ BasicPatternPointRec = record(IPatternPoint = record(IPatternPoint>; public constructor(ep1: TPointer1; ep2: TPointer2) := impl := - new BasicPatternPointRec>(ep1, ep2); + new BasicPatternPointRec>(ep1, ep2); public [MethodImpl(MethodImplOptions.AggressiveInlining)] function AnyEdgesDone := impl.AnyEdgesDone; @@ -200,8 +200,8 @@ BasicPatternPoint2 = record(IPatternPoint) public function Plus(cost: BasicJumpCost): BasicJumpCost := self.val+cost.val; public function ToString: string; override := - $'{TypeName(self)}({val})'; + $'{TypeName(self)}({val})'; end; @@ -276,7 +276,7 @@ BasicCharIterator = record(IPatternEdgePointer, IPatternEdg public static function operator<>(i1, i2: BasicCharIterator) := not (i1=i2); public function Equals(i: BasicCharIterator) := self=i; public function Equals(o: object): boolean; override := - (o is BasicCharIterator(var i)) and self.Equals(i); + (o is BasicCharIterator(var i)) and self.Equals(i); public property Current: char read s.First; @@ -326,8 +326,8 @@ BasicCharIterator = record(IPatternEdgePointer, IPatternEdg public function MakeCostJumps(i: BasicCharIterator) := BasicCharIterator.MakeCostJumps(self, i); public function ToString: string; override := - s.I1.ToString; -// $'{TypeName(self)}(ind={s.I1}; left={s})'; + s.I1.ToString; +// $'{TypeName(self)}(ind={s.I1}; left={s})'; end; @@ -363,11 +363,11 @@ BasicCharIterator = record(IPatternEdgePointer, IPatternEdg BasicPattern = static class public static function MinPaths(ep1: TPointer1; ep2: TPointer2): sequence of array of BasicPatternDiffBase; - where TPointer1: record, IPatternEdgePointer; - where TPointer2: record, IPatternEdgePointer; + where TPointer1: record, IPatternEdgePointer; + where TPointer2: record, IPatternEdgePointer; public static function MinPaths(ep1, ep2: TPointer): sequence of array of BasicPatternDiff; - where TPointer: record, IPatternEdgePointer; + where TPointer: record, IPatternEdgePointer; end; @@ -408,7 +408,7 @@ implementation end; procedure RemoveWorseThan(p: TPoint) := - pts.RemoveAll(j_res->j_res.Item1.IncLessThan(p)); + pts.RemoveAll(j_res->j_res.Item1.IncLessThan(p)); end; diff --git a/Patterns/MergedStrings.pas b/Patterns/MergedStrings.pas index afe13026..b7ce7876 100644 --- a/Patterns/MergedStrings.pas +++ b/Patterns/MergedStrings.pas @@ -111,7 +111,7 @@ MergedStringLength = record end; public function ToString: string; override := - $'{min}..{max}'; + $'{min}..{max}'; end; @@ -165,7 +165,7 @@ MergedStringCost = record(IJumpCost) end; public function ToString: string; override := - $'{TypeName(self)}[{strafe}, {merge_infs}, {merge_chrs}]'; + $'{TypeName(self)}[{strafe}, {merge_infs}, {merge_chrs}]'; end; @@ -241,7 +241,7 @@ MergedStringPointer = record(IPatternEdgePointer) public function CompareTo(p: MergedStringPointer) := Compare(self, p); public function ToString: string; override := - $'>>> {s} <<< [{data.part_i}, {data.solid_sym_used}]'; + $'>>> {s} <<< [{data.part_i}, {data.solid_sym_used}]'; end; @@ -271,21 +271,21 @@ implementation public property Length: MergedStringLength read new MergedStringLength(val.Length); override; public function TryApply(text: StringSection; c_min, c_max: integer): sequence of StringSection; override := - if val.Length.InRange(c_min, c_max) and text.StartsWith(val) then - |text.TakeFirst(val.Length)| else - System.Array.Empty&; + if val.Length.InRange(c_min, c_max) and text.StartsWith(val) then + |text.TakeFirst(val.Length)| else + System.Array.Empty&; public static function Compare(p1, p2: MergedStringPartSolid) := string.Compare(p1.val, p2.val); public procedure WriteTo(b: ColoredStringBuilderBase; escape_sym: char); override := - b.AddSubRange('solid', b-> - foreach var ch in self.val do - begin - if (ch=escape_sym) or (ch='@') then - b += escape_sym; - b += ch; - end - ); + b.AddSubRange('solid', b-> + foreach var ch in self.val do + begin + if (ch=escape_sym) or (ch='@') then + b += escape_sym; + b += ch; + end + ); end; MergedStringPartWild = sealed class(MergedStringPart) @@ -451,8 +451,7 @@ implementation end; end; - public procedure WriteTo(b: ColoredStringBuilderBase; escape_sym: char); override := - b.AddSubRange('wild', b-> + public procedure WriteTo(b: ColoredStringBuilderBase; escape_sym: char); override := b.AddSubRange('wild', b-> begin b += wild_beg; @@ -675,13 +674,13 @@ implementation function MergedStringPointer.IsOut := data.part_i = s.parts.Length; static function MergedString.Literal(s: string) := -new MergedString(new MergedStringPartSolid(s)); + new MergedString(new MergedStringPartSolid(s)); static function MergedString.Parse(s: StringSection; escape_sym: char) := -new MergedString(OptimizeParts(MakeParts(s, escape_sym)).ToArray); + new MergedString(OptimizeParts(MakeParts(s, escape_sym)).ToArray); procedure MergedString.WriteTo(b: ColoredStringBuilderBase; escape_sym: char) := -foreach var part in parts do part.WriteTo(b, escape_sym); + foreach var part in parts do part.WriteTo(b, escape_sym); static function MergedString.Compare(s1, s2: MergedString): integer; begin @@ -746,10 +745,10 @@ procedure MergedString.WriteTo(b: ColoredStringBuilderBase; escape_sym: public function ToParts(edge1: MergedString): sequence of MergedStringPart; abstract; public static function ToMergedString(edge1: MergedString; n: MergedStringJumpNode) := - new MergedString(MergedString.OptimizeParts( - PatternPath&(n) - .ToArray(n->n.ToParts(edge1)).SelectMany(ps->ps) - ).ToArray); + new MergedString(MergedString.OptimizeParts( + PatternPath&(n) + .ToArray(n->n.ToParts(edge1)).SelectMany(ps->ps) + ).ToArray); end; @@ -812,10 +811,10 @@ procedure MergedString.WriteTo(b: ColoredStringBuilderBase; escape_sym: end; public function ToParts(edge1: MergedString): sequence of MergedStringPart; override := - new MergedStringPart[](new MergedStringPartWild( - len1 * len2, - chars.ToHashSet - )); + new MergedStringPart[](new MergedStringPartWild( + len1 * len2, + chars.ToHashSet + )); end; @@ -1103,42 +1102,42 @@ MergedStringMltCostJumpData = record end; static function MergedString.AllMerges(s1, s2: MergedString) := -Pattern.MinPaths( - new MergedStringPoint2(s1, s2), - default(MergedStringJumpNode), - new MergedStringCost, - - (p, j)-> - begin - var p2 := NextZeroJumpPoint(p); + Pattern.MinPaths( + new MergedStringPoint2(s1, s2), + default(MergedStringJumpNode), + new MergedStringCost, - Result := |ValueTuple.Create(p2, - if p.Edge1=p2.Edge1 then j else - new MergedStringJumpNodeCopy(j, p.Edge1.data, p2.Edge1.data) - )|; + (p, j)-> + begin + var p2 := NextZeroJumpPoint(p); + + Result := |ValueTuple.Create(p2, + if p.Edge1=p2.Edge1 then j else + new MergedStringJumpNodeCopy(j, p.Edge1.data, p2.Edge1.data) + )|; + + end, - end, - - (p, j)-> - MergedStringMltCostJumpData.Create(p, j).AllCostJumps - -).Select(n-> -begin - Result := MergedStringJumpNode.ToMergedString(s1, n); - {$ifdef DEBUG} - - if s1 not in Result then raise new System.InvalidOperationException($'s1{#10}{s1}{#10}{s2}{#10}{Result}{#10}'); - if s2 not in Result then raise new System.InvalidOperationException($'s2{#10}{s1}{#10}{s2}{#10}{Result}{#10}'); - - foreach var esc_ch in '@\' do + (p, j)-> + MergedStringMltCostJumpData.Create(p, j).AllCostJumps + + ).Select(n-> begin - var r2 := MergedString.Parse(Result.ToString(esc_ch), esc_ch); - if Result <> r2 then - raise new System.InvalidOperationException($'{#10}{Result}{#10}{r2}{#10}'); - end; - - {$endif DEBUG} -end); + Result := MergedStringJumpNode.ToMergedString(s1, n); + {$ifdef DEBUG} + + if s1 not in Result then raise new System.InvalidOperationException($'s1{#10}{s1}{#10}{s2}{#10}{Result}{#10}'); + if s2 not in Result then raise new System.InvalidOperationException($'s2{#10}{s1}{#10}{s2}{#10}{Result}{#10}'); + + foreach var esc_ch in '@\' do + begin + var r2 := MergedString.Parse(Result.ToString(esc_ch), esc_ch); + if Result <> r2 then + raise new System.InvalidOperationException($'{#10}{Result}{#10}{r2}{#10}'); + end; + + {$endif DEBUG} + end); {$endregion operator*} @@ -1321,10 +1320,10 @@ function MergedStringInMakeJumps(p: MergedStringPoint2): sequence of MergedStrin end; static function MergedString.operator in(s1, s2: MergedString) := -Pattern.AllPaths( - new MergedStringPoint2(s1, s2), true, - (p, j) -> MergedStringInMakeJumps(p) -).Any; + Pattern.AllPaths( + new MergedStringPoint2(s1, s2), true, + (p, j) -> MergedStringInMakeJumps(p) + ).Any; {$endregion operator in} diff --git a/SubExecuters.pas b/SubExecuters.pas index 4bb92537..0f09e148 100644 --- a/SubExecuters.pas +++ b/SubExecuters.pas @@ -109,7 +109,7 @@ end; function GetUsedModules(fname: string; prev: array of string): sequence of string; -const savepcu_d = '{'+'$savepcu false}'; + const savepcu_d = '{'+'$savepcu false}'; begin if fname in prev then exit; prev := prev+|fname|; diff --git a/Testing/TestExecutor.pas b/Testing/TestExecutor.pas index 14a81a22..90ad8d86 100644 --- a/Testing/TestExecutor.pas +++ b/Testing/TestExecutor.pas @@ -1,57 +1,56 @@ -## uses System.IO, '../CLArgs'; - -procedure OnException(e: Exception; et: string := 'General') := -lock Console.Error do -begin - Console.Error.WriteLine($'%{et}Exception%'); - Console.Error.WriteLine(e); - Halt; -end; - -try - System.Globalization.CultureInfo.DefaultThreadCurrentUICulture := System.Globalization.CultureInfo.CurrentUICulture; - - System.AppDomain.CurrentDomain.UnhandledException += (o,e)-> - OnException(Exception(e.ExceptionObject)); - - var original_input := Console.In; - Console.SetIn(new System.IO.StringReader('')); - - var ep: System.Reflection.MethodInfo; - try - var executable := Path.ChangeExtension(Path.ChangeExtension(GetEXEFileName, nil), '.exe'); - if not FileExists(executable) then - raise new System.IO.FileNotFoundException($'File [{executable}] doesn''t exist'); - ep := System.Reflection.Assembly.LoadFile(executable).EntryPoint; - if ep=nil then raise new System.NullReferenceException; - except - on e: Exception do OnException(e, 'Load'); - end; - - if 'PauseWhenLoaded' in CommandLineArgs then - original_input.ReadLine; - - begin - var halt_thr := new System.Threading.Thread(()-> - try - var max_exec_time := GetArgs('MaxExecTime').Single.ToInteger; -// max_exec_time -= max_exec_time div 10; - Sleep(max_exec_time); - OnException(new System.TimeoutException($'More then {max_exec_time} milliseconds passed'), 'ExecutionTimeOut'); - except - on e: Exception do OnException(e); - end); - halt_thr.IsBackground := true; - halt_thr.Start; - end; - - try - ep.Invoke(nil, new object[0]); - except - on e: System.Reflection.TargetInvocationException do OnException(e.InnerException, 'Execution'); -// on e: Exception do OnException(e, 'Execution'); - end; - -except - on e: Exception do OnException(e); +## uses System.IO, '../CLArgs'; + +procedure OnException(e: Exception; et: string := 'General') := lock Console.Error do +begin + Console.Error.WriteLine($'%{et}Exception%'); + Console.Error.WriteLine(e); + Halt; +end; + +try + System.Globalization.CultureInfo.DefaultThreadCurrentUICulture := System.Globalization.CultureInfo.CurrentUICulture; + + System.AppDomain.CurrentDomain.UnhandledException += (o,e)-> + OnException(Exception(e.ExceptionObject)); + + var original_input := Console.In; + Console.SetIn(new System.IO.StringReader('')); + + var ep: System.Reflection.MethodInfo; + try + var executable := Path.ChangeExtension(Path.ChangeExtension(GetEXEFileName, nil), '.exe'); + if not FileExists(executable) then + raise new System.IO.FileNotFoundException($'File [{executable}] doesn''t exist'); + ep := System.Reflection.Assembly.LoadFile(executable).EntryPoint; + if ep=nil then raise new System.NullReferenceException; + except + on e: Exception do OnException(e, 'Load'); + end; + + if 'PauseWhenLoaded' in CommandLineArgs then + original_input.ReadLine; + + begin + var halt_thr := new System.Threading.Thread(()-> + try + var max_exec_time := GetArgs('MaxExecTime').Single.ToInteger; +// max_exec_time -= max_exec_time div 10; + Sleep(max_exec_time); + OnException(new System.TimeoutException($'More then {max_exec_time} milliseconds passed'), 'ExecutionTimeOut'); + except + on e: Exception do OnException(e); + end); + halt_thr.IsBackground := true; + halt_thr.Start; + end; + + try + ep.Invoke(nil, new object[0]); + except + on e: System.Reflection.TargetInvocationException do OnException(e.InnerException, 'Execution'); +// on e: Exception do OnException(e, 'Execution'); + end; + +except + on e: Exception do OnException(e); end; \ No newline at end of file