Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bindings. Typical stages of program execution First, the program is compiled Then everything is loaded into memory Then it is linked to any library routines.

Similar presentations


Presentation on theme: "Bindings. Typical stages of program execution First, the program is compiled Then everything is loaded into memory Then it is linked to any library routines."— Presentation transcript:

1 Bindings

2 Typical stages of program execution First, the program is compiled Then everything is loaded into memory Then it is linked to any library routines it uses –Linking and loading are often combined into a single step Finally, the program executes

3 Binding times A binding is an association of two things Typically, a name is bound to something Bindings can occur at different types. Examples: –Language design--keywords to language constructs –Compilation--Variable names to types –Linking--Names to library units –Loading--Code and data to storage locations –Execution--Variable names to values These are language-dependent examples!

4 FORTRAN bindings FORTRAN distinguishes declarations from statements Declarations are “non-executable” Declarations bind names to types (at “compile time”) and to storage locations (at “load time”) Declarations may bind initial values to variables Statements are executable (done at “run time”) Statements may also bind values to variables

5 Why binding time matters This function works correctly only the first time Some variables in C are initialized the same way FUNCTION SUM (A, N) DIMENSION A(N) -- specify A as an array of size N INTEGER TOTAL/0/ -- set TOTAL = 0 (at compile time) DO 50 I=1, N -- do statement 50 N times 50 TOTAL=TOTAL+A(I) -- add A[i] to TOTAL RETURN TOTAL -- return TOTAL as the result END

6 Storage allocation in FORTRAN The FORTRAN compiler binds all variables to storage locations relative to the start of the program unit The FORTRAN loader binds the relative locations to absolute locations This technique cannot support dynamic storage allocation Without dynamic allocation, recursion is impossible FORTRAN versions that support recursion don't use this storage model

7 A FORTRAN binding problem FORTRAN binds floating-point literals to storage locations The compiler puts the value into the storage location The language does not adequately protect the storage location It’s possible to bind a new value to the storage location Therefore, constants aren’t necessarily constant!

8 Storage allocation in Algol 60 An area of storage is set aside for “the stack” The Algol compiler binds variables to locations relative to “the top of the stack” The “top of the stack” is bound during execution This technique is ideally suited for supporting recursion Storage allocated on the stack must be discarded in reverse order of acquisition

9 Bindings in Java Method variables are bound much like in Algol 60 Java does not initialize method variables, but checks to make sure that you do –It is impossible to make this check perfectly Class and instance variables are initialized during object construction –Default is to initialize to zero (null) Messages are dynamically bound to methods

10 Overloading O-O languages permit method overloading –Methods with the same name but different signatures Ada and Prolog also permit operator overloading In most languages, operators (+, -, *, /, &, etc.) are bound at language design time Ada permits operator overloading during compilation Prolog permits operator overloading during execution Overloaded operators are hard to compile, easy to misuse

11 Summary Bindings can happen at various times Earlier bindings are more efficient; later bindings are more flexible Sometimes the same kind of binding can occur at different times Mysterious errors can result if bindings don’t occur when you expect them to

12 The End


Download ppt "Bindings. Typical stages of program execution First, the program is compiled Then everything is loaded into memory Then it is linked to any library routines."

Similar presentations


Ads by Google