Presentation is loading. Please wait.

Presentation is loading. Please wait.

Roslyn: el futuro de C#. Construir un compilador es complejo.

Similar presentations


Presentation on theme: "Roslyn: el futuro de C#. Construir un compilador es complejo."— Presentation transcript:

1 Roslyn: el futuro de C#

2 Construir un compilador es complejo

3 Fundamentos de un compilador

4 Compilador class Program { void Main() { } } ▫ program.exe CSC - VBC

5 Se pueden agrupar en  Front-end: sintaxis == “gramática“  Back-end: semántica == “significado" 5 Fases

6 6

7 Compiladores en.NET .NET siempre fue una plataforma amigable para la construcción de compiladores  Intermediate Language (IL)  Stack de Pila  Operaciones de alto nivel  Optimizaciones de bajo nivel via la plataforma  Reflection Emit  Tools para construcción de compiladores 

8 Demo Reflection Emit

9 Roslyn

10 Roslyn –.NET Compiler Platform Completa reescritura de los compiladores C# y Visual Basic Open Source Language Services Code Analysis APIs Extensibilidad Read-Eval-Print-Loop (REPL) Scripting

11 Core.NET Next gen JIT (“RyuJIT”) SIMD Runtime Compilers.NET Compiler Platform (“Roslyn”) Languages innovation Windows Desktop Azure and Windows Server Universal projects.NET Native ASP.NET updates Windows Convergence Native compilation Web apps.NET support for Azure Mobile Services Cloud Services Openness Windows Store iOS and Android.NET in devices and services

12 Compiler APIs

13 Symbol API API Layers Services Compiler Syntax Tree API Binding and Flow Analysis APIs Emit API Scripting API Workspace API Code FormattingFind All ReferencesName Simplification … Editor Services Code Actions ClassificationCompletion … Outlining

14 Syntax Tree API – Nodes CompilationUnit TypeDeclaration MethodDeclaration class C { void M() { } }// C ▫ ParameterListBlock var tree = CSharpSyntaxTree.ParseText("...");

15 Syntax Tree API – Tokens CompilationUnit TypeDeclaration classC{MethodDeclaration} EOF voidMParameterListBlock (){} class C { void M() { } }// C ▫

16 Syntax Tree API – Trivia CompilationUnit TypeDeclaration classC{MethodDeclaration} EOF voidMParameterListBlock () {} SPEOL // C SPx4SP EOL SPx4EOLSPx4 class∙C { ∙∙∙∙void∙M() ∙∙∙∙{ ∙∙∙∙} }// C ▫

17 Demo Syntax Tree API Symbol API Syntax Transformation Compilation API

18 Workspace API Host Environment Workspace Solution Project Document Solution 2 Solution n Apply Edit SyntaxTree Compilation Events (e.g. key presses)

19 Demo Diagnostics and Code Fix

20 C# 6

21 Primary Constructor Auto-Property Initializer public class Point(int x, int y) { public int X { get; } = x; public int Y { get; } = y; public double R { get; } = Math.Sqrt(x ^ x + y ^ y); public Point() : this(0, 0) { } public override string ToString() { return string.Format("({0},{1},{2})", X, Y, R); }

22 Exception Filtering try { Task[] tasks = new Task[10]; for (int i = 0; i < 10; i++) { tasks[i] = Task.Factory.StartNew(() => DoSomeWork( )); } var res = await Task.WhenAll(tasks); } catch (AggregateException e) if (e.InnerExceptions.Count > 2) { await WriteStatus(“filtered exception"); } finally { await WriteStatus(“finished"); }

23 Null propagating operator

24 Using static members

25 Lista completa

26 Demo C# 6

27 ¿Preguntas?

28 Referencias Libros Compilers: Principles, Techniques, and Tools – Aho et all Compiling for the.NET Common Language Runtime (CLR) - John Gough Web

29 ¡ Gracias!


Download ppt "Roslyn: el futuro de C#. Construir un compilador es complejo."

Similar presentations


Ads by Google