Skip to content

Commit c312da9

Browse files
committed
Replaced AAStarted andAAEnded messages by AAHappened. See issue #5
1 parent 4ec0057 commit c312da9

File tree

6 files changed

+79
-111
lines changed

6 files changed

+79
-111
lines changed

src/subscript/subscript/examples/TestHelloWorld.scala renamed to src/subscript/subscript/examples/HelloWorld.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//package subscript.test
1+
//package subscript.examples
22

33
import subscript._
44
import subscript.DSL._
@@ -10,8 +10,8 @@ import subscript.swing.SimpleSubscriptApplication
1010

1111
// Subscript sample application: "Hello world!", printed using a sequence of 2 code fragments
1212

13-
object TestHelloWorld extends TestHelloWorldApp
14-
class TestHelloWorldApp
13+
object HelloWorld extends HelloWorldApp
14+
class HelloWorldApp
1515
{
1616
// bridge method:
1717
def main( args: Array[String]): Unit = println("Success: "+_execute(_main(args)).hasSuccess)

src/subscript/subscript/swing/GraphicalDebugger.scala

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ class GraphicalDebuggerApp extends SimpleSubscriptApplication with ScriptDebugge
7070
var ss: List[String] = Nil
7171
if (c != null) {
7272
if ( c.success != null) ss ::= "Success"
73-
if (!c.aaEndeds .isEmpty) ss ::= "AA Ended"
74-
if (!c.aaStarteds .isEmpty) ss ::= "AA Started"
73+
if (!c.aaHappeneds .isEmpty) ss ::= "AA Happened"
7574
if (!c.deactivations.isEmpty) ss ::= "Deactivations"
7675
if ( c.activation != null) ss ::= "Activation"
7776
}
@@ -84,8 +83,7 @@ class GraphicalDebuggerApp extends SimpleSubscriptApplication with ScriptDebugge
8483
//"Activation "
8584
//"Deactivation"
8685
//"Continuation"
87-
//"AAStarted "
88-
//"AAEnded "
86+
//"AAHappened "
8987
//"Success "
9088
//"Break "
9189
//"Exclude "
@@ -94,8 +92,7 @@ class GraphicalDebuggerApp extends SimpleSubscriptApplication with ScriptDebugge
9492
val checkBox_step_Activation = new CheckBox {text = "Act" ; selected = true}
9593
val checkBox_step_Deactivation = new CheckBox {text = "Dea" ; selected = true}
9694
val checkBox_step_Continuation = new CheckBox {text = "Cnt" ; selected = true}
97-
val checkBox_step_AAStarted = new CheckBox {text = "AAS" ; selected = true}
98-
val checkBox_step_AAEnded = new CheckBox {text = "AAE" ; selected = true}
95+
val checkBox_step_AAHappened = new CheckBox {text = "AAH" ; selected = true}
9996
val checkBox_step_Success = new CheckBox {text = "Scs" ; selected = true}
10097
val checkBox_step_Break = new CheckBox {text = "Brk" ; selected = true}
10198
val checkBox_step_Exclude = new CheckBox {text = "Exc" ; selected = true}
@@ -104,8 +101,7 @@ class GraphicalDebuggerApp extends SimpleSubscriptApplication with ScriptDebugge
104101
val checkBox_log_Activation = new CheckBox {text = "Act" ; selected = true}
105102
val checkBox_log_Deactivation = new CheckBox {text = "Dea" ; selected = true}
106103
val checkBox_log_Continuation = new CheckBox {text = "Cnt" ; selected = true}
107-
val checkBox_log_AAStarted = new CheckBox {text = "AAS" ; selected = true}
108-
val checkBox_log_AAEnded = new CheckBox {text = "AAE" ; selected = true}
104+
val checkBox_log_AAHappened = new CheckBox {text = "AAH" ; selected = true}
109105
val checkBox_log_Success = new CheckBox {text = "Scs" ; selected = true}
110106
val checkBox_log_Break = new CheckBox {text = "Brk" ; selected = true}
111107
val checkBox_log_Exclude = new CheckBox {text = "Exc" ; selected = true}
@@ -116,8 +112,7 @@ class GraphicalDebuggerApp extends SimpleSubscriptApplication with ScriptDebugge
116112
contents += checkBox_step_Activation
117113
contents += checkBox_step_Deactivation
118114
contents += checkBox_step_Continuation
119-
contents += checkBox_step_AAStarted
120-
contents += checkBox_step_AAEnded
115+
contents += checkBox_step_AAHappened
121116
contents += checkBox_step_Success
122117
contents += checkBox_step_Break
123118
contents += checkBox_step_Exclude
@@ -127,8 +122,7 @@ class GraphicalDebuggerApp extends SimpleSubscriptApplication with ScriptDebugge
127122
contents += checkBox_log_Activation
128123
contents += checkBox_log_Deactivation
129124
contents += checkBox_log_Continuation
130-
contents += checkBox_log_AAStarted
131-
contents += checkBox_log_AAEnded
125+
contents += checkBox_log_AAHappened
132126
contents += checkBox_log_Success
133127
contents += checkBox_log_Break
134128
contents += checkBox_log_Exclude
@@ -350,14 +344,13 @@ class GraphicalDebuggerApp extends SimpleSubscriptApplication with ScriptDebugge
350344

351345
if (currentMessage!=null) {
352346
currentMessage match { // node.index is not checked by node.equals!!!!
353-
case AAStarted(mp,mc) if (p.index==mp.index&&c.index==mc.index) => drawArrow(x2, y2, x1, y1, "AA Started")
354-
case AAEnded (mp,mc) if (p.index==mp.index&&c.index==mc.index) => drawArrow(x2, y2, x1, y1, "AA Ended")
355-
case Success (mp,null) => // println("Success (mp,null)") // TBD: how come?
356-
case Success (mp,mc) if (p.index==mp.index&&c.index==mc.index) => drawArrow(x2, y2, x1, y1, "Success")
357-
case Break (mp,mc, activationMode) if (p.index==mp.index&&c.index==mc.index)
358-
=> drawArrow(x2, y2, x1, y1, getBreakText(activationMode))
359-
case Exclude (mp,mc) if (p.index==mp.index&&c.index==mc.index) => drawArrow(x1, y1, x2, y2, "Exclude")
360-
case _ => drawArrow(x1, y1, x2, y2, null)
347+
case AAHappened(mp,mc,mode) if(p.index==mp.index&&c.index==mc.index) => drawArrow(x2, y2, x1, y1, "AA Happened")
348+
case Success (mp,null) => // println("Success (mp,null)") // TBD: how come?
349+
case Success (mp,mc) if (p.index==mp.index&&c.index==mc.index) => drawArrow(x2, y2, x1, y1, "Success")
350+
case Break (mp,mc, activationMode) if (p.index==mp.index&&c.index==mc.index)
351+
=> drawArrow(x2, y2, x1, y1, getBreakText(activationMode))
352+
case Exclude (mp,mc) if (p.index==mp.index&&c.index==mc.index) => drawArrow(x1, y1, x2, y2, "Exclude")
353+
case _ => drawArrow(x1, y1, x2, y2, null)
361354
}
362355
}
363356
else drawArrow(x1, y1, x2, y2, null)
@@ -373,9 +366,8 @@ class GraphicalDebuggerApp extends SimpleSubscriptApplication with ScriptDebugge
373366
val fontMetrics = g.getFontMetrics
374367
interestingContinuationInternals(nn.continuation).foreach{s: String=>drawStringTopLeft(g, s, x, y); y += fontMetrics.getHeight - 2}
375368
case _ => if (currentMessage!=null&&currentMessage.node==n) currentMessage match {
376-
case s: Success if (s.child==null) => drawStringTopLeft(g, "Success" , x, y)
377-
case a: AAStarted if (a.child==null) => drawStringTopLeft(g, "AA Started", x, y)
378-
case a: AAEnded if (a.child==null) => drawStringTopLeft(g, "AA Ended" , x, y)
369+
case s: Success if (s.child==null) => drawStringTopLeft(g, "Success" , x, y)
370+
case a: AAHappened if (a.child==null) => drawStringTopLeft(g, "AA Happened", x, y)
379371
case _ =>
380372
}
381373
}
@@ -553,8 +545,7 @@ class GraphicalDebuggerApp extends SimpleSubscriptApplication with ScriptDebugge
553545
currentMessage match {
554546
case Activation(_) => checkBox_step_Activation .selected
555547
case Deactivation(_,_,_) => checkBox_step_Deactivation.selected
556-
case AAStarted(_,_) => checkBox_step_AAStarted .selected
557-
case AAEnded(_,_) => checkBox_step_AAEnded .selected
548+
case AAHappened(_,_,_) => checkBox_step_AAHappened .selected
558549
case Success(_,_) => checkBox_step_Success .selected
559550
case Break(_,_,_) => checkBox_step_Break .selected
560551
case Exclude(_,_) => checkBox_step_Exclude .selected
@@ -582,8 +573,7 @@ class GraphicalDebuggerApp extends SimpleSubscriptApplication with ScriptDebugge
582573
if (msg match {
583574
case Activation(_) => checkBox_log_Activation .selected
584575
case Deactivation(_,_,_) => checkBox_log_Deactivation.selected
585-
case AAStarted(_,_) => checkBox_log_AAStarted .selected
586-
case AAEnded(_,_) => checkBox_log_AAEnded .selected
576+
case AAHappened(_,_,_) => checkBox_log_AAHappened .selected
587577
case Success(_,_) => checkBox_log_Success .selected
588578
case Break(_,_,_) => checkBox_log_Break .selected
589579
case Exclude(_,_) => checkBox_log_Exclude .selected

src/subscript/subscript/vm/CallGraphMessage.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
package subscript.vm
2828
import scala.collection.mutable._
2929

30+
abstract class AAHappenedMode
31+
case object AtomicCodeFragmentExecuted extends AAHappenedMode
32+
case object DurationalCodeFragmentStarted extends AAHappenedMode
33+
case object DurationalCodeFragmentEnded extends AAHappenedMode
34+
3035
trait CallGraphMessage[N <: CallGraphNodeTrait] {
3136
var priority = 0 // TBD: determine good priority levels
3237
var index = -1
@@ -47,8 +52,7 @@ import scala.collection.mutable._
4752
var break: Break = null
4853
var aaActivated: AAActivated = null
4954
var caActivated: CAActivated = null
50-
var aaStarteds : List[AAStarted] = Nil
51-
var aaEndeds : List[AAEnded ] = Nil
55+
var aaHappeneds : List[AAHappened] = Nil
5256
var childNode : CallGraphNodeTrait = null
5357

5458
override def toString = {
@@ -59,8 +63,7 @@ import scala.collection.mutable._
5963
if (break !=null) result += " "+break
6064
if (aaActivated !=null) result += " "+aaActivated
6165
if (caActivated !=null) result += " "+caActivated
62-
if (aaStarteds !=Nil ) result += " "+aaStarteds.mkString
63-
if (aaEndeds !=Nil ) result += " "+aaEndeds.mkString
66+
if (aaHappeneds !=Nil ) result += " "+aaHappeneds.mkString
6467
if (childNode !=null) result += " "+childNode
6568
result
6669
}
@@ -81,10 +84,8 @@ import scala.collection.mutable._
8184
case class CAActivated (node: CallGraphNodeTrait,
8285
child: CallGraphNodeTrait) extends CallGraphMessageN {priority = 15} // for immediate handling
8386
case class CAActivatedTBD (node: N_call ) extends CallGraphMessageN {priority = 2} // for late handling
84-
case class AAStarted (node: CallGraphNodeTrait,
85-
child: CallGraphNodeTrait) extends CallGraphMessageN {priority = 17}
86-
case class AAEnded (node: CallGraphNodeTrait,
87-
child: CallGraphNodeTrait) extends CallGraphMessageN {priority = 16}
87+
case class AAHappened (node: CallGraphNodeTrait,
88+
child: CallGraphNodeTrait, mode: AAHappenedMode) extends CallGraphMessageN {priority = 17}
8889
case class AAToBeExecuted (node: CallGraphNodeTrait) extends CallGraphMessage[CallGraphNodeTrait] {priority = 1}
8990
case class AAToBeReexecuted (node: CallGraphNodeTrait) extends CallGraphMessage[CallGraphNodeTrait] {priority = 0}
9091
case class AAExecutionFinished(node: CallGraphNodeTrait) extends CallGraphMessage[CallGraphNodeTrait] {priority = 6}

src/subscript/subscript/vm/CallGraphNode.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ trait CallGraphNodeTrait {
6969

7070
var index = -1
7171
var stamp = 0
72-
var aaStartedCount = 0
72+
var aaHappenedCount = 0
7373
var properties: Map[Any,Any] = new HashMap[Any,Any]
7474
var _scriptExecutor: ScriptExecutor = null
7575
def scriptExecutor = _scriptExecutor
@@ -111,7 +111,7 @@ trait CallGraphNodeTrait {
111111
override def toString = index+" "+template
112112

113113
// TBD: are these necessary? :
114-
//var aaStartedCountAtLastSuccess = 0
114+
//var aaHappenedCountAtLastSuccess = 0
115115
//def recentSuccess = aaStartedCountAtLastSuccess==aaStartedCount
116116

117117
def n_ary_op_else_ancestor: N_n_ary_op = {
@@ -224,7 +224,7 @@ abstract class CallGraphTreeNode_n_ary extends CallGraphTreeParentNode {
224224
def getLogicalKind = T_n_ary_op.getLogicalKind(template)
225225
var continuation: Continuation = null
226226
var lastActivatedChild: CallGraphNodeTrait = null
227-
var aaStartedSinceLastOptionalBreak = false
227+
var aaHappenedSinceLastOptionalBreak = false
228228
def mustBreak = hadBreak = true
229229

230230
var breakWaker: CallGraphNodeTrait = null

src/subscript/subscript/vm/CodeExecutor.scala

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ import scala.collection.mutable._
3131
// code fragments, script calls, parameter checks, tests in if and while, annotations
3232
trait CodeExecutor // to make an empty class file so that ant will not get confused
3333
trait CodeExecutorTrait {
34-
// graph operations such as aaStarted may only be done when called from executor!
34+
// graph operations such as aaHappened may only be done when called from executor!
3535
var canceled = false // TBD(?) inspect this flag before execution
36+
var regardStartAndEndAsSeparateAtomicActions = false
37+
3638
def asynchronousAllowed: Boolean
3739

3840
def doCodeExecution[R](code: ()=>R): R = {
@@ -57,7 +59,7 @@ case class TinyCodeExecutor(n: CallGraphNodeTrait, scriptExecutor: ScriptExecuto
5759
abstract class AACodeFragmentExecutor[N<:N_atomic_action](_n: N, _scriptExecutor: ScriptExecutor) extends CodeExecutorTrait {
5860

5961
// Executor for Atomic Actions. These require some communication with the ScriptExecutor, to make sure that
60-
// graph messages such as AAStarted, AAEnded en Success are properly sent.
62+
// graph messages such as AAHappened en Success are properly sent.
6163
// Note: such messages may only be handled from the main ScriptExecutor loop!
6264
//
6365
// Since scala code execution from Subscript may be asynchronous (e.g., in the Swing thread or in a new thread),
@@ -80,8 +82,7 @@ abstract class AACodeFragmentExecutor[N<:N_atomic_action](_n: N, _scriptExecutor
8082
finally {n.isExecuting = false}
8183
executionFinished
8284
}
83-
def aaStarted = scriptExecutor.insert(AAStarted(n,null))
84-
def aaEnded = scriptExecutor.insert(AAEnded (n,null))
85+
def aaHappened(mode:AAHappenedMode) = scriptExecutor.insert(AAHappened (n,null,mode))
8586
def succeeded = {
8687
scriptExecutor.insert(Success (n,null))
8788
}
@@ -107,14 +108,14 @@ class NormalCodeFragmentExecutor[N<:N_atomic_action](n: N, scriptExecutor: Scrip
107108
// method scriptExecutor in trait CodeExecutorTrait of type => subscript.vm.ScriptExecutor is not defined
108109
// method n in trait CodeExecutorTrait of type => subscript.vm.CallGraphNodeTrait[_ <: subscript.vm.TemplateNode] is not defined CodeExecutor.scala /subscript/src/subscript/vm line 54 Scala Problem
109110

110-
111111
override def executeAA(lowLevelCodeExecutor: CodeExecutorTrait): Unit = {
112-
aaStarted
112+
if (regardStartAndEndAsSeparateAtomicActions) aaHappened(DurationalCodeFragmentStarted)
113113
doCodeExecution(lowLevelCodeExecutor)
114114
}
115115
override def afterExecuteAA = {
116116
if (!n.isExcluded) {
117-
aaEnded; succeeded; deactivate
117+
aaHappened( if (regardStartAndEndAsSeparateAtomicActions) DurationalCodeFragmentEnded else AtomicCodeFragmentExecuted)
118+
succeeded; deactivate
118119
}
119120
}
120121
}
@@ -124,7 +125,7 @@ class UnsureCodeFragmentExecutor(n: N_code_unsure, scriptExecutor: ScriptExecuto
124125
}
125126
override def afterExecuteAA = {
126127
if (n.hasSuccess) {
127-
aaStarted; aaEnded; succeeded; deactivate
128+
aaHappened(AtomicCodeFragmentExecuted); succeeded; deactivate
128129
}
129130
else if (n.result==UnsureExecutionResult.Ignore){ // allow for deactivating result
130131
n.result=UnsureExecutionResult.Success
@@ -147,7 +148,9 @@ trait CodeExecutorAdapter[CE<:CodeExecutorTrait] extends CodeExecutorTrait {
147148
}
148149
class ThreadedCodeFragmentExecutor(n: N_code_threaded, scriptExecutor: ScriptExecutor) extends NormalCodeFragmentExecutor(n, scriptExecutor) {
149150
override def interruptAA: Unit = if (myThread!=null) myThread.interrupt
151+
regardStartAndEndAsSeparateAtomicActions = true
150152
var myThread: Thread = null
153+
151154
override def doCodeExecution(lowLevelCodeExecutor: CodeExecutorTrait): Unit = {
152155
val runnable = new Runnable {
153156
def run() {
@@ -162,7 +165,11 @@ class ThreadedCodeFragmentExecutor(n: N_code_threaded, scriptExecutor: ScriptExe
162165
class SwingCodeExecutorAdapter[CE<:CodeExecutorTrait] extends CodeExecutorAdapter[CE]{
163166
def n = adaptee.n
164167
def scriptExecutor = adaptee.scriptExecutor
165-
override def executeAA: Unit = adaptee.executeAA(this) // Not to be called? TBD: clean up class/trait hierarchy
168+
169+
override def executeAA: Unit = {
170+
adaptee.regardStartAndEndAsSeparateAtomicActions = adaptee.asynchronousAllowed
171+
adaptee.executeAA(this) // Not to be called? TBD: clean up class/trait hierarchy
172+
}
166173
override def afterExecuteAA: Unit = adaptee.afterExecuteAA // TBD: clean up class/trait hierarchy so that this def can be ditched
167174
override def interruptAA: Unit = adaptee.interruptAA // TBD: clean up class/trait hierarchy so that this def can be ditched
168175
override def doCodeExecution[R](code: ()=>R): R = {
@@ -212,14 +219,12 @@ case class EventHandlingCodeFragmentExecutor[N<:N_atomic_action](_n: N, _scriptE
212219
if (n.isExcluded || !n.hasSuccess) return
213220
n match {
214221
case eh:N_code_eventhandling =>
215-
aaStarted
216-
aaEnded
222+
aaHappened(AtomicCodeFragmentExecuted)
217223
succeeded
218224
deactivate
219225

220226
case eh:N_code_eventhandling_loop =>
221-
aaStarted
222-
aaEnded
227+
aaHappened(AtomicCodeFragmentExecuted)
223228
eh.result match {
224229
case LoopingExecutionResult.Success =>
225230
case LoopingExecutionResult.Break => succeeded

0 commit comments

Comments
 (0)