Skip to content

Commit

Permalink
Added Integer>>bitOr: primitive
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <git@stefan-marr.de>
  • Loading branch information
smarr committed Jul 26, 2017
1 parent 3551a94 commit 4c9480d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions core-lib/Kernel.som
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class Kernel vmMirror: vmMirror = Object <: Value (
public & argument = ( ^ vmMirror int: self bitAnd: argument )
public << argument = ( ^ vmMirror int: self leftShift: argument )
public >>> argument= ( ^ vmMirror int: self unsignedRightShift: argument )
public bitOr: argument = ( ^ vmMirror int: self bitOr: argument )
public bitXor: argument = ( ^ vmMirror int: self bitXor: argument )

(* Comparing *)
Expand Down
6 changes: 6 additions & 0 deletions core-lib/TestSuite/IntegerTests.som
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ class IntegerTests usingPlatform: platform testFramework: minitest = (
self assert: 2 equals: (2 & 2).
)
public testOr = (
assert: (2 bitOr: 1) equals: 3.
assert: (0 bitOr: 2) equals: 2.
assert: (1 bitOr: 1) equals: 1.
)
public testBitXor = (
self assert: 0 equals: (1 bitXor: 1).
self assert: 3 equals: (2 bitXor: 1).
Expand Down
20 changes: 20 additions & 0 deletions src/som/primitives/bitops/BitOrPrim.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package som.primitives.bitops;

import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;

import som.primitives.Primitive;
import som.primitives.arithmetic.ArithmeticPrim;


@GenerateNodeFactory
@Primitive(primitive = "int:bitOr:", selector = "bitOr:")
public abstract class BitOrPrim extends ArithmeticPrim {
protected BitOrPrim(final boolean eagWrap, final SourceSection source) { super(eagWrap, source); }

@Specialization
public final long doLong(final long receiver, final long right) {
return receiver | right;
}
}
2 changes: 2 additions & 0 deletions src/som/vm/Primitives.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import som.primitives.arrays.NewPrimFactory;
import som.primitives.arrays.PutAllNodeFactory;
import som.primitives.bitops.BitAndPrimFactory;
import som.primitives.bitops.BitOrPrimFactory;
import som.primitives.bitops.BitXorPrimFactory;
import som.primitives.processes.ChannelPrimitivesFactory;
import som.primitives.threading.ConditionPrimitivesFactory;
Expand Down Expand Up @@ -346,6 +347,7 @@ private static List<NodeFactory<? extends ExpressionNode>> getFactories() {
allFactories.add(AtPrimFactory.getInstance());
allFactories.add(AtPutPrimFactory.getInstance());
allFactories.add(BitAndPrimFactory.getInstance());
allFactories.add(BitOrPrimFactory.getInstance());
allFactories.add(BitXorPrimFactory.getInstance());
allFactories.add(CopyPrimFactory.getInstance());
allFactories.add(CosPrimFactory.getInstance());
Expand Down
Binary file modified tests/dym/expected-results.tar.bz2
Binary file not shown.

0 comments on commit 4c9480d

Please sign in to comment.