In this project, you will complete an interpreter for JayMU. The JayMU system is strikingly different from the other languages in the Jay family in that we're writing a "wimpy interpreter"---it does not try to make a realistic model of memory, and it relies on the underlying Python interpreter's call stack to handle invocations. This allows us to concentrate on the parts that are new.
Copy the starter code from the course directory.
cp ~tvandrun/Public/cs365/proj7.tar .
You will complete the interpreterVisitor.py
.
This will involve not only finishing the
InterpreterVisitor
but also another visitor
to modify the body of the method updates to replace
enclosing scope variables with their values.
You'll notice that interpreter has two instance variables:
result
, for the result of the most
recently evaluated expression, and
sigma
, for the store.
sigma
is a dict associating variable names
with values.
Object values are dicts associating method names with
method ASTs.
Method ASTs include the return type and list of formals
(see jaymu_ast.cfg
) in addition to the body.
The body is the only thing that gets updated in
a method update.
Here is a brief description of what needs to be done for each visit method that needs to be finished.
visit_CallStmt
.
There are many things that need to be taken care of for
call statements:
JayMuRuntimeError
if not.
sigma
and make a new one.
this
,
and formal parameters of the method,
throwing a JayMuRuntimeError
if there
are too many or too few actual parameters.
visit_MethodUpdate
.
This method must check that the method being updated already
exists in the "root" (the object whose method is being updated),
raising a JayMuRuntimeError if it does not exist.
Then it must make a copy of the replacement body
(you may use the deepcopy()
function from
Python's copy
library).
Then it must take that new copy of the body and
replace all the occurrences of enclosing scope variables
with their current values.
The easiest way to do this is to write a second visitor
class (do it in the same file, interpreterVisitor.py
)
that will visit the body and modify it.
(In the extra visitor that I wrote, there were only three
methods: __init__()
,
visit_VariableWrapper()
, and one
other visit method.)
The tricky part will be to make sure this extra visitor does
not replace globals, formals and other locals of the method
update body, or this
.
Also, the root will be a dict mapping method names to
methods;
you do not want to overwrite the entire method (signature and all)
but only the body of that signature.
visit_Instantiation
.
This must set self.result
to a new dict
that has associations for all the methods given.
This will again require you to make a deep copy of the
methods of the instnatiation and use the extra visitor you write earlier
to replace all enclosing scope variables.
To turn in this project, please copy your
interpreterVisitor.py
to
/cslab.all/linux/class/cs365/(your id)/proj7
I will grade your project by running it against a collection of test files.
Due: Fri, April 22, 5:00 pm. This will overlap with project 8.