Skip to content

Commit a72085e

Browse files
committed
Prep for different timeout strategy
1 parent 58a5ab9 commit a72085e

File tree

5 files changed

+77
-38
lines changed

5 files changed

+77
-38
lines changed

public/css/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ label {
225225
visibility: visible;
226226
}
227227

228+
.server-status-timeout {
229+
color: white;
230+
background-image: linear-gradient(to bottom, #cacaca, #656565);
231+
visibility: visible;
232+
}
233+
228234
.control {
229235
display: flex;
230236
gap: 0.5rem;

src/index.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,38 @@ import { Diagnostic, lintGutter, setDiagnostics } from '@codemirror/lint';
33
import { EditorView, basicSetup } from "codemirror";
44
import { decode, encode } from "./encoding";
55
import { twelfHighlightStyle, twelfLanguage } from './twelf-mode';
6-
import { Status, TwelfError } from './twelf-worker-types';
6+
import { TwelfStatus, TwelfError, TwelfExecStatus } from './twelf-worker-types';
77
import { TwelfWorker, mkTwelfWorker } from './twelf-worker';
88

9-
function showStatus(status: Status) {
9+
function showStatus(status: TwelfExecStatus) {
1010
const serverStatus = (document.getElementById('server-status') as HTMLDivElement);
1111

12-
switch (status) {
13-
case Status.OK: {
14-
serverStatus.className = 'server-status server-status-ok';
15-
serverStatus.innerText = 'Server OK';
16-
17-
setTimeout(() => {
18-
serverStatus.classList.add('server-status-flash');
19-
}, 10);
20-
}
21-
break;
22-
case Status.ABORT: {
23-
serverStatus.className = 'server-status server-status-abort';
24-
serverStatus.innerText = 'Server ABORT';
12+
switch (status.t) {
13+
case 'twelfStatus': {
14+
switch (status.status) {
15+
case TwelfStatus.OK: {
16+
serverStatus.className = 'server-status server-status-ok';
17+
serverStatus.innerText = 'Server OK';
18+
19+
setTimeout(() => {
20+
serverStatus.classList.add('server-status-flash');
21+
}, 10);
22+
}
23+
break;
24+
case TwelfStatus.ABORT: {
25+
serverStatus.className = 'server-status server-status-abort';
26+
serverStatus.innerText = 'Server ABORT';
27+
} break;
28+
}
2529
} break;
30+
case 'timeout': {
31+
serverStatus.className = 'server-status server-status-timeout';
32+
serverStatus.innerText = 'Server TIMEOUT';
33+
}
2634
}
2735
}
2836

37+
2938
// Initialize editor component
3039
function initEditor(): EditorView {
3140
const editor = new EditorView({

src/twelf-service.ts

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Status, TwelfError, TwelfExecResponse } from "./twelf-worker-types";
1+
import { TwelfStatus, TwelfError, TwelfExecResponse, TwelfSideEffectData } from "./twelf-worker-types";
22
import { WasiSnapshotPreview1, args_get, args_sizes_get, clock_time_get, environ_sizes_get, fd_write } from "./wasi";
33

44
type TwelfExports = {
55
memory: WebAssembly.Memory;
66
twelf_open(argc: number, argv: number): void;
77
allocate(size: number): number;
8-
execute(): Status;
8+
execute(): TwelfStatus;
99
};
1010

1111
function debug(_x: string): void {
@@ -60,6 +60,34 @@ export class TwelfService {
6060

6161
constructor(public instance: WebAssembly.Instance, public output: string[]) { }
6262

63+
timeoutStatus(): TwelfExecResponse {
64+
return {
65+
status: { t: 'timeout' },
66+
...this.getSideEffectData()
67+
}
68+
}
69+
70+
getSideEffectData(): TwelfSideEffectData {
71+
const errorRegex = new RegExp('string:(\\d+?).(\\d+?)-(\\d+?).(\\d+?) Error: \n(.*)', 'g');
72+
let m;
73+
const errors: TwelfError[] = [];
74+
while (m = errorRegex.exec(this.output.join(''))) {
75+
errors.push({
76+
range: {
77+
line1: parseInt(m[1]),
78+
col1: parseInt(m[2]),
79+
line2: parseInt(m[3]),
80+
col2: parseInt(m[4]),
81+
},
82+
text: m[5],
83+
});
84+
}
85+
return {
86+
output: [...this.output],
87+
errors,
88+
}
89+
}
90+
6391
async exec(input: string): Promise<TwelfExecResponse> {
6492
this.output.splice(0); // Erase output
6593

@@ -81,24 +109,13 @@ export class TwelfService {
81109
}
82110
catch (e) {
83111
console.error(e);
84-
return Status.ABORT;
112+
return TwelfStatus.ABORT;
85113
}
86114
})();
87115

88-
const errorRegex = new RegExp('string:(\\d+?).(\\d+?)-(\\d+?).(\\d+?) Error: \n(.*)', 'g');
89-
let m;
90-
const errors: TwelfError[] = [];
91-
while (m = errorRegex.exec(this.output.join(''))) {
92-
errors.push({
93-
range: {
94-
line1: parseInt(m[1]),
95-
col1: parseInt(m[2]),
96-
line2: parseInt(m[3]),
97-
col2: parseInt(m[4]),
98-
},
99-
text: m[5],
100-
});
101-
}
102-
return { status, output: [...this.output], errors: errors };
116+
return {
117+
status: { t: 'twelfStatus', status },
118+
...this.getSideEffectData(),
119+
};
103120
}
104121
}

src/twelf-worker-types.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
export enum Status {
1+
export enum TwelfStatus {
22
OK = 0,
33
ABORT = 1,
44
}
55

6+
export type TwelfExecStatus =
7+
| { t: 'twelfStatus', status: TwelfStatus }
8+
| { t: 'timeout' }
9+
610
export type TwelfError = {
711
range: { line1: number, col1: number, line2: number, col2: number },
812
text: string,
@@ -14,11 +18,14 @@ export type TwelfExecRequest = {
1418
input: string,
1519
}
1620

17-
export type TwelfExecResponse = {
18-
status: Status,
21+
export type TwelfSideEffectData = {
1922
output: string[],
2023
errors: TwelfError[],
21-
}
24+
};
25+
26+
export type TwelfExecResponse = {
27+
status: TwelfExecStatus,
28+
} & TwelfSideEffectData;
2229

2330
export type TwelfReadyResponse = {};
2431

src/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { mkTwelfService } from "./twelf-service";
2-
import { Status, TwelfExecRequest, TwelfExecResponse, TwelfResponse, WithId } from "./twelf-worker-types";
2+
import { TwelfStatus, TwelfExecRequest, TwelfExecResponse, TwelfResponse, WithId } from "./twelf-worker-types";
33

44
async function go() {
55
const service = await mkTwelfService('./twelf.wasm');

0 commit comments

Comments
 (0)