And more store-passing interpreters

Slides:



Advertisements
Similar presentations
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Advertisements

Closures & Environments CS153: Compilers Greg Morrisett.
Type Checking, Inference, & Elaboration CS153: Compilers Greg Morrisett.
(define (f x) (if (< x 0) (lambda (y) (- y x)) (lambda (y) (- x y)))) GE f: P1 para:x body:(if … )
Assignments and Procs w/Params EOPL3 Chapter 4. Expressible vs. Denotable values Expressible Values –the language can express and compute these –represented.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
Imperative Programming: Mutable data (local state, letrec, set!) Example 1: counter (define counter (let ((count 0)) (lambda () (set! count (+ count 1))
3.6 Interpreter: Recursion Recall Scheme's letrec (recursive let ): > (letrec ((fact (lambda (x) (if (zero? x) 1 (* x (fact (- x 1))))) (fact 6)) 720 Question:
Lecture 4 More Examples of Karnaugh Map. Logic Reduction Using Karnaugh Map Create an Equivalent Karnaugh Map Each circle must be around a power of two.
Assemblers Dr. Monther Aldwairi 10/21/20071Dr. Monther Aldwairi.
6.001 SICP SICP – Evaluation I Recitation 11/19/2004 Eval review Evaluation examples define lambda apply New language elements.
Catriel Beeri Pls/Winter 2004/5 environment1 1 The Environment Model  Introduction and overview  A look at the execution model  Dynamic scoping  Static.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
SchemeCOP Introduction to Scheme. SchemeCOP Scheme Meta-language for coding interpreters –“ clean ” semantics Scheme = LISP + ALGOL –simple.
Cs784(Prasad)L123Assg1 Assignments. cs784(Prasad)L123Assg2 l-value vs. r-value Pascal/Ada: x := x + 1 C/Java: x = x + 1 l-value = location, address, reference,
Cs784(tk)1 Implementing Recursion. Recap: Goals Experimenting with PL design alternatives Scoping, parameter passing, arrays,... Runnable prototype of.
Plt /12/ Data Abstraction Programming Language Essentials 2nd edition Chapter 2.3 Representation Strategies for Data Types.
3.5 Procedures Recall procedures (functions) in Scheme: (let ((f (lambda(y z) (+ y (- z 5))) (f 2 28)) We would like something similar in our toy language:
Dr. Philip Cannata 1 Functions and Recursion. Dr. Philip Cannata 2 10 Java (Object Oriented) ASP RDF (Horn Clause Deduction, Semantic Web) Relation Jython.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 18: Think Globally, Mutate Locally.
Plt /17/ Environment-Passing Interpreters Programming Language Essentials 2nd edition Chapter 3.8 Parameter-Passing Variations.
Python Arrays. An array is a variable that stores a collection of things, like a list. For example a list of peoples names. We can access the different.
Abstraction: Procedures as Parameters CMSC Introduction to Computer Programming October 14, 2002.
Writing Equations of Lines. Find the equation of a line that passes through (2, -1) and (-4, 5).
Bank Account Environment Model Examples Prof. Tony White April 2010.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
Scope: What’s in a Name? CMSC Introduction to Computer Programming October 16, 2002.
The Slope of a Line 4.4 Objective 1 – Find the slope of a line using two of its points Objective 2 – Interpret slope as a rate of change in real-life situations.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
Scheme in Scheme 2. What’s next  Adding set!  Dynamic vs. lexical variable scope  Extending mcscheme v1 with libraries  Can mcscheme execute mcscheme?
PS4 #6: if you got points off because you didn’t do an intersect with accessible and the start states, submit a re- grade. Today: let, let*, letrec in.
The Substitution Method Objectives: To solve a system of equations by substituting for a variable.
Warm-Up 1) Determine whether (-1,7) is a solution of the system. 4 minutes 3x – y = -10 2) Solve for x where 5x + 3(2x – 1) = 5. -x + y = 8.
Environments, Stores, and Interpreters. Overview As we study languages we will build small languages that illustrate language features We will use two.
CS5205Semantics1 CS5205: Foundation in Programming Languages Semantics Static Semantics Dynamic Semantics Operational Semantics Big-step Small-Step Denotational.
Arrays – two dimensional Chapter 14 This chapter explains how to do the following with a two dimensional array: Declare, use indices, obtain size, pass.
SICP Interpretation part 2 Store operators in the environment Environment as explicit parameter Defining new procedures.
Operational Semantics of Scheme
The interpreter.
Introduction to Scheme
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Implementing Recursion
Env. Model Implementation
Closure conversion Compiling λ.
Hire Toyota Innova in Delhi for Outstation Tour
Class 19: Think Globally, Mutate Locally CS150: Computer Science
Installing and Using MARIE
First-class continuations
Mini Language Interpreter Programming Languages (CS 550)
The Metacircular Evaluator
The Metacircular Evaluator
Installing and Using MARIE
10:00.
3.7 Variable Assignment Recall instance variables in Python:
Bindings, Scope, and Extent
3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6))
Rate of Change and Slope
Continuation Marks A john clements talk.
Extending our interpreted language with Scheme’s set!
Copyright © 2014, 2010, 2007 Pearson Education, Inc.
Installing and Using MARIE
3.6 Interpreter: Recursion
STORE MANAGER RESPONSIBILITIES.
Chapter 3: Environment-Passing Interpreters
Environments, Stores, and Interpreters
6.001 SICP Interpretation Parts of an interpreter
Assignments and Procs w/Params
Recursive Procedures and Scopes
Rehearsal: Lazy Evaluation Infinite Streams in our lazy evaluator
4 minutes Warm-Up 1) Determine whether (-1,7) is a solution of the system. 3x – y = -10 -x + y = 8 2) Solve for x where 5x + 3(2x – 1) = 5.
Presentation transcript:

And more store-passing interpreters Desugaring letrec And more store-passing interpreters

Store-passing recap

(let loop ([x ivx] [y ivy] …) body) (letrec ([loop (lambda (x y …) body)]) (loop ivx ivy …))

(define (sum from to) (define total 0) (let loop () (set! total (+ total from)) (set! from (+ from 1)) (if (<= from to) (loop) total)))

(define (sum from to) (let loop ([i from] [total 0]) (if (<= i to) (loop (+ i 1) (+ total i)) total)))

env maps variables to addresses (x, env, st) env maps variables to addresses st maps addresses to values The current size of the store is the next address: | st |

(e2, env’[x ↦ |st2|], st2[|st2| ↦ v1]) ⇓ (v2, st3) (e0, env, st0) ⇓ (((λ (x) e2), env’), st1) (e1, env, st1) ⇓ (v1, st2) ((e0 e1), env, st0) ⇓ (v2, st3) ((λ (x) e), env, st) ⇓ (((λ (x) e), env), st) (x, env, st) ⇓ (st(env(x)), st)

(letrec* ([x0 e0] …) body) (let ([x0 ‘undefined] …) (set! x0 e0) ... body)

(letrec ([x0 e0] …) body) (let ([x0 ‘undefined] …) (let ([t0 e0]) (set! x0 t0) ... body))

Let’s code this up.