Camel Crossings: Perl & the Microsoft .NET Framework
Download
Report
Transcript Camel Crossings: Perl & the Microsoft .NET Framework
Camel Crossings: Perl &
the Microsoft .NET Framework
Brad Merrill, Microsoft
Jan Dubois, ActiveState
Eric Promislow, ActiveState
.NET Framework
Overview
Brad Merrill
.NET Languages Evangelist
.NET Developer Platform
.NET Blueprint
Visual
Studio.NET
Your Application
and Web Service
Other
Applications
Using Your
Service
End-User
Clients
.NET
Framework
Operations
Orchestration
Windows
CE, ME, 2000, .NET
Open Internet Protocols
SOAP, SCL, DISCO
HTTP, SMTP, XML, WAP, XSD
Your Internal Services
.NET Enterprise
Servers
.NET MyServices
Public Web Services
.NET Framework
Web
Services
User
Interface
Data & XML
Base Classes
Orchestration
.NET
Framework
.NET
Enterprise
Servers
Common Language Runtime
.NET
My
Services
Windows (CE, ME, 2000, and .NET)
Inside the .NET Framework
VB
C++
C#
Perl
Eiffel
Cobol
Web Services
User Interface
ASP.NET
Data and XML
Base Framework
Secure, integrated
class libraries
•Unifies programming models
across languages
•Enables cross-language
integration
•Factored for extensibility
Common Language Runtime
•Designed for tools
Active Server Pages .NET
Common Language Runtime
•High-productivity environment
for building and running Web
services
•Executes code, maintains security,
handles component “plumbing” and
dependencies
Acronyms
CLR – Common Language Runtime
CTS – Common Type System
EE – Execution Environment
CIL – Common Intermediate Language
CLS – Common Language Specification
Common Language Runtime
Security
Execution
Support
Base Classes
IL to
native code
compilers
Common Language Runtime
Frameworks
GC, stack walk, code manager
Class loader and layout
Common Type System
Static (compile time) typed
Object-Oriented
fields, methods, nested types, properties, etc.
Overloading resolved by the compiler
Virtual dispatch based on runtime type
Single implementation inheritance
Multiple interfaces
Managed Code
Metadata describes datatypes
Uses object references
Exception handling
ISO C++ can be managed
Managed Data
Layout provided by runtime
Lifetime managed by runtime (GC)
Automatic or Specified
Working set is compacted
Managed extensions required for C++
Terms
Managed Code
CIL implemented types and assemblies
Unmanaged Code
Native code
Win32, Kernel, etc.
Assemblies
Unit of deployment
Versioning
Provided by compiler use of attributes
Policy per-application as well as per-machine
Security boundary
One or more files, independent of packaging
Self-describing via manifest
Assemblies are granted permissions
Methods can demand permissions
Mediate type import and export
Types named relative to assembly
Applications
Are configurable units
Assemblies are located based on…
One or more assemblies
Application-specific files or data
Their logical name and
The application that loads them
Can have private versions of assemblies
Private version preferred over shared
Version policy can be per-application
Metadata
Key to simpler programming model
Generated automatically
Stored with code in executable file
(.dll or .exe)
Uses existing COFF format
Via existing extension mechanism
Stored in binary format
Convertible to/from XML Schema
Convertible to/from COM type libraries
Metadata: Creation And Use
Serialization
Source
Code
(e.g. SOAP)
Other
Compiler
Type Browser
Reflection
Designers
Compiler
Debugger
Metadata
Profiler
(and code)
Schema
Generator
Proxy Generator
XML encoding
(SDL or SUDS)
CIL: Key Design Points
Compilation, not interpretation
Stack-based
Typeless operations
Value types (C structs)
Size-agnostic (32/64 bit) integers
Pointers with arithmetic and indirection
Verification conditions specified
Execution Model
VB
Native
Code
Install time
Code Gen
C#
Cobol
Eiffel
CIL
Common Language Runtime
Pre-JIT
Image
Standard JIT
Compiler
Native
Code
Runtime Control Flow
Assembly
Execution
Support
Code
Managers
Security
System
Class
Loader
IL to native
code compiler
Managed
Native
Code
CPU
First
reference to
type
First call to
method
Interop Mechanisms
Platform invoke (P/Invoke)
Automated type marshalling
Implicit reference pinning
Knowledge of GC implications required
COM interop services
Built-in Attributes
Type library conversion tools provided
Registration provided by tools
Calling Unmanaged Code
Unmanaged
Native
Code
Common Language Runtime
JIT
Compiler
Managed
Native
Code
Interoperability Services
Type System
Standard
C#
Binary
Standard
VB
MFC/ATL
MSVCRT
C++
What Is The Common
Language Specification?
Rules for “published” contracts
Full common type system for internal
contracts and implementation
Three classes of use:
Doesn’t apply within a single assembly
Consumer tools
Extender tools
Frameworks
Design and naming patterns
Existing Type Systems
(define (hello)
(display
“Scheme”))
000010
000020
000030
000040
000050
IDENTIFICATION DIVISION.
PROGRAM-ID. MAIN.
PROCEDURE DIVISION.
DISPLAY “COBOL”.
END PROGRAM MAIN.
class Hello
{ public static void Main()
{ System.Console.WriteLine(“C#”);
}
}
Public Module Hello
Sub Main()
System.Console.WriteLine(“VB”)
End Sub
End Module
Existing Type Systems
000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. MAIN.
(define
(hello)
.assembly
hello {}
.assembly extern mscorlib
{} PROCEDURE DIVISION.
(display
000030
.method
static public void main() il managed
“Scheme”))
000040
DISPLAY “COBOL”.
{ .entrypoint
000050 END PROGRAM MAIN.
.maxstack 1
ldstr “CIL”
class call
Hello
void [mscorlib]
{ public
static void Main()
System.Console::WriteLine(class
System.String)
ret
{ System.Console.WriteLine(“C#”);
}
}
}
Public Module Hello
Sub Main()
System.Console.WriteLine(“VB”)
End Sub
End Module
CLS: Designing For Reach
Fujitsu
COBOL
Extensions
Microsoft
Managed
C++
Extensions
Common
Type System
COBOL
CLS
C++
Common Type System is too big for any single language
Common Language Specification is for cross-language use
Framework Classes
…
Debug
Win
Forms
Spans all programming languages
Object-oriented and consistent
Common type system built-in
Extensible
ASP.NET
Secure
Data
Base Classes
Common Language
Runtime
Class Benefits
Increases developer productivity by
reducing the number of APIs to learn
Enables cross language inheritance
and debugging
Makes it easy to add or modify
framework features
Allows creation of secure applications
Integrates well with tools
Active Server Pages .NET
Web Forms and Web Services
Provides factored architecture
Compiled
No-touch deployment system
ASP.NET
Intelligent state management
Base Classes
Common
Backwards compatible with ASP Language
Web
Services
components separate code from content
Web
Forms
Runtime
ASP.NET Benefits
Developer productivity increases
Tools easily use ASP.NET
Any programming language
VB.Net, JScript, C++, COBOL, Eiffel, Perl,
etc.
40% to 70% reduction in lines of code
Application performance increases
Simple deployment (e.g., with XCOPY)
Reliability, resilience increase
Easy to extend or replace features
Session state scales to Web Farms
Controls sense client and adapt output
HTML, DHTML, WML
ECMA
CLI – Common Language Infrastructure
CIL – Common Intermediate Language
A subset of the full CLR
A subset of the Framework class libraries
The Full Intermediate Instruction Set
C#
The Full C# Language Specification
ECMA
TG3 Specifications
CLI Partition I - Architecture
CLI Partition II – Metadata
CLI Partition III - CIL
CLI Partition IV - Library
CLI Partition V - Annexes
Class Library
http://msdn.microsoft.com/net/ecma
Resources
Microsoft .NET Framework SDK
Community
Visual Studio
http://www.gotdotnet.com
http://www.microsoft.com/msdn
Mailing Lists
http://discuss.microsoft.com
Questions?
PerlNET
Jan Dubois
[email protected]
© ActiveState Corp. 2002
Native Perl for .NET compiler?
We tried it:
Some runtime semantics impossible
XS Extension modules don’t work
Slow runtime
Looks like Perl, but not really compatible
Just a different syntax for C# ?
Let’s try again with Perl 6
© ActiveState Corp. 2002
PerlNET Overview
Interface with standard Perl interpreter
Advantages
Runs at normal speed
Complete Perl language support
Full support for extensions
Disadvantages
Heavyweight components
Moving between Perl and .NET is slower
© ActiveState Corp. 2002
How does it work?
Interface specifications in Perl source
PerlNET creates .NET proxy objects
Proxies use P/Invoke to call Perl
Perl uses COM interop to call .NET
Runtime layer marshals data
© ActiveState Corp. 2002
PerlNET Component
.NET Framework
Windows
Managed
Runtime
Perl Host
Module Proxy
Perl 5.6.1
Module.pm
.NET Interface
© ActiveState Corp. 2002
PerlNET Sample Code
© ActiveState Corp. 2002
Sample Code Metadata
© ActiveState Corp. 2002
C# Program using PerlNET
© ActiveState Corp. 2002
Challenges
Method overloading
Exception handling
Garbage collection
Efficient data marshaling
© ActiveState Corp. 2002
Supported .NET Features
Constructors & Inheritance
Methods incl. overloading
Fields, Properties & Indexers
Events (Delegates)
Enumerations
Exceptions
Custom attributes
Namespaces
P/Invoke
© ActiveState Corp. 2002
PerlNET Capabilities
Language interoperability
WinForms
ASP.NET
Web Services
Visual Studio .NET integration
© ActiveState Corp. 2002
Using PerlNET
Eric Promislow, ActiveState
[email protected]
© ActiveState Corp. 2002
Gains
String Processing & Regular Expressions
Network Connectivity
Databases
CPAN
.NET
COM Automation
Win32 API
Pure Perl
© ActiveState Corp. 2002
“PerlPad”
Adding juice to a notepad-like editor with
back-end Perl scripting
Find RegEx
Search & Replace RegEx
Use “ee” mode on substitution operator
© ActiveState Corp. 2002
Simple step-through example
C# client
Perl component
For debugging:
Make Perl project start-up
Debugging:Debug Mode: MultiLang
Build:Command-line: Add “-d”
Set breakpoints, go
© ActiveState Corp. 2002