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 f34f2c9 commit a265e27
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
Expand Up @@ -39,6 +39,37 @@ public boolean and(RubyObject other) {
}
}

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

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

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

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

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

@Specialization(guards = "isNotNil")
public boolean or(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
Expand Up @@ -48,6 +48,28 @@ static boolean isNotNil(RubyObject o) {
}
}

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

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

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

@Specialization
public boolean or(boolean other) {
return true;
}

@Specialization
public boolean or(RubyObject other) {
return true;
}
}

@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/or_tags.txt

This file was deleted.

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

This file was deleted.

0 comments on commit a265e27

Please sign in to comment.