Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jul 21, 2023
2 parents a335afe + 0d92128 commit 494408a
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 2 deletions.
38 changes: 38 additions & 0 deletions eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,44 @@ public int find(final String name) {
return 0;
}

/**
* Puts data to eo object by vertex.
* @param vertex Vertex off object.
* @param bytes Data to put.
* @todo #2237:45min Implement the "put" method. Now it does
* nothing and created to check rust2java interaction. This
* method relates to building a new eo object in rust insert.
* @checkstyle NonStaticMethodCheck (4 lines)
*/
public void put(final int vertex, final byte[] bytes) {
}

/**
* Binds child to parent.
* @param parent Vertex of the parent eo object.
* @param child Vertex of the child eo object.
* @param att Name of attribute.
* @todo #2237:45min Implement the "bind" method. It has tp
* put data to eo object by vertex. It does nothing now
* but it is called from rust via jni call_method function.
* @checkstyle NonStaticMethodCheck (4 lines)
*/
public void bind(final int parent, final int child, final String att) {
}

/**
* Copies the eo object.
* @param vertex Vertex of object to copy.
* @return Vertex of the copy.
* @todo #2237:45min Implement the "copy" method. Now it does
* nothing and created to check rust2java interaction. This
* method relates to building a new eo object in rust insert.
* @checkstyle NonStaticMethodCheck (4 lines)
*/
public int copy(final int vertex) {
return vertex;
}

/**
* Loads names map.
* @param src Where to load from.
Expand Down
57 changes: 57 additions & 0 deletions eo-runtime/src/main/rust/eo_env/src/eo_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,61 @@ impl<'local> EOEnv<'_> {
.i()
.unwrap()
}

pub fn put(&mut self, v: u32, bytes: &[u8]) -> Option<()> {
let jbytes = JObject::from(self.java_env.byte_array_from_slice(bytes).unwrap());
match self.java_env
.call_method(
&self.java_obj,
"put",
"(I[B)V",
&[JValue::Int(v as i32), JValue::from(&jbytes)]
)
.unwrap()
.v() {
Ok(()) => Some(()),
_ => None
}
}

pub fn bind(&mut self, v1: u32, v2: u32, name: &str) -> Option<()> {
match self.java_env
.call_method(
&self.java_obj,
"bind",
"(IILjava/lang/String;)V",
&[
JValue::Int(v1 as i32),
JValue::Int(v2 as i32),
JValue::from(&JObject::from(self.java_env.new_string(name).unwrap()))
]
).unwrap().v() {
Ok(()) => Some(()),
_ => None,
}
}

pub fn copy(&mut self, v: u32) -> Option<u32> {
match self.java_env
.call_method(
&self.java_obj,
"copy",
"(I)I",
&[
JValue::Int(v as i32),
]
).unwrap().i() {
Ok(ret) => Some(ret.try_into().unwrap()),
_ => None,
}
}

/*
* @todo #2237:60min Implement "dataize" method. It must
* call java dataizing method and get byte array from it.
* Then it have to return byte array as a result of dataization.
*/
pub fn dataize(&mut self, v: u32) -> Option<&[u32]> {
Some(&[0x0])
}
}
74 changes: 72 additions & 2 deletions eo-runtime/src/test/eo/org/eolang/rust-tests.eo
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,81 @@
use eo_env::EOEnv;

pub fn foo(mut env: EOEnv<'_>) -> i32 {
env.find("^")
env.find("^");
0
}
"""
*
assert-that > @
r
$.equal-to
0
0

[] > rust-put-not-fails
QQ.rust > r
"""
use eo_env::EOEnv;

pub fn foo(mut env: EOEnv<'_>) -> i32 {
env.put(3, &[0x00, 0x1a, 0xEE, 0xf, 0xf3]).unwrap();
0
}
"""
*
assert-that > @
r
$.not
$.less-than
0

[] > rust-bind-not-fails
QQ.rust > insert
"""
use eo_env::EOEnv;
pub fn foo(mut env: EOEnv<'_>) -> i32 {
let v1 = env.find("a") as u32;
let v2 = env.find("b") as u32;
env.bind(v1 , v2, "my-att");
return v1 as i32;
}
"""
*
assert-that > @
insert
$.not
$.less-than
0

[] > rust-copy-not-fails
QQ.rust > copy
"""
use eo_env::EOEnv;
pub fn foo(mut env: EOEnv<'_>) -> i32 {
let v = env.find("a") as u32;
let copy = env.copy(v).unwrap();
copy as i32
}
"""
*
assert-that > @
copy
$.not
$.less-than
0

[] > rust-dataize-not-fails
QQ.rust > dataized
"""
use eo_env::EOEnv;
pub fn foo(mut env: EOEnv<'_>) -> i32 {
let v = env.find("a") as u32;
let bytes = env.dataize(v).unwrap();
v as i32
}
"""
*
assert-that > @
dataized
$.not
$.less-than
0

4 comments on commit 494408a

@0pdd
Copy link

@0pdd 0pdd commented on 494408a Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2237-4d097292 discovered in eo-runtime/src/main/rust/eo_env/src/eo_env.rs) and submitted as #2292. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 494408a Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2237-e2051aed discovered in eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java) and submitted as #2293. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 494408a Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2237-37351366 discovered in eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java) and submitted as #2294. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on 494408a Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 2237-a32cd01f discovered in eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java) and submitted as #2295. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.