Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simuDAtor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
simuDAtor
Commits
64844704
Commit
64844704
authored
11 months ago
by
Martin
Browse files
Options
Downloads
Patches
Plain Diff
fixed the bug
parent
659d0545
No related branches found
No related tags found
1 merge request
!37
The integer memory table will not allow the user to inpu values larger than it can store
Pipeline
#133055
failed
11 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/simudator/gui/module_graphics_item/integer_memory_graphic.py
+23
-1
23 additions, 1 deletion
...udator/gui/module_graphics_item/integer_memory_graphic.py
with
23 additions
and
1 deletion
src/simudator/gui/module_graphics_item/integer_memory_graphic.py
+
23
−
1
View file @
64844704
...
...
@@ -17,6 +17,17 @@ class Base(Enum):
HEXADECIMAL
=
4
class
ValueToBig
(
Exception
):
"""
A class representing the error of a user inputting a value that does not fit in the memory.
Used to differentiate between wrong input using the exception python raises by default (ValueError)
and the error of a value that does not fit.
"""
pass
class
IntegerMemoryWindow
(
MemoryWindow
):
"""
A class showing the contents of a memory module in a new window.
...
...
@@ -187,6 +198,7 @@ class IntegerMemoryTable(MemoryTable):
item
=
self
.
item
(
row
,
col
)
value
=
item
.
text
()
max_value
=
2
**
self
.
_bit_length
# Turn every value into a positive int
# in base 10
...
...
@@ -203,6 +215,10 @@ class IntegerMemoryTable(MemoryTable):
self
.
_base
==
Base
.
DECIMAL_SIGNED
or
self
.
_base
==
Base
.
DECIMAL_UNSIGNED
):
value
=
int
(
value
)
if
value
>
max_value
:
raise
ValueToBig
except
ValueError
:
msg
=
None
if
self
.
_base
==
Base
.
BINARY
:
...
...
@@ -217,12 +233,18 @@ class IntegerMemoryTable(MemoryTable):
self
.
update
()
return
except
ValueToBig
:
self
.
_errorMessageWidget
.
showMessage
(
"
Input value does not fit within the bit length.
"
)
self
.
update
()
return
# Turn negative signed numbers into their positive unsigned
# counter part
# Ex 4 bits:
# -7 = 1001
# -7 + 16 % 16 = 9 = 1001 = -7
max_value
=
2
**
self
.
_bit_length
value
=
(
value
+
max_value
)
%
max_value
index
=
row
*
4
+
col
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment