Skip to content

Commit

Permalink
objectionary#2032: EOrust generating
Browse files Browse the repository at this point in the history
  • Loading branch information
levBagryansky committed Jun 16, 2023
1 parent 0d1c398 commit 0cf8b5a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ public void save(final Footprint footprint) throws IOException {
*/
private String transform() {
final String signature = String.format(
"#[no_mangle]%spub extern \"system\" fn Java_EOorg_EOeolang_EOrust_%s(_env: JNIEnv, _class: JClass,) -> jint {",
"#[no_mangle]%spub extern \"system\" fn Java_EOrust_EOnatives_%s_%s(_env: JNIEnv, _class: JClass,) -> jint {",
System.lineSeparator(),
this.name,
this.name
);
return String.join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void transformsCorrectly(@TempDir final Path temp) throws Exception {
"use jni::sys::{jint};",
"use jni::JNIEnv;",
"#[no_mangle]",
"pub extern \"system\" fn Java_EOorg_EOeolang_EOrust_simple(_env: JNIEnv, _class: JClass,) -> jint {"
"pub extern \"system\" fn Java_EOrust_EOnatives_simple_simple(_env: JNIEnv, _class: JClass,) -> jint {"
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion eo-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ SOFTWARE.
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
<!-- version from parent POM -->
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.llorllale</groupId>
Expand Down
60 changes: 59 additions & 1 deletion eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,21 @@
*/
package EOorg.EOeolang;

import EOrust.EOnatives.xhomextardis3xeoxeoxruntimextargetxeoxtest0;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.SystemUtils;
import org.cactoos.text.TextOf;
import org.eolang.AtComposite;
import org.eolang.AtFree;
import org.eolang.Data;
Expand All @@ -50,7 +62,16 @@
*/
@XmirObject(oname = "rust")
public class EOrust extends PhDefault {
private static ConcurrentHashMap<String, String> names;
static {
try {
names = load("target/eo-test/names");
} catch (IOException e) {
throw new RuntimeException(
"Cannot read the file target/eo-test/names",
e
);
}
final String lib;
if (SystemUtils.IS_OS_WINDOWS) {
lib = "common.dll";
Expand Down Expand Up @@ -91,8 +112,45 @@ public EOrust(final Phi sigma) {
new AtComposite(
this,
rho ->
new Data.ToPhi(1234L)
{
System.out.println();
return new Data.ToPhi(
(long) xhomextardis3xeoxeoxruntimextargetxeoxtest0.xhomextardis3xeoxeoxruntimextargetxeoxtest0()
);
}
)
);
}
private static ConcurrentHashMap<String, String> load(final String src) throws IOException {
System.out.println(Paths.get(src).toAbsolutePath());
try (ObjectInputStream map = new ObjectInputStream(
new ByteArrayInputStream(
Base64.getDecoder().decode(
new TextOf(Paths.get(src)).asString()
)
)
)) {
final Object result = map.readObject();
if (result.getClass() != ConcurrentHashMap.class) {
throw new ClassCastException(
String.format(
"Object inside %s has wrong class %s",
src,
result.getClass()
)
);
}
return (ConcurrentHashMap<String, String>) result;
} catch (final ClassNotFoundException exc) {
throw new IllegalArgumentException(
String.format(
"File %s contains invalid data",
src
),
exc
);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 0cf8b5a

Please sign in to comment.