Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 10 Function Implementation In theory, there.

Similar presentations


Presentation on theme: "Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 10 Function Implementation In theory, there."— Presentation transcript:

1 Copyright © 2006 The McGraw-Hill Companies, Inc. 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

2 Copyright © 2006 The McGraw-Hill Companies, Inc. 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 Copyright © 2006 The McGraw-Hill Companies, Inc. 10.4 Formal Treatment of Types and Semantics The type map for a function f, tm f, is a set of pairs and triples, representing global variables (tm G ), functions (tm F ), f’s parameters, and f’s locals. E.g., for the program in Figure 10.1:

4 Copyright © 2006 The McGraw-Hill Companies, Inc. Typing Function The function typing creates type maps for each individual function f in a program with globals G and functions F.

5 Copyright © 2006 The McGraw-Hill Companies, Inc. 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 Copyright © 2006 The McGraw-Hill Companies, Inc. 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 Copyright © 2006 The McGraw-Hill Companies, Inc. 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 Copyright © 2006 The McGraw-Hill Companies, Inc. 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 Copyright © 2006 The McGraw-Hill Companies, Inc. Allocate and Deallocate Functions allocate changes the state by adding a group of variable-address pairs to it. deallocate removes such a group.

10 Copyright © 2006 The McGraw-Hill Companies, Inc. Calling a Void Function Meaning Rule 10.1 in functional form, skipping temporarily the returned result:

11 Copyright © 2006 The McGraw-Hill Companies, Inc. Call/Return for a Non-Void Function The Call returns a Value; the Return identifies it:

12 Copyright © 2006 The McGraw-Hill Companies, Inc. 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.


Download ppt "Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 10 Function Implementation In theory, there."

Similar presentations


Ads by Google