SlideShare a Scribd company logo
Smalltalk in a .NET World How to write a Smalltalk compiler without writing a VM John Brant [email_address]
#Smalltalk Open source Smalltalk compiler Complete Source Available Self hosting Compiles Smalltalk directly to .NET executables and libraries
Building Smalltalk Virtual Machine .NET Virtual Machine Compiler RB parser Class Library ANSI Standard Development tools (debuggers, browsers, etc.)
What’s .NET Anyway? Common class library (collections, GUI, sockets, database, etc.) Common virtual machine and byte code instruction set Language isn’t supposed to matter
Why .NET? (business reasons) Backed by Microsoft  Lots of existing code Allow Smalltalk to be used for applications that “require .NET”
Why .NET? (personal reasons) Build a Smalltalk compiler  Make an experimental platform Learn .NET Unemployed
Smalltalk vs. .NET ? become:, change classes Non-resumable exceptions Resumable Exceptions Delegates Blocks Primitive integer types Tagged integers Strong, static typing Strong, dynamic typing .NET Smalltalk
Smalltalk vs. .NET II Structs & Enums ? Add classes/methods (can’t remove or recompile) Add/remove classes & methods Static, virtual, & non-virtual methods All methods are virtual .NET Smalltalk
Dynamic Typing Root super type Understands every message Sends #doesNotUnderstand: printString ^self doesNotUnderstand: (Message  selector: #printString arguments: #()) printString | stream | stream := WriteStream with: String new. self printOn: stream. ^stream contents Root Object Proxy
null vs. nil Special object for nil Class constructor initializes variables to nil Method temporaries initialized to nil only if they could be read before written method: aBoolean | temp one | aBoolean ifTrue: [temp := 5]. one := 1. ^temp + one temp := nil.
SmallIntegers No support for tagged integers Real integer objects 10x slower than tagged integers VW Tagged #Smalltalk 2r00001011 2r00000010
Blocks Create class for each block Create object from block class at runtime method ^#(1) collect: [:each | each + 1] method ^#(1) collect: (Method-Block new) MonadicBlock subclass: Method-Block instanceVariableNames: ‘’ … value: each ^each + 1
Block Variables Variable references Copied values (method/block arguments) Active variables (temporaries) method: arg | block temp | block := [temp + arg]. temp := 5. ^block value arg 5 method arg block temp block arg temp temp value
Block Returns Simulate using .NET exceptions 100x slower Tag object (integer) method1 self method2: [^1] method2: aBlock #(2) do:  [:each |  aBlock value. ^each] method2 method1 do: method2[ ] method1[ ]
Primitives Some actions aren’t representable (e.g., identityHash, +, etc.) Primitive tag Only one per method Compiler primitive: [] Used anywhere in method User can add new primitives Block code evaluated at compile time
Primitive Example identityHash ^Compiler  primitive:  [:codeGenerator |  codeGenerator call: (System.Object getMethod: 'GetHashCode'); constructNewObject: codeGenerator smalltalk  smallIntegerClass initializedConstructor] evaluate: self
Optimized Messages Certain messages aren’t sent (e.g., ifTrue:, whileTrue:, to:do:) Can hard code in compiler Instead use macros and “Compiler primitive: []” syntax
Macros RB’s rewrite rules ``@node ifTrue: ``@block     Compiler    primitive: [:codeGen :block | …]   evaluate: ``@node   uses: ``@block Allows arbitrary optimizations (e.g., ifNil:    isNil ifTrue:) Copy source interval for debugger
Connecting with .NET Over 2500 classes provided Seamless integration | algorithm stream | algorithm := HashAlgorithm create: ‘MD5’. stream := FileStream read: ‘rb.im’. [algorithm computeHash: stream]  ensure: [stream close]
Connecting Smalltalk to .NET Class references (Convert or System.Convert)  Typed Variables (System.Int32) Generic ObjectWrapper Messages for field, property, and method access  Constructors – #new* messages
Method arguments First keyword for method name/rest can be anything Arguments converted to .NET objects is-a tests for arguments Overloaded methods left-to-right, specific-to-generic System.Console::Write(int/char/…/object)
Console Example System.Console write: anObject (anObject isKindOf: SmallInteger) ifTrue: [System.Console write: anObject integer] ifFalse:  [(anObject isKindOf: Character)  ifTrue: [System.Console write: anObject character] ifFalse:  [(anObject isKindOf: String) ifTrue: [System.Console write: anObject string] ifFalse: [System.Console write: anObject]]]
Connecting .NET to Smalltalk Events use add_EventName: / remove_EventName: methods Delegates (#asDelegate:) Button new add_Click:    ([:obj :args | …] asDelegate: EventHandler) Exported Properties/Methods (specified by annotations) Interfaces & subclasses (to do)
#Smalltalk Development  (Version 1) Proof of concept VisualWorks program Compiled generated text file with ilasm (.NET’s assembler) Not seamless
#Smalltalk Development  (Version 2) Read .SIF files VisualWorks DLL connection to .NET Override qualified name lookup in VW to use .NET DLL System.Int32 Parse: ‘1234’ System.Reflection.Emit generate .exe file directly
#Smalltalk Development  (Version 3) Code based on Version 2 Self hosting Complete .exe compiler Compile three times (fixed point) Old code compiling new code New code compiling new code Verify new code compiled new code valid
Benchmarks 28.65 70.59 856.50 49.36 36.65 sorting strings 21.14 216.11 48.63 13.25 20.19 forming sets 18.27 179.71 128.79 27.09 98.44 generating strings * 181.13 140.38 43.15 42.22 generating primes 7.20 115.22 87.21 33.55 15.77 generating fractonaccis 2.17 42.67 61.88 30.91 6.80 evaluate blocks 8.07 161.35 37.65 16.12 28.96 perform selectors 14.11 74.77 74.77 37.35 29.91 copy objects 7.16 90.91 30.30 90.82 20.20 create objects 36.28 108.84 54.42 54.37 19.10 access strings 11.45 39.08 2266.67 75.48 64.76 add floats 14.07 576.97 576.97 2.62 36.06 add integers Squeak VW VA #Smalltalk Dolphin
Future work IDE (GUI builders, Browsers, etc.)  Add Subclassing/Interfaces Optimizations Reusing intermediate numerical values (e.g., i + j + k) Type inferencing – eliminating SmallIntegers (e.g., 1 to: 10 do: [:i | ]) Write programs
Contact Information #Smalltalk http://www.refactory.com/Software/SharpSmalltalk/ VisualWorks .NET DLL http://www.rileywhite.com/software/assemblyconnect.html .NET http://www.microsoft.com/net/ http://www.go-mono.com/

More Related Content

PPTX
.NET Multithreading/Multitasking
PPTX
.NET: Thread Synchronization Constructs
PPT
ppt on scanner class
PPTX
Introduction to TPL
PPT
Threads c sharp
PPTX
Java input
PPT
Intro To .Net Threads
PPTX
Threading in C#
.NET Multithreading/Multitasking
.NET: Thread Synchronization Constructs
ppt on scanner class
Introduction to TPL
Threads c sharp
Java input
Intro To .Net Threads
Threading in C#

What's hot (20)

PDF
Java fork join
PPTX
Fork and join framework
PPTX
Coroutines in Kotlin
PPTX
Whats new in .net framework 4
PDF
WTF is Twisted?
PPT
Threads And Synchronization in C#
PPTX
Buffer and scanner
KEY
Fork/Join for Fun and Profit!
PPTX
Multi-Threading
PDF
Fork Join (BeJUG 2012)
ODP
Multithreading 101
PDF
Adam Sitnik "State of the .NET Performance"
PPT
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
PDF
Java 8 - Stamped Lock
PPT
Distributed System by Pratik Tambekar
KEY
Grand Central Dispatch Design Patterns
PPT
iOS Multithreading
PDF
22 multi threading iv
PPTX
Java concurrency in practice
PPTX
Tutorial 4 adding some details
Java fork join
Fork and join framework
Coroutines in Kotlin
Whats new in .net framework 4
WTF is Twisted?
Threads And Synchronization in C#
Buffer and scanner
Fork/Join for Fun and Profit!
Multi-Threading
Fork Join (BeJUG 2012)
Multithreading 101
Adam Sitnik "State of the .NET Performance"
Exploiting Multicore CPUs Now: Scalability and Reliability for Off-the-shelf ...
Java 8 - Stamped Lock
Distributed System by Pratik Tambekar
Grand Central Dispatch Design Patterns
iOS Multithreading
22 multi threading iv
Java concurrency in practice
Tutorial 4 adding some details
Ad

Viewers also liked (7)

KEY
Opal compiler
ZIP
PDF
Squeak by Example - Fosdem08
PDF
Twisting the Triad
PDF
Smalltalk on rubinius
ODP
Swt 2009
PDF
Development and Features of the new Cincom Smalltalk ObjectStudio Launcher
Opal compiler
Squeak by Example - Fosdem08
Twisting the Triad
Smalltalk on rubinius
Swt 2009
Development and Features of the new Cincom Smalltalk ObjectStudio Launcher
Ad

Similar to Smalltalk in a .NET World (20)

PPTX
Whats New in Visual Studio 2012 for C++ Developers
PDF
Unmanaged Parallelization via P/Invoke
PPT
Introduction to Visual Studio.NET
PPT
Dot Net Framework
PPTX
Visual Studio 2010 and .NET 4.0 Overview
PDF
The Ring programming language version 1.5.2 book - Part 176 of 181
PDF
The Ring programming language version 1.5.4 book - Part 180 of 185
PPT
C#/.NET Little Wonders
PPTX
Legacy Code Kata v3.0
PPT
2310 b 03
PPT
Intro dotnet
PPT
Intro dotnet
PPT
Intro dotnet
PPT
Intro dotnet
PDF
L Fu - Dao: a novel programming language for bioinformatics
PDF
EKON 23 Code_review_checklist
PPT
Attributes & .NET components
PPT
C# features
PPTX
01. introduction to-programming
Whats New in Visual Studio 2012 for C++ Developers
Unmanaged Parallelization via P/Invoke
Introduction to Visual Studio.NET
Dot Net Framework
Visual Studio 2010 and .NET 4.0 Overview
The Ring programming language version 1.5.2 book - Part 176 of 181
The Ring programming language version 1.5.4 book - Part 180 of 185
C#/.NET Little Wonders
Legacy Code Kata v3.0
2310 b 03
Intro dotnet
Intro dotnet
Intro dotnet
Intro dotnet
L Fu - Dao: a novel programming language for bioinformatics
EKON 23 Code_review_checklist
Attributes & .NET components
C# features
01. introduction to-programming

More from ESUG (20)

PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
PDF
Directing Generative AI for Pharo Documentation
PDF
Even Lighter Than Lightweiht: Augmenting Type Inference with Primitive Heuris...
PDF
Composing and Performing Electronic Music on-the-Fly with Pharo and Coypu
PDF
Gamifying Agent-Based Models in Cormas: Towards the Playable Architecture for...
PDF
Analysing Python Machine Learning Notebooks with Moose
PDF
FASTTypeScript metamodel generation using FAST traits and TreeSitter project
PDF
Migrating Katalon Studio Tests to Playwright with Model Driven Engineering
PDF
Package-Aware Approach for Repository-Level Code Completion in Pharo
PDF
Evaluating Benchmark Quality: a Mutation-Testing- Based Methodology
PDF
An Analysis of Inline Method Refactoring
PDF
Identification of unnecessary object allocations using static escape analysis
PDF
Control flow-sensitive optimizations In the Druid Meta-Compiler
PDF
Clean Blocks (IWST 2025, Gdansk, Poland)
PDF
Encoding for Objects Matters (IWST 2025)
PDF
Challenges of Transpiling Smalltalk to JavaScript
PDF
Immersive experiences: what Pharo users do!
PDF
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
PDF
Cavrois - an Organic Window Management (ESUG 2025)
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
Micromaid: A simple Mermaid-like chart generator for Pharo
Directing Generative AI for Pharo Documentation
Even Lighter Than Lightweiht: Augmenting Type Inference with Primitive Heuris...
Composing and Performing Electronic Music on-the-Fly with Pharo and Coypu
Gamifying Agent-Based Models in Cormas: Towards the Playable Architecture for...
Analysing Python Machine Learning Notebooks with Moose
FASTTypeScript metamodel generation using FAST traits and TreeSitter project
Migrating Katalon Studio Tests to Playwright with Model Driven Engineering
Package-Aware Approach for Repository-Level Code Completion in Pharo
Evaluating Benchmark Quality: a Mutation-Testing- Based Methodology
An Analysis of Inline Method Refactoring
Identification of unnecessary object allocations using static escape analysis
Control flow-sensitive optimizations In the Druid Meta-Compiler
Clean Blocks (IWST 2025, Gdansk, Poland)
Encoding for Objects Matters (IWST 2025)
Challenges of Transpiling Smalltalk to JavaScript
Immersive experiences: what Pharo users do!
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
Cavrois - an Organic Window Management (ESUG 2025)

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
A Presentation on Artificial Intelligence
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Empathic Computing: Creating Shared Understanding
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
A Presentation on Artificial Intelligence
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Per capita expenditure prediction using model stacking based on satellite ima...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Empathic Computing: Creating Shared Understanding
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Electronic commerce courselecture one. Pdf
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf

Smalltalk in a .NET World

  • 1. Smalltalk in a .NET World How to write a Smalltalk compiler without writing a VM John Brant [email_address]
  • 2. #Smalltalk Open source Smalltalk compiler Complete Source Available Self hosting Compiles Smalltalk directly to .NET executables and libraries
  • 3. Building Smalltalk Virtual Machine .NET Virtual Machine Compiler RB parser Class Library ANSI Standard Development tools (debuggers, browsers, etc.)
  • 4. What’s .NET Anyway? Common class library (collections, GUI, sockets, database, etc.) Common virtual machine and byte code instruction set Language isn’t supposed to matter
  • 5. Why .NET? (business reasons) Backed by Microsoft Lots of existing code Allow Smalltalk to be used for applications that “require .NET”
  • 6. Why .NET? (personal reasons) Build a Smalltalk compiler Make an experimental platform Learn .NET Unemployed
  • 7. Smalltalk vs. .NET ? become:, change classes Non-resumable exceptions Resumable Exceptions Delegates Blocks Primitive integer types Tagged integers Strong, static typing Strong, dynamic typing .NET Smalltalk
  • 8. Smalltalk vs. .NET II Structs & Enums ? Add classes/methods (can’t remove or recompile) Add/remove classes & methods Static, virtual, & non-virtual methods All methods are virtual .NET Smalltalk
  • 9. Dynamic Typing Root super type Understands every message Sends #doesNotUnderstand: printString ^self doesNotUnderstand: (Message selector: #printString arguments: #()) printString | stream | stream := WriteStream with: String new. self printOn: stream. ^stream contents Root Object Proxy
  • 10. null vs. nil Special object for nil Class constructor initializes variables to nil Method temporaries initialized to nil only if they could be read before written method: aBoolean | temp one | aBoolean ifTrue: [temp := 5]. one := 1. ^temp + one temp := nil.
  • 11. SmallIntegers No support for tagged integers Real integer objects 10x slower than tagged integers VW Tagged #Smalltalk 2r00001011 2r00000010
  • 12. Blocks Create class for each block Create object from block class at runtime method ^#(1) collect: [:each | each + 1] method ^#(1) collect: (Method-Block new) MonadicBlock subclass: Method-Block instanceVariableNames: ‘’ … value: each ^each + 1
  • 13. Block Variables Variable references Copied values (method/block arguments) Active variables (temporaries) method: arg | block temp | block := [temp + arg]. temp := 5. ^block value arg 5 method arg block temp block arg temp temp value
  • 14. Block Returns Simulate using .NET exceptions 100x slower Tag object (integer) method1 self method2: [^1] method2: aBlock #(2) do: [:each | aBlock value. ^each] method2 method1 do: method2[ ] method1[ ]
  • 15. Primitives Some actions aren’t representable (e.g., identityHash, +, etc.) Primitive tag Only one per method Compiler primitive: [] Used anywhere in method User can add new primitives Block code evaluated at compile time
  • 16. Primitive Example identityHash ^Compiler primitive: [:codeGenerator | codeGenerator call: (System.Object getMethod: 'GetHashCode'); constructNewObject: codeGenerator smalltalk smallIntegerClass initializedConstructor] evaluate: self
  • 17. Optimized Messages Certain messages aren’t sent (e.g., ifTrue:, whileTrue:, to:do:) Can hard code in compiler Instead use macros and “Compiler primitive: []” syntax
  • 18. Macros RB’s rewrite rules ``@node ifTrue: ``@block  Compiler primitive: [:codeGen :block | …] evaluate: ``@node uses: ``@block Allows arbitrary optimizations (e.g., ifNil:  isNil ifTrue:) Copy source interval for debugger
  • 19. Connecting with .NET Over 2500 classes provided Seamless integration | algorithm stream | algorithm := HashAlgorithm create: ‘MD5’. stream := FileStream read: ‘rb.im’. [algorithm computeHash: stream] ensure: [stream close]
  • 20. Connecting Smalltalk to .NET Class references (Convert or System.Convert) Typed Variables (System.Int32) Generic ObjectWrapper Messages for field, property, and method access Constructors – #new* messages
  • 21. Method arguments First keyword for method name/rest can be anything Arguments converted to .NET objects is-a tests for arguments Overloaded methods left-to-right, specific-to-generic System.Console::Write(int/char/…/object)
  • 22. Console Example System.Console write: anObject (anObject isKindOf: SmallInteger) ifTrue: [System.Console write: anObject integer] ifFalse: [(anObject isKindOf: Character) ifTrue: [System.Console write: anObject character] ifFalse: [(anObject isKindOf: String) ifTrue: [System.Console write: anObject string] ifFalse: [System.Console write: anObject]]]
  • 23. Connecting .NET to Smalltalk Events use add_EventName: / remove_EventName: methods Delegates (#asDelegate:) Button new add_Click: ([:obj :args | …] asDelegate: EventHandler) Exported Properties/Methods (specified by annotations) Interfaces & subclasses (to do)
  • 24. #Smalltalk Development (Version 1) Proof of concept VisualWorks program Compiled generated text file with ilasm (.NET’s assembler) Not seamless
  • 25. #Smalltalk Development (Version 2) Read .SIF files VisualWorks DLL connection to .NET Override qualified name lookup in VW to use .NET DLL System.Int32 Parse: ‘1234’ System.Reflection.Emit generate .exe file directly
  • 26. #Smalltalk Development (Version 3) Code based on Version 2 Self hosting Complete .exe compiler Compile three times (fixed point) Old code compiling new code New code compiling new code Verify new code compiled new code valid
  • 27. Benchmarks 28.65 70.59 856.50 49.36 36.65 sorting strings 21.14 216.11 48.63 13.25 20.19 forming sets 18.27 179.71 128.79 27.09 98.44 generating strings * 181.13 140.38 43.15 42.22 generating primes 7.20 115.22 87.21 33.55 15.77 generating fractonaccis 2.17 42.67 61.88 30.91 6.80 evaluate blocks 8.07 161.35 37.65 16.12 28.96 perform selectors 14.11 74.77 74.77 37.35 29.91 copy objects 7.16 90.91 30.30 90.82 20.20 create objects 36.28 108.84 54.42 54.37 19.10 access strings 11.45 39.08 2266.67 75.48 64.76 add floats 14.07 576.97 576.97 2.62 36.06 add integers Squeak VW VA #Smalltalk Dolphin
  • 28. Future work IDE (GUI builders, Browsers, etc.) Add Subclassing/Interfaces Optimizations Reusing intermediate numerical values (e.g., i + j + k) Type inferencing – eliminating SmallIntegers (e.g., 1 to: 10 do: [:i | ]) Write programs
  • 29. Contact Information #Smalltalk http://www.refactory.com/Software/SharpSmalltalk/ VisualWorks .NET DLL http://www.rileywhite.com/software/assemblyconnect.html .NET http://www.microsoft.com/net/ http://www.go-mono.com/