| 1 |
// test cleaning up dangling references |
| 2 |
// code structure borrowed from Michael Heuer's LicK library |
| 3 |
|
| 4 |
class Procedure // or Runnable |
| 5 |
{ |
| 6 |
fun void run() |
| 7 |
{ |
| 8 |
// empty |
| 9 |
} |
| 10 |
} |
| 11 |
|
| 12 |
class Append extends Procedure |
| 13 |
{ |
| 14 |
Procedure g; |
| 15 |
Procedure h; |
| 16 |
|
| 17 |
fun void run() |
| 18 |
{ |
| 19 |
g.run(); |
| 20 |
h.run(); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
class SleepProcedure extends Procedure |
| 25 |
{ |
| 26 |
Sleep @ sleep; |
| 27 |
|
| 28 |
fun void run() |
| 29 |
{ |
| 30 |
sleep.sleep(); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
class Sleep |
| 35 |
{ |
| 36 |
0::ms => dur value; |
| 37 |
SleepProcedure _procedure; |
| 38 |
|
| 39 |
{ |
| 40 |
this @=> _procedure.sleep; |
| 41 |
} |
| 42 |
|
| 43 |
fun void sleep() |
| 44 |
{ |
| 45 |
value => now; |
| 46 |
} |
| 47 |
|
| 48 |
fun Procedure asProcedure() |
| 49 |
{ |
| 50 |
return _procedure; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
public class Loops |
| 56 |
{ |
| 57 |
0::ms => static dur none; |
| 58 |
// ChucK bug: this value appears not to be set as static |
| 59 |
52::week => static dur forever; |
| 60 |
|
| 61 |
fun static Procedure append(Procedure g, Procedure h) |
| 62 |
{ |
| 63 |
Append app; |
| 64 |
g @=> app.g; |
| 65 |
h @=> app.h; |
| 66 |
return app; |
| 67 |
} |
| 68 |
|
| 69 |
fun static Procedure append(Procedure g, dur wait) |
| 70 |
{ |
| 71 |
Sleep sleep; |
| 72 |
wait => sleep.value; |
| 73 |
return append(g, sleep.asProcedure()); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
// a procedure |
| 78 |
Procedure g; |
| 79 |
// call a function that returns an Object |
| 80 |
Loops.append(g, 64::ms) @=> Procedure p; |
| 81 |
|
| 82 |
// if we got here |
| 83 |
<<< "success" >>>; |