Moscow ML Code Generation for Microsoft .Net Niels Jørgen Kokholm Copenhagen Programming Language Seminar December 12th 2002... • Work in progress • With Peter Sestoft • Long time goal
Trang 1Moscow ML Code Generation for
Microsoft Net
Niels Jørgen Kokholm Copenhagen Programming Language
Seminar December 12th 2002
Trang 2Moscow ML
• Standard ML batch compiler (mosmlc)
• Standard ML Basis Library
• Interactive evaluation system (mosml)
• …
• Runs on CaML light runtime
• Written in Standard ML (and C)
Trang 3Microsoft Net
• Microsoft NET Framework/ECMA CLI
– Common Language Runtime (CLR)
• Virtual “stack” machine specification similar to JVM
– NET Framework class libraries
• Implementations:
– MS NET SDK
– MS SSCLI (rotor)
– Mono
– DotGNU Portable.NET
Trang 4• Work in progress
• With Peter Sestoft
• Long time goal: port Moscow ML to CLR
• Started as four week project at ITU
– May ’02 Andrzej Wasowski/PS
Trang 5• Assess usability of CLR as execution platform for functional languages and the portability of Moscow ML
• Expand the range of HW/SW platforms on which Moscow ML run (or avoid porting CaML Light)
• Leverage the safety and productivity potential of strongly typed languages in high-end, distributed, XML-aware, E-yada yada yada
• Learn about code generation in a non-toy setting
and about NET
Trang 6• Overall plan
– Feasibility study
• Can it be done with reasonable performance
– CLR code generation
• For pure Standard ML programs
– Basis Library part 1
• Parts used by compiler
– Bootstrap compiler
– Interactive system
– Basis Library part 2
Trang 7• CLR code generation + library part 3
– May 2002
• Bootstrap compiler
– October 2002
– No floating point types, quote/antiquote, …
– No complete regression test
• Performance compared to current Moscow ML
– Small code benchmarks: 1-4 times as slow
– Bootstrapped compiler: 5 times as slow
Status
Trang 8Related work
• Moscow ML on JVM
– Peter Berthelsen, master thesis 1998
• SML.NET
– Andrew Kennedy, Claudio Russo, Nick Benton (MS Research), released June 2002
– Standard ML compiler on CLR
– Bootstrapped from SML/NJ
• F#
– Don Syme, MS Research
Trang 9CaML light vs CLR
Evaluation stack accessible by
index
Only top of evaluation stack accessible
?
- Local variables
- Stack must be empty on entry to
try block
Tailor made types OO type system
? Tail recursion of method calls -
.uo exe, dll and netmodule files class
Textual assembler and RTCG library
Tailor made garbage collection All-purpose Garbage collection
Trang 10Moscow ML Code Generation
1 Parsing, typecheck,
translation
2 Compilation:
a) Closure splitting
b) Expression
compilation
3 Byte code emission
B y t e c o d e
S y m b o l i c ( m a c r o ) b y t e c o d e ( u n t y p e d ) L a m b d a E x p r e s s i o n s
S M L P r o g r a m
Trang 11Changing the backend 1
• Textual assembler vs RTCG?
• Verifiable or unverifiable code?
• Efficiency
Trang 12Changing the backend 2
• Representation of run time values
• Correct tail recursion
• Exception handling
• Boxing of primitive types
Trang 13Runtime value representation
Trang 14Closures
Trang 15Exception handling
Trang 16Boxing of primitive types
Trang 17Performance comparisons