Skip to content

Commit

Permalink
fix syntax training webworker importer. but still have issues related…
Browse files Browse the repository at this point in the history
… to pack loader
  • Loading branch information
tolstenko committed Dec 22, 2023
1 parent dcf7bf3 commit 0e47917
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
build**/
upstream**/
**/dist/
**/cmake-build**/

# build cache files
**/*.idx
Expand Down
7 changes: 4 additions & 3 deletions demo-syntax-training/src/components/SyntaxTraining.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {CopyOutlined, PlayCircleFilled, UndoOutlined} from "@ant-design/icons";
import { Editor, Monaco } from "@monaco-editor/react";
import {editor} from "monaco-editor";
const { Header, Content, Footer } = Layout;
import * as Comlink from "comlink";

import Emception from "./emception";
import EmceptionWorker from "./emception.worker";

const containerStyle: React.CSSProperties = {
width: '100%',
Expand Down Expand Up @@ -35,10 +36,10 @@ const SyntaxTrainingPage: React.FC<SyntaxTrainingPageProps> = ({

const [api, contextHolder] = notification.useNotification();

let emception: Emception;
let emception: any;
async function loadEmception(): Promise<any> {
showNotification("Loading emception...");
emception = new Emception();
emception = Comlink.wrap(new EmceptionWorker());
await emception.init();
showNotification("Emception loaded");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const preloads = [
];

class Emception {
fileSystem: FileSystem = null;
fileSystem = null;
tools = {};

async init() {
Expand Down Expand Up @@ -83,7 +83,7 @@ class Emception {

const processConfig = {
FS: fileSystem.FS,
onrunprocess: (...args) => this._run_process(args),
onrunprocess: (...args) => this._run_process(...args),
};

const tools = {
Expand All @@ -103,10 +103,10 @@ class Emception {
}
}

onprocessstart = (str) => {console.log("onprocessstart", str)};
onprocessend = (str) => {console.log("onprocessend", str)};
onstdout = (str) => {console.log(str)};
onstderr = (str) => {console.error(str)};
onprocessstart = () => {};
onprocessend = () => {};
onstdout = () => {};
onstderr = () => {};

run(...args) {
if (this.fileSystem.exists("/emscripten/cache/cache.lock")) {
Expand All @@ -117,8 +117,8 @@ class Emception {
`/emscripten/${args[0]}.py`,
...args.slice(1)
], {
print: (...args) => this.onstdout(args),
printErr: (...args) => this.onstderr(args),
print: (...args) => this.onstdout(...args),
printErr: (...args) => this.onstderr(...args),
cwd: "/working",
path: ["/emscripten"],
});
Expand All @@ -131,7 +131,7 @@ class Emception {
return result;
}

_run_process_impl(argv, opts:any = {}) {
_run_process_impl(argv, opts = {}) {
const emscripten_script = argv[0].match(/^((\/lazy)?\/emscripten\/.+?)(?:\.py)?$/)?.[1]
if (emscripten_script && this.fileSystem.exists(`${emscripten_script}.py`)) {
argv = [
Expand Down
6 changes: 6 additions & 0 deletions demo-syntax-training/src/components/emception.worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as Comlink from "comlink";
import Emception from "./emception.js";

const emception = new Emception();
globalThis.emception = emception;
Comlink.expose(emception);

0 comments on commit 0e47917

Please sign in to comment.