Continuations and Stackless Python Where Do You Want To Jump Today?

Slides:



Advertisements
Similar presentations
The Art of Avoiding Work
Advertisements

Construction process lasts until coding and testing is completed consists of design and implementation reasons for this phase –analysis model is not sufficiently.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Reliable Scripting Using Push Logic Push Logic David Greaves, Daniel Gordon University of Cambridge Computer Laboratory Reliable Scripting.
Chapter Modules CSC1310 Fall Modules Modules Modules are the highest level program organization unit, usually correspond to source files and.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Speeding it up Part 3: Out-Of-Order and SuperScalar execution dr.ir. A.C. Verschueren.
Tail Recursion. Problems with Recursion Recursion is generally favored over iteration in Scheme and many other languages – It’s elegant, minimal, can.
Concurrency The need for speed. Why concurrency? Moore’s law: 1. The number of components on a chip doubles about every 18 months 2. The speed of computation.
Overview Motivations Basic static and dynamic optimization methods ADAPT Dynamo.
Dynamic Typing COS 441 Princeton University Fall 2004.
CompSci Applets & Video Games. CompSci Applets & Video Games The Plan  Applets  Demo on making and running a simple applet from scratch.
THQ/Gas Powered Games Supreme Commander and Supreme Commander: Forged Alliance Thread for Performance.
Fast Paths in Concurrent Programs Wen Xu, Princeton University Sanjeev Kumar, Intel Labs. Kai Li, Princeton University.
PARALLEL PROGRAMMING with TRANSACTIONAL MEMORY Pratibha Kona.
PZ11B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ11B - Parallel execution Programming Language Design.
490dp Synchronous vs. Asynchronous Invocation Robert Grimm.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
Scripting Languages For Virtual Worlds. Outline Necessary Features Classes, Prototypes, and Mixins Static vs. Dynamic Typing Concurrency Versioning Distribution.
29-Jun-15 Java Concurrency. Definitions Parallel processes—two or more Threads are running simultaneously, on different cores (processors), in the same.
Compilers and Interpreters. Translation to machine language Every high level language needs to be translated to machine code There are different ways.
3-1 3 Compilers and interpreters  Compilers and other translators  Interpreters  Tombstone diagrams  Real vs virtual machines  Interpretive compilers.
SYSTEMS SUPPORT FOR GRAPHICAL LEARNING Ken Birman 1 CS6410 Fall /18/2014.
Applets & Video Games 1 Last Edited 1/10/04CPS4: Java for Video Games Applets &
Chun Chiu. Overview What is RISC? Characteristics of RISC What is CISC? Why using RISC? RISC Vs. CISC RISC Pipelines Advantage of RISC / disadvantage.
Chapter 1 Computer System Overview Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
SYSTEMS SUPPORT FOR GRAPHICAL LEARNING Ken Birman 1 CS6410 Fall /18/2014.
The Python Language Petr Přikryl Part I Socrates IP, 15th June 2004 TU of Brno, FIT, Czech Republic.
Previously Fetch execute cycle Pipelining and others forms of parallelism Basic architecture This week we going to consider further some of the principles.
Algorithms and Programming
CSC 310 – Imperative Programming Languages, Spring, 2009 Virtual Machines and Threaded Intermediate Code (instead of PR Chapter 5 on Target Machine Architecture)
1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project.
Introduction and Features of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
The HipHop Compiler from Facebook By Megha Gupta & Nikhil Kapoor.
Stackless Python: programming the way Guido prevented it intended.
Operating Systems Lecture No. 2. Basic Elements  At a top level, a computer consists of a processor, memory and I/ O Components.  These components are.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
Continuations and Stackless Python Where Do You Want To Jump Today?
Eagle: Maturation and Evolution 17th Annual Tcl Conference Joe Mistachkin.
Stackless Python: programming the way Guido prevented it.
1 The Evaluator. 2 Compiler vs. Interpreter Command Processing Unit The Computer Program in Low Level Machine Language Program in High Level Language.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
Prolog Program Style (ch. 8) Many style issues are applicable to any program in any language. Many style issues are applicable to any program in any language.
Chapter 3 - Language Design Principles
Processor Architecture
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Fall 2008Programming Development Techniques 1 Topic 20 Concurrency Section 3.4.
Group Communication Theresa Nguyen ICS243f Spring 2001.
CS 598 Scripting Languages Design and Implementation 12. Interpreter implementation.
1 Parallel execution Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Concurrency and Performance Based on slides by Henri Casanova.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
A Single Intermediate Language That Supports Multiple Implemtntation of Exceptions Delvin Defoe Washington University in Saint Louis Department of Computer.
The heavyweight parts of lightweight languages LL1 Workshop November 17, 2001.
Segments Introduction: slides 2–6, 8 10 minutes
Introduction to Web Assembly
Done By: Ashlee Lizarraga Ricky Usher Jacinto Roches Eli Gomez
Mechanism: Limited Direct Execution
The heavyweight parts of lightweight languages
Chapter 9 – Real Memory Organization and Management
Topic: Functions – Part 2
Closure Representations in Higher-Order Programming Languages
Java Concurrency 17-Jan-19.
Concurrency and Immutability
Eagle: Maturation and Evolution
Java Concurrency.
Java Concurrency.
Overview: Active Sensor networks
Java Concurrency 29-May-19.
Presentation transcript:

Continuations and Stackless Python Where Do You Want To Jump Today?

Stacklessssshhh Python... And the clueless implementor...

Applications of Stackless Python FAU – Florida Atlantic University *) –Soft real time control system for autonomous underwater vehicles. –Concurrent hierarchy of hierarchical state machines that can be loaded dynamically. Language Python. –Real thread implementation is expensive and operates at 1 Hz Resolution. Microthreads with Stackless Python supposed to run at 12 Hz or faster, also supporting multiple simultaneous behaviors. My current project Gordon McMillan: Highly parallelized FTP-Server (not open Source yet) Sam Rushing: Medusa on top of coroutines *?) MMPOG: Eve! Massively Multi-Player Online Game.  *) *) sponsored work *?) may become sponsored, soon

Moving Targets Early version: (1999) –Try to minimize changes in order to get into the core. Guido reejcts it but accepts the paper for IPC8. New version: (2000) –Still only a small number of changes –Massive changes to ceval.c for speed –Gave up on integration –Make it attractive even without stackless features –This is hard to maintain! Long delay for SLP 2.0. Version 2.0: (2000/2001) „The Kiel Edition“ Maintainability was re-gained –Minimized code-reorderings, all systematic optimization done by script

Stackless Python 2.2? No! Integration into Standard New implementation –Massive changes to core –Avoid *any* recursion if possible. –Coroutines, Generatrors, Microthreads –Not to be done by me (!!reasons: Gordo does it) –No continuations at all! Splitting paths? Stackless python will –do all of the above –Continue to support continuations Educational purposes Studying expense –Try to be faster

How Does It Work? Stackful Python: –... –Interpreter interprets opcodes –CALL_FUNCTION (Python function) –Builds new frame –Calls new interpreter, waiting... Interpreter interprets opcodes... –Continues with result

How Does It Work? Trampoline Style Stackless Python: –Dispatcher: Starts interpreter with topmost frame + result Interpreter interprets opcodes –CALL_FUNCTION (Python function) –Builds new frame –Returns to Dispatcher with unwind flag –Dispatcher: Starts interpreter with topmost frame + result Interpreter interprets opcodes –... and so on

Why Continuations? Appears to be the simplest possible, most powerful structure –Can model *any* kind of control flow (also any control flaw) –Can build Generators, Coroutines and Microthreads in Python –Can do much more! (But is it needed?) –Scheme does it, so Python too? –Can build very fast class-method like functions (see example)

Why Continuations - Example Def very_fast_with_state(*init_params): –… –# do complicated initialization –# prepare local state. Locals are persisting –args = continuation.return_current() –… –# do the cheap calculation –Return result fast_func = very_fast_with_state(“Hi”, 4) fast_func(1) # use it many times

Why Not Continuations? Generators, Coroutines and Microthreads can be implemented directly in C. –Will be much faster. –Safe encapsulation of internal continuations Full continuation support is cheap today –But may become expensive in the future (Stack optimization, native compiler) –Can build very fast class-method like functions with generators as well: (see example)

Why Not Continuations - Example Def very_fast_no_continuation(*init_params): –… –# do complicated initialization –# prepare local state. Locals are persisting –args = generator.initialize() –… –While 1: # do the cheap calculation Args = generator.suspend(result) fast_func = very_fast_no_continuation(“Hi”, 4) fast_func(1) # use it many times

Generator vs. Continuation Continuation is immutable Generator is mutable Continuation takes control over order of execution Generator does not introduce new control structure. Frame jumps from alone by opcode.

First Class vs. One-Shot Continuations are everywhere: –Program counter / return stack. –Every today‘s program consists of a series of one-shot continuations. One-shot: –The continuation does not survive its execution First-class continuation: –Does survive execution, can be executed infinite times –State of frame can always be reset First class is most powerful One-Shot is sufficient for Microthreads, Coroutines and Generators.

New Project: Cheetah Stackless from the ground First: Quick system-independent extension language Later: Fast system-specific extension language Forth related/inspired engine Parsed from restricted Python code Able to extend regular Python with new primitives Able to replace the whole Python implementation Sponsors are most welcome