1 / 12

Programming Languages 2nd edition Tucker and Noonan

Programming Languages 2nd edition Tucker and Noonan. Chapter 10 Function Implementation In theory, there is no difference between theory and practice, but not in practice. Anonymous. Contents. 10.1 Function Declaration and Call in Clite 10.2 Completing the Clite Type System

cathal
Télécharger la présentation

Programming Languages 2nd edition Tucker and Noonan

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Languages2nd editionTucker and Noonan Chapter 10 Function Implementation In theory, there is no difference between theory and practice, but not in practice. Anonymous

  2. Contents 10.1 Function Declaration and Call in Clite 10.2 Completing the Clite Type System 10.3 Semantics of Call and Return 10.4 Formal Treatment of Types and Semantics

  3. 10.4 Formal Treatment of Types and Semantics • The type map for a function f, tmf, is a set of pairs and triples, representing global variables (tmG), functions (tmF), f’s parameters, and f’s locals. E.g., for the program in Figure 10.1:

  4. Typing Function • The function typing creates type maps for each individual function f in a program with globals G and functions F.

  5. Validity of a Clite Program • A program is valid if its global variables and function declarations are valid, and each function is valid with respect to their type maps.

  6. Validity of a Clite Function • A function is valid if 1) its parameters and locals have unique names, 2) its statements are valid in its type map, and 3) it contains (does not contain) a return statement if it is a non-void (void) function.

  7. Validity of a Clite Call and Return • Validity of most Clite statements is defined in Chapter 6. Validity of a Call and a Return is defined below:

  8. Formalizing the Semantics of Clite • Memory (), Environment () and State (): • The State of a function f, f , is a triple f    a • where a addresses the top of the run-time stack, •  is a set of address-value pairs, and • f has f’s visible variables and their addresses.

  9. Allocate and Deallocate Functions • allocate changes the state by adding a group of variable-address pairs to it. • deallocate removes such a group.

  10. Calling a Void Function • Meaning Rule 10.1 in functional form, skipping temporarily the returned result:

  11. Call/Return for a Non-Void Function • The Call returns a Value; the Return identifies it:

  12. Meaning of a Block • Since a block can contain a Return, it must exit as soon as the return is encountered (Meaning Rule 10.3). Here is the functional definition.

More Related