comparison graal/com.oracle.truffle.ruby.nodes/src/com/oracle/truffle/ruby/nodes/core/FalseClassNodes.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 = "FalseClass")
18 public abstract class FalseClassNodes {
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
38 @CoreMethod(names = {"==", "===", "=~"}, needsSelf = false, minArgs = 1, maxArgs = 1)
39 public abstract static class EqualNode extends CoreMethodNode {
40
41 public EqualNode(RubyContext context, SourceSection sourceSection) {
42 super(context, sourceSection);
43 }
44
45 public EqualNode(EqualNode prev) {
46 super(prev);
47 }
48
49 @Specialization
50 public boolean equal(boolean other) {
51 return !other;
52 }
53
54 @Specialization
55 public boolean equal(Object other) {
56 return other instanceof Boolean && !((boolean) other);
57 }
58
59 }
60
61 @CoreMethod(names = "^", needsSelf = false, minArgs = 1, maxArgs = 1)
62 public abstract static class XorNode extends CoreMethodNode {
63
64 public XorNode(RubyContext context, SourceSection sourceSection) {
65 super(context, sourceSection);
66 }
67
68 public XorNode(XorNode prev) {
69 super(prev);
70 }
71
72 @Specialization
73 public boolean xor(boolean other) {
74 return false ^ other;
75 }
76
77 }
78
79 @CoreMethod(names = "to_s", needsSelf = false, maxArgs = 0)
80 public abstract static class ToSNode extends CoreMethodNode {
81
82 public ToSNode(RubyContext context, SourceSection sourceSection) {
83 super(context, sourceSection);
84 }
85
86 public ToSNode(ToSNode prev) {
87 super(prev);
88 }
89
90 @Specialization
91 public RubyString toS() {
92 return getContext().makeString("false");
93 }
94
95 }
96
97 }