Skip to content
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 3 commits into from
Jul 5, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions eo-runtime/src/test/eo/org/eolang/memory-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -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 > @
Expand Down Expand Up @@ -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>"
Copy link
Member

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 and float have the same size - 4 bytes (like in Java). Should we check their types? Or we might compare just size?

Copy link
Contributor Author

@Graur Graur Jun 29, 2023

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


[] > 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>"
Copy link
Member

Choose a reason for hiding this comment

The 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 -9,223,372,036,854,775,808?

Copy link
Contributor Author

@Graur Graur Jun 29, 2023

Choose a reason for hiding this comment

The 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