diff --git a/eo-runtime/src/main/eo/org/eolang/dataized.eo b/eo-runtime/src/main/eo/org/eolang/dataized.eo index d2283972dd..6200864ca7 100644 --- a/eo-runtime/src/main/eo/org/eolang/dataized.eo +++ b/eo-runtime/src/main/eo/org/eolang/dataized.eo @@ -37,7 +37,7 @@ # (dataized some-object).as-bytes > cached # ``` # -# Dataization is a process of retrieving data (bytes) from an object, by taking its \Delta +# Dataization is a process of retrieving data (bytes) from an object, by taking its Δ # attribute. # An example of usage: # @@ -50,9 +50,13 @@ # 5 > five # # (dataized foo).as-bytes > result # result is 00-00-00-00-00-00-00-05 -# result.as-number > f # f is 5 +# result.as-number > f # f is 5 # ``` # # Here, when `.as-bytes` is taken, the `dataized` dataizes (takes `bytes`) from the object `foo` # and returns them. The `.as-bytes` is used to prevent double dataization. -[target] > dataized /bytes +[target] > dataized + try > @ + target + error ex > [ex] + 01- diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOdataized.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOdataized.java deleted file mode 100644 index 6d254c8fe4..0000000000 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOdataized.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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) - * @checkstyle TrailingCommentCheck (3 lines) - */ -package EOorg.EOeolang; // NOPMD - -import org.eolang.AtVoid; -import org.eolang.Atom; -import org.eolang.Data; -import org.eolang.Dataized; -import org.eolang.PhDefault; -import org.eolang.Phi; -import org.eolang.Versionized; -import org.eolang.XmirObject; - -/** - * Dataized. - * @since 0.36.0 - */ -@Versionized -@XmirObject(oname = "dataized") -public final class EOdataized extends PhDefault implements Atom { - /** - * Ctor. - */ - @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") - public EOdataized() { - this.add("target", new AtVoid("target")); - } - - @Override - public Phi lambda() throws Exception { - return new Data.ToPhi( - new Dataized(this.take("target")).take() - ); - } -} diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java index 5ced014c03..0f1fe67eb8 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java @@ -28,8 +28,6 @@ */ package EOorg.EOeolang; // NOPMD -import java.util.function.Consumer; -import java.util.function.Function; import org.eolang.AtVoid; import org.eolang.Atom; import org.eolang.Data; @@ -60,190 +58,16 @@ public EOtry() { @Override public Phi lambda() { - return new PhTry(this.take("main"), this.take("catch"), this.take("finally")); - } - - /** - * Object that knows how to deal with {@link EOorg.EOeolang.EOerror.ExError}. - * @since 0.36.0 - */ - private static class PhTry implements Phi { - /** - * Body object. - */ - private final Phi body; - - /** - * Catch object. - */ - private final Phi ctch; - - /** - * Finally object. - */ - private final Phi last; - - /** - * Put function. - */ - private final Consumer> func; - - /** - * Ctor. - * @param body Body object - * @param ctch Catch object - * @param last Finally object - */ - PhTry(final Phi body, final Phi ctch, final Phi last) { - this.body = body; - this.ctch = ctch; - this.last = last; - this.func = new TryExecute(body, ctch); - } - - @Override - public void attach(final byte[] data) { - this.func.accept(phi -> phi.attach(data)); - } - - @Override - public byte[] delta() { - return new TryReturn( - this.body, this.ctch, this.last - ).apply(Data::delta); - } - - @Override - public Phi copy() { - return new PhTry(this.body.copy(), this.ctch.copy(), this.last.copy()); - } - - @Override - public Phi take(final String name) { - return new TryReturn( - this.body, this.ctch, this.last - ).apply(phi -> phi.take(name)); - } - - @Override - public boolean put(final int pos, final Phi object) { - return new TryReturn( - this.body, this.ctch, this.last - ).apply(phi -> phi.put(pos, object)); - } - - @Override - public boolean put(final String name, final Phi object) { - return new TryReturn( - this.body, this.ctch, this.last - ).apply(phi -> phi.put(name, object)); - } - - @Override - public String locator() { - return new TryReturn( - this.body, this.ctch, this.last - ).apply(Phi::locator); - } - - @Override - public String forma() { - return new TryReturn( - this.body, this.ctch, this.last - ).apply(Phi::forma); - } - - @Override - public String φTerm() { - return new TryReturn( - this.body, this.ctch, this.last - ).apply(Phi::φTerm); - } - } - - /** - * Tries to execute given function and catches {@link EOorg.EOeolang.EOerror.ExError}. - * @since 0.36.0 - */ - private static class TryExecute implements Consumer> { - /** - * Body object. - */ - private final Phi body; - - /** - * Catch object. - */ - private final Phi ctch; - - /** - * Ctor. - * @param main Body object - * @param ctch Catch object - */ - TryExecute(final Phi main, final Phi ctch) { - this.body = main; - this.ctch = ctch; - } - - @Override - public void accept(final Consumer func) { - try { - func.accept(this.body); - } catch (final EOerror.ExError ex) { - final Phi caught = this.ctch.copy(); - caught.put(0, ex.enclosure()); - func.accept(caught); - } - } - } - - /** - * Tries to return value from given function and catches {@link EOorg.EOeolang.EOerror.ExError}. - * @param Type of return value. - * @since 0.36.0 - */ - private static class TryReturn implements Function, T> { - /** - * Body object. - */ - private final Phi body; - - /** - * Catch object. - */ - private final Phi ctch; - - /** - * Finally object. - */ - private final Phi last; - - /** - * Ctor. - * @param main Body object - * @param ctch Catch object - * @param last Finally object - */ - TryReturn(final Phi main, final Phi ctch, final Phi last) { - this.body = main; - this.ctch = ctch; - this.last = last; - } - - @Override - public T apply(final Function func) { - T result; - try { - result = func.apply(this.body); - } catch (final EOerror.ExError ex) { - final Phi caught = this.ctch.copy(); - caught.put(0, ex.enclosure()); - result = func.apply(caught); - } finally { - new Dataized(this.last).take(); - } - return result; + byte[] result; + try { + result = new Dataized(this.take("main")).take(); + } catch (final EOerror.ExError ex) { + final Phi caught = this.take("catch").copy(); + caught.put(0, ex.enclosure()); + result = new Dataized(caught).take(); + } finally { + new Dataized(this.take("finally")).take(); } + return new Data.ToPhi(result); } } diff --git a/eo-runtime/src/test/eo/org/eolang/rust-tests.eo b/eo-runtime/src/test/eo/org/eolang/rust-tests.eo index bf74fce260..ee35a362c3 100644 --- a/eo-runtime/src/test/eo/org/eolang/rust-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/rust-tests.eo @@ -222,8 +222,7 @@ e > [e] true 0 - length. - message + message.as-bytes.size message # Test. @@ -251,9 +250,7 @@ e > [e] true eq. > @ - res.slice - 0 - to-check.length + res.slice 0 to-check.as-bytes.size to-check # Test. @@ -348,11 +345,7 @@ e > [e] true eq. > @ - slice. - res - 0 - length. - message + res.slice 0 message.as-bytes.size message # Test. diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOnet/EOsocketTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOnet/EOsocketTest.java index c0d476d7cd..09d0163549 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOnet/EOsocketTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOnet/EOsocketTest.java @@ -150,8 +150,8 @@ void refusesConnectionViaPosixSyscall() { assert socket >= 0; final SockaddrIn addr = new SockaddrIn( (short) CStdLib.AF_INET, - EOsocketTest.htons(1234), - Integer.reverseBytes(CStdLib.INSTANCE.inet_addr(EOsocketTest.LOCALHOST)) + EOsocketTest.htons(8080), + Integer.reverseBytes(CStdLib.INSTANCE.inet_addr("127.0.0.0")) ); final int connected = CStdLib.INSTANCE.connect(socket, addr, addr.size()); MatcherAssert.assertThat(