Skip to content

Commit

Permalink
fix(objectionary#3057): no free in cage
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Apr 10, 2024
1 parent 00f1cf1 commit b1988ec
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 159 deletions.
7 changes: 4 additions & 3 deletions .codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# are not available for the project. For example a lot of
# package name contains capital letter and such names are conventional.
exclude_paths:
- "eo-runtime/src/main/java/EOorg/EOeolang/EOmalloc$EOmemory_block_pointer$EOfree.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOmalloc$EOmemory_block_pointer$EOread.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOmalloc$EOmemory_block_pointer$EOwrite.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOcage$EOencaged$EOencage.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/Cages.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOcage$EOencaged$EOφ.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOcage$φ.java"
3 changes: 0 additions & 3 deletions eo-runtime/src/main/eo/org/eolang/cage.eo
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,3 @@

# Encage new object by locator.
[object] > encage /true

# Just remove object from the cage.
[] > free /true
18 changes: 0 additions & 18 deletions eo-runtime/src/main/java/EOorg/EOeolang/Cages.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,4 @@ Phi get(final int locator) {
return this.objects.get(locator);
}
}

/**
* Remove object from the cage by locator.
* @param locator Locator of the object
*/
void remove(final int locator) {
synchronized (this.objects) {
if (!this.objects.containsKey(locator)) {
throw new ExFailure(
String.format(
"Object with locator %d is absent in cage, can't remove",
locator
)
);
}
this.objects.remove(locator);
}
}
}

This file was deleted.

64 changes: 19 additions & 45 deletions eo-runtime/src/test/eo/org/eolang/cage-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
*
x.encage
a 7
and.
x.z.eq 7
x.free
x.z.eq 7

# Test.
[] > checks-forma-and-fixes
Expand All @@ -49,11 +47,7 @@
sum.encage
x.plus 1
x.encage 7
and.
and.
sum.eq 43
sum.free
x.free
sum.eq 43

# Test.
[] > dataizes-encaged-object-lazily-second
Expand All @@ -65,21 +59,15 @@
sum.encage
1.plus x
x.encage 7
and.
sum.eq 8
and.
sum.free
x.free
sum.eq 8

# Test.
[] > stores-abstract-object-into-cage
new. > c
cage
[]
112 > @
and. > @
c.eq 112
c.free
c.eq 112 > @

# Test.
[] > multi-layer-volatility
Expand Down Expand Up @@ -112,19 +100,15 @@
mb.write (mb.as-int.plus 1)
mb.as-int
and. > @
and.
eq.
seq
*
ca
ca.plus 40
seq
*
cb.z
cb.z.plus 40
and.
cb.free
ca.free
eq.
seq
*
ca
ca.plus 40
seq
*
cb.z
cb.z.plus 40
and.
ma.free
mb.free
Expand All @@ -146,11 +130,7 @@
x.add (pyint 1)
QQ.io.stdout
tmp.value
and.
tmp.value.eq 1
and.
x.free
tmp.free
tmp.value.eq 1

# Test.
[] > catches-encaging-objects-of-different-formas
Expand All @@ -162,9 +142,7 @@
[e]
cge.encage 10 > @
nop
and.
cge.eq 10
cge.free
cge.eq 10

# Check that cage stack leads to error. Just prints the error
# message if passes.
Expand All @@ -179,9 +157,7 @@
cge
FALSE
[stack-overflow-message]
and. > @
QQ.io.stdout stack-overflow-message
cge.free
QQ.io.stdout stack-overflow-message > @
FALSE

# Test.
Expand All @@ -192,8 +168,6 @@
# Func.
[x] > func
2.plus x > @
and. > @
eq.
c.func 5
7
c.free
eq. > @
c.func 5
7
4 changes: 1 addition & 3 deletions eo-runtime/src/test/eo/org/eolang/runtime-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@
and.
f1.eq 3
f1.free
and.
f0.free
f2.free
f0.free

# Test.
[] > recursion-without-arguments
Expand Down
23 changes: 0 additions & 23 deletions eo-runtime/src/test/java/EOorg/EOeolang/CagesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void initializesObjectForTheFirstTime() {
Assertions.assertDoesNotThrow(
() -> Cages.INSTANCE.get(locator)
);
Cages.INSTANCE.remove(locator);
}

@Test
Expand All @@ -58,7 +57,6 @@ void rencagesTheSameObject() {
Assertions.assertDoesNotThrow(
() -> Cages.INSTANCE.init(phi)
);
Cages.INSTANCE.remove(locator);
}

@Test
Expand All @@ -71,7 +69,6 @@ void encagesObjectWithLocator() {
Cages.INSTANCE.get(locator).hashCode(),
Matchers.equalTo(second.hashCode())
);
Cages.INSTANCE.remove(locator);
}

@Test
Expand All @@ -90,7 +87,6 @@ void failsToEncageObjectOfDifferentForma() {
ExFailure.class,
() -> Cages.INSTANCE.encage(locator, new Data.ToPhi(5L))
);
Cages.INSTANCE.remove(locator);
}

@Test
Expand All @@ -100,23 +96,4 @@ void failsToGetObjectIfWasNotInitialized() {
() -> Cages.INSTANCE.get(new PhFake().hashCode())
);
}

@Test
void removesObjectSuccessfully() {
final Phi phi = new PhFake();
final int locator = Cages.INSTANCE.init(phi);
Cages.INSTANCE.remove(locator);
Assertions.assertThrows(
ExFailure.class,
() -> Cages.INSTANCE.get(locator)
);
}

@Test
void failsToRemoveIfWasNotInitialized() {
Assertions.assertThrows(
ExFailure.class,
() -> Cages.INSTANCE.remove(new PhFake().hashCode())
);
}
}

0 comments on commit b1988ec

Please sign in to comment.