Skip to content

Commit

Permalink
Added optional detail string to actor assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
daumayr committed Mar 13, 2017
1 parent de36328 commit a65b90c
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 37 deletions.
37 changes: 30 additions & 7 deletions core-lib/Actors.som
Original file line number Diff line number Diff line change
Expand Up @@ -301,27 +301,50 @@ class Actors usingVmMirror: vmMirror usingKernel: kernel usingPlatform: platform
)

public assert: aBlock = (
vmMirror assertNow: aBlock.
vmMirror assertNow: aBlock msg: nil.
)

public assert: aBlock msg: msg = (
vmMirror assertNow: aBlock msg: msg.
)

public assertNext: aBlock = (
vmMirror assertNext: aBlock.
vmMirror assertNext: aBlock msg: nil.
)

public assertNext: aBlock msg: msg = (
vmMirror assertNext: aBlock msg: msg.
)

public assertFuture: aBlock = (
vmMirror assertFuture: aBlock.
vmMirror assertFuture: aBlock msg: nil.
)

public assertFuture: aBlock msg: msg = (
vmMirror assertFuture: aBlock msg: msg.
)

public assertGlobally: aBlock = (
vmMirror assertGlobally: aBlock.
vmMirror assertGlobally: aBlock msg: nil.
)

public assertGlobally: aBlock msg: msg= (
vmMirror assertGlobally: aBlock msg: msg.
)

public assert: aBlock until: anotherBlock = (
vmMirror assert: aBlock until: anotherBlock.
vmMirror assert: aBlock until: anotherBlock msg: nil.
)

public assert: aBlock until: anotherBlock msg: msg = (
vmMirror assert: aBlock until: anotherBlock msg: msg.
)

public assert: aBlock release: anotherBlock = (
vmMirror assert: aBlock release: anotherBlock.
vmMirror assert: aBlock release: anotherBlock msg: nil.
)

public assert: aBlock release: anotherBlock msg: msg = (
vmMirror assert: aBlock release: anotherBlock msg: msg.
)

)
4 changes: 2 additions & 2 deletions src/som/interpreter/actors/Actor.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ protected void processCurrentMessages(final ActorProcessingThread currentThread,
actor.checkAssertions(firstMessage);
}

actor.checkReceiveHooks(firstMessage);
actor.checkReceiveHooks(firstMessage);
firstMessage.execute();

if (VmSettings.ACTOR_TRACING) {
Expand All @@ -358,7 +358,7 @@ protected void processCurrentMessages(final ActorProcessingThread currentThread,
executionTimeStamps[i] = System.currentTimeMillis();
i++;
}

actor.checkReceiveHooks(msg);
msg.execute();
if (VmSettings.ACTOR_TRACING) {
currentThread.currentMessageId += 1;
Expand Down
147 changes: 123 additions & 24 deletions src/som/primitives/AssertionPrims.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import som.interpreter.actors.SPromise;
import som.interpreter.actors.SPromise.SResolver;
import som.interpreter.nodes.nary.BinaryComplexOperation;
import som.interpreter.nodes.nary.TernaryExpressionNode;
import som.interpreter.nodes.nary.UnaryBasicOperation;
import som.vm.VmSettings;
import som.vm.constants.Nil;
Expand All @@ -26,15 +27,15 @@
public class AssertionPrims {

@GenerateNodeFactory
@Primitive(primitive = "assertNext:")
public abstract static class AssertNextPrim extends UnaryBasicOperation{
@Primitive(primitive = "assertNext:msg:")
public abstract static class AssertNextPrim extends BinaryComplexOperation{

protected AssertNextPrim(final boolean eagerlyWrapped, final SourceSection source) {
super(eagerlyWrapped, source);
}

@Specialization
public final Object doSBlock(final SBlock statement) {
@Specialization (guards = "msg==null")
public final Object doSBlock(final SBlock statement, final Object msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}
Expand All @@ -49,18 +50,35 @@ public final Object doSBlock(final SBlock statement) {

return Nil.nilObject;
}

@Specialization
public final Object doSBlockWithMessage(final SBlock statement, final String msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}

if (Thread.currentThread() instanceof ActorProcessingThread) {
ActorProcessingThread apt = (ActorProcessingThread) Thread.currentThread();
Actor a = apt.getCurrentlyExecutingActor();
a.addAssertion(new NextAssertion(statement, msg));
} else {
throw new java.lang.RuntimeException("Assertion only available when processing messages");
}

return Nil.nilObject;
}
}

@GenerateNodeFactory
@Primitive(primitive = "assertNow:")
public abstract static class AssertNowPrim extends UnaryBasicOperation{
@Primitive(primitive = "assertNow:msg:")
public abstract static class AssertNowPrim extends BinaryComplexOperation{

protected AssertNowPrim(final boolean eagerlyWrapped, final SourceSection source) {
super(eagerlyWrapped, source);
}

@Specialization
public final Object doSBlock(final SBlock statement) {
@Specialization (guards = "msg==null")
public final Object doSBlock(final SBlock statement, final Object msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}
Expand All @@ -71,18 +89,31 @@ public final Object doSBlock(final SBlock statement) {

return Nil.nilObject;
}

@Specialization
public final Object doSBlockWithMessage(final SBlock statement, final String msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}

if (!(boolean) statement.getMethod().invoke(new Object[] {statement})) {
throw new AssertionError(msg);
}

return Nil.nilObject;
}
}

@GenerateNodeFactory
@Primitive(primitive = "assertFuture:")
public abstract static class AssertFuturePrim extends UnaryBasicOperation{
@Primitive(primitive = "assertFuture:msg:")
public abstract static class AssertFuturePrim extends BinaryComplexOperation{

protected AssertFuturePrim(final boolean eagerlyWrapped, final SourceSection source) {
super(eagerlyWrapped, source);
}

@Specialization
public final Object doSBlock(final SBlock statement) {
@Specialization(guards = "msg==null")
public final Object doSBlock(final SBlock statement, final Object msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}
Expand All @@ -97,18 +128,35 @@ public final Object doSBlock(final SBlock statement) {

return Nil.nilObject;
}

@Specialization
public final Object doSBlockWithMessage(final SBlock statement, final String msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}

if (Thread.currentThread() instanceof ActorProcessingThread) {
ActorProcessingThread apt = (ActorProcessingThread) Thread.currentThread();
Actor a = apt.getCurrentlyExecutingActor();
a.addAssertion(new FutureAssertion(statement, msg));
} else {
throw new java.lang.RuntimeException("Assertion only available when processing messages");
}

return Nil.nilObject;
}
}

@GenerateNodeFactory
@Primitive(primitive = "assertGlobally:")
public abstract static class AssertGloballyPrim extends UnaryBasicOperation{
@Primitive(primitive = "assertGlobally:msg:")
public abstract static class AssertGloballyPrim extends BinaryComplexOperation{

protected AssertGloballyPrim(final boolean eagerlyWrapped, final SourceSection source) {
super(eagerlyWrapped, source);
}

@Specialization
public final Object doSBlock(final SBlock statement) {
@Specialization(guards = "msg==null")
public final Object doSBlock(final SBlock statement, final Object msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}
Expand All @@ -123,18 +171,35 @@ public final Object doSBlock(final SBlock statement) {

return Nil.nilObject;
}

@Specialization
public final Object doSBlockWithMessage(final SBlock statement, final String msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}

if (Thread.currentThread() instanceof ActorProcessingThread) {
ActorProcessingThread apt = (ActorProcessingThread) Thread.currentThread();
Actor a = apt.getCurrentlyExecutingActor();
a.addAssertion(new GloballyAssertion(statement, msg));
} else {
throw new java.lang.RuntimeException("Assertion only available when processing messages");
}

return Nil.nilObject;
}
}

@GenerateNodeFactory
@Primitive(primitive = "assert:until:")
public abstract static class AssertUntilPrim extends BinaryComplexOperation{
@Primitive(primitive = "assert:until:msg:")
public abstract static class AssertUntilPrim extends TernaryExpressionNode{

protected AssertUntilPrim(final boolean eagerlyWrapped, final SourceSection source) {
super(eagerlyWrapped, source);
}

@Specialization
public final Object doSBlock(final SBlock statement, final SBlock until) {
@Specialization(guards = "msg == null")
public final Object doSBlock(final SBlock statement, final SBlock until, final Object msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}
Expand All @@ -149,18 +214,35 @@ public final Object doSBlock(final SBlock statement, final SBlock until) {

return Nil.nilObject;
}

@Specialization
public final Object doSBlockWithMessage(final SBlock statement, final SBlock until, final String msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}

if (Thread.currentThread() instanceof ActorProcessingThread) {
ActorProcessingThread apt = (ActorProcessingThread) Thread.currentThread();
Actor a = apt.getCurrentlyExecutingActor();
a.addAssertion(new UntilAssertion(statement, until, msg));
} else {
throw new java.lang.RuntimeException("Assertion only available when processing messages");
}

return Nil.nilObject;
}
}

@GenerateNodeFactory
@Primitive(primitive = "assert:release:")
public abstract static class AssertReleasePrim extends BinaryComplexOperation{
@Primitive(primitive = "assert:release:msg:")
public abstract static class AssertReleasePrim extends TernaryExpressionNode{

protected AssertReleasePrim(final boolean eagerlyWrapped, final SourceSection source) {
super(eagerlyWrapped, source);
}

@Specialization
public final Object doSBlock(final SBlock statement, final SBlock release) {
@Specialization(guards = "msg==null")
public final Object doSBlock(final SBlock statement, final SBlock release, final Object msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}
Expand All @@ -175,6 +257,23 @@ public final Object doSBlock(final SBlock statement, final SBlock release) {

return Nil.nilObject;
}

@Specialization
public final Object doSBlockWithMessage(final SBlock statement, final SBlock release, final String msg) {
if (!VmSettings.ENABLE_ASSERTIONS) {
return Nil.nilObject;
}

if (Thread.currentThread() instanceof ActorProcessingThread) {
ActorProcessingThread apt = (ActorProcessingThread) Thread.currentThread();
Actor a = apt.getCurrentlyExecutingActor();
a.addAssertion(new Assertion.ReleaseAssertion(statement, release, msg));
} else {
throw new java.lang.RuntimeException("Assertion only available when processing messages");
}

return Nil.nilObject;
}
}

@GenerateNodeFactory
Expand Down
Loading

0 comments on commit a65b90c

Please sign in to comment.