-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathproject_08.py
66 lines (45 loc) · 1.36 KB
/
project_08.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# VM II: Program Control
#
# See https://www.nand2tetris.org/project08
import project_07
class Translator(project_07.Translator):
"""Translates all VM opcodes to assembly instructions, extending the Translator from project 07.
"""
def __init__(self):
project_07.Translator.__init__(self)
#
# Program Flow — Basic Loop:
#
def label(self, name):
# SOLVERS: implement
return self.solved.label(name)
def if_goto(self, name):
# SOLVERS: implement
return self.solved.if_goto(name)
#
# Program Flow — Fibonacci Series:
#
def goto(self, name):
# SOLVERS: implement
return self.solved.goto(name)
#
# Function Calls — Simple Function:
#
def function(self, class_name, function_name, num_locals):
# SOLVERS: implement
return self.solved.function(class_name, function_name, num_locals)
def return_op(self):
# SOLVERS: implement
return self.solved.return_op()
#
# Function Calls — Nested Call:
#
def call(self, class_name, function_name, num_args):
# SOLVERS: implement
return self.solved.call(class_name, function_name, num_args)
#
# Function Calls - Fibonacci Element:
#
def preamble(self):
# SOLVERS: emit instructions to be
return self.solved.preamble()