From fb60f8884df69dcdffed0f21b00d5db492cb92f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Sun, 17 Dec 2017 12:40:06 +0100 Subject: [PATCH] bug fix #585 --- .../Graphics/GraphWPF/ArcSector.pas | 4 +- InstallerSamples/Graphics/GraphWPF/Clock.pas | 4 +- .../Graphics/GraphWPF/CurjaMurja.pas | 12 ++-- .../Graphics/GraphWPF/DrawGraphic.pas | 4 +- .../Graphics/GraphWPF/EllRectInWindow.pas | 2 +- .../Graphics/GraphWPF/Ellipses.pas | 4 +- InstallerSamples/Graphics/GraphWPF/anim1.pas | 4 +- InstallerSamples/Graphics/GraphWPF/anim2.pas | 6 +- InstallerSamples/Graphics/GraphWPF/anim4.pas | 4 +- InstallerSamples/Graphics/GraphWPF/mouse1.pas | 2 +- InstallerSamples/Graphics/GraphWPF/mouse2.pas | 4 +- ...ТочкиМногоугольника.pas | 6 +- .../ВыравниваниеТекста1.pas | 6 +- .../ВыравниваниеТекста2.pas | 6 +- .../GraphWPF/Многоугольник.pas | 6 +- .../Graphics/GraphWPF/Светофор.pas | 8 +-- .../Система координат.pas | 10 ++-- .../ТаблицаУмножения.pas | 4 +- .../System.Parallel/Parallel1.pas | 2 +- TestSuite/CompilationSamples/ArcSector.pas | 15 +++++ TestSuite/CompilationSamples/Clock.pas | 12 ++++ TestSuite/CompilationSamples/CurjaMurja.pas | 36 ++++++++++++ TestSuite/CompilationSamples/DrawGraphic.pas | 11 ++++ .../CompilationSamples/EllRectInWindow.pas | 7 +++ TestSuite/CompilationSamples/Ellipses.pas | 14 +++++ TestSuite/CompilationSamples/Parallel1.pas | 8 +++ TestSuite/CompilationSamples/Parallel2.pas | 46 +++++++++++++++ TestSuite/CompilationSamples/Parallel3.pas | 57 +++++++++++++++++++ TestSuite/CompilationSamples/anim1.pas | 16 ++++++ TestSuite/CompilationSamples/anim2.pas | 25 ++++++++ TestSuite/CompilationSamples/anim4.pas | 45 +++++++++++++++ TestSuite/CompilationSamples/mouse1.pas | 6 ++ TestSuite/CompilationSamples/mouse2.pas | 10 ++++ ...ТочкиМногоугольника.pas | 12 ++++ .../ВыравниваниеТекста1.pas | 30 ++++++++++ .../ВыравниваниеТекста2.pas | 34 +++++++++++ .../Многоугольник.pas | 20 +++++++ .../CompilationSamples/Светофор.pas | 19 +++++++ .../Система координат.pas | 18 ++++++ .../ТаблицаУмножения.pas | 16 ++++++ .../TreeConversion/syntax_tree_visitor.cs | 33 +++++++++-- 41 files changed, 535 insertions(+), 53 deletions(-) create mode 100644 TestSuite/CompilationSamples/ArcSector.pas create mode 100644 TestSuite/CompilationSamples/Clock.pas create mode 100644 TestSuite/CompilationSamples/CurjaMurja.pas create mode 100644 TestSuite/CompilationSamples/DrawGraphic.pas create mode 100644 TestSuite/CompilationSamples/EllRectInWindow.pas create mode 100644 TestSuite/CompilationSamples/Ellipses.pas create mode 100644 TestSuite/CompilationSamples/Parallel1.pas create mode 100644 TestSuite/CompilationSamples/Parallel2.pas create mode 100644 TestSuite/CompilationSamples/Parallel3.pas create mode 100644 TestSuite/CompilationSamples/anim1.pas create mode 100644 TestSuite/CompilationSamples/anim2.pas create mode 100644 TestSuite/CompilationSamples/anim4.pas create mode 100644 TestSuite/CompilationSamples/mouse1.pas create mode 100644 TestSuite/CompilationSamples/mouse2.pas create mode 100644 TestSuite/CompilationSamples/ВсеТочкиМногоугольника.pas create mode 100644 TestSuite/CompilationSamples/ВыравниваниеТекста1.pas create mode 100644 TestSuite/CompilationSamples/ВыравниваниеТекста2.pas create mode 100644 TestSuite/CompilationSamples/Многоугольник.pas create mode 100644 TestSuite/CompilationSamples/Светофор.pas create mode 100644 TestSuite/CompilationSamples/Система координат.pas create mode 100644 TestSuite/CompilationSamples/ТаблицаУмножения.pas diff --git a/InstallerSamples/Graphics/GraphWPF/ArcSector.pas b/InstallerSamples/Graphics/GraphWPF/ArcSector.pas index d2cea5b0c..b67e15e9e 100644 --- a/InstallerSamples/Graphics/GraphWPF/ArcSector.pas +++ b/InstallerSamples/Graphics/GraphWPF/ArcSector.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Дуги и секторы'; var (x,y) := (200,Window.Height/2); Circle(x,y,5); for var i:=1 to 18*2 do diff --git a/InstallerSamples/Graphics/GraphWPF/Clock.pas b/InstallerSamples/Graphics/GraphWPF/Clock.pas index dab908f30..7fd909eaf 100644 --- a/InstallerSamples/Graphics/GraphWPF/Clock.pas +++ b/InstallerSamples/Graphics/GraphWPF/Clock.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Цифровые часы'; Font.Size := 180; while True do begin diff --git a/InstallerSamples/Graphics/GraphWPF/CurjaMurja.pas b/InstallerSamples/Graphics/GraphWPF/CurjaMurja.pas index eed3c7c04..91574aa61 100644 --- a/InstallerSamples/Graphics/GraphWPF/CurjaMurja.pas +++ b/InstallerSamples/Graphics/GraphWPF/CurjaMurja.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Всякая Курья Мурья'; Pen.Width := 0.5; Brush.Color := RGB(128,200,100); Ellipse(100,100,30,20); @@ -23,14 +23,14 @@ begin Font.Color := Colors.Blue; Font.Name := 'Times New Roman'; Font.Style := FontStyle.BoldItalic; - TextOut(200,0,''); + TextOut(200,0,'Привет'); Sleep(1000); Window.Save('1.png'); - Window.Title := ''; + Window.Title := 'Сохранили'; Sleep(1000); Window.Clear; - Window.Title := ''; + Window.Title := 'Очистили'; Sleep(1000); Window.Load('1.png'); - Window.Title := ''; + Window.Title := 'Загрузили'; end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/DrawGraphic.pas b/InstallerSamples/Graphics/GraphWPF/DrawGraphic.pas index 2580ba67d..863236422 100644 --- a/InstallerSamples/Graphics/GraphWPF/DrawGraphic.pas +++ b/InstallerSamples/Graphics/GraphWPF/DrawGraphic.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Графики функций'; var ww := Window.Width / 2; var hh := Window.Height / 2; DrawGraph(x -> sin(4 * x) + cos(3 * x), -5, 5, 0, 0, ww, hh); diff --git a/InstallerSamples/Graphics/GraphWPF/EllRectInWindow.pas b/InstallerSamples/Graphics/GraphWPF/EllRectInWindow.pas index 564874776..12386e260 100644 --- a/InstallerSamples/Graphics/GraphWPF/EllRectInWindow.pas +++ b/InstallerSamples/Graphics/GraphWPF/EllRectInWindow.pas @@ -1,4 +1,4 @@ -uses GraphWPF; +uses GraphWPF; begin Pen.Width := 1; diff --git a/InstallerSamples/Graphics/GraphWPF/Ellipses.pas b/InstallerSamples/Graphics/GraphWPF/Ellipses.pas index 8a75e5b89..dbaf68a53 100644 --- a/InstallerSamples/Graphics/GraphWPF/Ellipses.pas +++ b/InstallerSamples/Graphics/GraphWPF/Ellipses.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Рисование эллипсов'; Pen.Width := 1; var n := 20000; for var i:=1 to n do diff --git a/InstallerSamples/Graphics/GraphWPF/anim1.pas b/InstallerSamples/Graphics/GraphWPF/anim1.pas index 8d4d92903..0160433a0 100644 --- a/InstallerSamples/Graphics/GraphWPF/anim1.pas +++ b/InstallerSamples/Graphics/GraphWPF/anim1.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Простая анимация'; var x := 30; Brush.Color := Colors.Beige; Circle(x,50,20); diff --git a/InstallerSamples/Graphics/GraphWPF/anim2.pas b/InstallerSamples/Graphics/GraphWPF/anim2.pas index adab6e7a5..d9a0a6dad 100644 --- a/InstallerSamples/Graphics/GraphWPF/anim2.pas +++ b/InstallerSamples/Graphics/GraphWPF/anim2.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' . '; + Window.Title := 'Отражение шарика. Вещественное направление движения'; Brush.Color := Colors.Beige; var x := 400.0; var y := 300.0; @@ -20,6 +20,6 @@ begin dy := -dy; Circle(x,y,20); if Milliseconds>2000 then - Window.Title := ': ' + (Milliseconds div 100)/10; + Window.Title := 'Секунды: ' + (Milliseconds div 100)/10; end; end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/anim4.pas b/InstallerSamples/Graphics/GraphWPF/anim4.pas index a61561d05..4d2d5a692 100644 --- a/InstallerSamples/Graphics/GraphWPF/anim4.pas +++ b/InstallerSamples/Graphics/GraphWPF/anim4.pas @@ -1,4 +1,4 @@ -uses GraphWPF; +uses GraphWPF; function RandomReal(a,b: real): real := Random*(b-a)+a; @@ -31,7 +31,7 @@ type end; begin - Window.Title := ' . '; + Window.Title := 'Отражение шариков. Анимация на основе кадра'; var n := 1000; var a := BallInfo.CreateRandomBallArray(n); diff --git a/InstallerSamples/Graphics/GraphWPF/mouse1.pas b/InstallerSamples/Graphics/GraphWPF/mouse1.pas index 59f22dc9f..8349d012e 100644 --- a/InstallerSamples/Graphics/GraphWPF/mouse1.pas +++ b/InstallerSamples/Graphics/GraphWPF/mouse1.pas @@ -1,4 +1,4 @@ -uses GraphWPF; +uses GraphWPF; begin OnMouseDown := (x,y,mb) -> if mb=1 then Circle(x,y,5); diff --git a/InstallerSamples/Graphics/GraphWPF/mouse2.pas b/InstallerSamples/Graphics/GraphWPF/mouse2.pas index 4cddff0c6..af3d6a87c 100644 --- a/InstallerSamples/Graphics/GraphWPF/mouse2.pas +++ b/InstallerSamples/Graphics/GraphWPF/mouse2.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Рисование мышью'; Pen.Color := Colors.Blue; Pen.Width := 3; OnMouseDown := (x,y,mb) -> MoveTo(x,y); diff --git a/InstallerSamples/Graphics/GraphWPF/ВсеТочкиМногоугольника.pas b/InstallerSamples/Graphics/GraphWPF/ВсеТочкиМногоугольника.pas index cc5df21eb..0779979c3 100644 --- a/InstallerSamples/Graphics/GraphWPF/ВсеТочкиМногоугольника.pas +++ b/InstallerSamples/Graphics/GraphWPF/ВсеТочкиМногоугольника.pas @@ -1,6 +1,6 @@ -uses GraphWPF; +uses GraphWPF; -procedure (x0,y0,r: real; n: integer); +procedure ВсеТочкиМногоугольника(x0,y0,r: real; n: integer); begin var q := Partition(0,2*Pi,n).Select(a->Pnt(x0 + r * Cos(a), y0 - r * Sin(a))); q.Cartesian(q).ForEach(p->Line(p[0].x,p[0].y,p[1].x,p[1].y,RandomColor)); @@ -8,5 +8,5 @@ end; begin Pen.Width := 0.5; - (400,300,290,30) + ВсеТочкиМногоугольника(400,300,290,30) end. diff --git a/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста1.pas b/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста1.pas index d5c6671b1..de8e67e62 100644 --- a/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста1.pas +++ b/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста1.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Выравнивание шрифта'; Font.Size := 20; var (x,y) := (200,200); var (w,h) := (400,200); @@ -15,7 +15,7 @@ begin DrawText(x,y,w,h,'RightTop',Alignment.RightTop); DrawText(x,y,w,h,'RightCenter',Alignment.RightCenter); DrawText(x,y,w,h,'RightBottom',Alignment.RightBottom); - // + // Выравнивание относительно точки TextOut(150,100,'PointRightBottom',Alignment.RightBottom); TextOut(150,100,'PointRightTop',Alignment.RightTop); TextOut(150,100,'PointLeftTop',Alignment.LeftTop); diff --git a/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста2.pas b/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста2.pas index a39daf9f2..f8e622973 100644 --- a/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста2.pas +++ b/InstallerSamples/Graphics/GraphWPF/ВыравниваниеТекста2.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Выравнивание шрифта'; Font.Size := 20; var sc := 40; @@ -19,7 +19,7 @@ begin DrawText(x,y,w,h,'RightTop',Alignment.RightTop); DrawText(x,y,w,h,'RightCenter',Alignment.RightCenter); DrawText(x,y,w,h,'RightBottom',Alignment.RightBottom); - // + // Выравнивание относительно точки TextOut(-5,5,'PointRightBottom',Alignment.RightBottom); TextOut(-5,5,'PointRightTop',Alignment.RightTop); TextOut(-5,5,'PointLeftTop',Alignment.LeftTop); diff --git a/InstallerSamples/Graphics/GraphWPF/Многоугольник.pas b/InstallerSamples/Graphics/GraphWPF/Многоугольник.pas index d77b27529..2d6e3c80d 100644 --- a/InstallerSamples/Graphics/GraphWPF/Многоугольник.pas +++ b/InstallerSamples/Graphics/GraphWPF/Многоугольник.pas @@ -1,6 +1,6 @@ -uses GraphWPF; +uses GraphWPF; -procedure (x0,y0,r: real; n: integer); +procedure Многоугольник(x0,y0,r: real; n: integer); begin var a := Pi / 2; MoveTo(x0 + r * Cos(a), y0 - r * Sin(a)); @@ -16,5 +16,5 @@ begin var (x0,y0) := (400.0,300.0); var r := 30.0; for var n := 3 to 11 do - (x0,y0,r+(n-3)*30,n) + Многоугольник(x0,y0,r+(n-3)*30,n) end. diff --git a/InstallerSamples/Graphics/GraphWPF/Светофор.pas b/InstallerSamples/Graphics/GraphWPF/Светофор.pas index 6dceb3ac2..26176c958 100644 --- a/InstallerSamples/Graphics/GraphWPF/Светофор.pas +++ b/InstallerSamples/Graphics/GraphWPF/Светофор.pas @@ -1,6 +1,6 @@ -uses GraphWPF; +uses GraphWPF; -procedure (x,y,r: real); +procedure Светофор(x,y,r: real); begin Rectangle(x,y,4*r,10*r,Colors.LightGray); x += 2*r; @@ -14,6 +14,6 @@ end; begin Pen.Width := 2; - Window.Title := ''; - (150,40,50); + Window.Title := 'Светофор'; + Светофор(150,40,50); end. \ No newline at end of file diff --git a/InstallerSamples/Graphics/GraphWPF/Система координат.pas b/InstallerSamples/Graphics/GraphWPF/Система координат.pas index 91cf94b45..343c23ee5 100644 --- a/InstallerSamples/Graphics/GraphWPF/Система координат.pas +++ b/InstallerSamples/Graphics/GraphWPF/Система координат.pas @@ -1,15 +1,15 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Система координат'; Font.Size := 20; - // SetMathematicCoords; // - // SetMathematicCoords(-10,10); // + // SetMathematicCoords; // так тоже можно + // SetMathematicCoords(-10,10); // так тоже можно SetMathematicCoords(-10,10,-9.2); DrawGrid; - Print(' :',XMin,XMax,YMin,YMax); + Print('Видимые координаты:',XMin,XMax,YMin,YMax); Polygon(Arr((-3,2),(2,1),(-2,-4)),ARGB(100,255,228,196)); TextOut(-3,2,'A(-3,2)',Alignment.RightBottom); diff --git a/InstallerSamples/Graphics/GraphWPF/ТаблицаУмножения.pas b/InstallerSamples/Graphics/GraphWPF/ТаблицаУмножения.pas index 26ec5e100..5565ca737 100644 --- a/InstallerSamples/Graphics/GraphWPF/ТаблицаУмножения.pas +++ b/InstallerSamples/Graphics/GraphWPF/ТаблицаУмножения.pas @@ -1,7 +1,7 @@ -uses GraphWPF; +uses GraphWPF; begin - Window.Title := ' '; + Window.Title := 'Таблица умножения'; Font.Size := 16; var n := 9; var w := 40; diff --git a/InstallerSamples/NETLibraries/System.Parallel/Parallel1.pas b/InstallerSamples/NETLibraries/System.Parallel/Parallel1.pas index 963ca3dae..5cdfcd0a7 100644 --- a/InstallerSamples/NETLibraries/System.Parallel/Parallel1.pas +++ b/InstallerSamples/NETLibraries/System.Parallel/Parallel1.pas @@ -1,4 +1,4 @@ -Uses System,System.Net,System.Threading.Tasks; +Uses System,System.Net,System.Threading.Tasks; begin Parallel.Invoke ( diff --git a/TestSuite/CompilationSamples/ArcSector.pas b/TestSuite/CompilationSamples/ArcSector.pas new file mode 100644 index 000000000..b67e15e9e --- /dev/null +++ b/TestSuite/CompilationSamples/ArcSector.pas @@ -0,0 +1,15 @@ +uses GraphWPF; + +begin + Window.Title := 'Дуги и секторы'; + var (x,y) := (200,Window.Height/2); + Circle(x,y,5); + for var i:=1 to 18*2 do + Arc(x,y,5*i,0,10*i); + (x,y) := (600,Window.Height/2); + for var i:=1 to 12 do + begin + Brush.Color := RandomColor; + Sector(x,y,180,30*(i-1),30*i); + end; +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/Clock.pas b/TestSuite/CompilationSamples/Clock.pas new file mode 100644 index 000000000..7fd909eaf --- /dev/null +++ b/TestSuite/CompilationSamples/Clock.pas @@ -0,0 +1,12 @@ +uses GraphWPF; + +begin + Window.Title := 'Цифровые часы'; + Font.Size := 180; + while True do + begin + DrawText(Window.ClientRect,System.DateTime.Now.ToLongTimeString,Colors.Red); + Sleep(1000); + Window.Clear; + end; +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/CurjaMurja.pas b/TestSuite/CompilationSamples/CurjaMurja.pas new file mode 100644 index 000000000..91574aa61 --- /dev/null +++ b/TestSuite/CompilationSamples/CurjaMurja.pas @@ -0,0 +1,36 @@ +uses GraphWPF; + +begin + Window.Title := 'Всякая Курья Мурья'; + Pen.Width := 0.5; + Brush.Color := RGB(128,200,100); + Ellipse(100,100,30,20); + Brush.Color := RandomColor; + Circle(170,100,20); + Brush.Color := RandomColor; + Rectangle(220,80,70,50); + Line(220,80,220+70,80+50); + //DrawImage(200,140,'cofe.jpg'); + Brush.Color := RGB(200,200,255); + Polygon(Arr(Pnt(20,20),Pnt(20,120),Pnt(120,20))); + Brush.Color := Colors.Black; + for var i:=0 to 400 do + Rectangle(1+2*i,2,0,0); + Font.Size := 30; + Font.Color := Colors.Red; + TextOut(0,0,'Hello'); + Font.Size := 40; + Font.Color := Colors.Blue; + Font.Name := 'Times New Roman'; + Font.Style := FontStyle.BoldItalic; + TextOut(200,0,'Привет'); + Sleep(1000); + Window.Save('1.png'); + Window.Title := 'Сохранили'; + Sleep(1000); + Window.Clear; + Window.Title := 'Очистили'; + Sleep(1000); + Window.Load('1.png'); + Window.Title := 'Загрузили'; +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/DrawGraphic.pas b/TestSuite/CompilationSamples/DrawGraphic.pas new file mode 100644 index 000000000..863236422 --- /dev/null +++ b/TestSuite/CompilationSamples/DrawGraphic.pas @@ -0,0 +1,11 @@ +uses GraphWPF; + +begin + Window.Title := 'Графики функций'; + var ww := Window.Width / 2; + var hh := Window.Height / 2; + DrawGraph(x -> sin(4 * x) + cos(3 * x), -5, 5, 0, 0, ww, hh); + DrawGraph(x -> x * x, -5, 5, ww - 1, 0, ww, hh); + DrawGraph(x -> exp(x), -5, 5, 0, hh-1, ww, hh); + DrawGraph(x -> x*cos(2*x-1), -5, 5, ww - 1, hh-1, ww, hh); +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/EllRectInWindow.pas b/TestSuite/CompilationSamples/EllRectInWindow.pas new file mode 100644 index 000000000..12386e260 --- /dev/null +++ b/TestSuite/CompilationSamples/EllRectInWindow.pas @@ -0,0 +1,7 @@ +uses GraphWPF; + +begin + Pen.Width := 1; + Rectangle(0,0,Window.Width-1,Window.Height-1); + Ellipse((Window.Width-1)/2,(Window.Height-1)/2,(Window.Width-1)/2,(Window.Height-1)/2); +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/Ellipses.pas b/TestSuite/CompilationSamples/Ellipses.pas new file mode 100644 index 000000000..dbaf68a53 --- /dev/null +++ b/TestSuite/CompilationSamples/Ellipses.pas @@ -0,0 +1,14 @@ +uses GraphWPF; + +begin + Window.Title := 'Рисование эллипсов'; + Pen.Width := 1; + var n := 20000; + for var i:=1 to n do + begin + if i mod 10000 = 0 then + Println(i,MillisecondsDelta); + Brush.Color := RandomColor; + Ellipse(Random(800),Random(600),Random(20),Random(20)); + end; +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/Parallel1.pas b/TestSuite/CompilationSamples/Parallel1.pas new file mode 100644 index 000000000..5cdfcd0a7 --- /dev/null +++ b/TestSuite/CompilationSamples/Parallel1.pas @@ -0,0 +1,8 @@ +Uses System,System.Net,System.Threading.Tasks; + +begin + Parallel.Invoke ( + procedure -> begin (new WebClient()).DownloadFile ('http://yandex.ru', 'yandex.html') end, + procedure -> begin (new WebClient()).DownloadFile ('http://pascalabc.net', 'pabc.html') end + ); +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/Parallel2.pas b/TestSuite/CompilationSamples/Parallel2.pas new file mode 100644 index 000000000..8b4fd3e05 --- /dev/null +++ b/TestSuite/CompilationSamples/Parallel2.pas @@ -0,0 +1,46 @@ +uses + System, System.Net, System.Threading.Tasks; + +type + Int = class + N: int64; + constructor(NN: int64); + begin + N := NN; + end; + + function IsPrime: boolean; + begin + Result := True; + for var i: int64 := 2 to round(sqrt(N)) do + if N mod i = 0 then + begin + Result := False; + exit; + end; + end; + end; + +type + BTask = Task; + +begin + var ss: array of int64 := (1265713689122381, 1265713689122461, 1265713689142451, 1265713689542501); // Все числа - простые + var tb := new BTask[4]; + // Запуск 4 потоков из пула потоков + // У каждого tb[i] свой Result! + for var i := 0 to ss.Length - 1 do + tb[i] := Task.Factory.StartNew((new Int(ss[i])).IsPrime); + + // Если поток не закончился, то обращение к tb[i].Result приостанавливает основную программу + for var i := 0 to tb.Length - 1 do + writeln(tb[i].Result); + // В эту точку мы попадем только после окончания всех четырех потоков + writeln(Milliseconds); + + // Последовательное выполнение + var t := Milliseconds; + for var i := 0 to ss.Length - 1 do + writeln((new Int(ss[i])).IsPrime); + writeln(Milliseconds - t); +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/Parallel3.pas b/TestSuite/CompilationSamples/Parallel3.pas new file mode 100644 index 000000000..c058cad1e --- /dev/null +++ b/TestSuite/CompilationSamples/Parallel3.pas @@ -0,0 +1,57 @@ +uses + System, System.Net, System.Threading.Tasks, System.Collections.Generic; + +type + ListSimple = class + l := new List(); + procedure AddSimple(N: int64); + begin + var Result := True; + for var i: int64 := 2 to round(sqrt(N)) do + if N mod i = 0 then + begin + Result := False; + break; + end; + // lock не позволяет нескольким потокам одновременно выполнять эту секцию. + // Это обязательно, иначе если несколько потоков одновременно будут пытаться добавить значение в список, список может оказаться испорченным + // Секция, охраняемая lock, называется критической + lock l do + if Result then + l.Add(N); + end; + end; + +var hh := 1000; + +begin + var ls := new ListSimple; + + var ii: int64 := 1265713689181; + + Parallel.For(ii,ii+hh,ls.AddSimple); + + writeln(ls.l.Count); + // ls.l := ls.l.OrderBy(x->x).ToList(); - это можно включить для проверки того, что в обоих списках - одинаковые простые числа + for var i:=0 to ls.l.Count-1 do + write(ls.l[i],' '); + // Надо обратить внимание, что выводится неупорядоченная последовательность простых чисел ! + + writeln; + writeln('Время выполнения = ',Milliseconds); + + // То же, но непараллельно + var ls1 := new ListSimple; + + var t := Milliseconds; + for var i:=ii to ii+hh-1 do + ls1.AddSimple(i); + writeln(ls1.l.Count); + for var i:=0 to ls1.l.Count-1 do + write(ls1.l[i],' '); + writeln; + writeln('Время выполнения = ',Milliseconds-t); + + // Проверка того, что списки простых как множества совпадают + writeln('Количество элементов в разности множеств = ',ls.l.Except(ls1.l).Count()); +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/anim1.pas b/TestSuite/CompilationSamples/anim1.pas new file mode 100644 index 000000000..0160433a0 --- /dev/null +++ b/TestSuite/CompilationSamples/anim1.pas @@ -0,0 +1,16 @@ +uses GraphWPF; + +begin + Window.Title := 'Простая анимация'; + var x := 30; + Brush.Color := Colors.Beige; + Circle(x,50,20); + loop 600 do + begin + Sleep(10); + Window.Clear; + x += 1; + Circle(x,50,20); + Window.Title := '' + (Milliseconds div 100)/10; + end; +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/anim2.pas b/TestSuite/CompilationSamples/anim2.pas new file mode 100644 index 000000000..d9a0a6dad --- /dev/null +++ b/TestSuite/CompilationSamples/anim2.pas @@ -0,0 +1,25 @@ +uses GraphWPF; + +begin + Window.Title := 'Отражение шарика. Вещественное направление движения'; + Brush.Color := Colors.Beige; + var x := 400.0; + var y := 300.0; + var dx := 2.1; + var dy := -1.2; + Circle(x,y,20); + while True do + begin + Sleep(10); + Window.Clear; + x += dx; + y += dy; + if not x.Between(0,Window.Width) then + dx := -dx; + if not y.Between(0,Window.Height) then + dy := -dy; + Circle(x,y,20); + if Milliseconds>2000 then + Window.Title := 'Секунды: ' + (Milliseconds div 100)/10; + end; +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/anim4.pas b/TestSuite/CompilationSamples/anim4.pas new file mode 100644 index 000000000..4d2d5a692 --- /dev/null +++ b/TestSuite/CompilationSamples/anim4.pas @@ -0,0 +1,45 @@ +uses GraphWPF; + +function RandomReal(a,b: real): real := Random*(b-a)+a; + +type + BallInfo = auto class + x,y,r,dx,dy: real; + c: Color; + procedure Move := (x,y) := (x+dx,y+dy); + procedure Draw := FillCircle(x,y,r,c); + procedure CheckDirection; + begin + if not x.Between(r,Window.Width-r) then + dx := -dx; + if not y.Between(r,Window.Height-r) then + dy := -dy; + end; + procedure Step; + begin + Move; + CheckDirection; + Draw; + end; + class function CreateRandomBallArray(n: integer): array of BallInfo; + begin + var rr := 20; + Result := ArrGen(n,i->new BallInfo(RandomReal(rr,Window.Width-rr), + RandomReal(rr,Window.Height-rr),RandomReal(5,15), + RandomReal(-3,3),RandomReal(-3,3),RandomColor)); + end; + end; + +begin + Window.Title := 'Отражение шариков. Анимация на основе кадра'; + + var n := 1000; + var a := BallInfo.CreateRandomBallArray(n); + + BeginFrameBasedAnimation(()-> + foreach var ball in a do + ball.Step + ); + + //BeginFrameBasedAnimation(()->a.ForEach(ball->ball.Step)); +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/mouse1.pas b/TestSuite/CompilationSamples/mouse1.pas new file mode 100644 index 000000000..8349d012e --- /dev/null +++ b/TestSuite/CompilationSamples/mouse1.pas @@ -0,0 +1,6 @@ +uses GraphWPF; + +begin + OnMouseDown := (x,y,mb) -> if mb=1 then Circle(x,y,5); + OnKeyDown := k -> Print(k); +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/mouse2.pas b/TestSuite/CompilationSamples/mouse2.pas new file mode 100644 index 000000000..af3d6a87c --- /dev/null +++ b/TestSuite/CompilationSamples/mouse2.pas @@ -0,0 +1,10 @@ +uses GraphWPF; + +begin + Window.Title := 'Рисование мышью'; + Pen.Color := Colors.Blue; + Pen.Width := 3; + OnMouseDown := (x,y,mb) -> MoveTo(x,y); + OnMouseMove := (x,y,mb) -> if mb=1 then LineTo(x,y); + OnKeyDown := k -> if k = Key.Space then Window.Save('a.png'); +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/ВсеТочкиМногоугольника.pas b/TestSuite/CompilationSamples/ВсеТочкиМногоугольника.pas new file mode 100644 index 000000000..0779979c3 --- /dev/null +++ b/TestSuite/CompilationSamples/ВсеТочкиМногоугольника.pas @@ -0,0 +1,12 @@ +uses GraphWPF; + +procedure ВсеТочкиМногоугольника(x0,y0,r: real; n: integer); +begin + var q := Partition(0,2*Pi,n).Select(a->Pnt(x0 + r * Cos(a), y0 - r * Sin(a))); + q.Cartesian(q).ForEach(p->Line(p[0].x,p[0].y,p[1].x,p[1].y,RandomColor)); +end; + +begin + Pen.Width := 0.5; + ВсеТочкиМногоугольника(400,300,290,30) +end. diff --git a/TestSuite/CompilationSamples/ВыравниваниеТекста1.pas b/TestSuite/CompilationSamples/ВыравниваниеТекста1.pas new file mode 100644 index 000000000..de8e67e62 --- /dev/null +++ b/TestSuite/CompilationSamples/ВыравниваниеТекста1.pas @@ -0,0 +1,30 @@ +uses GraphWPF; + +begin + Window.Title := 'Выравнивание шрифта'; + Font.Size := 20; + var (x,y) := (200,200); + var (w,h) := (400,200); + DrawRectangle(x,y,w,h); + DrawText(x,y,w,h,'LeftTop',Alignment.LeftTop); + DrawText(x,y,w,h,'LeftCenter',Alignment.LeftCenter); + DrawText(x,y,w,h,'LeftBottom',Alignment.LeftBottom); + DrawText(x,y,w,h,'CenterTop',Alignment.CenterTop); + DrawText(x,y,w,h,'Center'); + DrawText(x,y,w,h,'CenterBottom',Alignment.CenterBottom); + DrawText(x,y,w,h,'RightTop',Alignment.RightTop); + DrawText(x,y,w,h,'RightCenter',Alignment.RightCenter); + DrawText(x,y,w,h,'RightBottom',Alignment.RightBottom); + // Выравнивание относительно точки + TextOut(150,100,'PointRightBottom',Alignment.RightBottom); + TextOut(150,100,'PointRightTop',Alignment.RightTop); + TextOut(150,100,'PointLeftTop',Alignment.LeftTop); + TextOut(150,100,'PointLeftBottom',Alignment.LeftBottom); + FillCircle(150,100,5,Colors.Red); + TextOut(600,100,'PointCenterTop',Alignment.CenterTop); + TextOut(600,100,'PointCenterBottom',Alignment.CenterBottom); + FillCircle(600,100,5,Colors.Red); + TextOut(400,500,'PointLeftCenter',Alignment.LeftCenter); + TextOut(400,500,'PointRightCenter',Alignment.RightCenter); + FillCircle(400,500,5,Colors.Red); +end. diff --git a/TestSuite/CompilationSamples/ВыравниваниеТекста2.pas b/TestSuite/CompilationSamples/ВыравниваниеТекста2.pas new file mode 100644 index 000000000..f8e622973 --- /dev/null +++ b/TestSuite/CompilationSamples/ВыравниваниеТекста2.pas @@ -0,0 +1,34 @@ +uses GraphWPF; + +begin + Window.Title := 'Выравнивание шрифта'; + Font.Size := 20; + + var sc := 40; + SetMathematicCoords; + + var (x,y) := (-5,-2); + var (w,h) := (10,4); + DrawRectangle(x,y,w,h); + DrawText(x,y,w,h,'LeftTop',Alignment.LeftTop); + DrawText(x,y,w,h,'LeftCenter',Alignment.LeftCenter); + DrawText(x,y,w,h,'LeftBottom',Alignment.LeftBottom); + DrawText(x,y,w,h,'CenterTop',Alignment.CenterTop); + DrawText(x,y,w,h,'Center'); + DrawText(x,y,w,h,'CenterBottom',Alignment.CenterBottom); + DrawText(x,y,w,h,'RightTop',Alignment.RightTop); + DrawText(x,y,w,h,'RightCenter',Alignment.RightCenter); + DrawText(x,y,w,h,'RightBottom',Alignment.RightBottom); + // Выравнивание относительно точки + TextOut(-5,5,'PointRightBottom',Alignment.RightBottom); + TextOut(-5,5,'PointRightTop',Alignment.RightTop); + TextOut(-5,5,'PointLeftTop',Alignment.LeftTop); + TextOut(-5,5,'PointLeftBottom',Alignment.LeftBottom); + FillCircle(-5,5,0.1,Colors.Red); + TextOut(5,5,'PointCenterTop',Alignment.CenterTop); + TextOut(5,5,'PointCenterBottom',Alignment.CenterBottom); + FillCircle(5,5,0.1,Colors.Red); + TextOut(5,-5,'PointLeftCenter',Alignment.LeftCenter); + TextOut(5,-5,'PointRightCenter',Alignment.RightCenter); + FillCircle(5,-5,0.1,Colors.Red); +end. diff --git a/TestSuite/CompilationSamples/Многоугольник.pas b/TestSuite/CompilationSamples/Многоугольник.pas new file mode 100644 index 000000000..2d6e3c80d --- /dev/null +++ b/TestSuite/CompilationSamples/Многоугольник.pas @@ -0,0 +1,20 @@ +uses GraphWPF; + +procedure Многоугольник(x0,y0,r: real; n: integer); +begin + var a := Pi / 2; + MoveTo(x0 + r * Cos(a), y0 - r * Sin(a)); + loop n do + begin + a += 2 * Pi / n; + //FillCircle(x0 + r * Cos(a), y0 - r * Sin(a),3,Colors.Black); + LineTo(x0 + r * Cos(a), y0 - r * Sin(a)); + end; +end; + +begin + var (x0,y0) := (400.0,300.0); + var r := 30.0; + for var n := 3 to 11 do + Многоугольник(x0,y0,r+(n-3)*30,n) +end. diff --git a/TestSuite/CompilationSamples/Светофор.pas b/TestSuite/CompilationSamples/Светофор.pas new file mode 100644 index 000000000..26176c958 --- /dev/null +++ b/TestSuite/CompilationSamples/Светофор.pas @@ -0,0 +1,19 @@ +uses GraphWPF; + +procedure Светофор(x,y,r: real); +begin + Rectangle(x,y,4*r,10*r,Colors.LightGray); + x += 2*r; + y += 2*r; + var dy := 3*r; + + Circle(x,y,r,Colors.Red); + Circle(x,y + dy,r,Colors.Yellow); + Circle(x,y + 2*dy,r,Colors.Green); +end; + +begin + Pen.Width := 2; + Window.Title := 'Светофор'; + Светофор(150,40,50); +end. \ No newline at end of file diff --git a/TestSuite/CompilationSamples/Система координат.pas b/TestSuite/CompilationSamples/Система координат.pas new file mode 100644 index 000000000..343c23ee5 --- /dev/null +++ b/TestSuite/CompilationSamples/Система координат.pas @@ -0,0 +1,18 @@ +uses GraphWPF; + +begin + Window.Title := 'Система координат'; + Font.Size := 20; + + // SetMathematicCoords; // так тоже можно + // SetMathematicCoords(-10,10); // так тоже можно + SetMathematicCoords(-10,10,-9.2); + DrawGrid; + + Print('Видимые координаты:',XMin,XMax,YMin,YMax); + + Polygon(Arr((-3,2),(2,1),(-2,-4)),ARGB(100,255,228,196)); + TextOut(-3,2,'A(-3,2)',Alignment.RightBottom); + TextOut(2,1,'B(2,1)',Alignment.LeftBottom); + TextOut(-2,-4,'C(-2,-4)',Alignment.CenterTop); +end. diff --git a/TestSuite/CompilationSamples/ТаблицаУмножения.pas b/TestSuite/CompilationSamples/ТаблицаУмножения.pas new file mode 100644 index 000000000..5565ca737 --- /dev/null +++ b/TestSuite/CompilationSamples/ТаблицаУмножения.pas @@ -0,0 +1,16 @@ +uses GraphWPF; + +begin + Window.Title := 'Таблица умножения'; + Font.Size := 16; + var n := 9; + var w := 40; + var (x0,y0) := (50,50); + for var i:=0 to n-1 do + for var j:=0 to n-1 do + begin + var (xx,yy) := (x0+i*w,y0+j*w); + Rectangle(xx,yy,w,w); + DrawText(xx,yy,w,w,(i+1)*(j+1)); + end; +end. diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 98b43feb8..bd0b2494e 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -5496,6 +5496,7 @@ namespace PascalABCCompiler.TreeConverter { exprCounter++; } + List params_exprs = new List(); foreach (SyntaxTree.expression en in _method_call.parameters.expressions) { if (!(en is SyntaxTree.function_lambda_definition)) @@ -5506,13 +5507,37 @@ namespace PascalABCCompiler.TreeConverter else { var enLambda = (SyntaxTree.function_lambda_definition)en; - LambdaHelper.InferTypesFromVarStmt(ffn.parameters[exprCounter].type, enLambda, this); - enLambda.lambda_visit_mode = LambdaVisitMode.VisitForAdvancedMethodCallProcessing; - exprs[exprCounter] = convert_strong(en); - enLambda.lambda_visit_mode = LambdaVisitMode.VisitForInitialMethodCallProcessing; + if (ffn.parameters[Math.Min(exprCounter, ffn.parameters.Count - 1)].is_params) + { + LambdaHelper.InferTypesFromVarStmt(ffn.parameters[Math.Min(exprCounter, ffn.parameters.Count - 1)].type.element_type, enLambda, this); + enLambda.lambda_visit_mode = LambdaVisitMode.VisitForAdvancedMethodCallProcessing; + if (exprCounter <= ffn.parameters.Count - 1) + exprs[exprCounter] = convert_strong(en); + else + exprs.AddElement(convert_strong(en)); + enLambda.lambda_visit_mode = LambdaVisitMode.VisitForInitialMethodCallProcessing; + } + else + { + LambdaHelper.InferTypesFromVarStmt(ffn.parameters[exprCounter].type, enLambda, this); + enLambda.lambda_visit_mode = LambdaVisitMode.VisitForAdvancedMethodCallProcessing; + exprs[exprCounter] = convert_strong(en); + enLambda.lambda_visit_mode = LambdaVisitMode.VisitForInitialMethodCallProcessing; + + } exprCounter++; } } + /*if (params_exprs.Count > 0) + { + location loc = get_location(_method_call); + typeof_operator to = new typeof_operator(params_exprs[0].type, loc); + expression_node retv = convertion_data_and_alghoritms.create_simple_function_call(SystemLibrary.SystemLibInitializer.NewArrayProcedureDecl, loc, to, new int_const_node(params_exprs.Count, loc)); + base_function_call cnfc = retv as base_function_call; + foreach (expression_node e in params_exprs) + cnfc.parameters.AddElement(e); + exprs[exprCounter] = cnfc; + }*/ } catch (SeveralFunctionsCanBeCalled sf) {