Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 56 additions & 44 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.jruby</groupId>
<artifactId>jruby-prism</artifactId>
<packaging>jar</packaging>
<version>1.5.0</version>
<version>2.0.0-SNAPSHOT</version>
<name>jruby-prism</name>
<description>
Java portion of JRuby Prism parser support.
Expand Down Expand Up @@ -66,12 +66,12 @@
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-base</artifactId>
<version>10.0.0.0-SNAPSHOT</version>
<version>10.0.2.0</version>
</dependency>
<dependency>
<groupId>com.prism</groupId>
<artifactId>java-prism</artifactId>
<version>999-SNAPSHOT</version>
<groupId>org.jruby</groupId>
<artifactId>chicory-prism</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -116,45 +116,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<doclint>none</doclint>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
Expand Down Expand Up @@ -210,5 +171,56 @@
</plugins>
</build>
</profile>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<gpgArguments>
<gpgArgument>--pinentry-mode</gpgArgument>
<gpgArgument>loopback</gpgArgument>
</gpgArguments>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<doclint>none</doclint>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
34 changes: 23 additions & 11 deletions src/main/java/org/jruby/prism/ParserProviderPrism.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
package org.jruby.prism;

import jnr.ffi.LibraryLoader;
import org.jruby.Ruby;
import org.jruby.ir.builder.IRBuilderFactory;
import org.jruby.parser.Parser;
import org.jruby.parser.ParserManager;
import org.jruby.parser.ParserProvider;
import org.jruby.prism.parser.ParserPrism;
import org.jruby.prism.parser.ParserBindingPrism;
import org.jruby.prism.builder.IRBuilderFactoryPrism;
import org.jruby.prism.parser.ParserBindingPrism;
import org.jruby.prism.parser.ParserPrismNative;
import org.jruby.prism.parser.ParserPrismWasm;

import jnr.ffi.LibraryLoader;
import java.io.File;

public class ParserProviderPrism implements ParserProvider {
private static ParserBindingPrism prismLibrary;

public void initialize(String path) {
if (prismLibrary != null) {
System.out.println("Prism already initialized");
return;
if (new File(path).exists()) {
if (prismLibrary != null) {
System.out.println("Prism already initialized");
return;
}
prismLibrary = LibraryLoader.create(ParserBindingPrism.class).load(path);
// We do something extra here as a side-effect which is how we get an UnsatisfiedLinkError
// If the library didn't in fact find the .so or has other loading problems.
ParserBindingPrism.Buffer buffer = new ParserBindingPrism.Buffer(jnr.ffi.Runtime.getRuntime(prismLibrary));
} else {
prismLibrary = null;
}
prismLibrary = LibraryLoader.create(ParserBindingPrism.class).load(path);
// We do something extra here as a side-effect which is how we get an UnsatisfiedLinkError
// If the library didn't in fact find the .so or has other loading problems.
ParserBindingPrism.Buffer buffer = new ParserBindingPrism.Buffer(jnr.ffi.Runtime.getRuntime(prismLibrary));
}

public Parser getParser(Ruby runtime) {
return new ParserPrism(runtime, prismLibrary);
if (ParserManager.PARSER_WASM || prismLibrary == null) {
// uninitialized dynamic lib or wasm requested
return new ParserPrismWasm(runtime);
}

return new ParserPrismNative(runtime, prismLibrary);
}

public IRBuilderFactory getBuilderFactory() {
Expand Down
Loading