Skip to content

Commit 960fcf6

Browse files
committed
Updating with ability to branch correctly; implement getter, setter
1 parent d34436f commit 960fcf6

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

src/lpc/cmd.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,56 +89,56 @@ def parse(self, **kwargs):
8989
@accumulate
9090
def __add(self, acc, storage) -> int:
9191
add = int(storage._spaces[self._val])
92-
acc._value += add
92+
acc.value += add
9393

9494
@accumulate
9595
def __sub(self, acc, storage) -> int:
9696
sub = int(storage._spaces[self._val])
97-
acc._value -= sub
97+
acc.value -= sub
9898

9999
@storage
100100
def __sta(self, acc, storage):
101-
storage._spaces[self._val] = acc._value
101+
storage._spaces[self._val] = acc.value
102102

103103
@storage
104104
def __lda(self, acc, storage):
105-
acc._value = storage._spaces[self._val]
105+
acc.value = storage._spaces[self._val]
106106

107107
@storage
108108
def __bra(self, acc, storage):
109109
storage._counter = self._val
110110

111111
@storage
112112
def __brz(self, acc, storage):
113-
if acc._value == 0:
113+
if acc.value == 0:
114114
storage._counter = self._val
115115
else:
116116
storage._counter += 1
117117

118118
@storage
119119
def __brp(self, acc, storage):
120-
if acc._value > 0:
120+
if acc.value > 0:
121121
storage._counter = self._val
122122
else:
123123
storage._counter += 1
124124

125125
@manipulate
126126
def __sft(self, acc, storage):
127-
acc._value = str(acc._value).zfill(3)
127+
acc.value = str(acc.value).zfill(3)
128128
self._val = str(self._val).zfill(2)
129129
# Left shift first
130130
if int(self._val[0]) > 0:
131131
shifts = int(self._val[0])
132132
for _ in range(shifts):
133-
acc._value = f"{acc._value}0"
134-
acc._value = acc._value[-3:]
133+
acc.value = f"{acc.value}0"
134+
acc.value = acc.value[-3:]
135135
# Right shift second
136136
if int(self._val[1]) > 0:
137137
shifts = int(self._val[1])
138138
for _ in range(shifts):
139-
acc._value = f"0{acc._value}"
140-
acc._value = acc._value[0:3]
141-
acc._value = int(acc._value)
139+
acc.value = f"0{acc.value}"
140+
acc.value = acc.value[0:3]
141+
acc.value = int(acc.value)
142142

143143
@inputs
144144
def __inp(self, acc, storage, input: int = 0):
@@ -149,10 +149,10 @@ def __inp(self, acc, storage, input: int = 0):
149149
except:
150150
print("Invalid input.")
151151
sys.exit(1)
152-
acc._value = input
152+
acc.value = input
153153

154154
def __out(self, acc, storage):
155-
print(acc._value)
155+
print(acc.value)
156156
storage._counter += 1
157157

158158
@halt

src/lpc/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def debug_log(acc, storage) -> None:
1717
row = [str(val).zfill(3) if val else "---" for val in row]
1818
table.add_row(*row)
1919
console.print(table)
20-
console.print(f"ACC VALUE: {acc._value}")
20+
console.print(f"ACC VALUE: {acc.value}")
2121

2222
def main() -> None:
2323

src/lpc/parts.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ class Accumulator:
3333

3434
def __init__(self):
3535
self._value = 0
36+
self._carry= 0
37+
38+
@property
39+
def value(self):
40+
return self._value
41+
42+
@value.setter
43+
def value(self, value):
44+
value = int(value)
45+
self._value = int(self._value)
46+
if self._value > 9999:
47+
print("[ERROR] OVERFLOW!")
48+
sys.exit(1)
49+
if self._value >= 1000:
50+
self._carry = str(self.value)[0]
51+
self._value = value
52+
53+
@value.getter
54+
def x(self):
55+
return self._value
3656

3757
class Inputs:
3858

0 commit comments

Comments
 (0)