Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Aug 6, 2024
2 parents 88db63b + 87c61af commit bef64d3
Show file tree
Hide file tree
Showing 19 changed files with 939 additions and 29 deletions.
15 changes: 15 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
# package name contains capital letter and such names are conventional.
---
exclude_paths:
- "eo-runtime/src/main/java/EOorg/EOeolang/EOio/EOconsole$EOread$EOread_bytes.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOio/EOconsole$EOwrite$EOwritten_bytes.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOio/EOconsoleTest.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOsys/EOuname$EOφ.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOsys/package-info.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOnumberTest.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/package-info.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/DispatchedNativeMethod.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/DispatchedUnixSyscall.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOsys/EOposixTest.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOsys/EOosTest.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/DispatchedNativeDefault.java"
- "eo-runtime/src/test/java/EOorg/EOeolang/EOsys/DispatchedUnixSyscallTest.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/EOposix.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOsys/CStdLib.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOdir$EOmade$EOmkdir.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOdir$EOtmpfile$EOtouch.java"
- "eo-runtime/src/main/java/EOorg/EOeolang/EOfs/EOdir$EOwalk.java"
Expand Down
3 changes: 2 additions & 1 deletion eo-maven-plugin/src/main/java/org/eolang/maven/Central.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public void accept(final Dependency dep, final Path path) {
MojoExecutor.executeMojo(
MojoExecutor.plugin(
MojoExecutor.groupId("org.apache.maven.plugins"),
MojoExecutor.artifactId("maven-dependency-plugin")
MojoExecutor.artifactId("maven-dependency-plugin"),
MojoExecutor.version("3.6.1")
),
MojoExecutor.goal("unpack"),
MojoExecutor.configuration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.eolang.maven;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
Expand All @@ -32,7 +31,6 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.cactoos.list.ListOf;

/**
Expand All @@ -54,18 +52,6 @@ public final class DownloadDepsMojo extends SafeMojo {
new DepFunc("net.java.dev.jna", "jna", "5.14.0")
);

/**
* Directory where classes are stored in target.
* @checkstyle MemberNameCheck (8 lines)
*/
@Parameter(
defaultValue = "${project.build.directory}/classes",
readonly = true,
required = true
)
@SuppressWarnings("PMD.UnusedPrivateField")
private File classesDir;

/**
* The central.
*/
Expand Down
12 changes: 12 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ abstract class SafeMojo extends AbstractMojo {
@Component
protected BuildPluginManager manager;

/**
* Directory where classes are stored in target.
* @checkstyle VisibilityModifierCheck (10 lines)
* @checkstyle MemberNameCheck (8 lines)
*/
@Parameter(
defaultValue = "${project.build.directory}/classes",
readonly = true,
required = true
)
protected File classesDir;

/**
* File with foreign "tojos".
* @checkstyle VisibilityModifierCheck (10 lines)
Expand Down
2 changes: 2 additions & 0 deletions eo-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ SOFTWARE.
<id>compile</id>
<goals>
<goal>register</goal>
<goal>deps</goal>
<goal>assemble</goal>
<goal>verify</goal>
<goal>transpile</goal>
Expand All @@ -213,6 +214,7 @@ SOFTWARE.
<phase>generate-test-sources</phase>
<goals>
<goal>register</goal>
<goal>deps</goal>
<goal>assemble</goal>
<goal>verify</goal>
<goal>transpile</goal>
Expand Down
32 changes: 32 additions & 0 deletions eo-runtime/src/main/eo/org/eolang/sys/posix.eo
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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.

+architect [email protected]
+home https://github.com/objectionary/eo
+package org.eolang.sys
+rt jvm org.eolang:eo-runtime:0.0.0
+rt node eo2js-runtime:0.0.0
+version 0.0.0

# Makes a Unix syscall by name with POSIX interface.
# See https://filippo.io/linux-syscall-table/
[name args] > posix /int
69 changes: 69 additions & 0 deletions eo-runtime/src/main/java/EOorg/EOeolang/EOsys/CStdLib.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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)
*/
package EOorg.EOeolang.EOsys;

import com.sun.jna.Library;
import com.sun.jna.Native;

/**
* C standard library with unix syscalls.
* @since 0.40
*/
public interface CStdLib extends Library {

/**
* C STDLIB instance.
*/
CStdLib CSTDLIB = Native.load("c", CStdLib.class);

/**
* The "getpid" syscall.
*
* @return Process ID.
*/
int getpid();

/**
* The "write" syscall.
*
* @param descriptor File descriptor.
* @param buf Buffer.
* @param size Number of bytes to be written.
* @return Number of bytes was written.
*/
int write(Long descriptor, String buf, Long size);

/**
* The "read" syscall.
*
* @param descriptor File descriptor.
* @param buf Buffer.
* @param size Number of bytes to be read.
* @return Number of bytes was read.
*/
int read(Long descriptor, byte[] buf, Long size);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* 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)
*/
package EOorg.EOeolang.EOsys;

import com.sun.jna.Library;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.eolang.Dataized;
import org.eolang.Phi;

/**
* Default native call that uses {@link Library} and can be dispatched by name.
*
* @since 0.40
*/
public final class DispatchedNativeDefault implements DispatchedNativeMethod {
/**
* Native library.
*/
private final Library lib;

/**
* Dispatched method.
*/
private final Method method;

/**
* Ctor.
* @param lib Library.
* @param method Method.
*/
DispatchedNativeDefault(final Library lib, final Method method) {
this.lib = lib;
this.method = method;
}

/**
* Ctor.
* @param lib Library.
* @param name Method name.
*/
DispatchedNativeDefault(final Library lib, final String name) {
this(lib, DispatchedNativeDefault.findMethodUnsafe(name, lib));
}

@Override
public int call(final Phi... params) {
try {
return (int) this.method.invoke(this.lib, this.prepareParams(params));
} catch (final InvocationTargetException | IllegalAccessException ex) {
throw new IllegalStateException(
String.format(
"Problem while calling syscall with name \"%s\"",
this.method.getName()
),
ex
);
}
}

/**
* Prepares {@link Phi} parameters to be passed to native method.
* @param params Parameters {@link Phi}.
* @return Prepared parameters.
*/
private Object[] prepareParams(final Phi... params) {
final Object[] prepared = new Object[params.length];
final Class<?>[] types = this.method.getParameterTypes();
for (int iter = 0; iter < params.length; ++iter) {
prepared[iter] = new Dataized(params[iter]).take(types[iter]);
}
return prepared;
}

/**
* Finds method by name in native library.
* @param name Method name.
* @param lib Native library.
* @return Method.
* @throws NoSuchMethodException if method not found.
*/
private static Method findMethod(final String name, final Library lib)
throws NoSuchMethodException {
for (final Method method : lib.getClass().getMethods()) {
if (method.getName().equals(name)) {
return method;
}
}
throw new NoSuchMethodException(
String.format(
"Can't find syscall with name %s in class %s",
name,
lib.getClass().getName()
)
);
}

/**
* Finds method by name in native library.
* @param name Method name.
* @param lib Native library.
* @return Method.
*/
private static Method findMethodUnsafe(final String name, final Library lib) {
try {
return DispatchedNativeDefault.findMethod(name, lib);
} catch (final NoSuchMethodException ex) {
throw new IllegalArgumentException(
String.format("Can't find syscall with name \"%s\"", name),
ex
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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)
*/
package EOorg.EOeolang.EOsys;

import org.eolang.Phi;

/**
* Native method that can be called with EO objects ({@link Phi}) as arguments.
*
* @since 0.40
*/
public interface DispatchedNativeMethod {
/**
* Makes native method call.
*
* @param params Native methods parameters.
* @return Methods return code.
*/
int call(Phi... params);
}
Loading

0 comments on commit bef64d3

Please sign in to comment.