Skip to content
Draft
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
10 changes: 7 additions & 3 deletions core/pom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
"jruby.test.memory": '3G',
"jruby.compile.memory": '2G',

"create.sources.jar": false)
"create.sources.jar": false,

"prism.parser.version": '0.0.5-SNAPSHOT',
)

IO.foreach(File.join(basedir, '..', 'default.build.properties')) do |line|
line.chomp!
Expand Down Expand Up @@ -80,10 +83,11 @@

jar 'org.crac:crac:1.5.0'

jar 'org.jruby:jruby-prism:2.0.4'

jar 'ch.randelshofer:fastdoubleparser:2.0.1'

jar 'org.ruby-lang:prism-parser-api:${prism.parser.version}'
jar 'org.ruby-lang:prism-parser-wasm:${prism.parser.version}'

plugin_management do
plugin('org.eclipse.m2e:lifecycle-mapping:1.0.0',
lifecycleMappingMetadata: {
Expand Down
16 changes: 11 additions & 5 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ DO NOT MODIFY - GENERATED CODE
<parser.dir>core/src/main/java/org/jruby/parser</parser.dir>
<polyglot.dump.pom>pom.xml</polyglot.dump.pom>
<polyglot.dump.readonly>true</polyglot.dump.readonly>
<prism.parser.version>0.0.5-SNAPSHOT</prism.parser.version>
<rails.dir>${test.dir}/rails</rails.dir>
<rails.git.repo>git://github.com/rails/rails.git</rails.git.repo>
<rake.args></rake.args>
Expand Down Expand Up @@ -237,16 +238,21 @@ DO NOT MODIFY - GENERATED CODE
<artifactId>crac</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-prism</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>ch.randelshofer</groupId>
<artifactId>fastdoubleparser</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.ruby-lang</groupId>
<artifactId>prism-parser-api</artifactId>
<version>${prism.parser.version}</version>
</dependency>
<dependency>
<groupId>org.ruby-lang</groupId>
<artifactId>prism-parser-wasm</artifactId>
<version>${prism.parser.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>package</defaultGoal>
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/parser/ParserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.jruby.ir.persistence.util.IRFileExpert;
import org.jruby.management.ParserStats;
import org.jruby.platform.Platform;
import org.jruby.prism.ParserProviderPrism;
import org.jruby.runtime.Block;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
Expand Down Expand Up @@ -48,7 +49,8 @@ public ParserManager(Ruby runtime) {
this.runtime = runtime;
ParserProvider provider;
try {
provider = ParserServiceLoader.provider(Options.PARSER_PRISM.load() || Options.PARSER_WASM.load());
boolean loadPrism = Options.PARSER_PRISM.load() || Options.PARSER_WASM.load();
provider = loadPrism ? new ParserProviderPrism() : new ParserProviderDefault();
provider.initialize(runtime.getJRubyHome() + "/lib/libprism." + getLibraryExtension());
} catch (UnsatisfiedLinkError e) {
System.err.println("warning: Problem loading requested parser. Falling back to default parser.\nOriginal error message: " + e.getMessage());
Expand Down
31 changes: 0 additions & 31 deletions core/src/main/java/org/jruby/parser/ParserServiceLoader.java

This file was deleted.

46 changes: 46 additions & 0 deletions core/src/main/java/org/jruby/prism/ParserProviderPrism.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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.builder.IRBuilderFactoryPrism;
import org.jruby.prism.parser.ParserBindingPrism;
import org.jruby.prism.parser.ParserPrismNative;
import org.jruby.prism.parser.ParserPrismWasm;

import java.io.File;

public class ParserProviderPrism implements ParserProvider {
private static ParserBindingPrism prismLibrary;

public void initialize(String path) {
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;
}
}

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

return new ParserPrismNative(runtime, prismLibrary);
}

public IRBuilderFactory getBuilderFactory() {
return new IRBuilderFactoryPrism();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.jruby.prism.builder;

import org.jcodings.Encoding;
import org.jruby.ParseResult;
import org.jruby.ir.IRManager;
import org.jruby.ir.IRScope;
import org.jruby.ir.builder.IRBuilder;
import org.jruby.ir.builder.IRBuilderFactory;

public class IRBuilderFactoryPrism extends IRBuilderFactory {
public IRBuilder newIRBuilder(IRManager manager, IRScope newScope, IRBuilder parent, Encoding encoding) {
return new IRBuilderPrism(manager, newScope, parent, null, encoding);
}

// For BEGIN processing
public IRBuilder newIRBuilder(IRManager manager, IRScope newScope, IRBuilder parent, IRBuilder variableBuilder, Encoding encoding) {
return new IRBuilderPrism(manager, newScope, parent, variableBuilder, encoding);
}

public IRBuilder topIRBuilder(IRManager manager, IRScope newScope, ParseResult rootNode) {
return new IRBuilderPrism(manager, newScope, null, null, rootNode.getEncoding());
}
}
Loading
Loading