Skip to content

Commit

Permalink
[Truffle] Add support for cross language interop and interface to C e…
Browse files Browse the repository at this point in the history
…xtensions.
  • Loading branch information
chrisseaton committed Apr 20, 2015
1 parent 259ab45 commit 9f228b9
Show file tree
Hide file tree
Showing 42 changed files with 2,317 additions and 50 deletions.
9 changes: 0 additions & 9 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Expand Up @@ -1809,8 +1809,6 @@ public boolean shouldPrecompileAll() {
public static String IR_JIT_PASSES = Options.IR_JIT_PASSES.load();
public static String IR_INLINE_COMPILER_PASSES = Options.IR_INLINE_COMPILER_PASSES.load();

private TruffleHooksStub truffleHooks = null;

public static final boolean COROUTINE_FIBERS = Options.FIBER_COROUTINES.load();

/**
Expand Down Expand Up @@ -1843,13 +1841,6 @@ private static int initGlobalJavaVersion() {
return Opcodes.V1_5;
}
}
public void setTruffleHooks(TruffleHooksStub truffleHooks) {
this.truffleHooks = truffleHooks;
}

public TruffleHooksStub getTruffleHooks() {
return truffleHooks;
}

@Deprecated
public void setSafeLevel(int safeLevel) {
Expand Down
3 changes: 3 additions & 0 deletions spec/truffle/tags/core/string/strip_tags.txt
@@ -0,0 +1,3 @@
fails:String#strip returns a new string with leading and trailing whitespace removed
fails:String#strip returns a copy of self with trailing NULL bytes and whitespace
fails:String#strip taints the result when self is tainted
7 changes: 7 additions & 0 deletions test/truffle/cext/foo/ext/foo/add.c
@@ -0,0 +1,7 @@
#include <ruby.h>

#include "add.h"

VALUE add(VALUE self, VALUE a, VALUE b) {
return INT2NUM(NUM2INT(a) + NUM2INT(b));
}
1 change: 1 addition & 0 deletions test/truffle/cext/foo/ext/foo/add.h
@@ -0,0 +1 @@
VALUE add(VALUE self, VALUE a, VALUE b);
3 changes: 3 additions & 0 deletions test/truffle/cext/foo/ext/foo/extconf.rb
@@ -0,0 +1,3 @@
require 'mkmf'
$CFLAGS << ' -Wall'
create_makefile('foo/foo')
8 changes: 8 additions & 0 deletions test/truffle/cext/foo/ext/foo/foo.c
@@ -0,0 +1,8 @@
#include <ruby.h>

#include "add.h"

void Init_foo() {
VALUE Foo = rb_define_module("Foo");
rb_define_method(Foo, "add", add, 2);
}
7 changes: 7 additions & 0 deletions test/truffle/cext/inline.rb
@@ -0,0 +1,7 @@
p Truffle::CExt.supported?

Truffle::CExt.inline %{
#include <stdio.h>
}, %{
printf("Hello, World!\\n");
}
12 changes: 12 additions & 0 deletions test/truffle/cext/inline_capi.rb
@@ -0,0 +1,12 @@
p Truffle::CExt.supported?

Truffle::CExt.inline %{
VALUE add(VALUE self, VALUE a, VALUE b) {
return INT2NUM(NUM2INT(a) + NUM2INT(b));
}
}, %{
VALUE Test = rb_define_module("Test");
rb_define_method(Test, "add", add, 2);
}

p Test.add(14, 2)
7 changes: 7 additions & 0 deletions test/truffle/cext/inline_flags.rb
@@ -0,0 +1,7 @@
p Truffle::CExt.supported?

Truffle::CExt.inline %{
#include <stdio.h>
}, %{
printf("FOO was defined to be %d\\n", FOO);
}, %w(-DFOO=14)
5 changes: 5 additions & 0 deletions test/truffle/cext/require.rb
@@ -0,0 +1,5 @@
p Truffle::CExt.supported?

require 'foo/foo'

p Foo.add 14, 2
15 changes: 15 additions & 0 deletions truffle/pom.rb
Expand Up @@ -49,4 +49,19 @@
includes '**/*rb'
end
end

[ :dist, :'jruby-jars', :all, :release ].each do |name|
profile name do
plugin :shade do
execute_goals( 'shade',
:id => 'pack jruby-truffle-complete.jar',
:phase => 'verify',
:artifactSet => { :includes => [
'com.oracle:truffle',
'com.oracle:truffle-interop' ] },
:shadedArtifactAttached => 'true',
:shadedClassifierName => 'complete' )
end
end
end
end
118 changes: 118 additions & 0 deletions truffle/pom.xml
Expand Up @@ -96,4 +96,122 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dist</id>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>pack jruby-truffle-complete.jar</id>
<phase>verify</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.oracle:truffle</include>
<include>com.oracle:truffle-interop</include>
</includes>
</artifactSet>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>complete</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>jruby-jars</id>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>pack jruby-truffle-complete.jar</id>
<phase>verify</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.oracle:truffle</include>
<include>com.oracle:truffle-interop</include>
</includes>
</artifactSet>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>complete</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>all</id>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>pack jruby-truffle-complete.jar</id>
<phase>verify</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.oracle:truffle</include>
<include>com.oracle:truffle-interop</include>
</includes>
</artifactSet>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>complete</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>pack jruby-truffle-complete.jar</id>
<phase>verify</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.oracle:truffle</include>
<include>com.oracle:truffle-interop</include>
</includes>
</artifactSet>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>complete</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Expand Up @@ -98,6 +98,7 @@ public void init() {
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TrufflePrimitiveNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, EncodingNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, EncodingConverterNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TruffleInteropNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, MethodNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, UnboundMethodNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, ByteArrayNodesFactory.getFactories());
Expand Down Expand Up @@ -159,12 +160,6 @@ public void init() {
throw new RuntimeException(e);
}
}

// Hook

if (truffleContext.getHooks() != null) {
truffleContext.getHooks().afterInit(truffleContext);
}
}

@Override
Expand Down
19 changes: 0 additions & 19 deletions truffle/src/main/java/org/jruby/truffle/TruffleHooks.java

This file was deleted.

Expand Up @@ -1588,6 +1588,24 @@ public RubyBasicObject swapcaseSingleByte(RubyString string) {
}
}

@CoreMethod(names = "strip")
public abstract static class StripNode extends CoreMethodNode {

public StripNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public RubyString strip(RubyString string) {
notDesignedForCompilation();

// Hacky implementation to get something working

return getContext().makeString(string.toString().trim());
}

}

@CoreMethod(names = "dump", taintFromSelf = true)
@ImportStatic(StringGuards.class)
public abstract static class DumpNode extends CoreMethodNode {
Expand Down

0 comments on commit 9f228b9

Please sign in to comment.