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
coercion
the process by which a compiler automatically converts a value of one type to value of another type
26
coercion vs. overloading
coercion converts parameters to fit function def; overloading allows compiler to pick function implementation that fits
27
polymorphism
function with multiple forms/uses
28
parametric polymorphism
function with aset of types
29
subtype polymorphism
function with one type, and it's refinements
30
Hows does the compiled code locate a variable used in a function at run time?
Start address = base addr (of scope) + offset (in the scope)
31
code section
read only, stores source code
32
data section
static data, stack, heap
33
stack pointer register
esp
34
frame pointer register
ebp
35
frame layout
``` args temporaries local vars bookkeeping return addr ```
36
bookkeeping in stack frame
reference to the stack frame of the caller
37
static link
a pointer to the frame of enclosing function
38
dynamic link
pointer to the previous frame in the current execution
39
Example type errors
float addition on two ints, assign a string to float, pass int to func expecting string
40
type meanings
denotational: a set of values constructive: set of primitive types, type constructors, abstraction: an interface (set of operations)
41
Why types?
identify/prevent type errors, documentation, support optimization, program organization/abstraction
42
Constructed types
products, unions, arrays, lists
43
type system
type equilence, type compatibility, type safety
44
strongly typed
all type errors caught by type checking
45
weakly typed
type checking my miss type errors
46
static typing
type checking happens at compile time
47
dynamic typing
type checking happens at run time
48
type inference
the type-checker infers types for variables
49
example of type error in c
union U {int a; float p} u; float x = 1.0; u.a = 1; x = x + u.p;
50
records and structures
laid out contiguously, possible holes for alignment, compilers may re-arrange fields o minimize holes
51
discriminated union type
a combination of a tag (like an enum) and a payload per possibility (like a union)
52
sum type
alternation of types
53
product types
concatenation of types
54
c array
static/stack/heap allocated size statically/dynamically determined bound not checked
55
java array
heap allocated size dynamically determined array size is part of stored data (dope vector) array bounds checked
56
Row major address calculation
[10][100] | A[i][j] = 4(i*100+j)
57
Column major address calculation
[10][100] | A[i][j] = 4(j*10+i)
58
dangling reference
pointer to a deallocated address
59
tombstones
each ehap variable is given another memory location (tombstone); tombstone points to the heap variable; all pointers to var point to tombstone
60
locks and keys
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
references
restricted pointers - cannot be used as value or operated in anyway
62
Caller Save vs. Callee Save Separation of responsibility
Caller assumes callee will not destroy callee saves | Callee assumes nothing is value in caller saves
63
What needs to be done before P calls Q
Save current frame pointer, save caller-save registers, changing stack and frame pointers, save return addr, change prog counter, pass params
64
What needs to be done before Q returns to P
Restoring saved registers | Deallocating stack space of Q, restore program counter, pass return vals
65
Program Counter
Always points to the instruction following the one being executed, can be modified by jump, call, return
66
Typical calling sequence for caller
save registers, computes values of params, move them to stack or registers, switch control to callee
67
Typical calling seq for callee prologue
allocate frame (change sp), saves previous frame pointer and sets new one, saves registers that might be overwritten in the callee
68
Typical Calling Sequence Callee Epilogue
Moves return val into stack or register, restore callee-saves registers, restore fp and sp, transfer control to caller
69
Call-by-value
args evaluated to values, memory or registers allocated for args on AR, arg values copied into AR, AR destroyed when callee returns
70
Call by Value Characteristics
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
Call by Value Performance
Can pass in pointer to avoid copying cost
72
Call by Reference Calling Mechanism
Args are evaluated to their values; memory or registers allocated for args on AR, arg address stored in AR
73
Call by reference characteristics
formal parameter is an alias of actual parameter
74
Call by reference performance
avoids the cost of memory copy
75
Call by Value Return
Before callee returns, AR values copied back to actual arguments
76
Call by Name (Lazy Evaluation)
Arguments ARE NOT EVALUATED TO THEIR VALUES
77
Return Values
Fix size and size (callee stores values in callers AR) determined at run time (callee stores results in heap)
78
Callee is more nested
When func f1 calls f2 and n(f1) < n(f2) (callee more nested), f1 must be the immediate lexical ancestor of f2
79
Caller is more nested
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