Skip to content

Commit

Permalink
fix(objectionary#3057): freed
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Apr 7, 2024
1 parent 31bfd30 commit 5599642
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 33 deletions.
3 changes: 1 addition & 2 deletions eo-runtime/src/main/eo/org/eolang/cage.eo
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@
# Object encaged by locator.
[locator] > encaged
$ > self
it > @

# Retrieved encaged object by locator.
[] > it /?
[] > @ /?

# Encage new object by locator.
[object] > encage /true
Expand Down
10 changes: 2 additions & 8 deletions eo-runtime/src/main/eo/org/eolang/memory.eo
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,5 @@
[] > free
^.pointer.free > @

# Free memory and return data.
[] > freed
(cage bytes).new > data
seq > @
*
data.encage ^.pointer.read
^.free
data.freed
# Free memory and return the data.
[] > freed /bytes
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
import org.eolang.XmirObject;

/**
* Cage.encaged.it object.
* Cage.encaged.φ object.
* @since 0.36.0
*/
@Versionized
@XmirObject(oname = "cage.encaged.it")
final class EOcage$EOencaged$EOit extends PhDefault implements Atom {
@XmirObject(oname = "cage.encaged.@")
final class EOcage$EOencaged$EOφ extends PhDefault implements Atom {
/**
* Ctor.
* @param sigma Sigma
*/
EOcage$EOencaged$EOit(final Phi sigma) {
EOcage$EOencaged$EOφ(final Phi sigma) {
super(sigma);
}

Expand All @@ -56,8 +56,9 @@ public Phi lambda() throws Exception {
final int locator = Math.toIntExact(
new Param(this.take(Attr.RHO), "locator").strong(Long.class)
);
final Phi obj = Cages.INSTANCE.get(locator);
return new PhTracedLocator(
Cages.INSTANCE.get(locator),
obj,
locator
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2024 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/*
* @checkstyle PackageNameCheck (4 lines)
*/
package EOorg.EOeolang;

import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.Param;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.Versionized;
import org.eolang.XmirObject;

/**
* Memory.allocated.freed object.
* @since 0.36.0
* @checkstyle TypeNameCheck (5 lines)
*/
@Versionized
@XmirObject(oname = "memory.allocated.freed")
final class EOmemory$EOallocated$EOfreed extends PhDefault implements Atom {
/**
* Ctor.
* @param sigma Sigma
*/
EOmemory$EOallocated$EOfreed(final Phi sigma) {
super(sigma);
}

@Override
public Phi lambda() throws Exception {
final Phi data = new Data.ToPhi(
new Param(this).strong(byte[].class)
);
new Dataized(this.take(Attr.RHO).take("free")).take();
return data;
}
}
16 changes: 9 additions & 7 deletions eo-runtime/src/test/eo/org/eolang/cage-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
seq > @
*
x.encage 42
copy.freed.eq 42
42.eq copy.freed

# Test.
[] > dataizes-encaged-object-not-lazily-first
Expand Down Expand Up @@ -176,7 +176,7 @@
[e]
cge.encage 10 > @
nop
cge.freed.eq 10
10.eq cge.freed

# Check that cage stack leads to error. Just prints the error
# message if passes.
Expand All @@ -199,12 +199,14 @@

# Test.
[] > applies-after-retrieval
# Func.
[x] > func
2.plus x > @
(cage func).new > c
new. > c
cage
[]
# Func.
[x] > func
2.plus x > @
and. > @
eq.
c.it 5
c.func 5
7
c.free
6 changes: 2 additions & 4 deletions eo-runtime/src/test/eo/org/eolang/const-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@
seq > @
*
cached.as-int
cached.as-bytes
cached.as-bool
1.eq m.freed
TRUE

# Test.
[] > const-behaves-as-exclamationed
[] > const-behaves-as-exclamation
# Func.
[] > func
(memory 0).alloc > m
Expand Down
8 changes: 2 additions & 6 deletions eo-runtime/src/test/eo/org/eolang/memory-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@
*
a.write 10
b.write 20
and.
a.eq 10
and.
b.free
a.free
a.eq 10

# Test.
[] > memory-is-strictly-typed-bool-error-overflow
Expand Down Expand Up @@ -159,7 +155,7 @@
[] > memory-is-strictly-typed-string
(memory "HellX").alloc > m
and. > @
eq. > @
eq.
try
[]
m.write "Prot" > @
Expand Down
2 changes: 1 addition & 1 deletion eo-runtime/src/test/eo/org/eolang/while-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
while > res!
condition
[i] (condition.write FALSE > @)
and.
and. > @
(bool res).not
condition.free

Expand Down

0 comments on commit 5599642

Please sign in to comment.