comparison graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/NilClassNodes.java @ 13514:0fbee3eb71f0

Ruby: import project.
author Chris Seaton <chris.seaton@oracle.com>
date Mon, 06 Jan 2014 17:12:09 +0000
parents
children
comparison
equal deleted inserted replaced
13513:64a23ce736a0 13514:0fbee3eb71f0
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 = "NilClass")
18 public abstract class NilClassNodes {
19
20 @CoreMethod(names = "!", needsSelf = false, maxArgs = 0)
21 public abstract static class NotNode extends CoreMethodNode {
22
23 public NotNode(RubyContext context, SourceSection sourceSection) {
24 super(context, sourceSection);
25 }
26
27 public NotNode(NotNode prev) {
28 super(prev);
29 }
30
31 @Specialization
32 public boolean not() {
33 return true;
34 }
35 }
36
37 @CoreMethod(names = "==", needsSelf = false, minArgs = 1, maxArgs = 1)
38 public abstract static class EqualNode extends CoreMethodNode {
39
40 public EqualNode(RubyContext context, SourceSection sourceSection) {
41 super(context, sourceSection);
42 }
43
44 public EqualNode(EqualNode prev) {
45 super(prev);
46 }
47
48 @Specialization
49 public boolean equal(Object b) {
50 return b instanceof NilPlaceholder || b instanceof RubyNilClass;
51 }
52
53 }
54
55 @CoreMethod(names = "!=", needsSelf = false, minArgs = 1, maxArgs = 1)
56 public abstract static class NotEqualNode extends CoreMethodNode {
57
58 public NotEqualNode(RubyContext context, SourceSection sourceSection) {
59 super(context, sourceSection);
60 }
61
62 public NotEqualNode(NotEqualNode prev) {
63 super(prev);
64 }
65
66 @Specialization
67 public boolean equal(Object b) {
68 return !(b instanceof NilPlaceholder || b instanceof RubyNilClass);
69 }
70
71 }
72
73 @CoreMethod(names = "inspect", needsSelf = false, maxArgs = 0)
74 public abstract static class InpsectNode extends CoreMethodNode {
75
76 public InpsectNode(RubyContext context, SourceSection sourceSection) {
77 super(context, sourceSection);
78 }
79
80 public InpsectNode(InpsectNode prev) {
81 super(prev);
82 }
83
84 @Specialization
85 public RubyString inspect() {
86 return getContext().makeString("nil");
87 }
88 }
89
90 @CoreMethod(names = "nil?", needsSelf = false, maxArgs = 0)
91 public abstract static class NilNode extends CoreMethodNode {
92
93 public NilNode(RubyContext context, SourceSection sourceSection) {
94 super(context, sourceSection);
95 }
96
97 public NilNode(NilNode prev) {
98 super(prev);
99 }
100
101 @Specialization
102 public boolean nil() {
103 return true;
104 }
105 }
106
107 @CoreMethod(names = "to_i", needsSelf = false, maxArgs = 0)
108 public abstract static class ToINode extends CoreMethodNode {
109
110 public ToINode(RubyContext context, SourceSection sourceSection) {
111 super(context, sourceSection);
112 }
113
114 public ToINode(ToINode prev) {
115 super(prev);
116 }
117
118 @Specialization
119 public int toI() {
120 return 0;
121 }
122 }
123
124 @CoreMethod(names = "to_s", needsSelf = false, maxArgs = 0)
125 public abstract static class ToSNode extends CoreMethodNode {
126
127 public ToSNode(RubyContext context, SourceSection sourceSection) {
128 super(context, sourceSection);
129 }
130
131 public ToSNode(ToSNode prev) {
132 super(prev);
133 }
134
135 @Specialization
136 public RubyString toS() {
137 return getContext().makeString("");
138 }
139 }
140
141 }