Transcript here

Languages and Compilers
(SProg og Oversættere)
Bent Thomsen
Department of Computer Science
Aalborg University
1
What is Microsoft .NET?
• .NET is Microsoft’s vision of a world connected using
open standards
• .NET is the name given to the latest Microsoft
technology, products and development framework
• .NET is the basis for Microsoft’s current and future
roadmap
• ‘.NET is Microsoft’s platform for a new computing
model built around XML Web Services’
Microsoft Corporation Annual Report, 2001
• .Net is Microsoft’s core business Strategy
2
What does .NET encompass?
Clients
– Software for PC and mobile devices e.g. Windows XP, WinCE
– New devices such as Stinger phone and Xbox
Services
– Microsoft’s software for creating and consuming web services
– New user services such as Passport, Alert and Instant Messenger
– (Microsoft branded web services for use by consumers a.k.a. Hailstorm a.k.a.
MyServices)
Servers
– Current product range such as Windows 2000, Commerce Server 2000, BizTalk
Server 2000 and Content Management Server 2001
– much of this will be merged into .Net Server2003
Tools
– A new development framework for solution developers
• Common Language Runtime and Class Libraries
• Visual Studio .Net
3
Microsoft’s picture that explains .NET
4
What is a “Web Service”?
•
•
A Web service is like a Web site without a user interface, that serves programs instead
of people.
Instead of getting requests from browsers and returning web pages in response, a web
service:
– receives a request formatted in XML from an application,
– performs a task,
– and returns an XML-formatted response.
•
Web Services are delivered using open industry standards
–
–
–
–
–
Services to be described in WSDL
Services to located via UDDI
Data to be exchanged via XML
Protocols are HTTP and SOAP
Back-end systems developed in “traditional” programming languages, such as C++, VB,
C#,…
5
The ultimate application
The Virtual Enterprise
Company A
Mobile
Employees
Consumers, Partners
Company B
Mobile
Employees
Consumers, Partners
Customers
Partners
Suppliers
6
Such applications are hard to develop
• Developers need to master
–
–
–
–
Web programming (and mobile – WAP, iMode, ..)
Client/server
Database integration
Legacy system integration
• All with different and incoherent programming
models
7
Common Programming Model - .NET
XML Web
Services
Web
Forms
ASP.NET
Windows
Forms
Data and XML Classes
Base Framework Classes
Common Language Runtime
8
Execution model
COBOL
VB.NET
MC++
C#
.NET languages
Language compilers
MSIL code
(plus
metadata)
Loader/verifier
JIT compiler
Managed code
Execution
Uncompiled
method call
9
Compiling and Executing Managed Code
Compilation
Source
Code
Language
Compiler
Microsoft
Intermediate
Language
(MSIL)
The first time each
method is called
Native
Code
JIT
Compiler
Execution
10
What is in CLR?
• In .Net Programming Languages share a common higher-level
infrastructure, the Common Language Runtime (CLR):
– High level code is compiled to MIL
(Microsoft
Intermediate Language)
– MIL is compiled to machine code using JIT
– CLR has shared heap, which means no tricky cross-heap pointers
(cf reference counting in COM)
– CLR has a shared type system which means no marshalling
(cf string<->char* marshalling for Java<->C)
– CLR has a shared exception model which supports cross-language
exception handling
– CLR checks and enforces security restrictions on running code
– CLR handles loading and version control
– Libraries are organised into assemblies
11
Programming for .Net
•
•
•
•
•
Common Language Runtime + class libraries
ADO.NET
ASP.NET
Web services – XML, SOAP, UDDI, WSDL …
Programming languages
– C++, VB, C#, (J#)
– APL, COBOL, Eiffel, Forth, Fortran, Haskel, SML, Mercury, Mondrian,
Oberon, Pascal, Perl, Python, RPG, Scheme, SmallScript, …
• Visual Studio .Net
–
–
–
–
Professional
Server Edition
Mobile Internet Toolkit
Academic
12
Advanced Programming Language Research on .Net and
the CLR
• .NET and the CLR provide a great opportunity for
programming language designers and implementers:
– The runtime provides services (execution engine, garbage
collection,…) which make producing a good implementation of
new languages easier
– The frameworks & libraries mean you can actually do useful
things with your new language (graphics, networking, database
access, web services,…)
– Multi-language component-based programming makes it much
more practical for other people to use your language in their own
projects
13
An example - SML.NET by Nick Benton
• Compiler for SML that targets verifiable CIL
• Research Issues:
– Can we compile a polymorphic functional language to a monomorphic, objectoriented runtime?
• Yes
– How can we make it produce fast, compact code?
• Whole-program optimising compiler. Monomorphisation. Representation
tricks. Novel typed intermediate language using monads to track sideeffects.
– How can we make cross-language working easy?
• We extend SML to support all of the .NET CLS (Common Language
Specification), providing smooth bidirectional interoperability with .NET
framework libraries & other .NET languages
14
SML.NET interoperability
• Sounds great, but SML is not object-oriented
– So we are going to have to do some work…
• Possible approaches to interop:
– do not extend language; instead provide wrappers that give a functional view of a
CLS library (Haskell, Mercury).
• Powerful functional type systems can go a very long way towards
modelling OO type systems
– redesign the language (OO-SML?)
• Our approach – a middle way:
– re-use existing features where appropriate (non-object-oriented subset)
– extend language for convenient interop when “fit” is bad (object-oriented features)
– live with the CLS at boundaries: don’t try to export complex ML types to other
languages (what would they do with them?)
15
Re-use SML features
multiple args
void
null
static field
static method
CLS
namespace
delegate
mutability
using
private fields
tuple
unit
NONE
val binding
fun binding
SML
structure
first-class function
ref
open
local decls
16
Extend language
type test
cast patterns
class definitions
instance method invocation
instance field access
custom attributes
casts
classtype
obj.#meth
obj.#fld
attributes in classtype
exp :> ty
CLS
SML
17
Extract from WinForms interop
open System.Windows.Forms System.Drawing System.ComponentModel
no args = ML unit value
fun selectXML () =
CLS Namespace
let
= ML structure
val fileDialog = OpenFileDialog()
in
static method = ML function
fileDialog.#set_DefaultExt("XML");
fileDialog.#set_Filter("XML files (*.xml) |*.xml");
if fileDialog.#ShowDialog() = DialogResult.OK
then
static constant field = ML value
case fileDialog.#get_FileName() of
NONE => ()
instance method invocation
| SOME name =>
replaceTree (ReadXML.make name, "XML file '" ^ name ^ "'")
else ()
end
null value = NONE
CLS string = ML string
And note that there are no explicit types in this code
18
To come - Visual Studio Integration
• Bootstrap the compiler to produce a .NET component
for parsing, typechecking, etc. of SML
• Use interlanguage working extensions to expose that as
a COM component which can be glued into Visual
Studio
• Write new ML code to handle syntax highlighting,
tooltips, error reporting, etc.
19