From Interpreter to Compiler and Virtual Machine



Similar documents
BRICS. From Interpreter to Compiler and Virtual Machine: A Functional Derivation

BRICS. A Functional Correspondence between Evaluators and Abstract Machines

Chapter 7: Functional Programming Languages

Functional programming languages


Regression Verification: Status Report

Parameter passing in LISP

Problems and Measures Regarding Waste 1 Management and 3R Era of public health improvement Situation subsequent to the Meiji Restoration

>

Lecture 11: Tail Recursion; Continuations

COMPUTER SCIENCE TRIPOS

Stack Allocation. Run-Time Data Structures. Static Structures

FreshML: Programming with Binders Made Simple

Semantics and Verification of Software

Definitional Interpreters for Higher-Order Programming Languages *

Lecture Data Types and Types of a Language

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

Lab Experience 17. Programming Language Translation

Functional Programming in C++11

Lightweight Fusion by Fixed Point Promotion

Programming Language Pragmatics

CSc 372. Comparative Programming Languages. 21 : Haskell Accumulative Recursion. Department of Computer Science University of Arizona

CS170 Lab 11 Abstract Data Types & Objects

Programming Language Features (cont.) CMSC 330: Organization of Programming Languages. Parameter Passing in OCaml. Call-by-Value

Practical Generic Programming with OCaml

C++ Programming Language

ML for the Working Programmer

Checking Access to Protected Members in the Java Virtual Machine

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards


PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Moving from CS 61A Scheme to CS 61B Java

Crash Course in Java

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Compiler Construction

Topic VII. Data abstraction and modularity SML Modules a. References: Chapter 7 of ML for the working programmer (2ND

POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful

Polymorphic Type Inference and Abstract Data Types

Evaluation of Complexity of Some Programming Languages on the Travelling Salesman Problem

AURA: A language with authorization and audit

Grade 6 Math Circles. Binary and Beyond

Solving Problems Recursively

Inside the PostgreSQL Query Optimizer

Kotlin for Android Developers

Massachusetts Institute of Technology 6.005: Elements of Software Construction Fall 2011 Quiz 1 October 14, Instructions

Semester Review. CSC 301, Fall 2015

Glossary of Object Oriented Terms

Conditionals (with solutions)

csci 210: Data Structures Recursion

Anatomy of Programming Languages. William R. Cook

How To Write A Programmg With A State Monad And An Imperative Dsl

Andrew Pitts chapter for D. Sangorgi and J. Rutten (eds), Advanced Topics in Bisimulation and Coinduction, Cambridge Tracts in Theoretical Computer

A Scala Tutorial for Java programmers

Computer Programming I

Informatica e Sistemi in Tempo Reale

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

Fun with Phantom Types

Linearly Used Effects: Monadic and CPS Transformations into the Linear Lambda Calculus

Direct models of the computational lambda-calculus

Habanero Extreme Scale Software Research Project

Coeffects: Unified static analysis of context-dependence

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg

Tail call elimination. Michel Schinz

Introduction to Java

Creating a Java application using Perfect Developer and the Java Develo...

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Probabilità e Nondeterminismo nella teoria dei domini

The Two Envelopes Problem

C Programming. Charudatt Kadolkar. IIT Guwahati. C Programming p.1/34

Math 55: Discrete Mathematics

Part I. Multiple Choice Questions (2 points each):

Adding GADTs to OCaml the direct approach

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

LAB4 Making Classes and Objects

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Recursion vs. Iteration Eliminating Recursion

Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

From GWS to MapReduce: Google s Cloud Technology in the Early Days

Programming Languages in Artificial Intelligence

Java CPD (I) Frans Coenen Department of Computer Science

Computing Concepts with Java Essentials

J a v a Quiz (Unit 3, Test 0 Practice)

SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities

Object-Oriented Programming in Java

Observational Program Calculi and the Correctness of Translations

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Explain the relationship between a class and an object. Which is general and which is specific?

It has a parameter list Account(String n, double b) in the creation of an instance of this class.

Transcription:

BRICS From Interpreter to Compiler and Virtual Machine Mads Sig Ager BRICS, University of Aarhus, Denmark Joint work with Dariusz Biernacki, Olivier Danvy, and Jan Midtgaard 1 Examples of machines Krivine s machine CEK CLS CAM SECD ZAM JVM VEC 2

What is the difference between an abstract machine and a virtual machine? 3 What is the difference between an abstract machine and a virtual machine? A virtual machine has an instruction set. An abstract machine does not. 4

This work: From Interpreter to Compiler and Virtual Machine Compiler Interpreter Virtual Machine 5 Related work Lotsofit 6

This talk A methodology. Two examples: an evaluation function for the λ-calculus; a normalization function for the λ-calculus. 7 Methodology Defunctionalization. Closure conversion. CPS transformation. Factorization. 8

Defunctionalization (Reynolds, 1972) Who inhabits a function space? Answer: instances of lambda abstractions. Let us enumerate them and represent a function space as a sum: function declaration: sum constructor; function application: case. 9 A simple example (1/2) (* aux : (int -> int) -> int *) fun aux f = f 100 fun main x = aux (fn n => n+1) + aux (fn n => x+n) 10

A simple example (2/2) datatype lam = L0 L1 of int fun apply (L0, n) = n+1 apply (L1 x, n) = x+n fun aux f = apply (f, 100) fun main x = aux L0 + aux (L1 x) 11 Closure conversion Special case of defunctionalization: only one summand; apply function inlined. 12

CPS transformation 1. Names intermediate results. 2. Sequentializes their computation. 3. Introduces continuations. Or again: transforms into monadic normal form and picks the continuation monad. Or again: λ-counterpart of double negation. 13 Factorization [ ] maps source program to endofunction. We factorize into composition of combinators and recursive calls to [ ]. We name combinators. 14

Example Before factorization: eval (LAM t) = (fn (e, (c, e ) :: s) => eval t ((c, e ) :: e, s)) After factorization: eval (LAM t) = (eval t) o grab val grab = (fn (e, (c, e ) :: s) => ((c, e ) :: e, s)) 15 Evaluation function, call-by-name 16

Evaluation function, call-by-name Closure convert. Call-by-name CPS transform. Defunctionalize continuations. Factorize. Result: compiler and transition system. 17 Evaluation function, call-by-name Closure convert. Call-by-name CPS transform. Defunctionalize continuations. Factorize. Result: compiler and transition system.... Krivine s machine. 18

Evaluation function, call-by-value 19 Evaluation function, call-by-value Closure convert. Call-by-value CPS transform. Defunctionalize continuations. Factorize. Result: compiler and transition system. 20

Evaluation function, call-by-value Closure convert. Call-by-value CPS transform. Defunctionalize continuations. Factorize. Result: compiler and transition system.... CEK machine. 21 Assessment Krivine: the simplest derivation we know of. CEK: new reconstruction. 22

Assessment Krivine: the simplest derivation we know of. CEK: new reconstruction. They are two sides of the same coin. 23 Normalization function, call-by-name 24

Normalization function, call-by-name Closure convert. Call-by-name CPS transform. Defunctionalize continuations. Factorize. Result: compiler and transition system. 25 Normalization function, call-by-name Closure convert. Call-by-name CPS transform. Defunctionalize continuations. Factorize. Result: compiler and transition system.... a generalization of Krivine s machine. 26

Normalization function, call-by-value 27 Normalization function, call-by-value Closure convert. Call-by-value CPS transform. Defunctionalize continuations. Factorize. Result: compiler and transition system. 28

Normalization function, call-by-value Closure convert. Call-by-value CPS transform. Defunctionalize continuations. Factorize. Result: compiler and transition system.... a generalization of the CEK machine. 29 Assessment Two new virtual machines for strong normalization. Derived rather than discovered or invented. 30

Reynolds, 1972 Self-interpreters depend on the evaluation order of their meta-language. 31 Reynolds, 1972 Self-interpreters depend on the evaluation order of their meta-language. Case in point: Krivine s machine and CEK machine. 32

Reynolds, 1972 Self-interpreters depend on the evaluation order of their meta-language. Case in point: Krivine s machine and CEK machine. Well, the same holds for normalization functions. 33 Thank you. 34