Docsity

Language Features and Runtime Environments | ECS 142, Study notes of Computer Science

Partial preview of the text

Download Language Features and Runtime Environments | ECS 142 and more Study notes Computer Science in PDF only on Docsity!

Language Features and

Runtime Environments

Lecture 19 Dr. Sean Peisert – ECS 142 – Spring 2009 1

Status

< 2 weeks to go on project 3

Read Sec. 7.1 through 7.4 by next Monday, May 18 2

Overloading?

In Cool, we don’t allow function overloading. C++ & Java do.

How would we allow the equivalent of

myfunction(int c) and myfunction(char *p, int d)?

Keep a parameter list and check for duplicate parameter lists

myFunc(a : int) : Bool {false};

myFunc(b : bool, c : string) : Bool {false}; // OK

myFunc(d : int) // Error 4

Constants

We have:

Red : Int ← 0;

What would we have to do for:

Red : Const Int ← 0; 5

Status

We have covered the front-end phases:

Lexical Analysis

Syntax Analysis (Parsing)

Semantic Analysis

Now are the back end phases

Code Generation (we’ll do this first)

Optimization 7

Runtime Environments

Before discussing code generation, we need to understand what we are trying to generate

There are a number of standard techniques for structuring executable code that are widely used. 8

Run-Time Resources

Execution of a program is initially under the control of an operating system.

When a program is invoked:

The OS allocates space for the program

The code is loaded into part of the space

The OS jumps to the entry point (i.e., “main”) 10

Memory Layout

11 Code Other Space Low Address High Address Memory

What is “other space”?

Holds all data for the program

other space = data space

Compiler is responsible for:

Generating code

Orchestrating use of the data area 13

Code Generation Goals

  • Two goals:

Correctness

Speed

Most complications in code generation come from trying to be fast as well as correct. 14 

Activations

An invocation of procedure P is an activation of P.

The lifetime of an activation of P is:

All the steps to execute P

Including all the steps in procedures that P calls 16

Lifetimes of Variables

The lifetime of a variable x is the portion of execution in which x is defined.

Note that:

Lifetime is a dynamic (run-time) concept

Scope is a static concept 17

Example

Class Main { g() : Int { 1 }; f() : Int { g() }; main() : Int { { g(); f(); } }; } 19 main g g f

Example 2

Class Main { g() : Int { 1 }; f() : Int { g() }; main() : Int { { g(); f(); } }; } What is the activation tree for this example? 20