@@ -18,6 +18,16 @@ import {SYSTEM_PROCESS_STRING} from './Constants.mjs'
1818import { getCliArgs , TroupeCliArg } from './TroupeCliArgs.mjs' ;
1919const argv = getCliArgs ( ) ;
2020
21+ /** Enum for termination statuses. */
22+ export enum ThreadType {
23+ /** System service thread. */
24+ System = - 1 ,
25+ /** Main thread. */
26+ Main = 0 ,
27+ /** Other threads, spawned from 'Main' or 'System'. */
28+ Other = 1
29+ }
30+
2131/** Enum for termination statuses. */
2232enum TerminationStatus {
2333 /** Thread finished its computation. */
@@ -105,18 +115,16 @@ export class Scheduler implements SchedulerInterface {
105115 arg : any ,
106116 pc : Level ,
107117 block : Level ,
108- ismain : boolean = false ,
109- persist : boolean | null = null ,
110- isSystem : boolean = false )
118+ tType : ThreadType = ThreadType . Other )
111119 {
112120 // Create a new process ID at the given level.
113- const pid = isSystem ? SYSTEM_PROCESS_STRING : uuidv4 ( ) ;
121+ const pid = tType === ThreadType . System ? SYSTEM_PROCESS_STRING : uuidv4 ( ) ;
114122 const pidObj = new ProcessID ( this . rt_uuid , pid , this . __node ) ;
115- const newPid = new LVal ( pidObj , pc ) ;
123+ const newPid = new LVal ( pidObj , pc ) ;
116124
117125 // Epilogue for thread.
118- const halt = ismain ? ( ) => { this . haltMain ( persist ) } :
119- ( ) => { this . haltOther ( ) } ;
126+ const halt = tType === ThreadType . Main ? ( ) => { this . haltMain ( ) }
127+ : ( ) => { this . haltOther ( ) } ;
120128
121129 // New thread
122130 const t = new Thread
@@ -197,7 +205,7 @@ export class Scheduler implements SchedulerInterface {
197205 }
198206
199207 /** Epilogue for `main` thread: notify monitors, print and persist the final value */
200- haltMain ( persist = null ) {
208+ haltMain ( ) {
201209 this . __currentThread . raiseCurrentThreadPCToBlockingLev ( )
202210 let retVal = new LVal ( this . __currentThread . r0_val ,
203211 lub ( this . __currentThread . bl , this . __currentThread . r0_lev ) ,
@@ -207,6 +215,7 @@ export class Scheduler implements SchedulerInterface {
207215
208216 delete this . __alive [ this . __currentThread . tid . val . toString ( ) ] ;
209217 console . log ( ">>> Main thread finished with value:" , retVal . stringRep ( ) ) ;
218+ const persist = argv [ TroupeCliArg . Persist ] ;
210219 if ( persist ) {
211220 this . rtObj . persist ( retVal , persist )
212221 console . log ( "Saved the result value in file" , persist )
0 commit comments