@dodona/papyros 4.1.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/__vite-browser-external-9wXp6ZBx.js +1 -0
- package/dist/assets/__vite-browser-external-BIHI7g3E.js +1 -0
- package/dist/assets/index-C1AWjGcU.js +2202 -0
- package/dist/assets/manifest-BaVmi6rC.json +15 -0
- package/dist/assets/python_package.tar.gz-B8aMWvGt.load_by_url +0 -0
- package/dist/assets/worker-BhABRh01.js +5 -0
- package/dist/assets/worker-C2Ju1j5g.js +110 -0
- package/dist/index.html +26 -0
- package/dist/manifest.json +15 -0
- package/dist/robots.txt +3 -0
- package/package.json +1 -1
- package/dist/Library.d.ts +0 -11
- package/dist/Library.js +0 -11
- package/dist/Library.js.map +0 -1
- package/dist/ProgrammingLanguage.d.ts +0 -7
- package/dist/ProgrammingLanguage.js +0 -9
- package/dist/ProgrammingLanguage.js.map +0 -1
- package/dist/backend/Backend.d.ts +0 -92
- package/dist/backend/Backend.js +0 -79
- package/dist/backend/Backend.js.map +0 -1
- package/dist/backend/workers/javascript/JavaScriptWorker.d.ts +0 -39
- package/dist/backend/workers/javascript/JavaScriptWorker.js +0 -158
- package/dist/backend/workers/javascript/JavaScriptWorker.js.map +0 -1
- package/dist/backend/workers/javascript/worker.d.ts +0 -1
- package/dist/backend/workers/javascript/worker.js +0 -5
- package/dist/backend/workers/javascript/worker.js.map +0 -1
- package/dist/backend/workers/python/PythonWorker.d.ts +0 -32
- package/dist/backend/workers/python/PythonWorker.js +0 -117
- package/dist/backend/workers/python/PythonWorker.js.map +0 -1
- package/dist/backend/workers/python/python_package.tar.gz.load_by_url +0 -0
- package/dist/backend/workers/python/worker.d.ts +0 -1
- package/dist/backend/workers/python/worker.js +0 -5
- package/dist/backend/workers/python/worker.js.map +0 -1
- package/dist/communication/BackendEvent.d.ts +0 -33
- package/dist/communication/BackendEvent.js +0 -18
- package/dist/communication/BackendEvent.js.map +0 -1
- package/dist/communication/BackendEventQueue.d.ts +0 -59
- package/dist/communication/BackendEventQueue.js +0 -96
- package/dist/communication/BackendEventQueue.js.map +0 -1
- package/dist/communication/BackendManager.d.ts +0 -68
- package/dist/communication/BackendManager.js +0 -99
- package/dist/communication/BackendManager.js.map +0 -1
- package/dist/communication/InputServiceWorker.d.ts +0 -1
- package/dist/communication/InputServiceWorker.js +0 -37
- package/dist/communication/InputServiceWorker.js.map +0 -1
- package/dist/communication/InputWorker.d.ts +0 -22
- package/dist/communication/InputWorker.js +0 -63
- package/dist/communication/InputWorker.js.map +0 -1
- package/dist/frontend/components/CodeRunner.d.ts +0 -9
- package/dist/frontend/components/CodeRunner.js +0 -60
- package/dist/frontend/components/CodeRunner.js.map +0 -1
- package/dist/frontend/components/Debugger.d.ts +0 -7
- package/dist/frontend/components/Debugger.js +0 -75
- package/dist/frontend/components/Debugger.js.map +0 -1
- package/dist/frontend/components/Input.d.ts +0 -13
- package/dist/frontend/components/Input.js +0 -60
- package/dist/frontend/components/Input.js.map +0 -1
- package/dist/frontend/components/Output.d.ts +0 -14
- package/dist/frontend/components/Output.js +0 -157
- package/dist/frontend/components/Output.js.map +0 -1
- package/dist/frontend/components/PapyrosElement.d.ts +0 -8
- package/dist/frontend/components/PapyrosElement.js +0 -24
- package/dist/frontend/components/PapyrosElement.js.map +0 -1
- package/dist/frontend/components/app/App.d.ts +0 -24
- package/dist/frontend/components/app/App.js +0 -207
- package/dist/frontend/components/app/App.js.map +0 -1
- package/dist/frontend/components/app/ExamplePicker.d.ts +0 -7
- package/dist/frontend/components/app/ExamplePicker.js +0 -36
- package/dist/frontend/components/app/ExamplePicker.js.map +0 -1
- package/dist/frontend/components/app/LanguagePicker.d.ts +0 -7
- package/dist/frontend/components/app/LanguagePicker.js +0 -33
- package/dist/frontend/components/app/LanguagePicker.js.map +0 -1
- package/dist/frontend/components/app/ProgrammingLanguagePicker.d.ts +0 -7
- package/dist/frontend/components/app/ProgrammingLanguagePicker.js +0 -38
- package/dist/frontend/components/app/ProgrammingLanguagePicker.js.map +0 -1
- package/dist/frontend/components/app/examples/JavaScriptExamples.d.ts +0 -5
- package/dist/frontend/components/app/examples/JavaScriptExamples.js +0 -16
- package/dist/frontend/components/app/examples/JavaScriptExamples.js.map +0 -1
- package/dist/frontend/components/app/examples/PythonExamples.d.ts +0 -14
- package/dist/frontend/components/app/examples/PythonExamples.js +0 -163
- package/dist/frontend/components/app/examples/PythonExamples.js.map +0 -1
- package/dist/frontend/components/app/themes/ThemePicker.d.ts +0 -11
- package/dist/frontend/components/app/themes/ThemePicker.js +0 -48
- package/dist/frontend/components/app/themes/ThemePicker.js.map +0 -1
- package/dist/frontend/components/app/themes/ThemedButton.d.ts +0 -9
- package/dist/frontend/components/app/themes/ThemedButton.js +0 -53
- package/dist/frontend/components/app/themes/ThemedButton.js.map +0 -1
- package/dist/frontend/components/code_mirror/BatchInputEditor.d.ts +0 -8
- package/dist/frontend/components/code_mirror/BatchInputEditor.js +0 -51
- package/dist/frontend/components/code_mirror/BatchInputEditor.js.map +0 -1
- package/dist/frontend/components/code_mirror/CodeEditor.d.ts +0 -24
- package/dist/frontend/components/code_mirror/CodeEditor.js +0 -200
- package/dist/frontend/components/code_mirror/CodeEditor.js.map +0 -1
- package/dist/frontend/components/code_mirror/CodeMirrorEditor.d.ts +0 -22
- package/dist/frontend/components/code_mirror/CodeMirrorEditor.js +0 -111
- package/dist/frontend/components/code_mirror/CodeMirrorEditor.js.map +0 -1
- package/dist/frontend/components/code_mirror/Extensions.d.ts +0 -15
- package/dist/frontend/components/code_mirror/Extensions.js +0 -164
- package/dist/frontend/components/code_mirror/Extensions.js.map +0 -1
- package/dist/frontend/components/code_mirror/MaterialTheme.d.ts +0 -5
- package/dist/frontend/components/code_mirror/MaterialTheme.js +0 -115
- package/dist/frontend/components/code_mirror/MaterialTheme.js.map +0 -1
- package/dist/frontend/components/code_runner/ButtonLint.d.ts +0 -9
- package/dist/frontend/components/code_runner/ButtonLint.js +0 -72
- package/dist/frontend/components/code_runner/ButtonLint.js.map +0 -1
- package/dist/frontend/components/code_runner/Code.d.ts +0 -7
- package/dist/frontend/components/code_runner/Code.js +0 -48
- package/dist/frontend/components/code_runner/Code.js.map +0 -1
- package/dist/frontend/components/code_runner/RunState.d.ts +0 -7
- package/dist/frontend/components/code_runner/RunState.js +0 -41
- package/dist/frontend/components/code_runner/RunState.js.map +0 -1
- package/dist/frontend/components/input/BatchInput.d.ts +0 -9
- package/dist/frontend/components/input/BatchInput.js +0 -53
- package/dist/frontend/components/input/BatchInput.js.map +0 -1
- package/dist/frontend/components/input/InteractiveInput.d.ts +0 -13
- package/dist/frontend/components/input/InteractiveInput.js +0 -71
- package/dist/frontend/components/input/InteractiveInput.js.map +0 -1
- package/dist/frontend/state/Constants.d.ts +0 -38
- package/dist/frontend/state/Constants.js +0 -111
- package/dist/frontend/state/Constants.js.map +0 -1
- package/dist/frontend/state/Debugger.d.ts +0 -23
- package/dist/frontend/state/Debugger.js +0 -86
- package/dist/frontend/state/Debugger.js.map +0 -1
- package/dist/frontend/state/Examples.d.ts +0 -11
- package/dist/frontend/state/Examples.js +0 -36
- package/dist/frontend/state/Examples.js.map +0 -1
- package/dist/frontend/state/I18n.d.ts +0 -16
- package/dist/frontend/state/I18n.js +0 -75
- package/dist/frontend/state/I18n.js.map +0 -1
- package/dist/frontend/state/InputOutput.d.ts +0 -64
- package/dist/frontend/state/InputOutput.js +0 -146
- package/dist/frontend/state/InputOutput.js.map +0 -1
- package/dist/frontend/state/Papyros.d.ts +0 -40
- package/dist/frontend/state/Papyros.js +0 -115
- package/dist/frontend/state/Papyros.js.map +0 -1
- package/dist/frontend/state/Runner.d.ts +0 -123
- package/dist/frontend/state/Runner.js +0 -372
- package/dist/frontend/state/Runner.js.map +0 -1
- package/dist/frontend/state/Test.d.ts +0 -10
- package/dist/frontend/state/Test.js +0 -43
- package/dist/frontend/state/Test.js.map +0 -1
- package/dist/frontend/state/Translations.d.ts +0 -178
- package/dist/frontend/state/Translations.js +0 -187
- package/dist/frontend/state/Translations.js.map +0 -1
- package/dist/frontend/state/themes/blue-dark.d.ts +0 -2
- package/dist/frontend/state/themes/blue-dark.js +0 -56
- package/dist/frontend/state/themes/blue-dark.js.map +0 -1
- package/dist/frontend/state/themes/blue-light.d.ts +0 -2
- package/dist/frontend/state/themes/blue-light.js +0 -56
- package/dist/frontend/state/themes/blue-light.js.map +0 -1
- package/dist/frontend/state/themes/green-dark.d.ts +0 -2
- package/dist/frontend/state/themes/green-dark.js +0 -56
- package/dist/frontend/state/themes/green-dark.js.map +0 -1
- package/dist/frontend/state/themes/green-light.d.ts +0 -2
- package/dist/frontend/state/themes/green-light.js +0 -56
- package/dist/frontend/state/themes/green-light.js.map +0 -1
- package/dist/frontend/state/themes/red-dark.d.ts +0 -2
- package/dist/frontend/state/themes/red-dark.js +0 -56
- package/dist/frontend/state/themes/red-dark.js.map +0 -1
- package/dist/frontend/state/themes/red-light.d.ts +0 -2
- package/dist/frontend/state/themes/red-light.js +0 -56
- package/dist/frontend/state/themes/red-light.js.map +0 -1
- package/dist/util/Logging.d.ts +0 -15
- package/dist/util/Logging.js +0 -30
- package/dist/util/Logging.js.map +0 -1
- package/dist/util/Util.d.ts +0 -8
- package/dist/util/Util.js +0 -48
- package/dist/util/Util.js.map +0 -1
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Backend } from "../../Backend";
|
|
11
|
-
import { BackendEventType } from "../../../communication/BackendEvent";
|
|
12
|
-
/**
|
|
13
|
-
* Implementation of a JavaScript backend for Papyros
|
|
14
|
-
* by using eval and overriding some builtins
|
|
15
|
-
*/
|
|
16
|
-
export class JavaScriptWorker extends Backend {
|
|
17
|
-
/**
|
|
18
|
-
* Convert varargs to a string, similar to how the console does it
|
|
19
|
-
* @param {any[]} args The values to join into a string
|
|
20
|
-
* @return {string} The string representation
|
|
21
|
-
*/
|
|
22
|
-
static stringify(...args) {
|
|
23
|
-
const asString = args
|
|
24
|
-
.map((a) => {
|
|
25
|
-
if (Array.isArray(a)) {
|
|
26
|
-
return JSON.stringify(a);
|
|
27
|
-
}
|
|
28
|
-
else if (typeof a === "string") {
|
|
29
|
-
return a;
|
|
30
|
-
}
|
|
31
|
-
else if (typeof a === "number") {
|
|
32
|
-
return a + "";
|
|
33
|
-
}
|
|
34
|
-
else if (typeof a === "object" && "toString" in a) {
|
|
35
|
-
let aString = a.toString();
|
|
36
|
-
if (aString === "[object Object]") {
|
|
37
|
-
// useless toString, so use JSON
|
|
38
|
-
aString = JSON.stringify(a);
|
|
39
|
-
}
|
|
40
|
-
return aString;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
return JSON.stringify(args);
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
.join(" ");
|
|
47
|
-
return asString;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Prompt the user for input with a message
|
|
51
|
-
* @param {string} text The message to show when asking for input
|
|
52
|
-
* @return {string} The value the user gave
|
|
53
|
-
*/
|
|
54
|
-
prompt(text = "") {
|
|
55
|
-
return this.onEvent({
|
|
56
|
-
type: BackendEventType.Input,
|
|
57
|
-
data: text,
|
|
58
|
-
contentType: "text/plain",
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Print values to the output screen
|
|
63
|
-
* @param {any[]} args The values to log
|
|
64
|
-
*/
|
|
65
|
-
consoleLog(...args) {
|
|
66
|
-
this.queue.put(BackendEventType.Output, JavaScriptWorker.stringify(...args) + "\n", "text/plain");
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Print values to the error screen
|
|
70
|
-
* @param {any[]} args The error values to log
|
|
71
|
-
*/
|
|
72
|
-
consoleError(...args) {
|
|
73
|
-
this.queue.put(BackendEventType.Error, JavaScriptWorker.stringify(...args) + "\n", "text/plain");
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Helper method to generate suggestions based on properties in an object
|
|
77
|
-
* @param {number} from Where in the document the autocompletion starts
|
|
78
|
-
* @param {any} object Object with properties that might be relevant
|
|
79
|
-
* @return {CompletionResult} Autocompletion suggestions
|
|
80
|
-
*/
|
|
81
|
-
static completeProperties(from, object) {
|
|
82
|
-
const options = Object.keys(object).map((name) => {
|
|
83
|
-
return {
|
|
84
|
-
label: name,
|
|
85
|
-
type: typeof object[name] === "function" ? "function" : "variable",
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
from,
|
|
90
|
-
options,
|
|
91
|
-
validFor: /^[\w$]*$/,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
runCode(extras, code) {
|
|
95
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
this.extras = extras;
|
|
97
|
-
this.queue.reset();
|
|
98
|
-
// Builtins to store before execution and restore afterwards
|
|
99
|
-
// Workers do not have access to prompt
|
|
100
|
-
const oldContent = {
|
|
101
|
-
"console.log": console.log,
|
|
102
|
-
"console.error": console.error,
|
|
103
|
-
};
|
|
104
|
-
// Overrides for the builtins
|
|
105
|
-
const newContext = {
|
|
106
|
-
prompt: this.prompt.bind(this),
|
|
107
|
-
"console.log": this.consoleLog.bind(this),
|
|
108
|
-
"console.error": this.consoleError.bind(this),
|
|
109
|
-
};
|
|
110
|
-
// Override the builtins
|
|
111
|
-
new Function("ctx", Object.keys(newContext)
|
|
112
|
-
.map((k) => `${k} = ctx['${k}'];`)
|
|
113
|
-
.join("\n"))(newContext);
|
|
114
|
-
let result = null;
|
|
115
|
-
try {
|
|
116
|
-
// run the user's code
|
|
117
|
-
this.onEvent({
|
|
118
|
-
type: BackendEventType.Start,
|
|
119
|
-
contentType: "text/plain",
|
|
120
|
-
data: "RunCode",
|
|
121
|
-
});
|
|
122
|
-
result = yield eval(code);
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
// try to create a friendly traceback
|
|
126
|
-
Error.captureStackTrace(error);
|
|
127
|
-
result = yield this.onEvent({
|
|
128
|
-
type: BackendEventType.Error,
|
|
129
|
-
contentType: "application/json",
|
|
130
|
-
data: {
|
|
131
|
-
name: error.constructor.name,
|
|
132
|
-
what: error.message,
|
|
133
|
-
traceback: error.stack,
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
finally {
|
|
138
|
-
// restore the old builtins
|
|
139
|
-
new Function("ctx", Object.keys(oldContent)
|
|
140
|
-
.map((k) => `${k} = ctx['${k}'];`)
|
|
141
|
-
.join("\n"))(oldContent);
|
|
142
|
-
this.queue.flush();
|
|
143
|
-
this.onEvent({
|
|
144
|
-
type: BackendEventType.End,
|
|
145
|
-
contentType: "text/plain",
|
|
146
|
-
data: "CodeFinished",
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
return result;
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
lintCode() {
|
|
153
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
return Promise.resolve([]);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
//# sourceMappingURL=JavaScriptWorker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JavaScriptWorker.js","sourceRoot":"","sources":["../../../../src/backend/workers/javascript/JavaScriptWorker.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,E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WAAW,CAAC,KAAK,CAAC;qBACjC,IAAI,CAAC,IAAI,CAAC,CAClB,CAAC,UAAU,CAAC,CAAC;gBACd,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;gBACnB,IAAI,CAAC,OAAO,CAAC;oBACT,IAAI,EAAE,gBAAgB,CAAC,GAAG;oBAC1B,WAAW,EAAE,YAAY;oBACzB,IAAI,EAAE,cAAc;iBACvB,CAAC,CAAC;YACP,CAAC;YACD,OAAO,MAAM,CAAC;QAClB,CAAC;KAAA;IAEqB,QAAQ;;YAC1B,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC/B,CAAC;KAAA;CACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../../src/backend/workers/javascript/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,MAAM,GAAG,IAAI,gBAAgB,EAAE,CAAC;AACtC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Backend, RunMode, WorkerDiagnostic } from "../../Backend";
|
|
2
|
-
import { BackendEvent } from "../../../communication/BackendEvent";
|
|
3
|
-
import { PyodideExtras } from "pyodide-worker-runner";
|
|
4
|
-
/**
|
|
5
|
-
* Implementation of a Python backend for Papyros
|
|
6
|
-
* Powered by Pyodide (https://pyodide.org/)
|
|
7
|
-
*/
|
|
8
|
-
export declare class PythonWorker extends Backend<PyodideExtras> {
|
|
9
|
-
private pyodide;
|
|
10
|
-
private papyros;
|
|
11
|
-
/**
|
|
12
|
-
* Promise to asynchronously install imports needed by the code
|
|
13
|
-
*/
|
|
14
|
-
private installPromise;
|
|
15
|
-
constructor();
|
|
16
|
-
private static convert;
|
|
17
|
-
/**
|
|
18
|
-
* @return {any} Function to expose a method with Pyodide support
|
|
19
|
-
*/
|
|
20
|
-
protected syncExpose(): any;
|
|
21
|
-
private static getPyodide;
|
|
22
|
-
launch(onEvent: (e: BackendEvent) => void): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Helper method to install imports and prevent race conditions with double downloading
|
|
25
|
-
* @param {string} code The code containing import statements
|
|
26
|
-
*/
|
|
27
|
-
private installImports;
|
|
28
|
-
runModes(code: string): Array<RunMode>;
|
|
29
|
-
runCode(extras: PyodideExtras, code: string, mode?: string): Promise<any>;
|
|
30
|
-
lintCode(code: string): Promise<Array<WorkerDiagnostic>>;
|
|
31
|
-
provideFiles(inlineFiles: Record<string, string>, hrefFiles: Record<string, string>): Promise<void>;
|
|
32
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Backend, RunMode } from "../../Backend";
|
|
11
|
-
import { pyodideExpose, loadPyodideAndPackage } from "pyodide-worker-runner";
|
|
12
|
-
const pythonPackageUrl = new URL("./python_package.tar.gz.load_by_url", import.meta.url).href;
|
|
13
|
-
/**
|
|
14
|
-
* Implementation of a Python backend for Papyros
|
|
15
|
-
* Powered by Pyodide (https://pyodide.org/)
|
|
16
|
-
*/
|
|
17
|
-
export class PythonWorker extends Backend {
|
|
18
|
-
constructor() {
|
|
19
|
-
super();
|
|
20
|
-
this.pyodide = {};
|
|
21
|
-
this.installPromise = null;
|
|
22
|
-
}
|
|
23
|
-
static convert(data) {
|
|
24
|
-
return data.toJs ? data.toJs({ dict_converter: Object.fromEntries }) : data;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @return {any} Function to expose a method with Pyodide support
|
|
28
|
-
*/
|
|
29
|
-
syncExpose() {
|
|
30
|
-
return pyodideExpose;
|
|
31
|
-
}
|
|
32
|
-
static getPyodide() {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
return yield loadPyodideAndPackage({ url: pythonPackageUrl, format: ".tgz" });
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
launch(onEvent) {
|
|
38
|
-
const _super = Object.create(null, {
|
|
39
|
-
launch: { get: () => super.launch }
|
|
40
|
-
});
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
yield _super.launch.call(this, onEvent);
|
|
43
|
-
this.pyodide = yield PythonWorker.getPyodide();
|
|
44
|
-
// Python calls our function with a PyProxy dict or a Js Map,
|
|
45
|
-
// These must be converted to a PapyrosEvent (JS Object) to allow message passing
|
|
46
|
-
this.papyros = this.pyodide.pyimport("papyros").Papyros.callKwargs({
|
|
47
|
-
callback: (e) => {
|
|
48
|
-
const converted = PythonWorker.convert(e);
|
|
49
|
-
return this.onEvent(converted);
|
|
50
|
-
},
|
|
51
|
-
buffer_constructor: (cb) => {
|
|
52
|
-
this.queue.setCallback(cb);
|
|
53
|
-
return this.queue;
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
// preload micropip to allow installing packages
|
|
57
|
-
yield this.pyodide.loadPackage("micropip");
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Helper method to install imports and prevent race conditions with double downloading
|
|
62
|
-
* @param {string} code The code containing import statements
|
|
63
|
-
*/
|
|
64
|
-
installImports(code) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
var _a;
|
|
67
|
-
if (this.installPromise == null) {
|
|
68
|
-
this.installPromise = (_a = this.papyros) === null || _a === void 0 ? void 0 : _a.install_imports.callKwargs({
|
|
69
|
-
source_code: code,
|
|
70
|
-
ignore_missing: true,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
yield this.installPromise;
|
|
74
|
-
this.installPromise = null;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
runModes(code) {
|
|
78
|
-
var _a;
|
|
79
|
-
let modes = super.runModes(code);
|
|
80
|
-
if ((_a = this.papyros) === null || _a === void 0 ? void 0 : _a.has_doctests(code)) {
|
|
81
|
-
modes = [RunMode.Doctest, ...modes];
|
|
82
|
-
}
|
|
83
|
-
modes = [RunMode.Debug, ...modes];
|
|
84
|
-
return modes;
|
|
85
|
-
}
|
|
86
|
-
runCode(extras_1, code_1) {
|
|
87
|
-
return __awaiter(this, arguments, void 0, function* (extras, code, mode = "exec") {
|
|
88
|
-
var _a;
|
|
89
|
-
this.extras = extras;
|
|
90
|
-
if (extras.interruptBuffer) {
|
|
91
|
-
this.pyodide.setInterruptBuffer(extras.interruptBuffer);
|
|
92
|
-
}
|
|
93
|
-
yield this.installImports(code);
|
|
94
|
-
return yield ((_a = this.papyros) === null || _a === void 0 ? void 0 : _a.run_async.callKwargs({
|
|
95
|
-
source_code: code,
|
|
96
|
-
mode: mode,
|
|
97
|
-
}));
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
lintCode(code) {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
var _a;
|
|
103
|
-
yield this.installImports(code);
|
|
104
|
-
return PythonWorker.convert(((_a = this.papyros) === null || _a === void 0 ? void 0 : _a.lint(code)) || []);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
provideFiles(inlineFiles, hrefFiles) {
|
|
108
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
var _a;
|
|
110
|
-
yield ((_a = this.papyros) === null || _a === void 0 ? void 0 : _a.provide_files.callKwargs({
|
|
111
|
-
inline_files: JSON.stringify(inlineFiles),
|
|
112
|
-
href_files: JSON.stringify(hrefFiles),
|
|
113
|
-
}));
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=PythonWorker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PythonWorker.js","sourceRoot":"","sources":["../../../../src/backend/workers/python/PythonWorker.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAoB,MAAM,eAAe,CAAC;AAInE,OAAO,EAAE,aAAa,EAAiB,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE5F,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,qCAAqC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AAE9F;;;GAGG;AACH,MAAM,OAAO,YAAa,SAAQ,OAAsB;IAOpD;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,EAAsB,CAAC;QACtC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IAC/B,CAAC;IAEO,MAAM,CAAC,OAAO,CAAC,IAAS;QAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAChF,CAAC;IAED;;OAEG;IACgB,UAAU;QACzB,OAAO,aAAa,CAAC;IACzB,CAAC;IAEO,MAAM,CAAO,UAAU;;YAC3B,OAAO,MAAM,qBAAqB,CAAC,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAClF,CAAC;KAAA;IAEY,MAAM,CAAC,OAAkC;;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 -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../../src/backend/workers/python/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;AAClC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enum representing all possible types for supported events
|
|
3
|
-
*/
|
|
4
|
-
export declare enum BackendEventType {
|
|
5
|
-
Start = "start",
|
|
6
|
-
End = "end",
|
|
7
|
-
Input = "input",
|
|
8
|
-
Output = "output",
|
|
9
|
-
Sleep = "sleep",
|
|
10
|
-
Error = "error",
|
|
11
|
-
Interrupt = "interrupt",
|
|
12
|
-
Loading = "loading",
|
|
13
|
-
Frame = "frame",
|
|
14
|
-
FrameChange = "frame-change",
|
|
15
|
-
Stop = "stop"
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Interface for events used for communication between threads
|
|
19
|
-
*/
|
|
20
|
-
export interface BackendEvent {
|
|
21
|
-
/**
|
|
22
|
-
* The type of action generating this event
|
|
23
|
-
*/
|
|
24
|
-
type: BackendEventType;
|
|
25
|
-
/**
|
|
26
|
-
* The actual data stored in this event
|
|
27
|
-
*/
|
|
28
|
-
data: any;
|
|
29
|
-
/**
|
|
30
|
-
* The format used for the data to help with parsing
|
|
31
|
-
*/
|
|
32
|
-
contentType?: string;
|
|
33
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Enum representing all possible types for supported events
|
|
3
|
-
*/
|
|
4
|
-
export var BackendEventType;
|
|
5
|
-
(function (BackendEventType) {
|
|
6
|
-
BackendEventType["Start"] = "start";
|
|
7
|
-
BackendEventType["End"] = "end";
|
|
8
|
-
BackendEventType["Input"] = "input";
|
|
9
|
-
BackendEventType["Output"] = "output";
|
|
10
|
-
BackendEventType["Sleep"] = "sleep";
|
|
11
|
-
BackendEventType["Error"] = "error";
|
|
12
|
-
BackendEventType["Interrupt"] = "interrupt";
|
|
13
|
-
BackendEventType["Loading"] = "loading";
|
|
14
|
-
BackendEventType["Frame"] = "frame";
|
|
15
|
-
BackendEventType["FrameChange"] = "frame-change";
|
|
16
|
-
BackendEventType["Stop"] = "stop";
|
|
17
|
-
})(BackendEventType || (BackendEventType = {}));
|
|
18
|
-
//# sourceMappingURL=BackendEvent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BackendEvent.js","sourceRoot":"","sources":["../../src/communication/BackendEvent.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,gBAYX;AAZD,WAAY,gBAAgB;IACxB,mCAAe,CAAA;IACf,+BAAW,CAAA;IACX,mCAAe,CAAA;IACf,qCAAiB,CAAA;IACjB,mCAAe,CAAA;IACf,mCAAe,CAAA;IACf,2CAAuB,CAAA;IACvB,uCAAmB,CAAA;IACnB,mCAAe,CAAA;IACf,gDAA4B,CAAA;IAC5B,iCAAa,CAAA;AACjB,CAAC,EAZW,gBAAgB,KAAhB,gBAAgB,QAY3B"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { BackendEvent, BackendEventType } from "./BackendEvent";
|
|
2
|
-
/**
|
|
3
|
-
* Queue to limit the amount of messages sent between threads
|
|
4
|
-
* This prevents communication issues which arise either in Comlink
|
|
5
|
-
* or in the WebWorker message passing code
|
|
6
|
-
*/
|
|
7
|
-
export declare class BackendEventQueue {
|
|
8
|
-
/**
|
|
9
|
-
* Function to process events in the queue
|
|
10
|
-
*/
|
|
11
|
-
private callback;
|
|
12
|
-
/**
|
|
13
|
-
* The time in milliseconds before sending events through
|
|
14
|
-
*/
|
|
15
|
-
private flushTime;
|
|
16
|
-
/**
|
|
17
|
-
* Queue storing the BackendEvents before flushing
|
|
18
|
-
*/
|
|
19
|
-
private queue;
|
|
20
|
-
/**
|
|
21
|
-
* Time in milliseconds when the last flush occurred
|
|
22
|
-
*/
|
|
23
|
-
private lastFlushTime;
|
|
24
|
-
/**
|
|
25
|
-
* Decoder to convert data to strings
|
|
26
|
-
*/
|
|
27
|
-
private decoder;
|
|
28
|
-
/**
|
|
29
|
-
* @param {function(BackendEvent):void} callback Function to process events in the queue
|
|
30
|
-
* @param {number} flushTime The time in milliseconds before sending events through
|
|
31
|
-
*/
|
|
32
|
-
constructor(callback: (e: BackendEvent) => void, flushTime?: number);
|
|
33
|
-
/**
|
|
34
|
-
* Add an element to the queue
|
|
35
|
-
* @param {BackendEventType} type The type of the event
|
|
36
|
-
* @param {string | BufferSource | number} text The data for the event
|
|
37
|
-
* @param {string | any} extra Extra data for the event
|
|
38
|
-
* If string, interpreted as the contentType
|
|
39
|
-
* If anything else, it should contain a contentType
|
|
40
|
-
* If the contentType is not textual, an error is thrown
|
|
41
|
-
*/
|
|
42
|
-
put(type: BackendEventType, text: string | BufferSource | number, extra: string | any): void;
|
|
43
|
-
/**
|
|
44
|
-
* @return {boolean} Whether the queue contents should be flushed
|
|
45
|
-
*/
|
|
46
|
-
protected shouldFlush(): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Reset the queue contents for a new run
|
|
49
|
-
*/
|
|
50
|
-
reset(): void;
|
|
51
|
-
/**
|
|
52
|
-
* Flush the queue contents using the callback
|
|
53
|
-
*/
|
|
54
|
-
flush(): void;
|
|
55
|
-
/**
|
|
56
|
-
* @param {Function} callback The event-consuming callback
|
|
57
|
-
*/
|
|
58
|
-
setCallback(callback: (e: BackendEvent) => void): void;
|
|
59
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Queue to limit the amount of messages sent between threads
|
|
3
|
-
* This prevents communication issues which arise either in Comlink
|
|
4
|
-
* or in the WebWorker message passing code
|
|
5
|
-
*/
|
|
6
|
-
export class BackendEventQueue {
|
|
7
|
-
/**
|
|
8
|
-
* @param {function(BackendEvent):void} callback Function to process events in the queue
|
|
9
|
-
* @param {number} flushTime The time in milliseconds before sending events through
|
|
10
|
-
*/
|
|
11
|
-
constructor(callback, flushTime = 100) {
|
|
12
|
-
this.callback = callback;
|
|
13
|
-
this.flushTime = flushTime;
|
|
14
|
-
this.queue = [];
|
|
15
|
-
this.lastFlushTime = new Date().getTime();
|
|
16
|
-
this.decoder = new TextDecoder();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Add an element to the queue
|
|
20
|
-
* @param {BackendEventType} type The type of the event
|
|
21
|
-
* @param {string | BufferSource | number} text The data for the event
|
|
22
|
-
* @param {string | any} extra Extra data for the event
|
|
23
|
-
* If string, interpreted as the contentType
|
|
24
|
-
* If anything else, it should contain a contentType
|
|
25
|
-
* If the contentType is not textual, an error is thrown
|
|
26
|
-
*/
|
|
27
|
-
put(type, text, extra) {
|
|
28
|
-
let stringData = "";
|
|
29
|
-
if (typeof text === "number") {
|
|
30
|
-
stringData = text.toString();
|
|
31
|
-
}
|
|
32
|
-
else if (typeof text !== "string") {
|
|
33
|
-
stringData = this.decoder.decode(text);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
stringData = text;
|
|
37
|
-
}
|
|
38
|
-
let extraArgs = {};
|
|
39
|
-
let contentType = "text/plain";
|
|
40
|
-
if (extra) {
|
|
41
|
-
if (typeof extra === "string") {
|
|
42
|
-
contentType = extra;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
contentType = extra["contentType"];
|
|
46
|
-
delete extra["contentType"];
|
|
47
|
-
extraArgs = extra;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (this.queue.length === 0 ||
|
|
51
|
-
!contentType.startsWith("text") || // Non textual cannot be combined
|
|
52
|
-
this.queue[this.queue.length - 1].type !== type || // Different type
|
|
53
|
-
// Can't be combined if contentType doesn't match
|
|
54
|
-
this.queue[this.queue.length - 1].contentType !== contentType) {
|
|
55
|
-
this.queue.push(Object.assign({ type: type, data: stringData, contentType: contentType }, extraArgs));
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
// Same kind of event, combine into one
|
|
59
|
-
this.queue[this.queue.length - 1].data += stringData;
|
|
60
|
-
}
|
|
61
|
-
if (this.shouldFlush()) {
|
|
62
|
-
this.flush();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* @return {boolean} Whether the queue contents should be flushed
|
|
67
|
-
*/
|
|
68
|
-
shouldFlush() {
|
|
69
|
-
return (this.queue.length > 1 || // different types of Events present
|
|
70
|
-
new Date().getTime() - this.lastFlushTime > this.flushTime);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Reset the queue contents for a new run
|
|
74
|
-
*/
|
|
75
|
-
reset() {
|
|
76
|
-
this.queue = [];
|
|
77
|
-
this.lastFlushTime = new Date().getTime();
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Flush the queue contents using the callback
|
|
81
|
-
*/
|
|
82
|
-
flush() {
|
|
83
|
-
this.queue.forEach((e) => {
|
|
84
|
-
this.callback(e);
|
|
85
|
-
});
|
|
86
|
-
this.queue = [];
|
|
87
|
-
this.lastFlushTime = new Date().getTime();
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* @param {Function} callback The event-consuming callback
|
|
91
|
-
*/
|
|
92
|
-
setCallback(callback) {
|
|
93
|
-
this.callback = callback;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
//# sourceMappingURL=BackendEventQueue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BackendEventQueue.js","sourceRoot":"","sources":["../../src/communication/BackendEventQueue.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAsB1B;;;OAGG;IACH,YAAY,QAAmC,EAAE,SAAS,GAAG,GAAG;QAC5D,IAAI,CAAC,QAAQ,GAA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,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Backend } from "../backend/Backend";
|
|
2
|
-
import { ProgrammingLanguage } from "../ProgrammingLanguage";
|
|
3
|
-
import { BackendEvent, BackendEventType } from "./BackendEvent";
|
|
4
|
-
import { Channel } from "sync-message";
|
|
5
|
-
import { SyncClient } from "comsync";
|
|
6
|
-
/**
|
|
7
|
-
* Callback type definition for subscribers
|
|
8
|
-
* @param {BackendEvent} e The published event
|
|
9
|
-
*/
|
|
10
|
-
type BackendEventListener = (e: BackendEvent) => void;
|
|
11
|
-
/**
|
|
12
|
-
* Abstract class to implement the singleton pattern
|
|
13
|
-
* Static methods group functionality
|
|
14
|
-
*/
|
|
15
|
-
export declare abstract class BackendManager {
|
|
16
|
-
/**
|
|
17
|
-
* Map programming languages to Backend constructors
|
|
18
|
-
*/
|
|
19
|
-
private static createBackendMap;
|
|
20
|
-
/**
|
|
21
|
-
* Map to cache Backends per ProgrammingLanguage
|
|
22
|
-
*/
|
|
23
|
-
private static backendMap;
|
|
24
|
-
/**
|
|
25
|
-
* Map an event type to interested subscribers
|
|
26
|
-
* Uses an Array to maintain order of subscription
|
|
27
|
-
*/
|
|
28
|
-
private static subscriberMap;
|
|
29
|
-
/**
|
|
30
|
-
* Whether the BackendManager is publishing events
|
|
31
|
-
*/
|
|
32
|
-
private static halted;
|
|
33
|
-
/**
|
|
34
|
-
* The channel used to communicate with the SyncClients
|
|
35
|
-
*/
|
|
36
|
-
static channel: Channel;
|
|
37
|
-
/**
|
|
38
|
-
* @param {ProgrammingLanguage} language The language to support
|
|
39
|
-
* @param {Function} backendCreator The constructor for a SyncClient
|
|
40
|
-
*/
|
|
41
|
-
static registerBackend(language: ProgrammingLanguage, backendCreator: () => SyncClient<Backend>): void;
|
|
42
|
-
/**
|
|
43
|
-
* Start a backend for the given language and cache for reuse
|
|
44
|
-
* @param {ProgrammingLanguage} language The programming language supported by the backend
|
|
45
|
-
* @return {SyncClient<Backend>} A SyncClient for the Backend
|
|
46
|
-
*/
|
|
47
|
-
static getBackend(language: ProgrammingLanguage): SyncClient<Backend>;
|
|
48
|
-
/**
|
|
49
|
-
* Remove a backend for the given language
|
|
50
|
-
* @param {ProgrammingLanguage} language The programming language supported by the backend
|
|
51
|
-
* @return {boolean} Whether the remove operation had any effect
|
|
52
|
-
*/
|
|
53
|
-
static removeBackend(language: ProgrammingLanguage): boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Register a callback for when an event of a certain type is published
|
|
56
|
-
* @param {BackendEventType} type The type of event to subscribe to
|
|
57
|
-
* @param {BackendEventListener} subscriber Callback for when an event
|
|
58
|
-
* of the given type is published
|
|
59
|
-
*/
|
|
60
|
-
static subscribe(type: BackendEventType, subscriber: BackendEventListener): void;
|
|
61
|
-
/**
|
|
62
|
-
* Publish an event, notifying all listeners for its type
|
|
63
|
-
* @param {BackendEventType} e The event to publish
|
|
64
|
-
*/
|
|
65
|
-
static publish(e: BackendEvent): void;
|
|
66
|
-
private static halt;
|
|
67
|
-
}
|
|
68
|
-
export {};
|