-
Notifications
You must be signed in to change notification settings - Fork 0
/
instr.py
35 lines (24 loc) · 720 Bytes
/
instr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import fileio
from reg import fetch, assign, CONT
from stats import goto_stats
INSTR = 'INSTR'
NO_INSTR = '"???"'
DONE = 'DONE'
@goto_stats
def goto(label):
fileio.write_file(INSTR, _convert_label(label))
def curr_instr():
return fileio.read_file(INSTR, NO_INSTR)
# these aren't strictly necessary, but they're very convenient.
# conceptually, we can imagine that the CONT register has some
# specialized physical connection to INSTR register
# (or PC, or whatever it really is)
def goto_continue():
goto(fetch(CONT))
def set_continue(label):
assign(CONT, _convert_label(label))
def _convert_label(label):
try:
return label.__name__
except AttributeError:
return label