From ead77ff13e03c88a384c5a2e70aaef46f273a73f Mon Sep 17 00:00:00 2001 From: daumayr Date: Tue, 21 Mar 2017 14:42:30 +0100 Subject: [PATCH 1/3] Fix perform:withArguments: primitive --- core-lib/TestSuite/ReflectionTests.som | 85 ++++++++++--------- core-lib/TestSuite/TestRunner.som | 3 +- src/som/primitives/MirrorPrims.java | 24 ++++++ .../reflection/PerformWithArgumentsPrim.java | 34 -------- 4 files changed, 73 insertions(+), 73 deletions(-) delete mode 100644 src/som/primitives/reflection/PerformWithArgumentsPrim.java diff --git a/core-lib/TestSuite/ReflectionTests.som b/core-lib/TestSuite/ReflectionTests.som index f6fbb4e20..e923b35c6 100644 --- a/core-lib/TestSuite/ReflectionTests.som +++ b/core-lib/TestSuite/ReflectionTests.som @@ -1,5 +1,4 @@ -" - +(* $Id: ReflectionTest.som 30 2009-07-31 12:20:25Z michael.haupt $ Copyright (c) 2007-2013 see AUTHORS file @@ -22,44 +21,54 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -" +THE SOFTWARE.*) +class ReflectionTest usingPlatform: platform testFramework: minitest = ( +| private TestContext = minitest TestContext. + private system = platform system. + private platform = platform. + private Array = platform kernel Array. + private ObjectMirror = platform mirrors ObjectMirror. +| +) ( + public class FactoryMethodTest = TestContext ()( + public class ReflectionTarget = (| num ::= 0. |)( + public set: val = (num := val) + public get = (^ num) + ) -ReflectionTest = TestCase ( - testResondsTo = ( - self assert: (Object new respondsTo: #isNil). - self assert: (23 respondsTo: #isNil). - self assert: (23 respondsTo: #+). - ) - - testMethods = ( - "First method in Object should be #class." - self assert: #class equals: (Object methods at: 1) signature. - self assert: (Object hasMethod: #==). - ) - testPerform = ( - | o | - self assert: Integer equals: (23 perform: #class). - self assert: (23 perform: #between:and: withArguments: (Array with: 22 with: 24)). - - o := SuperTest new. - self assert: #super equals: (o perform: #something inSuperclass: SuperTestSuperClass). + (*public testResondsTo = ( + self assert: ((ObjectMirror reflecting: Object new) respondsTo: #isNil). + self assert: ((ObjectMirror reflecting: 23) respondsTo: #isNil). + self assert: ((ObjectMirror reflecting: 23) respondsTo: #+). + )*) - "Trying to see whether the stack in bytecode-based SOMs works properly" - self assert: #a equals: ((23 perform: #class) = Integer ifTrue: [#a] ifFalse: [#b]). + (*public testMethods = ( + | o | + o := ReflectionTarget new. + (ObjectMirror reflecting: o) classMirror methods doIndexes: [ :i | + ('' + ((ObjectMirror reflecting: o) classMirror methods) at: i) println. + ] - self assert: 28 equals: 5 + (23 perform: #value). - ) - - testInstVarAtAndPut = ( - | tmp | - "Testing #at: and #at:put:" - tmp := Pair withKey: 3 andValue: 42. - - self assert: tmp key equals: (tmp instVarAt: 1). - - tmp instVarAt: 1 put: #foo. - self assert: #foo equals: tmp key. - ) + self assert: #class equals: (Object methods at: 1) signature. + self assert: (Object hasMethod: #==). + )*) + + public testPerform = ( + | o | + + self assert: ((ObjectMirror reflecting: 23) perform: #between:and: withArguments: (Array with: 22 with: 24)). + + (*o := SuperTest new. + self assert: #super equals: (o perform: #something inSuperclass: SuperTestSuperClass).*) + + (*Trying to see whether the stack in bytecode-based SOMs works properly*) + + o := ReflectionTarget new. + assert: ((ObjectMirror reflecting: o) perform: ('get' asSymbol)) = 0. + ((ObjectMirror reflecting: o) perform: #set: withArguments: (Array with: 5)). + assert: ((ObjectMirror reflecting: o) perform: #get) = 5. + self assert: 28 equals: 5 + ((ObjectMirror reflecting: 23) perform: #value). + ) + ) : ( TEST_CONTEXT = () ) ) diff --git a/core-lib/TestSuite/TestRunner.som b/core-lib/TestSuite/TestRunner.som index 089f34bfe..21311f2b5 100644 --- a/core-lib/TestSuite/TestRunner.som +++ b/core-lib/TestSuite/TestRunner.som @@ -82,7 +82,8 @@ class TestRunner usingPlatform: platform = ( runAllKnownModules = ( | modules allSuccessful allTestsDonePromise | - modules := 'LanguageTests', + modules := 'ReflectionTests', + 'LanguageTests', 'MixinTests', 'CollectionTests', 'DoubleTests', diff --git a/src/som/primitives/MirrorPrims.java b/src/som/primitives/MirrorPrims.java index d424d4544..f07947c69 100644 --- a/src/som/primitives/MirrorPrims.java +++ b/src/som/primitives/MirrorPrims.java @@ -6,6 +6,7 @@ import com.oracle.truffle.api.dsl.GenerateNodeFactory; import com.oracle.truffle.api.dsl.Specialization; import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.nodes.NodeCost; import com.oracle.truffle.api.source.SourceSection; import som.VM; @@ -13,10 +14,12 @@ import som.interpreter.Types; import som.interpreter.nodes.dispatch.Dispatchable; import som.interpreter.nodes.nary.BinaryComplexOperation; +import som.interpreter.nodes.nary.TernaryExpressionNode; import som.interpreter.nodes.nary.UnaryExpressionNode; import som.primitives.reflection.AbstractSymbolDispatch; import som.primitives.reflection.AbstractSymbolDispatchNodeGen; import som.vm.constants.Classes; +import som.vmobjects.SArray; import som.vmobjects.SArray.SImmutableArray; import som.vmobjects.SArray.SMutableArray; import som.vmobjects.SClass; @@ -81,6 +84,27 @@ public final Object doPerform(final VirtualFrame frame, final Object rcvr, } } + @GenerateNodeFactory + @Primitive(primitive = "obj:perform:withArguments:") + public abstract static class PerformWithArgumentsPrim extends TernaryExpressionNode { + @Child protected AbstractSymbolDispatch dispatch; + public PerformWithArgumentsPrim(final boolean eagWrap, final SourceSection source) { + super(eagWrap, source); + dispatch = AbstractSymbolDispatchNodeGen.create(source); + } + + @Specialization + public final Object doPerform(final VirtualFrame frame, final Object rcvr, + final SSymbol selector, final SArray argsArr) { + return dispatch.executeDispatch(frame, rcvr, selector, argsArr); + } + + @Override + public NodeCost getCost() { + return dispatch.getCost(); + } + } + @GenerateNodeFactory @Primitive(primitive = "classDefinition:") public abstract static class ClassDefinitionPrim extends UnaryExpressionNode { diff --git a/src/som/primitives/reflection/PerformWithArgumentsPrim.java b/src/som/primitives/reflection/PerformWithArgumentsPrim.java deleted file mode 100644 index 19a7d22d3..000000000 --- a/src/som/primitives/reflection/PerformWithArgumentsPrim.java +++ /dev/null @@ -1,34 +0,0 @@ -package som.primitives.reflection; - -import com.oracle.truffle.api.dsl.GenerateNodeFactory; -import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.frame.VirtualFrame; -import com.oracle.truffle.api.nodes.NodeCost; -import com.oracle.truffle.api.source.SourceSection; - -import som.interpreter.nodes.nary.TernaryExpressionNode; -import som.vmobjects.SArray; -import som.vmobjects.SSymbol; - - -@GenerateNodeFactory -public abstract class PerformWithArgumentsPrim extends TernaryExpressionNode { - - @Child protected AbstractSymbolDispatch dispatch; - - public PerformWithArgumentsPrim(final SourceSection source) { - super(false, source); - dispatch = AbstractSymbolDispatchNodeGen.create(source); - } - - @Specialization - public final Object doObject(final VirtualFrame frame, - final Object receiver, final SSymbol selector, final SArray argsArr) { - return dispatch.executeDispatch(frame, receiver, selector, argsArr); - } - - @Override - public NodeCost getCost() { - return dispatch.getCost(); - } -} From ca864b2d011e48a0b72dc6faed5683743de6932c Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Tue, 11 Apr 2017 15:31:33 +0200 Subject: [PATCH 2/3] Adapt test style a little Signed-off-by: Stefan Marr --- core-lib/TestSuite/ReflectionTests.som | 32 +++++++++++--------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/core-lib/TestSuite/ReflectionTests.som b/core-lib/TestSuite/ReflectionTests.som index e923b35c6..4ab655e13 100644 --- a/core-lib/TestSuite/ReflectionTests.som +++ b/core-lib/TestSuite/ReflectionTests.som @@ -1,6 +1,4 @@ (* -$Id: ReflectionTest.som 30 2009-07-31 12:20:25Z michael.haupt $ - Copyright (c) 2007-2013 see AUTHORS file Software Architecture Group, Hasso Plattner Institute, Potsdam, Germany http://www.hpi.uni-potsdam.de/swa/ @@ -23,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*) class ReflectionTest usingPlatform: platform testFramework: minitest = ( -| private TestContext = minitest TestContext. +| private TestContext = minitest TestContext. private system = platform system. private platform = platform. private Array = platform kernel Array. @@ -36,13 +34,12 @@ class ReflectionTest usingPlatform: platform testFramework: minitest = ( public get = (^ num) ) - - (*public testResondsTo = ( + (* public testResondsTo = ( self assert: ((ObjectMirror reflecting: Object new) respondsTo: #isNil). self assert: ((ObjectMirror reflecting: 23) respondsTo: #isNil). self assert: ((ObjectMirror reflecting: 23) respondsTo: #+). - )*) - + ) *) + (*public testMethods = ( | o | o := ReflectionTarget new. @@ -55,20 +52,17 @@ class ReflectionTest usingPlatform: platform testFramework: minitest = ( )*) public testPerform = ( - | o | - - self assert: ((ObjectMirror reflecting: 23) perform: #between:and: withArguments: (Array with: 22 with: 24)). - - (*o := SuperTest new. - self assert: #super equals: (o perform: #something inSuperclass: SuperTestSuperClass).*) - - (*Trying to see whether the stack in bytecode-based SOMs works properly*) + | o mirrorO mirror23 | + mirror23 := ObjectMirror reflecting: 23. + self assert: (mirror23 perform: #between:and: withArguments: (Array with: 22 with: 24)). o := ReflectionTarget new. - assert: ((ObjectMirror reflecting: o) perform: ('get' asSymbol)) = 0. - ((ObjectMirror reflecting: o) perform: #set: withArguments: (Array with: 5)). - assert: ((ObjectMirror reflecting: o) perform: #get) = 5. - self assert: 28 equals: 5 + ((ObjectMirror reflecting: 23) perform: #value). + mirrorO := ObjectMirror reflecting: o. + assert: (mirrorO perform: #get) equals: 0. + mirrorO perform: #set: withArguments: (Array with: 5). + + assert: (mirrorO perform: #get) equals: 5. + assert: 28 equals: 5 + (mirror23 perform: #value) ) ) : ( TEST_CONTEXT = () ) ) From f3c26fd8f503baa14c426c17d0fdefe3aea4427d Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Tue, 11 Apr 2017 15:32:22 +0200 Subject: [PATCH 3/3] Added ReflectionTests to JUnit tests Signed-off-by: Stefan Marr --- tests/som/tests/SomTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/som/tests/SomTests.java b/tests/som/tests/SomTests.java index 83c819f99..e95e6a800 100644 --- a/tests/som/tests/SomTests.java +++ b/tests/som/tests/SomTests.java @@ -59,6 +59,7 @@ public static Iterable data() { {"BenchmarkHarnessTests", null }, {"ActorTests", null }, {"ProcessTests", null }, + {"ReflectionTests", null }, {"RegressionTests", null }, {"ThreadingTests", null }, {"TransactionTests", null },