SU-CS143 MAY062025
Last edited: August 8, 2025- The type of every attribute must be filled in the environment \(O\) before type checking can happen, because otherwise it may refer to an attribute defined later
- best practice: store object and method tables separately
lub
the function \(lub\qty(X,Y)\), the least upper bound of \(X\) and \(Y\), is \(Z\) if:
\begin{equation} X \leq Z \wedge Y \leq Z \end{equation}
\(X\) is the lub.
\begin{equation} \forall Z’, X \leq Z’ \wedge Y \leq Z’ \implies Z \leq Z' \end{equation}
SU-CS143 MAY082025
Last edited: August 8, 2025Primary Goals
- management of run-time resources
- correspondence between static and dynamic data structures
- storage organization
Run time execution
- execution of a program is under the control of the OS
- when a program is invoked…
- the OS allocates space for the program
- the load is loaded into a part of that space
- the OS jumps to the entropy point for the first instruction
Typically the order is
Assumptions
- execution is sequential: control pass from one point to another
- concurrency break this
- when a procedure is called, control should return to the point immediately after the call
- exceptions break this, but we won’t have them
activation
- invocation of procedure \(P\) is what we call an “activation” of \(P\)
- lifetime of \(P\) is
- all steps for activating \(P\)
- all steps in \(P\)
activation tree
- when \(P\) calls \(Q\), \(Q\) returns before \(P\)
- activation lifetimes can therefore be a tree
since there’s only ever one path from main to the current active function call, we can use a stack and keep track of information in the call stack on the stack.
SU-CS143 MAY152025
Last edited: August 8, 2025“If \(B\) is a subclass of \(A\), then an object of \(B\) can be used wherever \(A\) is expected.”
To do this, we will lay out:
the pointer *
points to a method table
Other Semantics than structural operational semantics
Runtime Errors
We have to catch some runtime errors:
- calling on voids
- method dispatch problems
What to track in context?
- environment: where in memory a variable is stored?
Map<Symbol, void *>
- store: what is in memory?
Map<void *, Value>
This means that a judgment is:
SU-CS143 MAY202025
Last edited: August 8, 2025Its optimization time!!
Program Optimization
“maximum benefit for minimal cost”
When should optimization happen?
AST?
- pro: machine independent
- con: no notion registers, not language dependent
Assembly?
- pro: many optimization opportunities
- con: machine dependent
And so, we really should be doing this with some IR.
Three-address intermediate code
Each instruction is of the form:
x := y op z
x := op z
where x
, z
are registers, constants, etc.
basic block
A basic block is a sequence with no labels (except in the first point) an no jumps (except in the last point). So when we are inside a basic block, we can optimize the code inside sans worry about control flow.
SU-CS143 MAY222025
Last edited: August 8, 2025more Program Optimization