Skip to content

Commit cfc8c18

Browse files
committed
Sort through and add some types for SchedulerInterface
1 parent 3d33450 commit cfc8c18

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

rt/src/Scheduler.mts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { mkTuple } from './ValuesUtil.mjs';
77
import { SchedulerInterface } from './SchedulerInterface.mjs';
88
import { RuntimeInterface } from './RuntimeInterface.mjs';
99
import { LVal } from './Lval.mjs'
10+
import { Level } from "./Level.mjs";
1011
import {ProcessID, pid_equals} from './process.mjs'
1112
import SandboxStatus from './SandboxStatus.mjs'
1213
import {ThreadError, TroupeError} from './TroupeError.mjs'
@@ -106,11 +107,18 @@ export class Scheduler implements SchedulerInterface {
106107
}
107108

108109
/** Create a new thread `t` for the given function to be evaluated and schedule it. */
109-
scheduleNewThreadAtLevel (thefun, arg, levpc, levblock, ismain = false, persist=null, isSystem = false) {
110+
scheduleNewThreadAtLevel (f: () => any,
111+
arg: any,
112+
pc: Level,
113+
block: Level,
114+
ismain: boolean = false,
115+
persist: boolean | null = null,
116+
isSystem: boolean = false)
117+
{
110118
// Create a new process ID at the given level.
111119
const pid = isSystem ? SYSTEM_PROCESS_STRING : uuidv4();
112120
const pidObj = new ProcessID(this.rt_uuid, pid, this.__node);
113-
const newPid = new LVal(pidObj, levpc);
121+
const newPid = new LVal(pidObj, pc);
114122

115123
// Epilogue for thread.
116124
const halt = ismain ? () => { this.haltMain (persist) } :
@@ -120,10 +128,10 @@ export class Scheduler implements SchedulerInterface {
120128
const t = new Thread
121129
( newPid
122130
, halt
123-
, thefun
131+
, f
124132
, arg
125-
, levpc
126-
, levblock
133+
, pc
134+
, block
127135
, new SandboxStatus.NORMAL()
128136
, this.rtObj
129137
, this );
@@ -134,9 +142,9 @@ export class Scheduler implements SchedulerInterface {
134142
return newPid;
135143
}
136144

137-
/** Schedule the given function as the very next thing to be run. */
138-
schedule(thefun, args, nm) {
139-
this.__currentThread.runNext(thefun, args, nm);
145+
/** Schedule the given function as the very next thing to be run on the current thread. */
146+
schedule(f: () => any, args: any, namespace: any) {
147+
this.__currentThread.runNext(f, args, namespace);
140148
this.scheduleThread(this.__currentThread);
141149
}
142150

@@ -206,7 +214,7 @@ export class Scheduler implements SchedulerInterface {
206214
delete this.__alive[this.__currentThread.tid.val.toString()];
207215
console.log(">>> Main thread finished with value:", retVal.stringRep());
208216
if (persist) {
209-
this.rtObj.persist(retVal, persist )
217+
this.rtObj.persist(retVal, persist)
210218
console.log("Saved the result value in file", persist)
211219
}
212220
return null;
@@ -220,8 +228,8 @@ export class Scheduler implements SchedulerInterface {
220228
}
221229

222230
/** Kill thread `t` with the error message `s` sent to its monitors. */
223-
stopThreadWithErrorMessage (t: Thread, s: string) {
224-
this.notifyMonitors(TerminationStatus.ERR, s);
231+
stopThreadWithErrorMessage (t: Thread, errMsg: string) {
232+
this.notifyMonitors(TerminationStatus.ERR, errMsg);
225233
delete this.__alive [t.tid.val.toString()];
226234
}
227235

rt/src/SchedulerInterface.mts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import { Thread } from "./Thread.mjs";
2+
import { LVal } from './Lval.mjs'
3+
import { Level } from "./Level.mjs";
24

35
export interface SchedulerInterface {
4-
// tailToTroupeFun(f: any, arg:any)
5-
// tailToTroupeFun_raw(f: any)
6-
// stepThread();
7-
resetScheduler();
8-
scheduleNewThreadAtLevel(fun: any, arg: any, pc: any, blockingTopLev: any);
9-
scheduleThread(theThread: any);
10-
resumeLoopAsync();
11-
blockThread(__currentThread: Thread);
12-
isAlive(toPid: any);
13-
getThread(toPid: any);
14-
unblockThread(toPid: any);
15-
schedule(fun: any, args: any[], namespace: any);
166
__currentThread: Thread;
17-
stopThreadWithErrorMessage (t:Thread, s:string)
18-
19-
}
7+
8+
resetScheduler(): void;
9+
10+
scheduleNewThreadAtLevel(fun: () => any, arg: any, pc: Level, block: Level): LVal;
11+
scheduleThread(t: Thread): void;
12+
schedule(fun: () => any, args: any[], namespace: any): void;
13+
14+
blockThread(t: Thread): void;
15+
unblockThread(tid: LVal): void;
16+
17+
isAlive(tid: LVal): boolean;
18+
getThread(tid: LVal): Thread;
19+
20+
stopThreadWithErrorMessage (t: Thread, errMsg: string): void
21+
22+
resumeLoopAsync(): void;
23+
}

0 commit comments

Comments
 (0)