-1

Hi I'm currently implementing my first language using the truffle language framework. I would like to write now some unit test but I get alwaays the same error. Here is the code for a simple addition node:

package truffle.nodes.expression;

import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
import truffle.nodes.util.BinaryNode;

import java.util.logging.Logger;

public abstract class AdditionNode extends BinaryNode {
    private final Logger logger;

    protected AdditionNode(Logger logger) {
        this.logger = logger;
    }

    @Specialization(rewriteOn = ArithmeticException.class)
    protected int addInt(int leftNode, int rightNode) {
        logger.info(() -> "Addition between int:" + leftNode + "+" + rightNode);

        return Math.addExact(leftNode, rightNode);
    }

    @Specialization (replaces = "addInt", rewriteOn = ArithmeticException.class)
    protected long addLong(long leftNode, long rightNode) {
        logger.info(() -> "Addition between long:" + leftNode + "+" + rightNode);

        return Math.addExact(leftNode, rightNode);
    }

    @Specialization (replaces = "addLong")
    protected double addDouble(double leftNode, double rightNode) {
        logger.info(() -> "Addition between double:" + leftNode + "+" + rightNode);

        return leftNode + rightNode;
    }

    @Fallback
    protected Object addUndefined (Object leftNode, Object rightNode) {
        logger.info( () -> "Addition between undefined:" + leftNode + "+" + rightNode);

        return null;
    }
}

This is how a example unit test would like:

@Test
    public void CorrectAddition() {
        ArdenNode ardenNode = AdditionNodeGen.create(logger, new IntNumberNode(logger,12), new IntNumberNode(logger, 24));
        ArdenRootNode rootNode = new ArdenRootNode(ardenNode);
        CallTarget callTarget = rootNode.getCallTarget();

        var result = callTarget.call();

        assertEquals(36,result);
    }

And this is my pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>ardensyntaxgrammar</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <argLine>-Dgraalvm.locatorDisabled=true</argLine> <!--Use this only during developing, for example unit test, not in production-->
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.antlr</groupId>
                <artifactId>antlr4-maven-plugin</artifactId>
                <version>4.13.0</version>
                <configuration>
                    <sourceDirectory>src/main/java/antlr</sourceDirectory>
                    <outputDirectory>src/main/java/antlrgen</outputDirectory>
                    <listener>false</listener>
                    <visitor>true</visitor>
                </configuration>
                <executions>
                    <execution>
                        <id>antlr</id>
                        <goals>
                            <goal>antlr4</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin> <!--This plugin is needed, otherwise truffle-dsl-processor will run into an exception, because it uses an old antlr4 runtime-->
                <!--https://github.com/oracle/graal/issues/5157 -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <annotationProcessorPaths>
                        <annotationProcessorPath>
                            <groupId>org.graalvm.truffle</groupId>
                            <artifactId>truffle-dsl-processor</artifactId>
                            <version>22.3.1</version>
                        </annotationProcessorPath>
                    </annotationProcessorPaths>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.graalvm.truffle</groupId>
                        <artifactId>truffle-dsl-processor</artifactId>
                        <version>22.3.1</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4</artifactId>
            <version>4.13.0</version>
        </dependency>
        <dependency>
            <groupId>org.graalvm.truffle</groupId>
            <artifactId>truffle-api</artifactId>
            <version>22.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>5.9.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

Unfortnately I always get this error:

Exception in thread "main" java.lang.IllegalAccessError: superclass access check failed: class truffle.nodes.util.ArdenNode (in unnamed module @0x57fa26b7) cannot access class com.oracle.truffle.api.nodes.Node (in module org.graalvm.truffle) because module org.graalvm.truffle does not export com.oracle.truffle.api.nodes to unnamed module @0x57fa26b7
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)

Could you please help me?

Tanoyto
  • 1
  • 4
  • I've found this article, but I still wasn't able to fix the problem: https://docs.oracle.com/en/graalvm/enterprise/20/docs/graalvm-as-a-platform/implement-language/#disable-class-path-separation Section Disable Class Path Separation – Tanoyto Aug 08 '23 at 08:34
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – LinFelix Aug 08 '23 at 14:03

0 Answers0