-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new memory behaviour #2189
Merged
Merged
new memory behaviour #2189
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,13 @@ | |
+package org.eolang | ||
+version 0.0.0 | ||
|
||
# @todo #761:30min Let's make sure memory can only accept one "type" of data primitives. | ||
# If we try to write a float into a memory that was initialized with an int, we should | ||
# get an error. The same goes for strings and booleans. We should also make sure that | ||
# we can't write a string that is longer than the memory size. We should also make sure | ||
# that we can't write a number that is bigger than the memory size. And etc. | ||
# We can also implement memory in EO instead of Java and let it use ram object. | ||
# Let's not forget to update the "Origins of Objects" paper. | ||
[] > writes-into-memory | ||
memory 0 > x | ||
assert-that > @ | ||
|
@@ -88,3 +95,124 @@ | |
b.write 20 | ||
a | ||
$.equal-to 10 | ||
|
||
[] > memory-is-strictly-typed-int-error | ||
memory 42 > m | ||
nop > @ | ||
assert-that | ||
try | ||
[] | ||
m.write 3.1416 > @ | ||
[e] | ||
e > @ | ||
nop | ||
$.equal-to "Memory type missmatch: expected <int>, got <float>" | ||
|
||
[] > memory-is-strictly-typed-int-error-overflow | ||
memory 256 > m | ||
nop > @ | ||
assert-that | ||
try | ||
[] | ||
m.write (9223372036854775807.plus 1) > @ | ||
[e] | ||
e > @ | ||
nop | ||
$.equal-to "Not enough memory to write: expected <2^63 - 1>, got <2^63>" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Graur Should we throw an exception in that case? Maybe it's better just to write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I like it, thanks! |
||
|
||
[] > memory-is-strictly-typed-float-error | ||
memory 3.24 > m | ||
nop > @ | ||
assert-that | ||
try | ||
[] | ||
m.write 2556 > @ | ||
[e] | ||
e > @ | ||
nop | ||
$.equal-to "Memory type missmatch: expected <float>, got <int>" | ||
|
||
[] > memory-is-strictly-typed-float-error-overflow | ||
memory 256.24 > m | ||
1.79e308 > float-max-value | ||
nop > @ | ||
assert-that | ||
try | ||
[] | ||
m.write (float-max-value.plus 0.1e308) > @ | ||
[e] | ||
e > @ | ||
nop | ||
$.equal-to "Not enough memory to write: expected <1.79e308>, got <1.8e308>" | ||
|
||
[] > memory-is-strictly-typed-bool-error | ||
memory TRUE > m | ||
nop > @ | ||
assert-that | ||
try | ||
[] | ||
m.write "Not good" > @ | ||
[e] | ||
e > @ | ||
nop | ||
$.equal-to "Memory type missmatch: expected <bool>, got <string>" | ||
|
||
[] > memory-is-strictly-typed-string-error-overflow | ||
memory "Hello" > m | ||
nop > @ | ||
assert-that | ||
try | ||
[] | ||
m.write "Much longer string!" > @ | ||
[e] | ||
e > @ | ||
nop | ||
$.equal-to "Not enough memory to write: expected <5>, got <20>" | ||
|
||
[] > memory-is-strictly-typed-int | ||
memory 12248 > m | ||
nop > @ | ||
assert-that | ||
try | ||
[] | ||
m.write 2556 > @ | ||
[e] | ||
e > @ | ||
nop | ||
$.equal-to 2556 | ||
|
||
[] > memory-is-strictly-typed-float | ||
memory 245.88 > m | ||
nop > @ | ||
assert-that | ||
try | ||
[] | ||
m.write 82.22 > @ | ||
[e] | ||
e > @ | ||
nop | ||
$.equal-to 82.22 | ||
|
||
[] > memory-is-strictly-typed-string | ||
memory "Hello" > m | ||
nop > @ | ||
assert-that | ||
try | ||
[] | ||
m.write "Hell" > @ | ||
[e] | ||
e > @ | ||
nop | ||
$.equal-to "Hell" | ||
|
||
[] > memory-is-strictly-typed-bool | ||
memory FALSE > m | ||
nop > @ | ||
assert-that | ||
try | ||
[] | ||
m.write TRUE > @ | ||
[e] | ||
e > @ | ||
nop | ||
$.equal-to TRUE |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Graur Let's imagine, that
int
andfloat
have the same size - 4 bytes (like in Java). Should we check their types? Or we might compare just size?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@volodya-lombrozo Yes, you are right. Thanks!
Moreover there is no chance to compare types if I try to implement it in EO. So we decided to avoid this change