StaDyn (programming language)
StaDyn is an object-oriented general-purpose programming language for the .NET platform that supports both static and dynamic typing in the same programming language. The StaDyn compiler gathers type information for the dynamically typed code. That type information is used to detect type errors at compilation time and to perform significant optimizations. For that purpose, it provides type reconstruction (inference), flow-sensitive types, union and intersection types, constraint-based typing, alias analysis and method specialization.
Its first prototype appeared in 2007, as a modification of C# 3.0. Type inference was supported by including StaDyn is designed by Francisco Ortin[1] from the University of Oviedo. The language has been implemented by different members of the Computational Reflection research group,[2] including Miguel Garcia, Jose Baltasar García Perez-Schofield and Jose Quiroga, besides Francisco Ortin. The name StaDyn is a portmanteau of static and dynamic, denoting its aim to provide the benefits of both static and dynamic typing. Code samplesVariables with different typesJust like dynamic languages, variables may hold different types in the same scope: using System;
class Program {
public static void Main() {
Console.Write("Number: ");
var age = Console.In.ReadLine();
Console.WriteLine("Digits: " + age.Length);
age = Convert.ToInt32(age);
age++;
Console.WriteLine("Happy birthday, you are " + age +
" years old now.");
int length = age.Length; // * Compiler error
}
}
The The generated code does not use a single Flow-sensitive types
using System;
class Program {
public static void Main(String[] args) {
var exception;
if (args.Length > 0)
exception = new ApplicationException("An application exception.");
else
exception = new SystemException("A system exception.");
Console.WriteLine(exception.Message);
}
}
It is safe to get the In the following program: using System;
class Program {
public static void Main(String[] args) {
var exception;
switch (args.Length) {
case 0:
exception = new ApplicationException("An application exception.");
break;
case 1:
exception = new SystemException("A system exception.");
break;
default:
exception = "This is not an exception.";
break;
}
Console.WriteLine(exception.Message); // * Compiler error with var, but not with dynamic
Console.WriteLine(exception.Unknown); // * Compiler error
}
}
The Although Type inference of fields
class Wrapper {
private var attribute;
public Wrapper(var attribute) {
this.attribute = attribute;
}
public var get() {
return attribute;
}
public void set(var attribute) {
this.attribute = attribute;
}
}
class Test {
public static void Main() {
string aString;
int aInt;
Wrapper wrapper = new Wrapper("Hello");
aString = wrapper.get();
aInt = wrapper.get(); // * Compiler error
wrapper.set(3);
aString = wrapper.get(); // * Compiler error
aInt = wrapper.get();
}
}
The Constraint-based typesLet's analyze the following method: public static var upper(var parameter) {
return parameter.ToUpper();
}
The type of The programmer may use either Runtime performanceThe type information gathered by StaDyn is used to perform significant optimizations in the generated code: [10] the number of type inspections and type casts are reduced, reflection is avoided, frequent types are cached, and methods with constraints are specialized. The point of all the optimizations is to reduce the number of type-checking operations performed at runtime, which is the main performance penalty of most dynamic languages. Many of those type checks are undertaken earlier by the StaDyn compiler. A detailed evaluation of the runtime performance of StaDyn is detailed in.[4] See alsoReferences
External links |
Portal di Ensiklopedia Dunia