Skip to content

Commit

Permalink
Merge pull request #3548 from maxonfjvipon/fix/#3540/malloc-resized
Browse files Browse the repository at this point in the history
fix(#3540): `malloc.resized` object
  • Loading branch information
yegor256 authored Nov 25, 2024
2 parents 4305631 + 943335b commit 7b05356
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 35 deletions.
3 changes: 1 addition & 2 deletions .codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@
# package name contains capital letter and such names are conventional.
---
exclude_paths:
- "eo-runtime/src/main/java/EOorg/EOeolang/EOmalloc$EOof$EOallocated$EOresize.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOmalloc$EOof$EOallocated$EOsize.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOmalloc$EOof$EOallocated$EOresized.java"
2 changes: 1 addition & 1 deletion .github/workflows/mvn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
name: mvn
strategy:
matrix:
os: [ ubuntu-24.04, windows-2022, macos-12 ]
os: [ ubuntu-24.04, windows-2022, macos-13 ]
java: [ 11, 21 ]
runs-on: ${{ matrix.os }}
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.yegor256.MktmpResolver;
import com.yegor256.farea.Farea;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -67,7 +68,9 @@ void convertsPhiToXmir(@Mktmp final Path temp) throws Exception {
f -> {
f.clean();
f.files().file("target/eo/phi/foo.phi").write(
"{ ⟦ a ↦ Φ.org.eolang.bytes ( α0 ↦ ⟦ Δ ⤍ 00- ⟧ ) ⟧}".getBytes()
"{ ⟦ a ↦ Φ.org.eolang.bytes ( α0 ↦ ⟦ Δ ⤍ 00- ⟧ ) ⟧}".getBytes(
StandardCharsets.UTF_8
)
);
f.build()
.plugins()
Expand Down Expand Up @@ -97,7 +100,7 @@ void failsOnBrokenPhiSyntax(@Mktmp final Path temp) throws Exception {
f -> {
f.clean();
f.files().file("target/eo/phi/foo.phi").write(
"{ ⟦ a ↦ Φ.org.eolang.bytes ( Δ ⤍ 00- ) ⟧}".getBytes()
"{ ⟦ a ↦ Φ.org.eolang.bytes ( Δ ⤍ 00- ) ⟧}".getBytes(StandardCharsets.UTF_8)
);
f.build()
.plugins()
Expand Down
4 changes: 2 additions & 2 deletions eo-runtime/src/main/eo/org/eolang/malloc.eo
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@
[] > size /number

# Resizes allocated block in memory and returns `true`.
# Here `size` must be positive `number`.
# Here `new-size` must be positive `number`.
# The `error` returned if failed to resize block in memory.
[size] > resize /true
[new-size] > resized /allocated

# Read `length` bytes with `offset` from the allocated block in memory.
[offset length] > read /bytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,44 @@
import org.eolang.AtVoid;
import org.eolang.Atom;
import org.eolang.Attr;
import org.eolang.Data;
import org.eolang.Dataized;
import org.eolang.Expect;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.Versionized;
import org.eolang.XmirObject;

/**
* Malloc.of.allocated.resize object.
* Malloc.of.allocated.resized object.
* @since 0.41.0
* @checkstyle TypeNameCheck (5 lines)
*/
@Versionized
@XmirObject(oname = "malloc.of.allocated.resize")
@XmirObject(oname = "malloc.of.allocated.resized")
@SuppressWarnings("PMD.AvoidDollarSigns")
public final class EOmalloc$EOof$EOallocated$EOresize extends PhDefault implements Atom {
public final class EOmalloc$EOof$EOallocated$EOresized extends PhDefault implements Atom {
/**
* Ctor.
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
EOmalloc$EOof$EOallocated$EOresize() {
this.add("size", new AtVoid("size"));
EOmalloc$EOof$EOallocated$EOresized() {
this.add("new-size", new AtVoid("new-size"));
}

@Override
public Phi lambda() {
Heaps.INSTANCE.resize(
new Dataized(this.take(Attr.RHO).take("id")).asNumber().intValue(),
new Dataized(this.take("size")).asNumber().intValue()
);
return new Data.ToPhi(true);
final Phi rho = this.take(Attr.RHO);
final int id = Expect.at(rho, "id")
.that(phi -> new Dataized(phi).asNumber())
.otherwise("must be a number")
.that(Double::intValue)
.it();
final int size = Expect.at(this, "new-size")
.that(phi -> new Dataized(phi).asNumber())
.otherwise("must be a number")
.that(Double::intValue)
.it();
Heaps.INSTANCE.resize(id, size);
return rho;
}
}
24 changes: 9 additions & 15 deletions eo-runtime/src/test/eo/org/eolang/malloc-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,10 @@
malloc.for > @
01-02-03-04
[m] >>
seq > @
*
m.resize 6
^.b.put
and.
m.size.eq 6
m.get.eq 01-02-03-04-00-00
^.b.put > @
and.
(m.resized 6).size.eq 6
m.get.eq 01-02-03-04-00-00

# This unit test is supposed to check the functionality of the corresponding object.
[] > malloc-decreases-block-size
Expand All @@ -256,16 +253,13 @@
malloc.for > @
01-02-03-04-05
[m] >>
seq > @
*
m.resize 3
^.b.put
and.
m.size.eq 3
m.get.eq 01-02-03
^.b.put > @
and.
(m.resized 3).size.eq 3
m.get.eq 01-02-03

# This unit test is supposed to check the functionality of the corresponding object.
[] > throws-on-changing-size-to-negative
malloc.of > @
1
m.resize -1 > [m]
m.resized -1 > [m]
4 changes: 2 additions & 2 deletions eo-runtime/src/test/java/integration/SnippetIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ void runsAllSnippets(final String yml, final @Mktmp Path temp) throws IOExceptio
f.properties()
.set("project.build.sourceEncoding", StandardCharsets.UTF_8.name())
.set("project.reporting.outputEncoding", StandardCharsets.UTF_8.name());
f.files().file("src/main/eo").save(
Paths.get(System.getProperty("user.dir")).resolve("src/main/eo")
f.files().file("src/main").save(
Paths.get(System.getProperty("user.dir")).resolve("src/main")
);
f.files()
.file(String.format("src/main/eo/%s", file))
Expand Down

0 comments on commit 7b05356

Please sign in to comment.