Skip to content

Commit 48de773

Browse files
committed
[Truffle] A bit more work on Marshal.
1 parent 658b588 commit 48de773

File tree

9 files changed

+137
-14
lines changed

9 files changed

+137
-14
lines changed

core/src/main/ruby/jruby/truffle/core.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
# Load bootstrap (ordered according to Rubinius' load_order.txt)
2323
require_relative 'core/rubinius/kernel/bootstrap/basic_object'
24-
2524
require_relative 'core/rubinius/kernel/bootstrap/false'
2625
require_relative 'core/rubinius/kernel/bootstrap/gc'
2726
require_relative 'core/rubinius/kernel/bootstrap/kernel'
2827
require_relative 'core/rubinius/kernel/bootstrap/nil'
2928
require_relative 'core/rubinius/kernel/bootstrap/string'
29+
require_relative 'core/rubinius/kernel/bootstrap/symbol'
3030
require_relative 'core/rubinius/kernel/bootstrap/time'
3131
require_relative 'core/rubinius/kernel/bootstrap/true'
3232
require_relative 'core/rubinius/kernel/bootstrap/type'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) 2007-2014, Evan Phoenix and contributors
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# * Redistributions of source code must retain the above copyright notice, this
8+
# list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright notice
10+
# this list of conditions and the following disclaimer in the documentation
11+
# and/or other materials provided with the distribution.
12+
# * Neither the name of Rubinius nor the names of its contributors
13+
# may be used to endorse or promote products derived from this software
14+
# without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
class Symbol
28+
29+
def is_constant?
30+
Rubinius.primitive :symbol_is_constant
31+
raise PrimitiveFailure, "Symbol#is_constant primitive failed."
32+
end
33+
34+
end

spec/truffle/tags/core/marshal/load_tags.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ fails:Marshal.load loads a Random
6868
fails:Marshal.load raises an ArgumentError with full constant name when the dumped constant is missing
6969
fails:Marshal.load when source is tainted returns a tainted object
7070
fails:Marshal.load when source is tainted does not taint Symbols
71-
fails:Marshal.load when source is tainted does not taint Fixnums
7271
fails:Marshal.load when source is tainted does not taint Bignums
73-
fails:Marshal.load when source is tainted does not taint Floats
7472
fails:Marshal.load for an Array loads an array containing the same objects
7573
fails:Marshal.load for an Array loads an array having ivar
7674
fails:Marshal.load for a Hash loads an extended_user_hash with a parameter to initialize

spec/truffle/tags/core/marshal/restore_tags.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ fails:Marshal.restore loads a Random
6868
fails:Marshal.restore raises an ArgumentError with full constant name when the dumped constant is missing
6969
fails:Marshal.restore when source is tainted returns a tainted object
7070
fails:Marshal.restore when source is tainted does not taint Symbols
71-
fails:Marshal.restore when source is tainted does not taint Fixnums
7271
fails:Marshal.restore when source is tainted does not taint Bignums
73-
fails:Marshal.restore when source is tainted does not taint Floats
7472
fails:Marshal.restore for an Array loads an array containing the same objects
7573
fails:Marshal.restore for an Array loads an array having ivar
7674
fails:Marshal.restore for a Hash loads an extended_user_hash with a parameter to initialize

truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,22 @@ public FrozenNode(FrozenNode prev) {
800800
}
801801

802802
@Specialization
803-
public boolean isFrozen(RubyBasicObject self) {
804-
notDesignedForCompilation();
803+
public boolean isFrozen(int self) {
804+
return true;
805+
}
806+
807+
@Specialization
808+
public boolean isFrozen(long self) {
809+
return true;
810+
}
805811

812+
@Specialization
813+
public boolean isFrozen(double self) {
814+
return true;
815+
}
816+
817+
@Specialization
818+
public boolean isFrozen(RubyBasicObject self) {
806819
return self.isFrozen();
807820
}
808821

truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,35 @@ public Object match(RubyString string, RubyRegexp regexp) {
370370
}
371371
}
372372

373+
@CoreMethod(names = "ascii_only?")
374+
public abstract static class ASCIIOnlyNode extends CoreMethodNode {
375+
376+
public ASCIIOnlyNode(RubyContext context, SourceSection sourceSection) {
377+
super(context, sourceSection);
378+
}
379+
380+
public ASCIIOnlyNode(ASCIIOnlyNode prev) {
381+
super(prev);
382+
}
383+
384+
@Specialization
385+
public boolean asciiOnly(RubyString string) {
386+
notDesignedForCompilation();
387+
388+
if (!string.getBytes().getEncoding().isAsciiCompatible()) {
389+
return false;
390+
}
391+
392+
for (byte b : string.getBytes().unsafeBytes()) {
393+
if ((b & 0x80) != 0) {
394+
return false;
395+
}
396+
}
397+
398+
return true;
399+
}
400+
}
401+
373402
@CoreMethod(names = "b")
374403
public abstract static class BNode extends CoreMethodNode {
375404

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/RubiniusPrimitiveManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static RubiniusPrimitiveManager create() {
4646
nodeFactories.addAll(ObjectPrimitiveNodesFactory.getFactories());
4747
nodeFactories.addAll(TimePrimitiveNodesFactory.getFactories());
4848
nodeFactories.addAll(StringPrimitiveNodesFactory.getFactories());
49+
nodeFactories.addAll(SymbolPrimitiveNodesFactory.getFactories());
4950
nodeFactories.addAll(FixnumPrimitiveNodesFactory.getFactories());
5051
nodeFactories.addAll(FloatPrimitiveNodesFactory.getFactories());
5152
nodeFactories.addAll(EncodingPrimitiveNodesFactory.getFactories());
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
3+
* code is released under a tri EPL/GPL/LGPL license. You can use it,
4+
* redistribute it and/or modify it under the terms of the:
5+
*
6+
* Eclipse Public License version 1.0
7+
* GNU General Public License version 2
8+
* GNU Lesser General Public License version 2.1
9+
*/
10+
package org.jruby.truffle.nodes.rubinius;
11+
12+
import com.oracle.truffle.api.CompilerDirectives;
13+
import com.oracle.truffle.api.dsl.Specialization;
14+
import com.oracle.truffle.api.source.SourceSection;
15+
import com.oracle.truffle.api.utilities.ConditionProfile;
16+
import org.jcodings.exception.EncodingException;
17+
import org.jcodings.specific.ASCIIEncoding;
18+
import org.jruby.truffle.runtime.RubyContext;
19+
import org.jruby.truffle.runtime.control.RaiseException;
20+
import org.jruby.truffle.runtime.core.RubyEncoding;
21+
import org.jruby.truffle.runtime.core.RubyString;
22+
import org.jruby.truffle.runtime.core.RubySymbol;
23+
import org.jruby.util.ByteList;
24+
import org.jruby.util.StringSupport;
25+
26+
/**
27+
* Rubinius primitives associated with the Ruby {@code Symbol} class.
28+
*/
29+
public abstract class SymbolPrimitiveNodes {
30+
31+
@RubiniusPrimitive(name = "symbol_is_constant")
32+
public static abstract class SymbolIsConstantPrimitiveNode extends RubiniusPrimitiveNode {
33+
34+
public SymbolIsConstantPrimitiveNode(RubyContext context, SourceSection sourceSection) {
35+
super(context, sourceSection);
36+
}
37+
38+
public SymbolIsConstantPrimitiveNode(SymbolIsConstantPrimitiveNode prev) {
39+
super(prev);
40+
}
41+
42+
@Specialization
43+
public boolean symbolIsConstant(RubySymbol symbol) {
44+
notDesignedForCompilation();
45+
final String string = symbol.toString();
46+
return string.length() > 0 && Character.isUpperCase(string.charAt(0));
47+
}
48+
49+
}
50+
51+
}

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/VMPrimitiveNodes.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
import org.jruby.truffle.nodes.objects.ClassNode;
2020
import org.jruby.truffle.nodes.objects.ClassNodeFactory;
2121
import org.jruby.truffle.runtime.RubyContext;
22-
import org.jruby.truffle.runtime.core.RubyClass;
23-
import org.jruby.truffle.runtime.core.RubyModule;
24-
import org.jruby.truffle.runtime.core.RubyNilClass;
25-
import org.jruby.truffle.runtime.core.RubyThread;
22+
import org.jruby.truffle.runtime.core.*;
2623

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

6966
@Specialization
70-
public Object vmGetModuleName(Object object) {
71-
throw new UnsupportedOperationException("vm_get_module_name");
67+
public RubyString vmGetModuleName(RubyModule module) {
68+
notDesignedForCompilation();
69+
return getContext().makeString(module.getName());
7270
}
7371

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

211209
@Specialization
212210
public Object vmSingletonClassObject(Object object) {
213-
throw new UnsupportedOperationException("vm_singleton_class_object");
211+
notDesignedForCompilation();
212+
return object instanceof RubyClass && ((RubyClass) object).isSingleton();
214213
}
215214

216215
}

0 commit comments

Comments
 (0)