Skip to content

Commit

Permalink
[Truffle] Implemented TrueClass#& and FalseClass#&.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Nov 21, 2014
1 parent 8c6750d commit f34f2c9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
Expand Up @@ -17,6 +17,28 @@
@CoreClass(name = "FalseClass")
public abstract class FalseClassNodes {

@CoreMethod(names = "&", needsSelf = false, required = 1)
public abstract static class AndNode extends CoreMethodNode {

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

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

@Specialization
public boolean and(boolean other) {
return false;
}

@Specialization
public boolean and(RubyObject other) {
return false;
}
}

@CoreMethod(names = "^", needsSelf = false, required = 1)
public abstract static class XorNode extends CoreMethodNode {

Expand Down
Expand Up @@ -17,6 +17,37 @@
@CoreClass(name = "TrueClass")
public abstract class TrueClassNodes {

@CoreMethod(names = "&", needsSelf = false, required = 1)
public abstract static class AndNode extends CoreMethodNode {

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

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

@Specialization
public boolean and(boolean other) {
return other;
}

@Specialization
public boolean and(RubyNilClass other) {
return false;
}

@Specialization(guards = "isNotNil")
public boolean and(RubyObject other) {
return true;
}

static boolean isNotNil(RubyObject o) {
return ! (o instanceof RubyNilClass);
}
}

@CoreMethod(names = "^", needsSelf = false, required = 1)
public abstract static class XorNode extends CoreMethodNode {

Expand Down
1 change: 0 additions & 1 deletion spec/truffle/tags/core/false/and_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/true/and_tags.txt

This file was deleted.

0 comments on commit f34f2c9

Please sign in to comment.