From 14de12944e06f32a440b6ff9d373779da48d3a75 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Fri, 21 Jul 2023 17:00:05 +0300 Subject: [PATCH 01/16] #2283: should work --- .../java/org/eolang/maven/rust/Native.java | 2 +- .../org/eolang/maven/rust/PrimeModule.java | 8 ++- .../src/main/java/EOorg/EOeolang/EOrust.java | 3 +- .../src/main/rust/eo_env/src/eo_enum.rs | 57 +++++++++++++++++++ eo-runtime/src/main/rust/eo_env/src/eo_env.rs | 28 ++++++++- .../src/test/eo/org/eolang/rust-tests.eo | 10 ++-- 6 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 eo-runtime/src/main/rust/eo_env/src/eo_enum.rs diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/rust/Native.java b/eo-maven-plugin/src/main/java/org/eolang/maven/rust/Native.java index 0a6c7a9527..24c34a239f 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/rust/Native.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/rust/Native.java @@ -75,7 +75,7 @@ public void save(final Footprint footprint) throws IOException { this.name ), String.format( - " public static native int %s", + " public static native byte[] %s", this.name ), " (final EOrust eo);", diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java b/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java index 5902888377..9918432fe7 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java @@ -42,14 +42,16 @@ public PrimeModule(final String method, final String file) { "mod foo;", "use foo::foo;", "use jni::JNIEnv;", - "use jni::objects::{JClass, JObject};", + "use jni::objects::{JByteArray, JClass, JObject};", "use jni::sys::{jint};", "use eo_env::EOEnv;", "#[no_mangle]", "pub extern \"system\" fn", String.format("Java_EOrust_natives_%s_%s", method, method), - "<'local> (env: JNIEnv<'local>, _class: JClass<'local>, universe: JObject<'local>) -> jint", - "{ return foo(EOEnv::new(env, _class, universe)); }" + "<'local> (env: JNIEnv<'local>, _class: JClass<'local>, universe: JObject<'local>) -> JByteArray", + "{ let mut my_env = MyEnv::new(env, _class, universe); ", + "let arr = foo(&mut my_env).eo2vec();", + "my_env.java_env.byte_array_from_slice(&arr.as_slice()).unwrap() }" ), file ); diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java index 1c6d211ab1..4a1c70fb42 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java @@ -129,8 +129,9 @@ public EOrust(final Phi sigma) { name ) ).getDeclaredMethod(name, new Class[]{EOrust.class}); + byte[] res = (byte[]) method.invoke(null, this); return new Data.ToPhi( - Long.valueOf((int) method.invoke(null, this)) + Long.valueOf(res.length) ); } ) diff --git a/eo-runtime/src/main/rust/eo_env/src/eo_enum.rs b/eo-runtime/src/main/rust/eo_env/src/eo_enum.rs new file mode 100644 index 0000000000..bf6d55eab5 --- /dev/null +++ b/eo-runtime/src/main/rust/eo_env/src/eo_enum.rs @@ -0,0 +1,57 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2023 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. + */ + +pub enum EO { + EOVertex(u32), + EODouble(f64), + EOInt(i64), + EOString(String), + EORaw(Box<[u8]>), +} + +impl EO { + pub fn eo2vec(&self) -> Vec { + match self { + EO::EOVertex(v) => { + let mut res: Vec = vec![0; 1 + 4]; + res[0] = 0; + res[1..].copy_from_slice(&v.to_le_bytes()); + res + } + EO::EODouble(x) => { + let mut res = vec![1; 1 + 8]; + res[1..].copy_from_slice(&x.to_be_bytes()); + res + } + EO::EOInt(x) => { + let mut res: Vec = vec![2; 1 + 8]; + res[0] = 0; + res[1..].copy_from_slice(&x.to_le_bytes()); + res + } + EO::EOString(_) => { vec![0xff] } + EO::EORaw(_) => { vec![0xff] } + } + } +} diff --git a/eo-runtime/src/main/rust/eo_env/src/eo_env.rs b/eo-runtime/src/main/rust/eo_env/src/eo_env.rs index 29af75cda2..4057454f2f 100644 --- a/eo-runtime/src/main/rust/eo_env/src/eo_env.rs +++ b/eo-runtime/src/main/rust/eo_env/src/eo_env.rs @@ -1,9 +1,34 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2023 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. + */ + +pub mod eo_enum; use jni::JNIEnv; use jni::objects::{JClass, JObject, JValue}; #[allow(dead_code)] pub struct EOEnv<'local> { - java_env: JNIEnv<'local>, + pub java_env: JNIEnv<'local>, java_class: JClass<'local>, java_obj: JObject<'local> } @@ -79,6 +104,7 @@ impl<'local> EOEnv<'_> { * call java dataizing method and get byte array from it. * Then it have to return byte array as a result of dataization. */ + #[allow(unused_variables)] pub fn dataize(&mut self, v: u32) -> Option<&[u32]> { Some(&[0x0]) } 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 0faa9eaa10..816cdaada0 100644 --- a/eo-runtime/src/test/eo/org/eolang/rust-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/rust-tests.eo @@ -40,8 +40,9 @@ * assert-that > @ r - $.equal-to - 2 + $.not + $.less-than + 0 [] > rust-find-returns-int QQ.rust > r @@ -56,8 +57,9 @@ * assert-that > @ r - $.equal-to - 0 + $.not + $.less-than + 0 [] > rust-put-not-fails QQ.rust > r From 561798c0144546ba9fa664bca0734b5f0d8c3810 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Fri, 21 Jul 2023 19:43:44 +0300 Subject: [PATCH 02/16] #2283: maven plugin tests fail --- .../org/eolang/maven/rust/PrimeModule.java | 7 +- .../org/eolang/maven/BinarizeMojoTest.java | 5 ++ .../eolang/maven/BinarizeParseMojoTest.java | 4 +- .../maven/binarize/eo_env/src/eo_env.rs | 3 +- .../org/eolang/maven/binarize/simple-rust.eo | 2 +- .../org/eolang/maven/binarize/twice-rust.eo | 8 +-- .../java/org/eolang/parser/SyntaxTest.java | 2 +- .../src/main/java/EOorg/EOeolang/EOrust.java | 35 +++++++++- .../src/main/rust/eo_env/src/eo_enum.rs | 13 ++-- .../src/test/eo/org/eolang/rust-tests.eo | 67 +++++++++++++------ 10 files changed, 105 insertions(+), 41 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java b/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java index 9918432fe7..156c94ba76 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java @@ -43,15 +43,14 @@ public PrimeModule(final String method, final String file) { "use foo::foo;", "use jni::JNIEnv;", "use jni::objects::{JByteArray, JClass, JObject};", - "use jni::sys::{jint};", "use eo_env::EOEnv;", "#[no_mangle]", "pub extern \"system\" fn", String.format("Java_EOrust_natives_%s_%s", method, method), "<'local> (env: JNIEnv<'local>, _class: JClass<'local>, universe: JObject<'local>) -> JByteArray", - "{ let mut my_env = MyEnv::new(env, _class, universe); ", - "let arr = foo(&mut my_env).eo2vec();", - "my_env.java_env.byte_array_from_slice(&arr.as_slice()).unwrap() }" + "{ let mut eo_env = EOEnv::new(env, _class, universe); ", + "let arr = foo(&mut eo_env).eo2vec();", + "eo_env.java_env.byte_array_from_slice(&arr.as_slice()).unwrap() }" ), file ); diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java index 0581a9beb6..919736cc0f 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java @@ -23,6 +23,7 @@ */ package org.eolang.maven; +import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -48,6 +49,8 @@ final class BinarizeMojoTest { */ public static final Path SRC = Paths.get("src/test/resources/org/eolang/maven/binarize/"); + public static final File ENV = new File("../eo-runtime/src/main/rust/eo_env"); + /** * BinarizeMojo can binarize without errors. * @param temp Temporary directory. @@ -60,6 +63,7 @@ void binarizesWithoutErrors(@TempDir final Path temp) throws Exception { final FakeMaven maven; synchronized (BinarizeMojoTest.class) { maven = new FakeMaven(temp) + .with("eoEnvDir", BinarizeMojoTest.ENV) .withProgram(BinarizeMojoTest.SRC.resolve("simple-rust.eo")) .withProgram(BinarizeMojoTest.SRC.resolve("twice-rust.eo")); } @@ -89,6 +93,7 @@ void savesToCache(@TempDir final Path temp) throws IOException { final Path cache = temp.resolve(".cache"); synchronized (BinarizeMojoTest.class) { maven = new FakeMaven(temp) + .with("eoEnvDir", BinarizeMojoTest.ENV) .withProgram(BinarizeMojoTest.SRC.resolve("simple-rust.eo")) .with("cache", cache); } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java index c47ed5b81a..2261f3a405 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java @@ -71,7 +71,7 @@ void parsesSimpleEoProgram(@TempDir final Path temp) throws Exception { new TextOf(res.get(rust)).asString(), Matchers.stringContainsInOrder( "use rand::Rng;", - "pub fn foo(mut env: EOEnv<'_>) -> i32 {", + "pub fn foo(mut env: EOEnv<'_>) -> EO {", " let mut rng = rand::thread_rng();", " print!(\"Hello world\");", " let i = rng.gen::();", @@ -88,7 +88,7 @@ void parsesSimpleEoProgram(@TempDir final Path temp) throws Exception { ) ) ).asString(), - Matchers.containsString("public static native int") + Matchers.containsString("public static native byte[]") ); } diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/src/eo_env.rs b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/src/eo_env.rs index 7361d82ff6..fb4c07749c 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/src/eo_env.rs +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/src/eo_env.rs @@ -1,9 +1,10 @@ +pub mod eo_enum; use jni::JNIEnv; use jni::objects::{JClass, JObject}; #[allow(dead_code)] pub struct EOEnv<'local> { - java_env: JNIEnv<'local>, + pub java_env: JNIEnv<'local>, java_class: JClass<'local>, java_obj: JObject<'local> } diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/simple-rust.eo b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/simple-rust.eo index c8ae6abbaa..b24d990909 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/simple-rust.eo +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/simple-rust.eo @@ -7,7 +7,7 @@ use rand::Rng; use eo_env::EOEnv; - pub fn foo(mut env: EOEnv<'_>) -> i32 { + pub fn foo(mut env: EOEnv<'_>) -> EO { let mut rng = rand::thread_rng(); print!("Hello world"); let i = rng.gen::(); diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/twice-rust.eo b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/twice-rust.eo index e5ddaff396..5f3af4f5d1 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/twice-rust.eo +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/twice-rust.eo @@ -6,10 +6,10 @@ """ use eo_env::EOEnv; - pub fn foo(mut _env: EOEnv<'_>) -> i32 { + pub fn foo(mut _env: EOEnv<'_>) -> EO { let x = rand::random::(); println!("{}", x); - x + EOInt(x as i64) } """ * @@ -21,10 +21,10 @@ """ use eo_env::EOEnv; - pub fn foo(mut _env: EOEnv<'_>) -> i32 { + pub fn foo(mut _env: EOEnv<'_>) -> EO { print!("Hello 大 2"); let x = rand::random::(); - x + EOInt(x as i64) } """ * diff --git a/eo-parser/src/test/java/org/eolang/parser/SyntaxTest.java b/eo-parser/src/test/java/org/eolang/parser/SyntaxTest.java index 00cb9980ae..be471f8bac 100644 --- a/eo-parser/src/test/java/org/eolang/parser/SyntaxTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/SyntaxTest.java @@ -54,7 +54,7 @@ final class SyntaxTest { @Test - void parsesSimpleCode() throws Exception { + void EOFloatpleCode() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Syntax syntax = new Syntax( "test-1", diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java index 4a1c70fb42..aa82c45e83 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java @@ -32,8 +32,10 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.lang.reflect.Method; +import java.nio.ByteBuffer; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.SystemUtils; @@ -130,9 +132,7 @@ public EOrust(final Phi sigma) { ) ).getDeclaredMethod(name, new Class[]{EOrust.class}); byte[] res = (byte[]) method.invoke(null, this); - return new Data.ToPhi( - Long.valueOf(res.length) - ); + return EOrust.translate(res); } ) ); @@ -229,4 +229,33 @@ private static ConcurrentHashMap load(final String src) throws I ); } } + + private static Phi translate(final byte[] message) { + final byte determinant = message[0]; + final byte[] content = Arrays.copyOfRange(message, 1, message.length); + final Phi ret; + switch (determinant) { + case 0: + throw new ExFailure( + "Returning vertex is not implemented yet" + ); + case 1: + ByteBuffer byteBuffer = ByteBuffer.allocate(Double.BYTES); + byteBuffer.put(content); + byteBuffer.flip(); + ret = new Data.ToPhi(byteBuffer.getDouble()); + break; + case 2: + byteBuffer = ByteBuffer.allocate(Long.BYTES); + byteBuffer.put(content); + byteBuffer.flip(); + ret = new Data.ToPhi(byteBuffer.getLong()); + break; + default: + throw new ExFailure( + "Returning Strings and raw bytes is not implemented yet" + ); + } + return ret; + } } diff --git a/eo-runtime/src/main/rust/eo_env/src/eo_enum.rs b/eo-runtime/src/main/rust/eo_env/src/eo_enum.rs index bf6d55eab5..4929c7aca0 100644 --- a/eo-runtime/src/main/rust/eo_env/src/eo_enum.rs +++ b/eo-runtime/src/main/rust/eo_env/src/eo_enum.rs @@ -24,7 +24,7 @@ pub enum EO { EOVertex(u32), - EODouble(f64), + EOFloat(f64), EOInt(i64), EOString(String), EORaw(Box<[u8]>), @@ -39,15 +39,16 @@ impl EO { res[1..].copy_from_slice(&v.to_le_bytes()); res } - EO::EODouble(x) => { - let mut res = vec![1; 1 + 8]; + EO::EOFloat(x) => { + let mut res = vec![0; 1 + 8]; + res[0] = 1; res[1..].copy_from_slice(&x.to_be_bytes()); res } EO::EOInt(x) => { - let mut res: Vec = vec![2; 1 + 8]; - res[0] = 0; - res[1..].copy_from_slice(&x.to_le_bytes()); + let mut res: Vec = vec![0; 1 + 8]; + res[0] = 2; + res[1..].copy_from_slice(&x.to_be_bytes()); res } EO::EOString(_) => { vec![0xff] } 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 816cdaada0..66717b0df4 100644 --- a/eo-runtime/src/test/eo/org/eolang/rust-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/rust-tests.eo @@ -26,32 +26,54 @@ +package org.eolang +version 0.0.0 -[] > rust-creates-object +[] > rust-returns-int QQ.rust > r """ use eo_env::EOEnv; + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOInt}; - pub fn foo(mut _env: EOEnv<'_>) -> i32 { + pub fn foo(_env: &mut EOEnv) -> EO { println!("Hello world from rust"); let x = 4.0_f32; - x.sqrt() as i32 + EOInt(x.sqrt() as i64) } """ * assert-that > @ r - $.not - $.less-than - 0 + $.equal-to + 2 + +[] > rust-returns-doable + QQ.rust > r + """ + use eo_env::EOEnv; + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOFloat}; + + pub fn foo(_env: &mut EOEnv) -> EO { + println!("Hello world from EOFloat"); + let x = 4.0_f64; + EOFloat(x.sqrt()) + } + """ + * + assert-that > @ + r + $.equal-to + 2.0 [] > rust-find-returns-int QQ.rust > r """ use eo_env::EOEnv; + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOInt}; - pub fn foo(mut env: EOEnv<'_>) -> i32 { + pub fn foo(env: &mut EOEnv) -> EO { env.find("^"); - 0 + EOInt(0 as i64) } """ * @@ -65,10 +87,11 @@ QQ.rust > r """ use eo_env::EOEnv; - - pub fn foo(mut env: EOEnv<'_>) -> i32 { + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOInt}; + pub fn foo(env: &mut EOEnv) -> EO { env.put(3, &[0x00, 0x1a, 0xEE, 0xf, 0xf3]).unwrap(); - 0 + EOInt(0 as i64) } """ * @@ -82,11 +105,13 @@ QQ.rust > insert """ use eo_env::EOEnv; - pub fn foo(mut env: EOEnv<'_>) -> i32 { + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOInt}; + pub fn foo(env: &mut EOEnv) -> EO { let v1 = env.find("a") as u32; let v2 = env.find("b") as u32; - env.bind(v1 , v2, "my-att"); - return v1 as i32; + env.bind(v1 , v2, "EO-att"); + return EOInt(v1 as i64); } """ * @@ -100,10 +125,12 @@ QQ.rust > copy """ use eo_env::EOEnv; - pub fn foo(mut env: EOEnv<'_>) -> i32 { + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOInt}; + pub fn foo(env: &mut EOEnv) -> EO { let v = env.find("a") as u32; let copy = env.copy(v).unwrap(); - copy as i32 + EOInt(copy as i64) } """ * @@ -117,10 +144,12 @@ QQ.rust > dataized """ use eo_env::EOEnv; - pub fn foo(mut env: EOEnv<'_>) -> i32 { + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOInt}; + pub fn foo(env: &mut EOEnv) -> EO { let v = env.find("a") as u32; - let bytes = env.dataize(v).unwrap(); - v as i32 + let _bytes = env.dataize(v).unwrap(); + EOInt(v as i64) } """ * From 1d9105ee8de3015d2ffaac8a204f391c34b13945 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sat, 22 Jul 2023 23:46:17 +0300 Subject: [PATCH 03/16] #2283: removed eo_env in eo-maven-plugin and leave path to eo_env in eo-runtime --- .../test/java/org/eolang/maven/FakeMaven.java | 2 +- .../eolang/maven/binarize/eo_env/Cargo.toml | 12 ----------- .../maven/binarize/eo_env/src/eo_env.rs | 20 ------------------- 3 files changed, 1 insertion(+), 33 deletions(-) delete mode 100644 eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/Cargo.toml delete mode 100644 eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/src/eo_env.rs diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java index 4e65f95fae..992db9a0ea 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java @@ -231,7 +231,7 @@ public FakeMaven execute(final Class mojo) throws IO this.params.putIfAbsent("objectionary", new Objectionary.Fake()); this.params.putIfAbsent( "eoEnvDir", - new File("src/test/resources/org/eolang/maven/binarize/eo_env") + new File("../eo-runtime/src/main/rust/eo_env") ); } final Moja moja = new Moja<>(mojo); diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/Cargo.toml b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/Cargo.toml deleted file mode 100644 index d7f29f7e3a..0000000000 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "eo_env" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -jni = "0.21.1" - -[lib] -path = "src/eo_env.rs" \ No newline at end of file diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/src/eo_env.rs b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/src/eo_env.rs deleted file mode 100644 index fb4c07749c..0000000000 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/eo_env/src/eo_env.rs +++ /dev/null @@ -1,20 +0,0 @@ -pub mod eo_enum; -use jni::JNIEnv; -use jni::objects::{JClass, JObject}; - -#[allow(dead_code)] -pub struct EOEnv<'local> { - pub java_env: JNIEnv<'local>, - java_class: JClass<'local>, - java_obj: JObject<'local> -} - -impl<'local> EOEnv<'_> { - pub fn new(java_env: JNIEnv<'local>, java_class: JClass<'local>, java_obj: JObject<'local>) -> EOEnv<'local> { - EOEnv { - java_env, - java_class, - java_obj - } - } -} From a855163508cae34ae70e87ad40ed9245d103078f Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sat, 22 Jul 2023 23:47:17 +0300 Subject: [PATCH 04/16] #2283: updated to new signature of eo_env --- .../java/org/eolang/maven/BinarizeMojoTest.java | 4 ---- .../org/eolang/maven/BinarizeParseMojoTest.java | 16 ++++++++++------ .../org/eolang/maven/binarize/simple-rust.eo | 8 +++++--- .../org/eolang/maven/binarize/twice-rust.eo | 8 ++++++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java index 919736cc0f..f0234ad5dc 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java @@ -49,8 +49,6 @@ final class BinarizeMojoTest { */ public static final Path SRC = Paths.get("src/test/resources/org/eolang/maven/binarize/"); - public static final File ENV = new File("../eo-runtime/src/main/rust/eo_env"); - /** * BinarizeMojo can binarize without errors. * @param temp Temporary directory. @@ -63,7 +61,6 @@ void binarizesWithoutErrors(@TempDir final Path temp) throws Exception { final FakeMaven maven; synchronized (BinarizeMojoTest.class) { maven = new FakeMaven(temp) - .with("eoEnvDir", BinarizeMojoTest.ENV) .withProgram(BinarizeMojoTest.SRC.resolve("simple-rust.eo")) .withProgram(BinarizeMojoTest.SRC.resolve("twice-rust.eo")); } @@ -93,7 +90,6 @@ void savesToCache(@TempDir final Path temp) throws IOException { final Path cache = temp.resolve(".cache"); synchronized (BinarizeMojoTest.class) { maven = new FakeMaven(temp) - .with("eoEnvDir", BinarizeMojoTest.ENV) .withProgram(BinarizeMojoTest.SRC.resolve("simple-rust.eo")) .with("cache", cache); } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java index 2261f3a405..883955d7ce 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java @@ -71,11 +71,11 @@ void parsesSimpleEoProgram(@TempDir final Path temp) throws Exception { new TextOf(res.get(rust)).asString(), Matchers.stringContainsInOrder( "use rand::Rng;", - "pub fn foo(mut env: EOEnv<'_>) -> EO {", + "pub fn foo(_env: &EOEnv) -> EO {", " let mut rng = rand::thread_rng();", " print!(\"Hello world\");", - " let i = rng.gen::();", - " i", + " let i = rng.gen::();", + " EOInt(i)", "}" ) ); @@ -94,7 +94,7 @@ void parsesSimpleEoProgram(@TempDir final Path temp) throws Exception { @Test void binarizesTwiceRustProgram(@TempDir final Path temp) throws Exception { - final Path src = Paths.get("src/test/resources/org/eolang/maven/binarize/twice-rust.eo"); + final Path src = BinarizeMojoTest.SRC.resolve("twice-rust.eo"); final FakeMaven maven; synchronized (BinarizeParseMojoTest.class) { maven = new FakeMaven(temp).withProgram(src); @@ -119,14 +119,18 @@ void binarizesTwiceRustProgram(@TempDir final Path temp) throws Exception { MatcherAssert.assertThat( new TextOf(res.get(one)).asString(), Matchers.stringContainsInOrder( - "pub fn foo(mut _env: EOEnv<'_>) -> i32 {", + "use eo_env::eo_enum::EO;", + "use eo_env::eo_enum::EO::{EOInt};", + "pub fn foo(_env: &EOEnv) -> EO {", "println!(\"{}\", x);" ) ); MatcherAssert.assertThat( new TextOf(res.get(two)).asString(), Matchers.stringContainsInOrder( - "pub fn foo(mut _env: EOEnv<'_>) -> i32 {", + "use eo_env::eo_enum::EO;", + "use eo_env::eo_enum::EO::{EOInt};", + "pub fn foo(_env: &EOEnv) -> EO {", "print!(\"Hello 大 2\");" ) ); diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/simple-rust.eo b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/simple-rust.eo index b24d990909..305dc3cd05 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/simple-rust.eo +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/simple-rust.eo @@ -6,12 +6,14 @@ """ use rand::Rng; use eo_env::EOEnv; + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOInt}; - pub fn foo(mut env: EOEnv<'_>) -> EO { + pub fn foo(_env: &EOEnv) -> EO { let mut rng = rand::thread_rng(); print!("Hello world"); - let i = rng.gen::(); - i + let i = rng.gen::(); + EOInt(i) } """ * diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/twice-rust.eo b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/twice-rust.eo index 5f3af4f5d1..35528a1a6b 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/twice-rust.eo +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/binarize/twice-rust.eo @@ -5,8 +5,10 @@ QQ.rust > r """ use eo_env::EOEnv; + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOInt}; - pub fn foo(mut _env: EOEnv<'_>) -> EO { + pub fn foo(_env: &EOEnv) -> EO { let x = rand::random::(); println!("{}", x); EOInt(x as i64) @@ -20,8 +22,10 @@ QQ.rust > r """ use eo_env::EOEnv; + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOInt}; - pub fn foo(mut _env: EOEnv<'_>) -> EO { + pub fn foo(_env: &EOEnv) -> EO { print!("Hello 大 2"); let x = rand::random::(); EOInt(x as i64) From ad6d2ae7b9138c686a8bc86dd31d29650dbeb541 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 23 Jul 2023 01:51:47 +0300 Subject: [PATCH 05/16] #2283: unused import --- .../src/test/java/org/eolang/maven/BinarizeMojoTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java index f0234ad5dc..0581a9beb6 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeMojoTest.java @@ -23,7 +23,6 @@ */ package org.eolang.maven; -import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; From c406fc8951710ef6add06abb7b5db24d16b50f03 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 23 Jul 2023 01:56:08 +0300 Subject: [PATCH 06/16] #2283: restored to master --- eo-parser/src/test/java/org/eolang/parser/SyntaxTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-parser/src/test/java/org/eolang/parser/SyntaxTest.java b/eo-parser/src/test/java/org/eolang/parser/SyntaxTest.java index be471f8bac..00cb9980ae 100644 --- a/eo-parser/src/test/java/org/eolang/parser/SyntaxTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/SyntaxTest.java @@ -54,7 +54,7 @@ final class SyntaxTest { @Test - void EOFloatpleCode() throws Exception { + void parsesSimpleCode() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Syntax syntax = new Syntax( "test-1", From c9aa20624f27a81cf59cca02fa4c96f4758cbb02 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 23 Jul 2023 02:12:30 +0300 Subject: [PATCH 07/16] #2283: removed unused import --- .../src/test/java/org/eolang/maven/BinarizeParseMojoTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java index 883955d7ce..572aff8429 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/BinarizeParseMojoTest.java @@ -24,7 +24,6 @@ package org.eolang.maven; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Map; import org.cactoos.text.TextOf; import org.eolang.jucs.ClasspathSource; From cd9818b3dc4ff50b2bb5e10f9f98de8344ce353f Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 23 Jul 2023 02:13:18 +0300 Subject: [PATCH 08/16] #2283: Updated to new signature of rust inserts --- .../src/test/java/org/eolang/maven/rust/NativeTest.java | 2 +- .../src/test/java/org/eolang/maven/rust/PrimeModuleTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/rust/NativeTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/rust/NativeTest.java index c451847d44..771ddd2e37 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/rust/NativeTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/rust/NativeTest.java @@ -52,7 +52,7 @@ void savesCorrectly(@TempDir final Path temp) throws Exception { "package mypackage;", "import EOorg.EOeolang.EOrust;", "public class name {", - " public static native int name", + " public static native byte[] name", " (final EOrust eo);", "}" ) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/rust/PrimeModuleTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/rust/PrimeModuleTest.java index 8a39b1134b..9355f12673 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/rust/PrimeModuleTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/rust/PrimeModuleTest.java @@ -49,7 +49,7 @@ void savesCorrectly(@TempDir final Path temp) throws Exception { ).asString(), Matchers.stringContainsInOrder( String.format("Java_EOrust_natives_%s_%s", method, method), - "<'local> (env: JNIEnv<'local>, _class: JClass<'local>, universe: JObject<'local>) -> jint" + "<'local> (env: JNIEnv<'local>, _class: JClass<'local>, universe: JObject<'local>) -> JByteArray" ) ); } From a373e998856c8f6f7f27a98c4c23bbca329baac3 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 23 Jul 2023 02:31:56 +0300 Subject: [PATCH 09/16] #2283: Added todo --- .../src/main/java/EOorg/EOeolang/EOrust.java | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java index aa82c45e83..7dd74dd962 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java @@ -130,9 +130,10 @@ public EOrust(final Phi sigma) { "EOrust.natives.%s", name ) - ).getDeclaredMethod(name, new Class[]{EOrust.class}); - byte[] res = (byte[]) method.invoke(null, this); - return EOrust.translate(res); + ).getDeclaredMethod(name, EOrust.class); + return EOrust.translate( + (byte[]) method.invoke(null, this) + ); } ) ); @@ -230,6 +231,17 @@ private static ConcurrentHashMap load(final String src) throws I } } + /** + * Translates byte message from rust side to Phi object. + * @param message Message that native method returns. + * @return Phi object. + * @todo #2283:45min Implement handling of vertex returning. + * It must convert message array from 1 to last byte to the int + * and return eo object with corresponding vertex then. + * @todo #2283:45min Implement handling of String returning. + * It must convert message array from 1 to last byte to the String + * and return eo object with converted String Data. + */ private static Phi translate(final byte[] message) { final byte determinant = message[0]; final byte[] content = Arrays.copyOfRange(message, 1, message.length); @@ -240,16 +252,16 @@ private static Phi translate(final byte[] message) { "Returning vertex is not implemented yet" ); case 1: - ByteBuffer byteBuffer = ByteBuffer.allocate(Double.BYTES); - byteBuffer.put(content); - byteBuffer.flip(); - ret = new Data.ToPhi(byteBuffer.getDouble()); + ByteBuffer buffer = ByteBuffer.allocate(Double.BYTES); + buffer.put(content); + buffer.flip(); + ret = new Data.ToPhi(buffer.getDouble()); break; case 2: - byteBuffer = ByteBuffer.allocate(Long.BYTES); - byteBuffer.put(content); - byteBuffer.flip(); - ret = new Data.ToPhi(byteBuffer.getLong()); + buffer = ByteBuffer.allocate(Long.BYTES); + buffer.put(content); + buffer.flip(); + ret = new Data.ToPhi(buffer.getLong()); break; default: throw new ExFailure( From aa516d4f17ba8b51e3beed724ae9fa49320418b4 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 23 Jul 2023 02:32:18 +0300 Subject: [PATCH 10/16] #2283: marked unused field --- eo-runtime/src/main/rust/eo_env/src/eo_env.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/eo-runtime/src/main/rust/eo_env/src/eo_env.rs b/eo-runtime/src/main/rust/eo_env/src/eo_env.rs index 4057454f2f..3c6793a980 100644 --- a/eo-runtime/src/main/rust/eo_env/src/eo_env.rs +++ b/eo-runtime/src/main/rust/eo_env/src/eo_env.rs @@ -26,18 +26,17 @@ pub mod eo_enum; use jni::JNIEnv; use jni::objects::{JClass, JObject, JValue}; -#[allow(dead_code)] pub struct EOEnv<'local> { pub java_env: JNIEnv<'local>, - java_class: JClass<'local>, + _java_class: JClass<'local>, java_obj: JObject<'local> } impl<'local> EOEnv<'_> { - pub fn new(java_env: JNIEnv<'local>, java_class: JClass<'local>, java_obj: JObject<'local>) -> EOEnv<'local> { + pub fn new(java_env: JNIEnv<'local>, _java_class: JClass<'local>, java_obj: JObject<'local>) -> EOEnv<'local> { EOEnv { java_env, - java_class, + _java_class, java_obj } } From b661c499ef790d01ee23d174221b4f840f61ac14 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 23 Jul 2023 15:05:28 +0300 Subject: [PATCH 11/16] #2283: Added tests to check translating correctness. --- .../src/test/eo/org/eolang/rust-tests.eo | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) 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 66717b0df4..469990bfd0 100644 --- a/eo-runtime/src/test/eo/org/eolang/rust-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/rust-tests.eo @@ -26,7 +26,7 @@ +package org.eolang +version 0.0.0 -[] > rust-returns-int +[] > rust-returns-positive-int QQ.rust > r """ use eo_env::EOEnv; @@ -35,8 +35,7 @@ pub fn foo(_env: &mut EOEnv) -> EO { println!("Hello world from rust"); - let x = 4.0_f32; - EOInt(x.sqrt() as i64) + EOInt(2) } """ * @@ -45,7 +44,25 @@ $.equal-to 2 -[] > rust-returns-doable +[] > rust-returns-negative-int + QQ.rust > r + """ + use eo_env::EOEnv; + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOInt}; + + pub fn foo(_env: &mut EOEnv) -> EO { + println!("Hello world from rust"); + EOInt(-10) + } + """ + * + assert-that > @ + r + $.equal-to + -10 + +[] > rust-returns-positive-doable QQ.rust > r """ use eo_env::EOEnv; @@ -53,16 +70,31 @@ use eo_env::eo_enum::EO::{EOFloat}; pub fn foo(_env: &mut EOEnv) -> EO { - println!("Hello world from EOFloat"); - let x = 4.0_f64; - EOFloat(x.sqrt()) + EOFloat(1.23456789) } """ * assert-that > @ r $.equal-to - 2.0 + 1.23456789 + +[] > rust-returns-negative-doable + QQ.rust > r + """ + use eo_env::EOEnv; + use eo_env::eo_enum::EO; + use eo_env::eo_enum::EO::{EOFloat}; + + pub fn foo(_env: &mut EOEnv) -> EO { + EOFloat(-1.23456789) + } + """ + * + assert-that > @ + r + $.equal-to + -1.23456789 [] > rust-find-returns-int QQ.rust > r @@ -72,8 +104,7 @@ use eo_env::eo_enum::EO::{EOInt}; pub fn foo(env: &mut EOEnv) -> EO { - env.find("^"); - EOInt(0 as i64) + EOInt(env.find("^").into()) } """ * From 91c34694b657af49b375e7a92bab940db22d488d Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 23 Jul 2023 15:06:10 +0300 Subject: [PATCH 12/16] #2283: Added @todo about Universe implementation --- eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java index 7dd74dd962..619fbed60b 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java @@ -58,6 +58,10 @@ * @checkstyle MethodNameCheck (100 lines) * @checkstyle LineLengthCheck (100 lines) * @checkstyle TypeNameCheck (5 lines) + * @todo #2283: 90min Create Universe class. now its functionality is + * assigned to "EORust", which is why it is overcomplicated. "Universe" + * should perform a model of interaction with "eo" objects through + * methods "find", "put", "copy", "dataize" and "bind". */ @XmirObject(oname = "rust") public class EOrust extends PhDefault { From c43aabd8aed68ba398b4354c093e9685308463a0 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 23 Jul 2023 15:31:12 +0300 Subject: [PATCH 13/16] #2283: Added lifetime parameter --- .../src/main/java/org/eolang/maven/rust/PrimeModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java b/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java index 156c94ba76..63a566547b 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/rust/PrimeModule.java @@ -47,7 +47,7 @@ public PrimeModule(final String method, final String file) { "#[no_mangle]", "pub extern \"system\" fn", String.format("Java_EOrust_natives_%s_%s", method, method), - "<'local> (env: JNIEnv<'local>, _class: JClass<'local>, universe: JObject<'local>) -> JByteArray", + "<'local> (env: JNIEnv<'local>, _class: JClass<'local>, universe: JObject<'local>) -> JByteArray<'local>", "{ let mut eo_env = EOEnv::new(env, _class, universe); ", "let arr = foo(&mut eo_env).eo2vec();", "eo_env.java_env.byte_array_from_slice(&arr.as_slice()).unwrap() }" From ed11b7a634e78f24bdc8d47054dd2173a4f0e058 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 23 Jul 2023 15:31:26 +0300 Subject: [PATCH 14/16] #2283: Edited todo description --- eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java index 619fbed60b..8da34c372c 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java @@ -58,7 +58,7 @@ * @checkstyle MethodNameCheck (100 lines) * @checkstyle LineLengthCheck (100 lines) * @checkstyle TypeNameCheck (5 lines) - * @todo #2283: 90min Create Universe class. now its functionality is + * @todo #2283:90min Create Universe class. now its functionality is * assigned to "EORust", which is why it is overcomplicated. "Universe" * should perform a model of interaction with "eo" objects through * methods "find", "put", "copy", "dataize" and "bind". From 869893aedf218ed5709a9f8e2ea78343a54f1aea Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 24 Jul 2023 12:19:21 +0300 Subject: [PATCH 15/16] #2283: typo in todo description --- eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java index 8da34c372c..e89b83d37b 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java @@ -58,7 +58,7 @@ * @checkstyle MethodNameCheck (100 lines) * @checkstyle LineLengthCheck (100 lines) * @checkstyle TypeNameCheck (5 lines) - * @todo #2283:90min Create Universe class. now its functionality is + * @todo #2283:90min Create Universe class. Now its functionality is * assigned to "EORust", which is why it is overcomplicated. "Universe" * should perform a model of interaction with "eo" objects through * methods "find", "put", "copy", "dataize" and "bind". From 89612a4601af7c1f25bf252b936d26f330e738dc Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 24 Jul 2023 12:51:49 +0300 Subject: [PATCH 16/16] #2283: Added return type validating --- eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java index e89b83d37b..66ad9fd061 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java @@ -135,6 +135,14 @@ public EOrust(final Phi sigma) { name ) ).getDeclaredMethod(name, EOrust.class); + if (method.getReturnType() != byte[].class) { + throw new ExFailure( + "Return type of %s is %s, required %s", + method, + method.getReturnType(), + byte[].class + ); + } return EOrust.translate( (byte[]) method.invoke(null, this) );