Skip to content

Commit ed30e42

Browse files
committed
Переделки в PABCSystem - теперь используются yield
Исправлена мелкая ошибка - в генерируемом коде var res исправлена на var $res
1 parent 381df67 commit ed30e42

File tree

7 files changed

+141
-79
lines changed

7 files changed

+141
-79
lines changed

Configuration/GlobalAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal static class RevisionClass
1515
public const string Major = "3";
1616
public const string Minor = "1";
1717
public const string Build = "0";
18-
public const string Revision = "1290";
18+
public const string Revision = "1291";
1919

2020
public const string MainVersion = Major + "." + Minor;
2121
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;

Configuration/Version.defs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%MINOR%=1
2-
%REVISION%=1290
31
%COREVERSION%=0
2+
%REVISION%=1291
3+
%MINOR%=1
44
%MAJOR%=3
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
!define VERSION '3.1.0.1290'
1+
!define VERSION '3.1.0.1291'

SyntaxVisitors/YieldVisitors/ProcessYieldsCapturedVars.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,19 @@ type_declarations GenClassesForYield(procedure_definition pd,
184184

185185

186186
// frninja 20/04/16 - поддержка шаблонных классов
187-
var stl = new statement_list(new var_statement("res", new new_expr(this.CreateClassReference(className), new expression_list())));
187+
var stl = new statement_list(new var_statement("$res", new new_expr(this.CreateClassReference(className), new expression_list())));
188188

189189

190-
//stl.AddMany(lid.Select(id => new assign(new dot_node("res", id), id)));
191-
stl.AddMany(lid.Select(id => new assign(new dot_node("res", new ident(formalParamsMap[id.name])), id)));
190+
//stl.AddMany(lid.Select(id => new assign(new dot_node("$res", id), id)));
191+
stl.AddMany(lid.Select(id => new assign(new dot_node("$res", new ident(formalParamsMap[id.name])), id)));
192192

193193
// frninja 08/12/15 - захват self
194194
if (iteratorClassName != null && !pd.proc_header.class_keyword)
195195
{
196-
stl.Add(new assign(new dot_node("res", YieldConsts.Self), new ident("self")));
196+
stl.Add(new assign(new dot_node("$res", YieldConsts.Self), new ident("self")));
197197
}
198198

199-
stl.Add(new assign("Result", "res"));
199+
stl.Add(new assign("Result", "$res"));
200200

201201
// New body
202202
pd.proc_body = new block(stl);
@@ -263,18 +263,18 @@ type_declarations GenClassesForYield(procedure_definition pd,
263263
//SyntaxTreeBuilder.BuildClassDefinition(interfaces1, cm1));
264264

265265

266-
var stl1 = new statement_list(new var_statement("res", new new_expr(this.CreateClassReference(className), new expression_list())));
266+
var stl1 = new statement_list(new var_statement("$res", new new_expr(this.CreateClassReference(className), new expression_list())));
267267

268268

269-
stl1.AddMany(lid.Select(id => new assign(new dot_node("res", new ident(formalParamsMap[id.name])), new ident(formalParamsMap[id.name]))));
269+
stl1.AddMany(lid.Select(id => new assign(new dot_node("$res", new ident(formalParamsMap[id.name])), new ident(formalParamsMap[id.name]))));
270270

271271
// Переприсваивание self
272272
if (iteratorClassName != null && !pd.proc_header.class_keyword)
273273
{
274-
stl1.Add(new assign(new dot_node("res", YieldConsts.Self), new ident(YieldConsts.Self)));
274+
stl1.Add(new assign(new dot_node("$res", YieldConsts.Self), new ident(YieldConsts.Self)));
275275
}
276276

277-
stl1.Add(new assign("Result", "res"));
277+
stl1.Add(new assign("Result", "$res"));
278278

279279

280280
GetEnumeratorBody.Add(new if_node(new bin_expr(new ident(YieldConsts.State), new int32_const(0), Operators.Equal),
@@ -928,8 +928,8 @@ public override void visit(procedure_definition pd)
928928

929929
// Обработка метода для корректного захвата локальных переменных и их типов
930930
// - это уже не надо - иногда можно включать чтобы посмотреть, что собой представляет функция после Loweringа
931-
IEnumerable<var_def_statement> localsClonesCollection;
932-
CreateLocalVariablesTypeProxies(pd, out localsClonesCollection);
931+
//IEnumerable<var_def_statement> localsClonesCollection;
932+
//CreateLocalVariablesTypeProxies(pd, out localsClonesCollection);
933933

934934
// frninja 16/11/15: перенес ниже чтобы работал захват для lowered for
935935

TestSuite/CompilationSamples/PABCSystem.pas

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,9 +3788,9 @@ function Seq<T>(params a: array of T): sequence of T;
37883788
Result := res;
37893789
end;
37903790

3791-
type
3791+
{type
37923792
// Вспомогательный класс для генерации бесконечной последовательности целых, начиная с заданного значения
3793-
{ IntNumbersClass = class(SeqBaseInteger,IEnumerable<integer>,IEnumerator<integer>)
3793+
IntNumbersClass = class(SeqBaseInteger,IEnumerable<integer>,IEnumerator<integer>)
37943794
private
37953795
first,cur: integer;
37963796
public
@@ -3815,7 +3815,7 @@ { IntNumbersClass = class(SeqBaseInteger,IEnumerable<integer>,IEnumerator<integ
38153815
end;}
38163816

38173817
// Вспомогательный класс для генерации рекуррентных последовательностей
3818-
IterateClass<T> = class(SeqBase<T>,IEnumerable<T>,IEnumerator<T>)
3818+
{ IterateClass<T> = class(SeqBase<T>,IEnumerable<T>,IEnumerator<T>)
38193819
private
38203820
first: T;
38213821
cur: T;
@@ -3890,18 +3890,33 @@ Iterate2Class<T> = class(SeqBase<T>,IEnumerable<T>,IEnumerator<T>)
38903890
b := second;
38913891
isfirst := true;
38923892
end;
3893-
end;
3893+
end;}
38943894

38953895
/// Возвращает бесконечную рекуррентную последовательность элементов, задаваемую начальным элементом first и функцией next
38963896
function Iterate<T>(first: T; next: T->T): sequence of T;
38973897
begin
3898-
Result := IterateClass&<T>.Create(first,next).Select(x->T(x));
3898+
yield first;
3899+
while True do
3900+
begin
3901+
first := next(first);
3902+
yield first;
3903+
end;
3904+
//Result := IterateClass&<T>.Create(first,next).Select(x->T(x));
38993905
end;
39003906

39013907
/// Возвращает бесконечную рекуррентную последовательность элементов, задаваемую начальными элементами first, second и функцией next
39023908
function Iterate<T>(first,second: T; next: (T,T)->T): sequence of T;
39033909
begin
3904-
Result := Iterate2Class&<T>.Create(first,second,next).Select(x->T(x));
3910+
yield first;
3911+
yield second;
3912+
while True do
3913+
begin
3914+
var nxt := next(first,second);
3915+
yield nxt;
3916+
first := second;
3917+
second := nxt;
3918+
end;
3919+
// Result := Iterate2Class&<T>.Create(first,second,next).Select(x->T(x));
39053920
end;
39063921

39073922
function SeqGen<T>(count: integer; first: T; next: T -> T): sequence of T;
@@ -7911,60 +7926,49 @@ function Iterate<T>(Self,second: T; next: (T,T) -> T): sequence of T; extensionm
79117926
/// Возвращает бесконечную последовательность целых от текущего значения с шагом 1
79127927
function Step(Self: integer): sequence of integer; extensionmethod;
79137928
begin
7914-
//Result := IntNumbersClass.Create(Self);
7915-
var s := Self;
79167929
while True do
79177930
begin
7918-
yield s;
7919-
s += 1;
7931+
yield Self;
7932+
Self += 1;
79207933
end;
79217934
end;
79227935

79237936
/// Возвращает бесконечную последовательность целых от текущего значения с шагом step
79247937
function Step(Self: integer; step: integer): sequence of integer; extensionmethod;
79257938
begin
7926-
{var slf := Self;
7927-
Result := IntNumbersClass.Create().Select(x->x*step+slf);}
7928-
var s := Self;
79297939
while True do
79307940
begin
7931-
yield s;
7932-
s += step;
7941+
yield Self;
7942+
Self += step;
79337943
end;
79347944
end;
79357945

79367946
/// Возвращает бесконечную последовательность вещественных от текущего значения с шагом step
79377947
function Step(Self: real; step: real): sequence of real; extensionmethod;
79387948
begin
7939-
{var slf := Self;
7940-
Result := IntNumbersClass.Create().Select(x->x*step+slf);}
7941-
var s := Self;
79427949
while True do
79437950
begin
7944-
yield s;
7945-
s += step;
7951+
yield Self;
7952+
Self += step;
79467953
end;
79477954
end;
79487955

79497956
// Возвращает бесконечную последовательность элементов, совпадающих с данным
79507957
///--
79517958
function &Repeat<T>(Self: T): sequence of T; extensionmethod;
79527959
begin
7953-
var s := Self;
79547960
while True do
7955-
yield s;
7961+
yield Self;
79567962
end;
79577963

79587964
/// Повторяет последовательность бесконечное число раз
79597965
function Cycle<T>(Self: sequence of T): sequence of T; extensionmethod;
79607966
begin
7961-
var s := Self;
79627967
while True do
79637968
begin
7964-
foreach var x in s do
7969+
foreach var x in Self do
79657970
yield x;
79667971
end;
7967-
// Result := SeqFill(MaxInt,Self).SelectMany(x->x);
79687972
end;
79697973

79707974
//------------------------------------------------------------------------------
@@ -7986,7 +7990,10 @@ function Print<T>(Self: sequence of T; delim: string): sequence of T; extensionm
79867990
/// Выводит последовательность на экран, используя пробел в качестве разделителя
79877991
function Print<T>(Self: sequence of T): sequence of T; extensionmethod;
79887992
begin
7989-
Result := Self.Print(PrintDelimDefault);
7993+
if typeof(T)=typeof(char) then
7994+
Result := Self.Print('')
7995+
else
7996+
Result := Self.Print(PrintDelimDefault);
79907997
end;
79917998

79927999
/// Выводит последовательность на экран, используя delim в качестве разделителя, и переходит на новую строку
@@ -8000,7 +8007,10 @@ function Println<T>(Self: sequence of T; delim: string): sequence of T; extensio
80008007
/// Выводит последовательность на экран, используя пробел качестве разделителя, и переходит на новую строку
80018008
function Println<T>(Self: sequence of T): sequence of T; extensionmethod;
80028009
begin
8003-
Result := Self.Println(PrintDelimDefault);
8010+
if typeof(T)=typeof(char) then
8011+
Result := Self.Println('')
8012+
else
8013+
Result := Self.Println(PrintDelimDefault);
80048014
end;
80058015

80068016
/// Выводит последовательность строк в файл
@@ -8025,7 +8035,9 @@ function JoinIntoString<T>(Self: sequence of T; delim: string): string; extensio
80258035
/// Преобразует элементы последовательности в строковое представление, после чего объединяет их в строку, используя пробел в качестве разделителя
80268036
function JoinIntoString<T>(Self: sequence of T): string; extensionmethod;
80278037
begin
8028-
Result := Self.JoinIntoString(' ');
8038+
if typeof(T) = typeof(char) then
8039+
Result := Self.JoinIntoString('')
8040+
else Result := Self.JoinIntoString(' ');
80298041
end;
80308042

80318043
/// Применяет действие к каждому элементу последовательности
@@ -8144,15 +8156,25 @@ function Cartesian<T,T1>(Self: sequence of T; b: sequence of T1): sequence of (T
81448156
begin
81458157
if b=nil then
81468158
raise new System.ArgumentNullException('b');
8147-
Result := Self.Select(x->b.Select(y->(x,y))).SelectMany(x->x);
8159+
8160+
foreach var x in Self do
8161+
foreach var y in b do
8162+
yield (x,y)
8163+
8164+
//Result := Self.Select(x->b.Select(y->(x,y))).SelectMany(x->x);
81488165
end;
81498166

81508167
/// Декартово произведение последовательностей
81518168
function Cartesian<T,T1,T2>(Self: sequence of T; b: sequence of T1; func: (T,T1)->T2): sequence of T2; extensionmethod;
81528169
begin
81538170
if b=nil then
81548171
raise new System.ArgumentNullException('b');
8155-
Result := Self.Select(x->b.Select(y->(x,y))).SelectMany(x->x).Select(x->func(x[0],x[1]));
8172+
8173+
foreach var x in Self do
8174+
foreach var y in b do
8175+
yield func(x,y)
8176+
8177+
// Result := Self.Select(x->b.Select(y->(x,y))).SelectMany(x->x).Select(x->func(x[0],x[1]));
81568178
end;
81578179

81588180
/// Разбивает последовательности на две в позиции ind
@@ -8290,11 +8312,20 @@ function Pairwise<T>(Self: sequence of T): sequence of (T,T); extensionmethod;
82908312
end
82918313
end;
82928314

8293-
82948315
/// Превращает последовательность в последовательность пар соседних элементов, применяет func к каждой паре полученных элементов и получает новую последовательность
82958316
function Pairwise<T,Res>(Self: sequence of T; func:(T,T)->Res): sequence of Res; extensionmethod;
82968317
begin
8297-
Result := Self.ZipTuple(Self.Skip(1)).Select(x->func(x[0],x[1]));
8318+
var previous: T;
8319+
var it := Self.GetEnumerator();
8320+
if (it.MoveNext()) then
8321+
previous := it.Current;
8322+
8323+
while (it.MoveNext()) do
8324+
begin
8325+
yield func(previous,it.Current);
8326+
previous := it.Current;
8327+
end
8328+
// Result := Self.ZipTuple(Self.Skip(1)).Select(x->func(x[0],x[1]));
82988329
end;
82998330

83008331
/// Разбивает последовательность на серии длины size

bin/Lib/PABCRtl.dll

2.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)