Exam 2 Flashcards

1
Q

scope

A

visibility of names in source program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

storage

A

memory space associated with names

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

lifetime

A

the time interval a variable is allocated with memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

static (lexical) scope

A

scopes can be determined by the compiler, all bindings for identifiers can be resolved by examining the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

let

A

scope of a variable declared in expression is the body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

let*

A

scope of a variable declared in expression is body and other expressions following

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

letrec

A

variable does not need to be defined first for it to be in scope (allows for recursive definitions)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

symbol table

A

table of names and their bindings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

single scope

A

a dictionary or hash map

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

nested scope

A

a tree of symbol tables; each scope has one symbol table, each symbol table may have a parent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Name collision in symbol table

A

To find a binding:

  1. start from table of current scope
  2. Go up until name is found
  3. Fail if no table contains the name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Static Scoping

A

bindings determined by lexical structure, local renaming principle

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Dynamic scoping

A

bindings depend on flow of control

always use most recent, active binding, names important, meaning of a variable can change

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

scope vs. lifetime

A
scope = visibility of a binding/name
lifetime = creation/destruction of storage
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

global variable

A

static area, visible in entire program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

local variable

A

stack, visible in a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

when are scope and lifetime not the same?

A

heap allocated memory, functions returned as values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

shallow binding

A

subroutine is passed as a parameter, binding happens when subroutine is called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

deep binding

A

when a subroutine is passed as a parameter, when the reference is created

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

function closure

A

for deep binding; contains a pointer to function and current symbol table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What type of binding is implemented for dynamic scoping

A

both shallow and deep; shallow has a higher cost at run time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What type of binding is implemented for static scoping?

A

Deep binding; shallow binding has never been implemented

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

alias

A

two variables point to the same memory location

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

overloading

A

uses the number or type of parameters to distinguish functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

coercion

A

the process by which a compiler automatically converts a value of one type to value of another type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

coercion vs. overloading

A

coercion converts parameters to fit function def; overloading allows compiler to pick function implementation that fits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

polymorphism

A

function with multiple forms/uses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

parametric polymorphism

A

function with aset of types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

subtype polymorphism

A

function with one type, and it’s refinements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Hows does the compiled code locate a variable used in a function at run time?

A

Start address = base addr (of scope) + offset (in the scope)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

code section

A

read only, stores source code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

data section

A

static data, stack, heap

33
Q

stack pointer register

A

esp

34
Q

frame pointer register

A

ebp

35
Q

frame layout

A
args 
temporaries
local vars
bookkeeping
return addr
36
Q

bookkeeping in stack frame

A

reference to the stack frame of the caller

37
Q

static link

A

a pointer to the frame of enclosing function

38
Q

dynamic link

A

pointer to the previous frame in the current execution

39
Q

Example type errors

A

float addition on two ints, assign a string to float, pass int to func expecting string

40
Q

type meanings

A

denotational: a set of values
constructive: set of primitive types, type constructors,
abstraction: an interface (set of operations)

41
Q

Why types?

A

identify/prevent type errors, documentation, support optimization, program organization/abstraction

42
Q

Constructed types

A

products, unions, arrays, lists

43
Q

type system

A

type equilence, type compatibility, type safety

44
Q

strongly typed

A

all type errors caught by type checking

45
Q

weakly typed

A

type checking my miss type errors

46
Q

static typing

A

type checking happens at compile time

47
Q

dynamic typing

A

type checking happens at run time

48
Q

type inference

A

the type-checker infers types for variables

49
Q

example of type error in c

A

union U {int a; float p} u;
float x = 1.0;
u.a = 1;
x = x + u.p;

50
Q

records and structures

A

laid out contiguously, possible holes for alignment, compilers may re-arrange fields o minimize holes

51
Q

discriminated union type

A

a combination of a tag (like an enum) and a payload per possibility (like a union)

52
Q

sum type

A

alternation of types

53
Q

product types

A

concatenation of types

54
Q

c array

A

static/stack/heap allocated
size statically/dynamically determined
bound not checked

55
Q

java array

A

heap allocated
size dynamically determined
array size is part of stored data (dope vector)
array bounds checked

56
Q

Row major address calculation

A

[10][100]

A[i][j] = 4(i*100+j)

57
Q

Column major address calculation

A

[10][100]

A[i][j] = 4(j*10+i)

58
Q

dangling reference

A

pointer to a deallocated address

59
Q

tombstones

A

each ehap variable is given another memory location (tombstone); tombstone points to the heap variable; all pointers to var point to tombstone

60
Q

locks and keys

A

when heap var allocated:
allocate storage; allocate an int which holds a lock value; return a pari of key value and address; key value = lock value

61
Q

references

A

restricted pointers - cannot be used as value or operated in anyway

62
Q

Caller Save vs. Callee Save Separation of responsibility

A

Caller assumes callee will not destroy callee saves

Callee assumes nothing is value in caller saves

63
Q

What needs to be done before P calls Q

A

Save current frame pointer, save caller-save registers, changing stack and frame pointers, save return addr, change prog counter, pass params

64
Q

What needs to be done before Q returns to P

A

Restoring saved registers

Deallocating stack space of Q, restore program counter, pass return vals

65
Q

Program Counter

A

Always points to the instruction following the one being executed, can be modified by jump, call, return

66
Q

Typical calling sequence for caller

A

save registers, computes values of params, move them to stack or registers, switch control to callee

67
Q

Typical calling seq for callee prologue

A

allocate frame (change sp), saves previous frame pointer and sets new one, saves registers that might be overwritten in the callee

68
Q

Typical Calling Sequence Callee Epilogue

A

Moves return val into stack or register, restore callee-saves registers, restore fp and sp, transfer control to caller

69
Q

Call-by-value

A

args evaluated to values, memory or registers allocated for args on AR, arg values copied into AR, AR destroyed when callee returns

70
Q

Call by Value Characteristics

A

Formal and Actual Parameters have separate memory: their values may diverge; actual parameters may not directly be changed in callee, args can be complex expressions

71
Q

Call by Value Performance

A

Can pass in pointer to avoid copying cost

72
Q

Call by Reference Calling Mechanism

A

Args are evaluated to their values; memory or registers allocated for args on AR, arg address stored in AR

73
Q

Call by reference characteristics

A

formal parameter is an alias of actual parameter

74
Q

Call by reference performance

A

avoids the cost of memory copy

75
Q

Call by Value Return

A

Before callee returns, AR values copied back to actual arguments

76
Q

Call by Name (Lazy Evaluation)

A

Arguments ARE NOT EVALUATED TO THEIR VALUES

77
Q

Return Values

A

Fix size and size (callee stores values in callers AR) determined at run time (callee stores results in heap)

78
Q

Callee is more nested

A

When func f1 calls f2 and n(f1) < n(f2) (callee more nested), f1 must be the immediate lexical ancestor of f2

79
Q

Caller is more nested

A

When f1 calls f2 and n(f1) >= n(f2) caller is more nested, f1 must be defined in some function f3, and f2 is immediately defined in f3