Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2313 universe #2316

Merged
merged 10 commits into from
Aug 13, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Native(final String name, final String pack) {
"package %s;",
pack
),
"import EOorg.EOeolang.EOrust;",
"import org.eolang.Universe;",
String.format(
"public class %s {",
name
Expand All @@ -55,7 +55,7 @@ public Native(final String name, final String pack) {
" public static native byte[] %s",
name
),
" (final EOrust eo);",
" (final Universe universe);",
"}"
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ void savesCorrectly(@TempDir final Path temp) throws Exception {
).asString(),
Matchers.stringContainsInOrder(
"package mypackage;",
"import EOorg.EOeolang.EOrust;",
"import org.eolang.Universe;",
"public class name {",
" public static native byte[] name",
" (final EOrust eo);",
" (final Universe universe);",
"}"
)
);
Expand Down
57 changes: 3 additions & 54 deletions eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eolang.ExFailure;
import org.eolang.PhDefault;
import org.eolang.Phi;
import org.eolang.Universe;
import org.eolang.XmirObject;

/**
Expand Down Expand Up @@ -134,7 +135,7 @@ public EOrust(final Phi sigma) {
"EOrust.natives.%s",
name
)
).getDeclaredMethod(name, EOrust.class);
).getDeclaredMethod(name, Universe.class);
if (method.getReturnType() != byte[].class) {
throw new ExFailure(
"Return type of %s is %s, required %s",
Expand All @@ -144,65 +145,13 @@ public EOrust(final Phi sigma) {
);
}
return EOrust.translate(
(byte[]) method.invoke(null, this)
(byte[]) method.invoke(null, new Universe(rho))
);
}
)
);
}

/**
* Finds vertex of eo object by its location.
* @param name Relative location of the object to find.
* @return Vertex of the object to find.
* @todo #2237:45min Implement finding by location.
* Name argument is something like "^.^.some-obj".
* This string must be splitted by '.' and then for
* every part it is necessary to call this.attr().get()
* @checkstyle NonStaticMethodCheck (4 lines)
*/
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
3 changes: 3 additions & 0 deletions eo-runtime/src/main/java/org/eolang/Phi.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* name would be "Object", but it's already occupied by Java. That's why
* we call it Phi.
*
* It is guaranteed that the hash codes of different Phi are different,
* and equal to the vertex.
*
* @since 0.1
*/
public interface Phi extends Term {
Expand Down
118 changes: 118 additions & 0 deletions eo-runtime/src/main/java/org/eolang/Universe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* 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.
*/
package org.eolang;

/**
* Class to manipulate eo objects within "Universe" paradigm.
* @since 0.30
*/
public class Universe {

/**
* Connector to eo objects.
*/
private final Phi connector;
levBagryansky marked this conversation as resolved.
Show resolved Hide resolved

/**
* Ctor.
* @param connector Connector.
*/
public Universe(final Phi connector) {
this.connector = connector;
}

/**
* Ctor.
*/
public Universe() {
this(Phi.Φ);
}

/**
* Finds vertex of eo object by its location.
* @param name Relative location of the object to find.
* @return Vertex of the object to find.
* @todo #2237:45min Implement finding by location.
* Name argument is something like "^.^.some-obj".
* This string must be splitted by '.' and then for
* every part it is necessary to call this.attr().get()
* @checkstyle NonStaticMethodCheck (4 lines)
*/
public int find(final String name) {
return this.connector.hashCode();
}

/**
* 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@levBagryansky You need to add something here to avoid style checkers failings

//Empty yet.
}

/**
* 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) {
levBagryansky marked this conversation as resolved.
Show resolved Hide resolved
//Empty yet.
}

/**
* 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;
}

/**
* Dataizes the eo object by vertex and return byte array.
* @param vertex Vertex of eo-object.
* @return Raw data.
* @todo #2313:60min Implement the "dataize" method.
* It should dataize eo object by its vertex.
* This method is going to be called from rust insert
* and should not be static.
*/
public static byte[] dataize(final int vertex) {
return new byte[]{0b1111111};
}
}
Loading