roslyn: el futuro de c#
DESCRIPTION
Roslyn: el futuro de C#TRANSCRIPT
Roslyn: el futuro de C#
Rodolfo [email protected]@rodolfofhttp://shockbyte.net
Construir un compilador es complejo
Fundamentos de un compilador
Compilador
?class Program{ void Main() { }} ▫
program.exe
CSC - VBC
Se pueden agrupar en Front-end: sintaxis == “gramática“ Back-end: semántica == “significado"
5
Fases
6
Fases
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 http://irony.codeplex.com
Demo
Reflection Emit
Roslyn
Roslyn – .NET Compiler PlatformCompleta reescritura de los compiladores C# y Visual BasicOpen Source
Language ServicesCode Analysis APIsExtensibilidadRead-Eval-Print-Loop (REPL)Scripting
Ecosistema .NET
Core .NET
Next gen JIT (“RyuJIT”)
SIMD
Runtime Compilers .NET Compiler Platform (“Roslyn”)
Languages innovation
Windows Desktop
Azure and Windows Server
Universal projects
.NET NativeASP.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
Compiler APIs
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 Classification Completion …Outlining
Syntax Tree API – NodesCompilationUnit
TypeDeclaration
MethodDeclaration
class C{ void M() { }}// C▫
ParameterList
Block
var tree = CSharpSyntaxTree.ParseText("...");
Syntax Tree API – TokensCompilationUnit
TypeDeclaration
class
C {MethodDeclaratio
n}
EOF
void MParameterLi
stBlock
( ) { }
class C{ void M() { }}// C▫
Syntax Tree API – TriviaCompilationUnit
TypeDeclaration
class
C {MethodDeclaratio
n}
EOF
void MParameterLi
stBlock
( )
{ }
SP EOL EOL // C
SPx4 SP
EOL
EOL
EOLSPx4 EOL SPx4
class∙C{∙∙∙∙void∙M()∙∙∙∙{∙∙∙∙}}// C▫
Demo
Syntax Tree APISymbol APISyntax TransformationCompilation API
Workspace APIHost Environment
Workspace
Solution
Project Project
Document
Document
Solution2 Solutionn
Apply
Edit Edit
SyntaxTree
Compilation
Events (e.g. key presses)
Demo
Diagnostics and Code Fix
C# 6
Primary ConstructorAuto-Property Initializerpublic 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); }}
Exception Filteringtry{
Task[] tasks = new Task[10]; for (int i = 0; i < 10; i++) { tasks[i] = Task.Factory.StartNew(() => DoSomeWork(10000000)); } var res = await Task.WhenAll(tasks);}catch (AggregateException e) if (e.InnerExceptions.Count > 2){
await WriteStatus(“filtered exception");}finally{
await WriteStatus(“finished");}
Null propagating operator
Using static members
Demo
C# 6
¿Preguntas?
ReferenciasLibros
Compilers: Principles, Techniques, and Tools – Aho et all
Compiling for the .NET Common Language Runtime (CLR) - John Gough
Webhttp://irony.codeplex.comhttp://roslyn.codeplex.com