Camel Crossings: Perl & the Microsoft .NET Framework

basiliskcanoeΛογισμικό & κατασκευή λογ/κού

2 Νοε 2013 (πριν από 3 χρόνια και 10 μήνες)

68 εμφανίσεις

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

Open Internet Protocols

SOAP, SCL, DISCO


HTTP, SMTP, XML, WAP, XSD

Your Application

and Web Service

.NET

Framework

Windows

CE, ME, 2000, .NET

Operations

End
-
User

Clients

Other

Applications


Using Your

Service

Orchestration

Your Internal Services

.NET Enterprise
Servers

.NET MyServices

Public Web Services

Visual

Studio.NET

Windows (CE, ME, 2000, and .NET)

Orchestration

.NET

Enterprise

Servers

.NET

My

Services

.NET

Framework

.NET Framework

Base Classes

Data & XML

User

Interface

Common Language Runtime

Web

Services

Inside the .NET Framework

Common Language Runtime

Base Framework

Data and XML

Web Services

User Interface

VB

C++

C#

ASP.NET

Perl

Eiffel

Cobol

Common Language Runtime


Executes code, maintains security,
handles component “plumbing” and
dependencies

Secure, integrated
class libraries


Unifies programming models
across languages


Enables cross
-
language
integration


Factored for extensibility


Designed for tools

Active Server Pages .NET


High
-
productivity environment
for building and running Web
services

Acronyms


CLR


Common Language Runtime


CTS


Common Type System


EE


Execution Environment


CIL


Common Intermediate Language


CLS


Common Language Specification

Common Language Runtime

Common Language Runtime

Frameworks

Class loader and layout

IL to

native code

compilers

GC, stack walk, code manager

Security

Execution

Support

Base Classes

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


Automatic or Specified


Lifetime managed by runtime (GC)


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


One or more files, independent of packaging


Self
-
describing via manifest


Versioning


Provided by compiler use of attributes


Policy per
-
application as well as per
-
machine


Security boundary


Assemblies are granted permissions


Methods can demand permissions


Mediate type import and export


Types named relative to assembly

Applications


Are configurable units


One or more assemblies


Application
-
specific files or data


Assemblies are located based on…


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

Metadata

(and code)

Debugger

Schema

Generator

Profiler

Other

Compiler

Proxy Generator

Type Browser

Compiler

Source

Code

XML encoding

(SDL or SUDS)

Serialization

(e.g. SOAP)

Designers

Reflection

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

VB

C#

Cobol

Eiffel

CIL

Native

Code

Pre
-
JIT

Image

Standard JIT

Compiler

Native

Code

Install time

Code Gen

Common Language Runtime

Execution Model

Runtime Control Flow

Class

Loader

IL to native

code compiler

CPU

Security

System

Code

Managers

Managed

Native

Code

Assembly

First call to
method

First
reference to
type

Execution

Support

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

Native

Code

JIT

Compiler

Native

Code

Common Language Runtime

Unmanaged

Managed

Interoperability Services

C#

VB

C++

MSVCRT

MFC/ATL

Type System

Standard

Binary

Standard

What Is The Common
Language Specification?


Rules for “published” contracts


Doesn’t apply within a single assembly


Full common type system for internal
contracts and implementation


Three classes of use:


Consumer tools


Extender tools


Frameworks


Design and naming patterns

Existing Type Systems

class Hello

{ public static void Main()


{ System.Console.WriteLine(“C#”);


}

}

Public Module Hello


Sub Main()


System.Console.WriteLine(“VB”)


End Sub

End Module

000010 IDENTIFICATION DIVISION.

000020 PROGRAM
-
ID. MAIN.

000030 PROCEDURE DIVISION.

000040 DISPLAY “COBOL”.

000050 END PROGRAM MAIN.

(define (hello)


(display


“Scheme”))

Existing Type Systems

class Hello

{ public static void Main()


{ System.Console.WriteLine(“C#”);


}

}

Public Module Hello


Sub Main()


System.Console.WriteLine(“VB”)


End Sub

End Module

000010 IDENTIFICATION DIVISION.

000020 PROGRAM
-
ID. MAIN.

000030 PROCEDURE DIVISION.

000040 DISPLAY “COBOL”.

000050 END PROGRAM MAIN.

(define (hello)


(display


“Scheme”))

.assembly hello {}

.assembly extern mscorlib {}

.method static public void main() il managed

{ .entrypoint


.maxstack 1


ldstr “CIL”


call

void [mscorlib]


System.Console::WriteLine(class System.String)


ret

}

CLS: Designing For Reach

COBOL


C++

Common
Type System

CLS

Microsoft

Managed
C++

Extensions

Fujitsu

COBOL

Extensions


Common Type System is too big for any single language


Common Language Specification is for cross
-
language use

Framework Classes


Spans all programming languages


Object
-
oriented and consistent


Common type system built
-
in


Extensible


Secure

Common Language
Runtime





Base Classes

ASP.NET

Data

Debug

Win
Forms



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


components separate code from content


Provides factored architecture


Compiled


No
-
touch deployment system


Intelligent state management


Backwards compatible with ASP

Common
Language
Runtime

Base Classes







ASP.NET

Web
Forms

Web
Services

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


A subset of the full CLR


A subset of the Framework class libraries


CIL


Common Intermediate Language


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


http://www.gotdotnet.com


Visual Studio


http://www.microsoft.com/msdn


Mailing Lists


http://discuss.microsoft.com


Questions?


© ActiveState Corp. 2002

PerlNET

Jan Dubois

JanD@ActiveState.com


© 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

Perl Host

Perl 5.6.1

Module Proxy

Managed
Runtime

Module.pm

.NET Framework

Windows

.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

EricP@ActiveState.com


© 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