Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/SymbolNodes.java @ 13529:856c2c294f84
Merge.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 07 Jan 2014 18:53:04 +0100 |
parents | 0fbee3eb71f0 |
children |
comparison
equal
deleted
inserted
replaced
13528:5a0c694ef735 | 13529:856c2c294f84 |
---|---|
1 /* | |
2 * Copyright (c) 2013 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 com.oracle.truffle.ruby.nodes.core; | |
11 | |
12 import com.oracle.truffle.api.*; | |
13 import com.oracle.truffle.api.dsl.*; | |
14 import com.oracle.truffle.ruby.runtime.*; | |
15 import com.oracle.truffle.ruby.runtime.core.*; | |
16 | |
17 @CoreClass(name = "Symbol") | |
18 public abstract class SymbolNodes { | |
19 | |
20 @CoreMethod(names = {"==", "==="}, minArgs = 1, maxArgs = 1) | |
21 public abstract static class EqualNode extends CoreMethodNode { | |
22 | |
23 public EqualNode(RubyContext context, SourceSection sourceSection) { | |
24 super(context, sourceSection); | |
25 } | |
26 | |
27 public EqualNode(EqualNode prev) { | |
28 super(prev); | |
29 } | |
30 | |
31 @Specialization | |
32 public boolean equal(@SuppressWarnings("unused") RubyString a, @SuppressWarnings("unused") NilPlaceholder b) { | |
33 return false; | |
34 } | |
35 | |
36 @Specialization | |
37 public boolean equal(RubySymbol a, RubySymbol b) { | |
38 return a.toString().equals(b.toString()); | |
39 } | |
40 | |
41 @Specialization | |
42 public boolean equal(RubySymbol a, RubyString b) { | |
43 return a.toString().equals(b.toString()); | |
44 } | |
45 | |
46 @Specialization | |
47 public boolean equal(RubySymbol a, int b) { | |
48 return a.toString().equals(Integer.toString(b)); | |
49 } | |
50 | |
51 } | |
52 | |
53 @CoreMethod(names = "empty?", maxArgs = 0) | |
54 public abstract static class EmptyNode extends CoreMethodNode { | |
55 | |
56 public EmptyNode(RubyContext context, SourceSection sourceSection) { | |
57 super(context, sourceSection); | |
58 } | |
59 | |
60 public EmptyNode(EmptyNode prev) { | |
61 super(prev); | |
62 } | |
63 | |
64 @Specialization | |
65 public boolean empty(RubySymbol symbol) { | |
66 return symbol.toString().isEmpty(); | |
67 } | |
68 | |
69 } | |
70 | |
71 @CoreMethod(names = "to_proc", maxArgs = 0) | |
72 public abstract static class ToProcNode extends CoreMethodNode { | |
73 | |
74 public ToProcNode(RubyContext context, SourceSection sourceSection) { | |
75 super(context, sourceSection); | |
76 } | |
77 | |
78 public ToProcNode(ToProcNode prev) { | |
79 super(prev); | |
80 } | |
81 | |
82 @Specialization | |
83 public RubyProc toProc(RubySymbol symbol) { | |
84 // TODO(CS): this should be doing all kinds of caching | |
85 return symbol.toProc(); | |
86 } | |
87 } | |
88 | |
89 @CoreMethod(names = "to_sym", maxArgs = 0) | |
90 public abstract static class ToSymNode extends CoreMethodNode { | |
91 | |
92 public ToSymNode(RubyContext context, SourceSection sourceSection) { | |
93 super(context, sourceSection); | |
94 } | |
95 | |
96 public ToSymNode(ToSymNode prev) { | |
97 super(prev); | |
98 } | |
99 | |
100 @Specialization | |
101 public RubySymbol toSym(RubySymbol symbol) { | |
102 return symbol; | |
103 } | |
104 | |
105 } | |
106 | |
107 } |