Skip to content
Snippets Groups Projects
Commit 450458f0 authored by Martin Högstedt's avatar Martin Högstedt
Browse files

fixed index out of range error

parent a7a8015a
No related branches found
No related tags found
1 merge request!20fixed index out of range error
Pipeline #131679 passed
......@@ -31,7 +31,7 @@ class Memory(Module):
self.output_s = output_signal
# Internal state
self.memory = [0 for i in range(size)]
self.memory = [0 for _ in range(size)]
self.current_adress = 0
self.is_write = False
......
......@@ -7,6 +7,7 @@ from qtpy.QtWidgets import (
QTextEdit,
QVBoxLayout,
QWidget,
QErrorMessage,
)
from simudator.core.modules import Memory
......@@ -57,6 +58,7 @@ class MiaMemoryGraphicsItem(MemoryGraphicsItem):
def __init__(self, memory_module: Memory, **kwargs):
super().__init__(memory_module, **kwargs)
self.memory_window = None
self.errorMessageWidget = QErrorMessage()
def draw_graphics_item(self) -> None:
# Same as normal memory but no control signal
......@@ -145,6 +147,12 @@ class MiaMemoryGraphicsItem(MemoryGraphicsItem):
)
else:
module_state = self.module.get_state()
module_state['memory'][parsed_adress] = parsed_value
self.module.set_state(module_state)
self.update_graphics_signal.emit()
try:
module_state['memory'][parsed_adress] = parsed_value
except IndexError:
self.errorMessageWidget.showMessage(
"Address entered was larger than memory space. Max address is 0xff"
)
else:
self.module.set_state(module_state)
self.update_graphics_signal.emit()
......@@ -280,10 +280,8 @@ class MIA_CPU(Processor):
self.micro_memory = uM
self.lambdas = {}
def is_new_instruction(self) -> bool:
return self.get_module("uPC").value == 0
......@@ -297,7 +295,7 @@ class MIA_CPU(Processor):
op_code = ir.op
return self.get_module("K1").get_label(int(op_code))
def run_asm_instruction(self, num_instructions = 1) -> None:
def run_asm_instruction(self, num_instructions=1) -> None:
"""
Runs 'num_instructions' assembler instructions on Mia.
......@@ -313,7 +311,6 @@ class MIA_CPU(Processor):
self.do_tick()
def should_halt(self) -> bool:
micro_memory_state = self.micro_memory.get_state()
return micro_memory_state["halt"]
......@@ -382,7 +379,7 @@ class MIA_CPU(Processor):
gui.addAllSignals()
gui.show()
# gui.loadLayoutFromFile("mia_layout")
gui.loadLayoutFromFile("mia_layout")
app.exec()
def launch_cli(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment