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

Material Type: Notes; Professor: Peisert; Class: Compilers; Subject: Engineering Computer Science; University: University of California - Davis; Term: Spring 2009;

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-b0p-1
koofers-user-b0p-1 🇺🇸

10 documents

1 / 41

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29

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