PerlNET: The Camel Talks.NET Jan Dubois The Perl Conference 6 San Diego, July 26 th 2002.

Slides:



Advertisements
Similar presentations
.NET Overview Managed Code (MSIL) Managed Code (MSIL) CLR CLR JIT Compiler JIT Compiler Multi-Platform Multi-Platform Multi-Lingual (C#, VB.NET, Perl,
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Camel Crossings: Perl & the Microsoft.NET Framework Brad Merrill, Microsoft Jan Dubois, ActiveState Eric Promislow, ActiveState.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 1.1 of…
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Names and Scopes CS 351. Program Binding We should be familiar with this notion. A variable is bound to a method or current block e.g in C++: namespace.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
C#/.NET Jacob Lewallen. C# vs.NET.NET is a platform. Many languages compile to.NET: –VB.NET –Python.NET –Managed C++ –C#
Chapter 12: Advanced Topics: Exception Handling Visual Basic.NET Programming: From Problem Analysis to Program Design.
ASP.NET Programming with C# and SQL Server First Edition
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Intro to dot Net Dr. John Abraham UTPA – Fall 09 CSCI 3327.
OOP Languages: Java vs C++
Overview of Microsoft.Net and Vb.Net ITSE 2349 Spring 2002 Material from Microsoft.Net an Overview for ACC faculty by Stuart Laughton and Introduction.
1 Introduction to.NET Framework. 2.NETFramework Internet COM+ Orchestration Orchestration Windows.NET Enterprise ServersBuildingBlockServices Visual Studio.NET.
Introduction to .Net Framework
Java and C++, The Difference An introduction Unit - 00.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Meir Botner David Ben-David. Project Goal Build a messenger that allows a customer to communicate with a service provider for a fee.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
.NET Framework & C#.
Microsoft Visual Basic 2005: Reloaded Second Edition
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Web Services Week 2 Aims: Getting started with creating simple C# applications within Visual Studio.NET Objectives: –An introduction to the syntax of C#.NET.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
CS795/895: Introduction. Topics Distributed Systems –Availability –Performance –Web Services Security –Authentication –Authorization –Confidentiality.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Managed C++. Objectives Overview to Visual C++.NET Concepts and architecture Developing with Managed Extensions for C++ Use cases Managed C++, Visual.
.NET Language Supports. .NET Language Support Operating System Common Language Runtime Base Class Library ADO.NET and XML ASP.NET Web Forms Web Services.
.NET Framework Danish Sami UG Lead.NetFoundry
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
.Net – The First Glance What Is.Net, Why Use.Net.
tom perkins1 XML Web Services -.NET FRAMEWORK – Part 1 CHAPTER 1.1 – 1.3.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Intro to dot Net Dr. John Abraham UTPA CSCI 3327.
Bill Campbell, UMB Microsoft's.NET C# and The Common Language Runtime.
C# and.NET. .NET Architecture  Compiling and running code that targets.NET  Advantages of Microsoft Intermediate Language (MSIL)  Value and Reference.
Tips & Tricks: Writing Performant Managed Code Rico Mariani FUNL04 Performance Architect Microsoft Corporation.
Introduction to C# By: Abir Ghattas Michel Barakat.
DEV394.NET Framework: Migrating To Managed Code Adam Nathan QA Lead Richard Lander Program Manager Microsoft Corporation.
.NET Mobile Application Development XML Web Services.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
July 22, 2001Introduction to.NET1 Introduction to.NET Framework Gholamali Semsarzadeh July 2001.
User Interface Programming in C#: Basics and Events Chris North CS 3724: HCI.
Lecture Set 1 Part B: Understanding Visual Studio and.NET – Structure and Terminology 1/16/ :04 PM.
Yingcai Xiao Programming and Debugging in Unity Yingcai Xiao.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Introducing the Microsoft® .NET Framework
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
Programming and Debugging
Module 9: Memory and Resource Management
Jim Fawcett CSE775 – Distributed Objects Spring 2009
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Object-Orientated Programming
.NET and .NET Core 2. .NET Runtimes Pan Wuming 2017.
CS360 Windows Programming
Introduction to C# AKEEL AHMED.
Programming in C# CHAPTER 1
Programming and Debugging
(Computer fundamental Lab)
Paul Stubbs MCSD, MCSE 4.0, MCP+I, MCT, MCAD .Net
Classes and Objects Imran Rashid CTO at ManiWeber Technologies.
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2018
Jim Fawcett CSE681 – Software Modeling and Analysis Fall 2006
IS 135 Business Programming
Presentation transcript:

PerlNET: The Camel Talks.NET Jan Dubois The Perl Conference 6 San Diego, July 26 th 2002

Agenda  How does PerlNET work  PerlNET Challenges  Demonstrations  Questions and Answers

.NET Acronyms  CLR– Common Language Runtime  CTS– Common Type System  CLS– Common Language Spec  CIL– Common Intermediate Language

.NET Terms  Managed Code & Data  Types implemented in CIL  Uses object references  Garbage collection  Unmanaged Code & Data  Platform native code (e.g. Win32, Kernel)  Direct memory access

PerlNET Design Goals  Perl  Standard Perl Syntax  Full support for XS extension modules  Reasonable execution speed .NET  Using.NET objects from Perl  Implementing.NET objects in Perl  Cross-language inheritance support  CLS compliance

PerlNET Component Perl Host Perl Module Proxy Managed Runtime Module.pm.NET FrameworkWindows.NET Interface

PerlNET Features  Constructors & Inheritance  Methods incl. overloading  Fields, Properties & Indexers  Events (Delegates)  Enumerations  Exceptions  Custom attributes  Namespaces  P/Invoke

Challenges  Overloading  Data Marshalling  Object Lifetime  Exception Handling  Debugging

Overloading .NET  Statically typed  Overloaded constructors & methods  Perl  Dynamically typed  Runtime parameter inspection

Implementing overloaded methods package PerlObj; =for interface void Write(char arg); void Write(short arg); void Write(int arg); void Write(long arg); void Write(double arg); void Write(decimal arg); =cut sub Write { my($this, $arg) print $arg; } package PerlObj; =for interface string Property; private field string data; =cut sub Property { my($this, $val) if (defined $val) { $this->{data} = $val; } return $this->{data}; } Called from C # : obj.Property = "My Value"; Console.WriteLine(obj.Property);

use PerlNET qw(AUTOCALL bool);Prints: use namespace "System"; # call Write(System.Int32) my $var = 1; Console->Write($var);=> 1 # call Write(System.Double) $var += 1; Console->Write($var);=> 2 # call Write(System.Int32) Console->Write(int($var));=> 2 # call Write(System.String) Console->Write("$var");=> 2 # call Write(System.Boolean) Console->Write(bool($var));=> True Calling overloaded methods

Passing.NET types to Perl  Value types passed as bit patterns  Wrapped in a Perl object  Can be passed back to.NET as same type  Overloaded operators  Reference types are passed as GCHandles  Reference counted on the Perl side

Passing Perl variable to.NET  All variables passed as IntPtrs  PerlRT knows Perl variable layout  “Unsafe” managed code accesses Perl variable internals as needed  Data passed back to Perl is not unpacked

Marshalling Strings System.String constructed directly from Perl scalar value: Encoding enc = (Flags & sv_flags.UTF8) == 0 ? Encoding.Default : Encoding.UTF8; byte *xpv = (byte*)*(int*)sv; return new String((sbyte*)*(int*)xpv, 0, *(int*)(xpv+4), enc);

Object Lifetime  Perl  Counts references  Calls DESTROY() method immediately  Deterministic destruction order .NET  Tracks object references  Calls Finalize() method “later”  Managed objects destroyed in arbitrary order  Cannot access other objects in Finalize()

IDisposable interface  Explicit Dispose() paradigm PerlObj obj = new PerlObj(); try { // Work with obj obj.DoSomething(); } finally { if (obj != null) obj.Dispose(); }  C # syntactic sugar using (PerlObj obj = new PerlObj()) { // Work with obj obj.DoSomething(); }

PerlNET object lifetime  PerlNET makes sure that DESTROY is called (eventually)  PerlNET objects are not collected by.NET  unless they are explicitly disposed  or at the end of the program

Exception Handling class CSharpObj { static void Main() { try { PerlObj.bar(new CSharpObj()); } catch (Exception e) { Console.WriteLine(e); } void foo() { Console.WriteLine("inside foo"); throw new ApplicationException(); } package PerlObj; =for interface static void bar(any obj); =cut sub bar { my $obj = shift; print "inside bar\n"; eval { $obj->foo() }; print if $obj->foo(); print "not reached\n"; }  inside foo   inside bar   inside foo   System.ApplicationException: Error in the application. at CSharpObj.foo()   System.ApplicationException: Error in the application. at PerlObj.bar(Object obj) at CSharpObj.Main() 

Debugging  Perl debugger partially written in Perl  Breakpoints freeze all managed threads  Workaround: run Perl in separate thread (uses different call stack)  “Step out” doesn’t work (need to set breakpoint manually)

Wrapping a CPAN Module  Install CPAN module  Create interface specification  Compile into.NET assembly  Use from C # program

Windows Forms Sample  Create simple Form  Add Textbox and Button  Implement delegate for Click event

Cross-Language Inheritance  Design GUI using Visual C#  Add data members and virtual callbacks  Implement callbacks in Perl

ASP.NET  Active Server Pages.NET  HTML + Source code  Inherits System.Web.UI.Page behavior  Compiles into.NET assembly  Cached by IIS / ASP.NET  Perl for ASP.NET  CodeGenerator translates CodeDOM  PerlNET creates.NET component

Web Services  Based on ASP.NET CodeGenerator  Just add [WebMethod] custom attribute  ASP.NET provides  Interactive interface for testing  WSDL description

Summary  PerlNET is part of the Perl Dev Kit  Migrating Perl applications to.NET  Reusing CPAN modules from other languages  Native compiler to CIL for Perl 6?

Questions & Answers