1 / 20

Run Time Environments

Run Time Environments. Read Pages 427-449 Homework: Lab 7. Run Time Environments. The compiler must create and maintain a runtime environment to interact with OS and other system software Storage allocation Access to variables and data. Code P : G Static Vars. Frame 1

bart
Télécharger la présentation

Run Time Environments

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. Run Time Environments Read Pages 427-449 Homework: Lab 7

  2. Run Time Environments • The compiler must create and maintain a runtime environment to interact with OS and other system software • Storage allocation • Access to variables and data

  3. Code P : G Static Vars. Frame 1 (main) Frame 2 (Fun1) . . . L Frame N (Fun N) : Heap Activation Records • Activation records are also called stack frames • Each frame holds information about a procedure call • Stores the 7 things below, created when the function is called

  4. Activation Records

  5. Procedure Calls • Activation records can be managed by maintaining 2 kinds of links between them • control link: (dynamic link) – points to the activation record of the runtime caller • this would be the L of the calling function • activation record on top is the callee of the one below it, the caller; this has to be, because only one thing can be active at one time • access link: (static link) – is used to implement lexically scoped languages • set compile time • indicates nesting

  6. Procedure Calls • return value – used by the called procedure to return a value to the calling procedure • save machine status – information about the state of the machine before the procedure is called (registers: PC,AC) return address, • actual parameters – used by the calling procedure to supply parameters to he called procedure • local data – data local to the procedure • determined at compile time • keep count of the allocated addresses relative to L • temporary variables – variable that is temporary within the procedure that is used for evaluation results

  7. Static Allocation • static= compile time stuff • dynamic = runtime stuff • stored value is determined at runtime • the ID name is bound to a storage location as the program is compiled • the amount of storage is dependent on the type

  8. Limitations of Statics • size of the data object & constraints on its memory position must be known at compile time • recursive procedures are restricted because all activations of a procedure use the same bindings for local names • data structures can not be allocated dynamically

  9. Stack Allocation • storage is organized as a stack of activation records • pushed & popped as activation begins & ends • values for locals are lost when the activation ends because their storage disappears

  10. Calling Sequence • call sequence – creates an activation record & enters information into its fields • this is done at compile time & appears in the target code • return sequence – restores the state of the machine so the calling procedure can continue execution

  11. A Call Sequence • The caller evaluates the actuals (arguments) • The caller stores a return address & the old value of the top of the stack onto the callee’s activation record • top_sp (L) is set to the activation record of the callee • The callee saves register values and other state information • Callee initializes local data and begins execution

  12. Return Sequence • calleeplaces a return value ‘next to’ the activation record of the caller • using the information in the status field, the callee restores top_sp & other registers & branches to the return address • the caller copies the return value into its own activation record & uses it

  13. Example Symbol Table function M function Pvariables x, y, z function Q function R • nesting indicates containment

  14. Example cont. • Set up access and control links • control links on the stack points to the activation record that called it • access links point to the nearest activation record that indicates the function it was defined in • Shows nesting

  15. Example cont. Activation Stack • Draw the access and control links for the activation stack

  16. Non-Local/Non-Global • Stored in an out nesting but no globally • Ex. intxmain()int y fun1(y)int z fun2(z)y=z //y is not local in fun2() but is not global

  17. Scoping Rules • static scope rule(lexical) – most closely nested • whenever we see ‘lexical’ stuff, make a relation to ‘static’ stuff • dynamic scope rule – determined at runtime by considering current activations

  18. Static Scope • suppose procedure p at level nprefers to procedure x at nesting level nx • case 1: (np < nx) x is declared in p • np = nx - 1 • access link in the called procedure points to the access link in the activation record of the caller • access link and control link are the same

  19. Static Scope • case 2: (np >= nx) compute D = np – nx + 1;then follow D control links from the caller p & set x’s access link to that address • Example: suppose R calls Q and nR= 4, np= 2 • What is P’s access link set to?

  20. Implementing Function Calls • See funcalls handout!

More Related