Skip to content

Commit 9580d91

Browse files
committed
Finally nailing down SFT
1 parent 54a1541 commit 9580d91

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"
44

55
[project]
66
name = "little-python-computer"
7-
version = "0.2.0"
7+
version = "0.2.1"
88
dependencies = [
99
"arglite"
1010
]

src/lpc/cmd.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,21 @@ def __brp(self, acc, storage):
128128

129129
@manipulate
130130
def __sft(self, acc, storage):
131-
acc.value = str(acc.value).zfill(3)
132131
self._val = str(self._val).zfill(2)
133132
# Left shift first
134133
if int(self._val[0]) > 0:
135134
shifts = int(self._val[0])
136-
tmp = str(acc.value)
137-
for _ in range(shifts):
138-
tmp = f"{tmp}0"
139-
acc.value = tmp[-3:]
135+
tmp = str(acc.value).zfill(4) + ('0' * shifts)
136+
acc.value = tmp[-4:]
137+
if shifts >= 4:
138+
acc.value = 0
140139
# Right shift second
141140
if int(self._val[1]) > 0:
142141
shifts = int(self._val[1])
143-
tmp = str(acc.value)
144-
for _ in range(shifts):
145-
tmp = f"0{tmp}"
146-
acc.value = tmp[0:3]
142+
tmp = ('0' * shifts) + str(acc.value).zfill(4)
143+
acc.value = tmp[0:4]
144+
if shifts >= 4:
145+
acc.value = 0
147146
acc.value = int(acc.value)
148147

149148
@inputs

0 commit comments

Comments
 (0)