SlideServe
Menu
Préférences
© SlideServe · v2026

Understanding Runtime Environments in Programming Languages

emmett avatar
17 diapositives · 339 Views · Jul 15, 2014

This document delves into key concepts of runtime environments, covering aspects such as activation trees, scope of names, parameter passing, and storage organization. It discusses the implications of procedural calls, symbol tables, and dynamic storage allocation, as outlined by Neng-Fa Zhou. Learn about modularity, information hiding, and how control stacks function within large systems, enhancing your understanding of how programs execute and manage resources. Gain insights into recursive procedures, different parameter passing techniques, and implications of memory management in programming.

Understanding Runtime Environments in Programming Languages - slide 1
01 / 17Understanding Runtime Environments in Programming Languages
1 / 17

Télécharger la présentation

Understanding Runtime Environments in Programming Languages
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Runtime Environments • Source language issues • trace the execution of a program • activation trees • the scope of a name • parameter passing • Storage organization • the control stack • symbol tables • dynamic storage allocation by Neng-Fa Zhou

  2. Procedures and Functions • Structural programming • combine shared code • parameterized • Advantages over a flat language • Modularity • blocks for building large systems • Information hiding • Separate compilation by Neng-Fa Zhou

  3. Procedure Definitions and Calls formal parameters • Function definition • Function call void sort(int a[], int l, int u){ ... } return type actual parameters sort(a,0,100) by Neng-Fa Zhou

  4. Trace the Execution of Programs >qsort(1,9) >partition(1,9) <partition(1,9) >qsort(1,3) >partition(1,3) <partition(1,3) ... <qsort(1,3) >qsort(5,9) ... <qsort(5,9) <qsort(1,9) void qsort(int l, int u){ int i; if (l>=u) return; i = partition(l,u); qsort(l,i-1); qsort(i+1,u); } activation by Neng-Fa Zhou

  5. Activation Trees q(1,9) • each node represents an activation • the root represents the main program • node A is a parent of node B if A calls B • the order of siblings is determined by the lifetimes of the activations p(1,9) q(1,3) q(5,9) p(1,3) q(1,0) q(2,3) by Neng-Fa Zhou

  6. The Scope of a Name main(){ int a = 0; int b = 0; { int b = 1; { int a = 2; printf("%d %d\n",a,b); } { int b = 3; printf("%d %d\n",a,b); } printf("%d %d\n",a,b); } printf("%d %d\n",a,b); } most closely nested rule by Neng-Fa Zhou

  7. Parameter Passing • Call by value • primitive types, pointers, structures in C • all data types in Java • Call by reference • arrays in C • var arguments in Pascal • Call by name • in-line expansion by Neng-Fa Zhou

  8. Call by Value actual • formal and actual are independent a 1. evaluate the actual parameter 2. pass it to the activation record a 3. use the formal parameter as a local variable formal by Neng-Fa Zhou

  9. Call by Reference actual • formal becomes an alias for actual • when formal is updated, actual is also updated a formal by Neng-Fa Zhou

  10. Call by Name • The body is substituted for the call • The local names of the called procedure are renamed if necessary to keep them different from those in the calling procedure • The actual parameter are surrounded by parentheses if necessary by Neng-Fa Zhou

  11. Questions to Ask • May procedures be recursive? • What happens to the values of local names when control returns from an activation of a procedure? • May a procedure refer to nonlocal names? • How are parameters passed? • May procedures be passed as parameters? • May procedures be returned as results? • Must storage be deallocated explicitly? by Neng-Fa Zhou

  12. Storage Organization Code Code: program + library Static data: global variables Stack: activation frames Heap: dynamically allocated memory Static Data Stack Heap by Neng-Fa Zhou

  13. Control Stack • A frame is pushed onto the stack each time a procedure is called • The frame is popped off after the execution ends >qsort(1,9) >partition(1,9) <partition(1,9) >qsort(1,3) >partition(1,3) qs(1,9) qs(1,3) top_sp pa(1,3) by Neng-Fa Zhou

  14. Activation Records (Frames) returned value actual parameters optional control link: parent frame etc. access link: frame of the outer procedure machine status: program counter registers optional control link optional access link saved machine status local data temporaries by Neng-Fa Zhou

  15. Calling and Returning Sequences • Calling sequence • evaluate actual parameters • set callee's frame (arguments,return address,parent) • reset the top_sp register • save registers including the program counter • initialize local data • begin execution caller callee by Neng-Fa Zhou

  16. Calling and Returning Sequences • Returning sequence • place return value • restore the state including P and top_sp • continue execution callee caller by Neng-Fa Zhou

  17. Dangling References main(){ int *p; p = dangle(); } int *dangle(){ int i=23; return &i; } by Neng-Fa Zhou