2016-03-28 13:27:03 +00:00
|
|
|
|
|
|
|
#include 'Stix.st'.
|
|
|
|
|
|
|
|
#################################################################
|
|
|
|
## MAIN
|
|
|
|
#################################################################
|
|
|
|
|
|
|
|
## TODO: use #define to define a class or use #class to define a class.
|
|
|
|
## use #extend to extend a class
|
|
|
|
## using #class for both feels confusing.
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
extend Apex
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
extend SmallInteger
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method getTrue: anInteger
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
^anInteger + 9999.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method inc
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
^self + 1.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class TestObject(Object)
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
dcl(#class) Q R.
|
|
|
|
dcl(#classinst) a1 a2.
|
2016-06-03 15:46:01 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method test999
|
2016-06-03 15:46:01 +00:00
|
|
|
{
|
|
|
|
^self.Q
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class B.TestObject(Object)
|
2016-06-03 15:46:01 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
dcl(#class) Q R.
|
|
|
|
dcl(#classinst) a1 a2.
|
2016-06-03 15:46:01 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method test000
|
2016-06-03 15:46:01 +00:00
|
|
|
{
|
|
|
|
^self.Q
|
|
|
|
}
|
2016-03-28 13:27:03 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
pooldic ABC
|
2016-06-03 16:16:23 +00:00
|
|
|
{
|
|
|
|
#KKK := 20.
|
|
|
|
}
|
|
|
|
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
class MyObject(TestObject)
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) main111
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
| s3 |
|
|
|
|
s3 := Semaphore new.
|
|
|
|
Processor signal: s3 after: 1 and: 50.
|
|
|
|
s3 wait.
|
|
|
|
'END OF MAIN' dump.
|
|
|
|
}
|
|
|
|
|
2016-05-17 15:12:27 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) main987
|
2016-05-17 15:12:27 +00:00
|
|
|
{
|
|
|
|
|t1 t2 s1 s2 s3|
|
|
|
|
|
|
|
|
'START OF MAIN' dump.
|
|
|
|
|
|
|
|
s1 := Semaphore new.
|
2016-05-18 15:10:00 +00:00
|
|
|
s2 := Semaphore forMutualExclusion.
|
2016-05-17 15:12:27 +00:00
|
|
|
|
|
|
|
t1 := [
|
2016-05-18 15:10:00 +00:00
|
|
|
##1000 timesRepeat: ['BLOCK #1' dump].
|
|
|
|
s2 critical: [
|
|
|
|
10000 timesRepeat: ['BLOCK #1' dump ].
|
|
|
|
Exception signal: 'Raised Exception at process t1'.
|
|
|
|
]
|
2016-05-17 15:12:27 +00:00
|
|
|
] newProcess.
|
|
|
|
t2 := [
|
2016-05-18 15:10:00 +00:00
|
|
|
##1000 timesRepeat: ['BLOCK #2' dump].
|
|
|
|
s2 critical: [
|
|
|
|
10000 timesRepeat: ['BLOCK #2' dump. ]
|
|
|
|
].
|
2016-05-17 15:12:27 +00:00
|
|
|
|
|
|
|
s1 signal.
|
|
|
|
] newProcess.
|
|
|
|
|
|
|
|
t1 resume.
|
|
|
|
t2 resume.
|
|
|
|
|
|
|
|
s1 wait.
|
|
|
|
|
2016-06-03 16:16:23 +00:00
|
|
|
ABC.KKK dump.
|
2016-05-17 15:12:27 +00:00
|
|
|
'END OF MAIN' dump.
|
|
|
|
|
2016-05-18 11:10:54 +00:00
|
|
|
|
|
|
|
"
|
|
|
|
|
|
|
|
|s1|
|
|
|
|
s1 := Semaphore new.
|
|
|
|
s1 signal.
|
|
|
|
'XXXXXXXXXXXXXXXX' dump.
|
|
|
|
s1 wait.
|
|
|
|
"
|
|
|
|
|
2016-06-13 15:52:09 +00:00
|
|
|
}
|
2016-06-18 00:12:27 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) aaa_123
|
2016-06-18 00:12:27 +00:00
|
|
|
{
|
|
|
|
| v1 |
|
|
|
|
v1 := [
|
|
|
|
| k |
|
|
|
|
k := 99.
|
|
|
|
[
|
|
|
|
[
|
2016-12-13 15:18:19 +00:00
|
|
|
##[ Exception signal: 'simulated error' ] ensure: [('ensure 1 ' & (k asString)) dump ].
|
|
|
|
[ ^ 20 ] ensure: [ ('ensure 1 ' & (k asString)) dump. ].
|
2016-06-18 00:12:27 +00:00
|
|
|
] ensure: ['ensure 2' dump ].
|
|
|
|
] ensure: ['ensure 3' dump ].
|
|
|
|
] on: Exception do: [:ex |
|
2016-12-13 15:18:19 +00:00
|
|
|
('EXCETION - ' & ex messageText) dump.
|
2016-06-18 00:12:27 +00:00
|
|
|
## Exception signal: 'qqq'.
|
|
|
|
].
|
|
|
|
^v1
|
|
|
|
}
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) main
|
2016-06-13 15:52:09 +00:00
|
|
|
{
|
2016-05-17 15:12:27 +00:00
|
|
|
| v1 |
|
|
|
|
'START OF MAIN' dump.
|
|
|
|
##[1 xxx] ifCurtailed: ['XXXXXXXX CURTAILED XXXXXXXXX' dump].
|
|
|
|
##['ENSURE TEST' dump] ensure: ['XXXXXXXXX ENSURE XXXXXXXXXXXXXx' dump].
|
|
|
|
|
2016-06-13 15:52:09 +00:00
|
|
|
##v1 := [ ['kkk' dump.] ensure: ['XXXXXXXXX ENSURE XXXXXXXXXXXXXx' dump. 30] ] on: Exception do: [:ex | 'EXCEPTION OUTSIDE ENSURE...' dump. ].
|
|
|
|
##v1 dump.
|
2016-05-17 15:12:27 +00:00
|
|
|
|
2016-06-13 15:52:09 +00:00
|
|
|
|
|
|
|
##[ Exception signal: 'simulated error' ] on: Exception do: [:ex | 'CAUGHT...' dump. Exception signal: 'jjjjjjj' ].
|
|
|
|
|
|
|
|
"[
|
|
|
|
[ Exception signal: 'simulated error' ] ensure: ['ensure 1' dump ].
|
2016-12-13 15:18:19 +00:00
|
|
|
] on: Exception do: [:ex | ('EXCETION - ' & ex messageText) dump. Exception signal: 'qqq'. ]."
|
2016-06-13 15:52:09 +00:00
|
|
|
|
|
|
|
"[1 xxx] ifCurtailed: ['XXXXXXXX CURTAILED XXXXXXXXX' dump. Exception signal: 'jjjj']."
|
|
|
|
|
2016-06-18 00:12:27 +00:00
|
|
|
" v1 := [
|
2016-06-13 15:52:09 +00:00
|
|
|
| k |
|
|
|
|
k := 99.
|
|
|
|
[
|
2016-06-18 00:12:27 +00:00
|
|
|
[
|
2016-12-13 15:18:19 +00:00
|
|
|
##[ Exception signal: 'simulated error' ] ensure: [('ensure 1 ' & (k asString)) dump ].
|
|
|
|
[ ^20 ] ensure: [('ensure 1 ' & (k asString)) dump ].
|
2016-06-18 00:12:27 +00:00
|
|
|
] ensure: ['ensure 2' dump ].
|
|
|
|
] ensure: ['ensure 3' dump ].
|
2016-06-13 15:52:09 +00:00
|
|
|
] on: Exception do: [:ex |
|
2016-12-13 15:18:19 +00:00
|
|
|
('EXCETION - ' & ex messageText) dump.
|
2016-06-13 15:52:09 +00:00
|
|
|
## Exception signal: 'qqq'.
|
|
|
|
].
|
2016-06-18 00:12:27 +00:00
|
|
|
"
|
2016-06-22 03:23:14 +00:00
|
|
|
|
2016-06-18 00:12:27 +00:00
|
|
|
v1 := self aaa_123.
|
2016-06-13 15:52:09 +00:00
|
|
|
'--------------------------------' dump.
|
|
|
|
v1 dump.
|
2016-06-22 03:23:14 +00:00
|
|
|
'--------------------------------' dump.
|
2016-06-13 15:52:09 +00:00
|
|
|
'END OF MAIN' dump.
|
2016-05-17 15:12:27 +00:00
|
|
|
}
|
2016-06-13 15:52:09 +00:00
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) main22222
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
|t1 t2 s1 s2 s3|
|
|
|
|
|
|
|
|
'START OF MAIN' dump.
|
|
|
|
|
|
|
|
s1 := Semaphore new.
|
|
|
|
s2 := Semaphore new.
|
|
|
|
s3 := Semaphore new.
|
|
|
|
|
|
|
|
t1 := [
|
2016-07-01 16:31:47 +00:00
|
|
|
10 timesRepeat: ['BLOCK #1' dump. Processor sleepFor: 1.].
|
2016-03-28 13:27:03 +00:00
|
|
|
s1 signal
|
|
|
|
] newProcess.
|
2016-05-15 15:51:41 +00:00
|
|
|
t2 := [
|
2016-07-01 16:31:47 +00:00
|
|
|
5 timesRepeat: ['BLOCK #2' dump. "Processor sleepFor: 1." ].
|
2016-05-15 15:51:41 +00:00
|
|
|
'SIGNALLING S2...' dump. s2 signal.
|
|
|
|
] newProcess.
|
2016-03-28 13:27:03 +00:00
|
|
|
|
|
|
|
t1 resume.
|
|
|
|
t2 resume.
|
|
|
|
|
|
|
|
Processor signal: s3 after: 10.
|
|
|
|
|
|
|
|
'STARTED t1 and t2' dump.
|
2016-05-15 15:51:41 +00:00
|
|
|
|
2016-03-28 13:27:03 +00:00
|
|
|
s2 wait.
|
2016-05-15 15:51:41 +00:00
|
|
|
's2 WAITED....' dump.
|
|
|
|
s1 wait.
|
|
|
|
's1 WAITED....' dump.
|
|
|
|
|
2016-03-28 13:27:03 +00:00
|
|
|
|
2016-05-15 15:51:41 +00:00
|
|
|
'WAITING ON S3...' dump.
|
2016-03-28 13:27:03 +00:00
|
|
|
##Processor unsignal: s3.
|
|
|
|
s3 wait.
|
|
|
|
|
|
|
|
10 timesRepeat: ['WAITED t1 and t2' dump].
|
|
|
|
'END OF MAIN' dump.
|
|
|
|
}
|
|
|
|
|
2017-01-06 09:53:40 +00:00
|
|
|
method(#class) test_semaphore_heap
|
2016-03-28 13:27:03 +00:00
|
|
|
{
|
|
|
|
| sempq a |
|
|
|
|
sempq := SemaphoreHeap new.
|
|
|
|
|
|
|
|
'--------------------------' dump.
|
|
|
|
|
|
|
|
1 to: 200 by: 1 do: [ :i |
|
|
|
|
| sem |
|
|
|
|
sem := Semaphore new.
|
|
|
|
sem fireTime: (200 - i).
|
|
|
|
sempq insert: sem
|
|
|
|
].
|
|
|
|
|
|
|
|
'--------------------------' dump.
|
|
|
|
sempq deleteAt: 40.
|
|
|
|
sempq deleteAt: 50.
|
|
|
|
|
|
|
|
[sempq size > 0] whileTrue: [
|
|
|
|
| sem |
|
|
|
|
sem := sempq popTop.
|
|
|
|
sem fireTime dump.
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2016-06-03 16:16:23 +00:00
|
|
|
|