Skip to content
Permalink
Browse files
[Truffle] A bit more work on Marshal.
  • Loading branch information
chrisseaton committed Jan 26, 2015
1 parent 658b588 commit 48de77314ab013ba70c73e55db7b67d8c06c11e5
@@ -21,12 +21,12 @@

# Load bootstrap (ordered according to Rubinius' load_order.txt)
require_relative 'core/rubinius/kernel/bootstrap/basic_object'

require_relative 'core/rubinius/kernel/bootstrap/false'
require_relative 'core/rubinius/kernel/bootstrap/gc'
require_relative 'core/rubinius/kernel/bootstrap/kernel'
require_relative 'core/rubinius/kernel/bootstrap/nil'
require_relative 'core/rubinius/kernel/bootstrap/string'
require_relative 'core/rubinius/kernel/bootstrap/symbol'
require_relative 'core/rubinius/kernel/bootstrap/time'
require_relative 'core/rubinius/kernel/bootstrap/true'
require_relative 'core/rubinius/kernel/bootstrap/type'
@@ -0,0 +1,34 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Rubinius nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class Symbol

def is_constant?
Rubinius.primitive :symbol_is_constant
raise PrimitiveFailure, "Symbol#is_constant primitive failed."
end

end
@@ -68,9 +68,7 @@ fails:Marshal.load loads a Random
fails:Marshal.load raises an ArgumentError with full constant name when the dumped constant is missing
fails:Marshal.load when source is tainted returns a tainted object
fails:Marshal.load when source is tainted does not taint Symbols
fails:Marshal.load when source is tainted does not taint Fixnums
fails:Marshal.load when source is tainted does not taint Bignums
fails:Marshal.load when source is tainted does not taint Floats
fails:Marshal.load for an Array loads an array containing the same objects
fails:Marshal.load for an Array loads an array having ivar
fails:Marshal.load for a Hash loads an extended_user_hash with a parameter to initialize
@@ -68,9 +68,7 @@ fails:Marshal.restore loads a Random
fails:Marshal.restore raises an ArgumentError with full constant name when the dumped constant is missing
fails:Marshal.restore when source is tainted returns a tainted object
fails:Marshal.restore when source is tainted does not taint Symbols
fails:Marshal.restore when source is tainted does not taint Fixnums
fails:Marshal.restore when source is tainted does not taint Bignums
fails:Marshal.restore when source is tainted does not taint Floats
fails:Marshal.restore for an Array loads an array containing the same objects
fails:Marshal.restore for an Array loads an array having ivar
fails:Marshal.restore for a Hash loads an extended_user_hash with a parameter to initialize
@@ -800,9 +800,22 @@ public FrozenNode(FrozenNode prev) {
}

@Specialization
public boolean isFrozen(RubyBasicObject self) {
notDesignedForCompilation();
public boolean isFrozen(int self) {
return true;
}

@Specialization
public boolean isFrozen(long self) {
return true;
}

@Specialization
public boolean isFrozen(double self) {
return true;
}

@Specialization
public boolean isFrozen(RubyBasicObject self) {
return self.isFrozen();
}

@@ -370,6 +370,35 @@ public Object match(RubyString string, RubyRegexp regexp) {
}
}

@CoreMethod(names = "ascii_only?")
public abstract static class ASCIIOnlyNode extends CoreMethodNode {

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

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

@Specialization
public boolean asciiOnly(RubyString string) {
notDesignedForCompilation();

if (!string.getBytes().getEncoding().isAsciiCompatible()) {
return false;
}

for (byte b : string.getBytes().unsafeBytes()) {
if ((b & 0x80) != 0) {
return false;
}
}

return true;
}
}

@CoreMethod(names = "b")
public abstract static class BNode extends CoreMethodNode {

@@ -46,6 +46,7 @@ public static RubiniusPrimitiveManager create() {
nodeFactories.addAll(ObjectPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(TimePrimitiveNodesFactory.getFactories());
nodeFactories.addAll(StringPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(SymbolPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(FixnumPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(FloatPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(EncodingPrimitiveNodesFactory.getFactories());
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2015 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.rubinius;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jcodings.exception.EncodingException;
import org.jcodings.specific.ASCIIEncoding;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyEncoding;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubySymbol;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

/**
* Rubinius primitives associated with the Ruby {@code Symbol} class.
*/
public abstract class SymbolPrimitiveNodes {

@RubiniusPrimitive(name = "symbol_is_constant")
public static abstract class SymbolIsConstantPrimitiveNode extends RubiniusPrimitiveNode {

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

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

@Specialization
public boolean symbolIsConstant(RubySymbol symbol) {
notDesignedForCompilation();
final String string = symbol.toString();
return string.length() > 0 && Character.isUpperCase(string.charAt(0));
}

}

}
@@ -19,10 +19,7 @@
import org.jruby.truffle.nodes.objects.ClassNode;
import org.jruby.truffle.nodes.objects.ClassNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyThread;
import org.jruby.truffle.runtime.core.*;

/**
* Rubinius primitives associated with the VM.
@@ -67,8 +64,9 @@ public VMGetModuleNamePrimitiveNode(VMGetModuleNamePrimitiveNode prev) {
}

@Specialization
public Object vmGetModuleName(Object object) {
throw new UnsupportedOperationException("vm_get_module_name");
public RubyString vmGetModuleName(RubyModule module) {
notDesignedForCompilation();
return getContext().makeString(module.getName());
}

}
@@ -210,7 +208,8 @@ public VMObjectSingletonClassObjectPrimitiveNode(VMObjectSingletonClassObjectPri

@Specialization
public Object vmSingletonClassObject(Object object) {
throw new UnsupportedOperationException("vm_singleton_class_object");
notDesignedForCompilation();
return object instanceof RubyClass && ((RubyClass) object).isSingleton();
}

}

0 comments on commit 48de773

Please sign in to comment.