Week 3 gives the UOp language loops: RANGE n is a loop variable taking the values , and END(body, range) runs body once per value of that range. Implement an interpreter for loop programs given as nested tuples.
Effects
("store", buf, index, value): write value at position index of buffer buf.("group", e1, e2, ...): run the effects in order.("end", body, rng), with rng = ("range", name, n): run body for each value of the loop variable name, in increasing order.Values
("range", name, n): the current value of loop variable name.("load", buf, index).("add", a, b), ("mul", a, b), ("max", a, b), floor ("div", a, b) and floor ("mod", a, b).run(effects, buffers) executes the list of top-level effects in order on a copy of buffers (a dict from name to list) and returns the copy. Execution is sequential, so every load sees all stores executed before it.
Raise errors for invalid programs:
ValueError("unbound range <name>") when a range is used outside an end of that range.ValueError("range <name> already open") when an end re-opens a range that is already being iterated.IndexError for a load or store outside its buffer.