Skip to content
Permalink
Browse files
Merge branch 'master' into truffle-head
  • Loading branch information
chrisseaton committed Dec 29, 2014
2 parents 126a6e6 + 41bcacf commit ee07e39f670158adea6d9f6a98c499abef8f472f
Showing with 307 additions and 129 deletions.
  1. +16 −13 core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java
  2. +1 −5 core/src/main/java/org/jruby/embed/util/SystemPropertyCatcher.java
  3. +4 −0 core/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java
  4. +17 −2 core/src/main/java/org/jruby/truffle/nodes/core/BindingNodes.java
  5. +71 −0 core/src/main/java/org/jruby/truffle/nodes/core/TrufflePrimitiveNodes.java
  6. +0 −6 core/src/main/java/org/jruby/truffle/nodes/objects/SingletonClassNode.java
  7. +1 −0 core/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
  8. +5 −0 core/src/main/java/org/jruby/truffle/runtime/core/RubyBignum.java
  9. +0 −5 core/src/main/java/org/jruby/truffle/runtime/subsystems/FeatureManager.java
  10. +3 −3 core/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
  11. +0 −1 core/src/main/ruby/jruby/truffle/standard/stringio.rb
  12. +1 −1 default.build.properties
  13. +17 −4 lib/ruby/stdlib/erb.rb
  14. +1 −1 lib/ruby/stdlib/net/http/response.rb
  15. +7 −5 lib/ruby/stdlib/open-uri.rb
  16. +14 −16 lib/ruby/stdlib/prime.rb
  17. +9 −1 lib/ruby/stdlib/rubygems/defaults/jruby.rb
  18. +10 −15 lib/ruby/stdlib/uri/generic.rb
  19. +54 −39 lib/ruby/stdlib/uri/rfc3986_parser.rb
  20. +14 −6 lib/ruby/stdlib/win32/registry.rb
  21. +24 −0 lib/ruby/truffle/shims/stringio.rb
  22. +1 −1 ...y_bundles_with_embedded_gems/test/src/test/java/org/jruby/embed/osgi/test/JRubyOsgiEmbedTest.java
  23. +1 −1 .../src/templates/osgi_all_inclusive/src/test/java/org/jruby/embed/osgi/test/JRubyOsgiEmbedTest.java
  24. +9 −2 spec/truffle/tags/language/block_tags.txt
  25. +12 −0 spec/truffle/tags/language/lambda_tags.txt
  26. +3 −0 spec/truffle/tags/language/method_tags.txt
  27. +1 −2 spec/truffle/tags/language/predefined_tags.txt
  28. +11 −0 spec/truffle/tags/language/variables_tags.txt
@@ -2,6 +2,8 @@

import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.osgi.framework.Bundle;

@@ -64,21 +66,22 @@ public IsolatedScriptingContainer( LocalContextScope scope,
{
super(scope, behavior, lazy);

// get the right classloader
ClassLoader cl = this.getClass().getClassLoader();
if (cl == null) cl = Thread.currentThread().getContextClassLoader();
setClassLoader( cl );

setLoadPaths( Arrays.asList( "uri:classloader:" ) );

// set the right jruby home
setHomeDirectory( "uri:classloader:" + JRUBY_HOME );

// setup the isolated GEM_PATH, i.e. without $HOME/.gem/**
runScriptlet("require 'rubygems/defaults/jruby';"
+ "Gem::Specification.reset;"
+ "Gem::Specification.add_dir 'uri:classloader:" + JRUBY_HOME + "/lib/ruby/gems/shared';"
+ "Gem::Specification.add_dir 'uri:classloader:';");
setEnvironment(null);
}

@Override
public void setEnvironment(Map environment) {
if (environment == null || !environment.containsKey("GEM_PATH")) {
Map env = environment == null ? new HashMap() : new HashMap(environment);
env.put("GEM_PATH", "");
super.setEnvironment(env);
}
else {
super.setEnvironment(environment);
}
}

public void addLoadPath( ClassLoader cl ) {
@@ -140,6 +143,6 @@ private String createUri(ClassLoader cl, String ref) {
}

private void addGemPath(String uri) {
runScriptlet( "Gem::Specification.add_dir '" + uri + "' unless Gem::Specification.dirs.member?( '" + uri + "' )" );
runScriptlet( "require 'rubygems/defaults/jruby';Gem::Specification.add_dir '" + uri + "' unless Gem::Specification.dirs.member?( '" + uri + "' )" );
}
}
@@ -194,13 +194,9 @@ public static String findJRubyHome(Object instance) {
return jrubyhome;
} else if ((jrubyhome = SafePropertyAccessor.getProperty("jruby.home")) != null) {
return jrubyhome;
} else if (Thread.currentThread().getContextClassLoader() == null ||
Thread.currentThread().getContextClassLoader().equals(SystemPropertyCatcher.class.getClassLoader())) {
} else {
return "uri:classloader://META-INF/jruby.home";
}
else {
return "classpath:/META-INF/jruby.home";
}
}

public static String findFromJar(Object instance) {
@@ -95,6 +95,7 @@ public void init() {
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TimeNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TrueClassNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TruffleDebugNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TrufflePrimitiveNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, EncodingNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, EncodingConverterNodesFactory.getFactories());

@@ -134,6 +135,9 @@ public void init() {
// Libraries copied unmodified from MRI
loadPath.slowPush(truffleContext.makeString(new File(home, "lib/ruby/truffle/mri").toString()));

// Shims
loadPath.slowPush(truffleContext.makeString(new File(home, "lib/ruby/truffle/shims").toString()));

// Hook

if (truffleContext.getHooks() != null) {
@@ -53,8 +53,23 @@ public LocalVariableSetNode(LocalVariableSetNode prev) {
public Object localVariableSetNode(RubyBinding binding, RubySymbol symbol, Object value) {
notDesignedForCompilation();

final MaterializedFrame frame = binding.getFrame();
frame.setObject(frame.getFrameDescriptor().findFrameSlot(symbol.toString()), value);
MaterializedFrame frame = binding.getFrame();

while (true) {
final FrameSlot frameSlot = frame.getFrameDescriptor().findFrameSlot(symbol.toString());

if (frameSlot != null) {
frame.setObject(frameSlot, value);
break;
}

frame = RubyArguments.getDeclarationFrame(frame.getArguments());

if (frame == null) {
throw new UnsupportedOperationException();
}
}

return value;
}
}
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.runtime.DebugOperations;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBinding;
import org.jruby.util.Memo;

@CoreClass(name = "Truffle::Primitive")
public abstract class TrufflePrimitiveNodes {

@CoreMethod(names = "binding_of_caller", onSingleton = true)
public abstract static class BindingOfCallerNode extends CoreMethodNode {

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

public BindingOfCallerNode(BindingOfCallerNode prev) {
super(prev);
}

@Specialization
public RubyBinding bindingOfCaller() {
/*
* When you use this method you're asking for the binding of the caller at the call site. When we get into
* this method, that is then the binding of the caller of the caller.
*/

notDesignedForCompilation();

final Memo<Integer> frameCount = new Memo<>(0);

final MaterializedFrame frame = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<MaterializedFrame>() {

@Override
public MaterializedFrame visitFrame(FrameInstance frameInstance) {
if (frameCount.get() == 1) {
return frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE, false).materialize();
} else {
frameCount.set(frameCount.get() + 1);
return null;
}
}

});

return new RubyBinding(
getContext().getCoreLibrary().getBindingClass(),
RubyArguments.getSelf(frame.getArguments()),
frame);
}

}

}
@@ -62,12 +62,6 @@ protected Object singletonClass(double value) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantDefineSingleton(this));
}

@Specialization
protected Object singletonClass(RubyBignum value) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantDefineSingleton(this));
}

@Specialization
protected RubyClass singletonClass(RubyBasicObject object) {
return object.getSingletonClass(this);
@@ -264,6 +264,7 @@ public void initialize() {
trueClass = new RubyClass(context, objectClass, objectClass, "TrueClass");
truffleModule = new RubyModule(context, objectClass, "Truffle");
truffleDebugModule = new RubyModule(context, truffleModule, "Debug");
new RubyModule(context, truffleModule, "Primitive");
typeErrorClass = new RubyClass(context, objectClass, standardErrorClass, "TypeError");
typeErrorClass.setAllocator(new RubyException.ExceptionAllocator());
zeroDivisionErrorClass = new RubyClass(context, objectClass, standardErrorClass, "ZeroDivisionError");
@@ -25,6 +25,11 @@ public RubyBignum(RubyClass rubyClass, BigInteger value) {
this.value = value;
}

@Override
public boolean hasNoSingleton() {
return true;
}

@CompilerDirectives.TruffleBoundary
public RubyBignum negate() {
return create(value.negate());
@@ -41,11 +41,6 @@ public boolean require(String feature, RubyNode currentNode) throws IOException
try {
// Some features are handled specially

if (feature.equals("stringio")) {
context.getCoreLibrary().loadRubyCore("jruby/truffle/standard/stringio.rb");
return true;
}

if (feature.equals("zlib")) {
context.getWarnings().warn("zlib not yet implemented");
return true;
@@ -80,8 +80,8 @@ public class BodyTranslator extends Translator {
debugIgnoredCalls.add("upto");
}

public static final Set<String> FRAME_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$+", "$&", "$`", "$'"));
public static final Set<String> THREAD_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$_", "$~", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9"));
public static final Set<String> FRAME_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$_", "$+", "$&", "$`", "$'"));
public static final Set<String> THREAD_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$~", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9")); // "$_"

public BodyTranslator(RubyNode currentNode, RubyContext context, BodyTranslator parent, TranslatorEnvironment environment, Source source, boolean topLevel) {
super(currentNode, context, source);
@@ -1146,7 +1146,7 @@ public RubyNode visitGlobalAsgnNode(org.jruby.ast.GlobalAsgnNode node) {
return new WriteInstanceVariableNode(context, sourceSection, name, threadLocalVariablesObjectNode, rhs, true);
} else if (FRAME_LOCAL_GLOBAL_VARIABLES.contains(name)) {
if (environment.getNeverAssignInParentScope()) {
environment.declareVar(node.getName());
environment.declareVar(name);
}

RubyNode localVarNode = environment.findLocalVarNode(node.getName(), sourceSection);

This file was deleted.

@@ -38,4 +38,4 @@ version.ruby=2.2.0
version.ruby.major=2.2
version.ruby.minor=0
version.ruby.patchlevel=0
version.ruby.revision=48765
version.ruby.revision=49005
@@ -797,8 +797,9 @@ def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
@safe_level = safe_level
compiler = make_compiler(trim_mode)
set_eoutvar(compiler, eoutvar)
@src, @enc = *compiler.compile(str)
@src, @encoding = *compiler.compile(str)
@filename = nil
@lineno = 0
end

##
@@ -811,10 +812,22 @@ def make_compiler(trim_mode)
# The Ruby code generated by ERB
attr_reader :src

# The encoding to eval
attr_reader :encoding

# The optional _filename_ argument passed to Kernel#eval when the ERB code
# is run
attr_accessor :filename

# The optional _lineno_ argument passed to Kernel#eval when the ERB code
# is run
attr_accessor :lineno

def location=((filename, lineno))
@filename = filename
@lineno = lineno if lineno
end

#
# Can be used to set _eoutvar_ as described in ERB::new. It's probably
# easier to just use the constructor though, since calling this method
@@ -844,10 +857,10 @@ def result(b=new_toplevel)
if @safe_level
proc {
$SAFE = @safe_level
eval(@src, b, (@filename || '(erb)'), 0)
eval(@src, b, (@filename || '(erb)'), @lineno)
}.call
else
eval(@src, b, (@filename || '(erb)'), 0)
eval(@src, b, (@filename || '(erb)'), @lineno)
end
end

@@ -869,7 +882,7 @@ def new_toplevel
# print MyClass.new.render('foo', 123)
def def_method(mod, methodname, fname='(ERB)')
src = self.src
magic_comment = "#coding:#{@enc}\n"
magic_comment = "#coding:#{@encoding}\n"
mod.module_eval do
eval(magic_comment + "def #{methodname}\n" + src + "\nend\n", binding, fname, -2)
end
@@ -37,7 +37,7 @@ def read_new(sock) #:nodoc: internal use only

def read_status_line(sock)
str = sock.readline
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)\s*(.*)\z/in.match(str) or
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str) or
raise Net::HTTPBadResponse, "wrong status line: #{str.dump}"
m.captures
end
@@ -295,10 +295,12 @@ def OpenURI.open_http(buf, target, proxy, options) # :nodoc:
http.verify_mode = options[:ssl_verify_mode] || OpenSSL::SSL::VERIFY_PEER
store = OpenSSL::X509::Store.new
if options[:ssl_ca_cert]
if File.directory? options[:ssl_ca_cert]
store.add_path options[:ssl_ca_cert]
else
store.add_file options[:ssl_ca_cert]
Array(options[:ssl_ca_cert]).each do |cert|
if File.directory? cert
store.add_path cert
else
store.add_file cert
end
end
else
store.set_default_paths
@@ -680,7 +682,7 @@ module OpenRead
#
# [:ssl_ca_cert]
# Synopsis:
# :ssl_ca_cert=>filename
# :ssl_ca_cert=>filename or an Array of filenames
#
# :ssl_ca_cert is used to specify CA certificate for SSL.
# If it is given, default certificates are not used.

0 comments on commit ee07e39

Please sign in to comment.