Skip to content

Commit

Permalink
babylonian editor works again
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-README.md,AUTO-COMMIT-src-babylonian-programming-editor-babylonian-programming-editor.js,AUTO-COMMIT-src-babylonian-programming-editor-worker-ast-worker-babel-wrapper.js,AUTO-COMMIT-src-babylonian-programming-editor-worker-ast-worker.js,AUTO-COMMIT-src-babylonian-programming-editor-worker-ast-worker-promise-wrapper.js,AUTO-COMMIT-src-babylonian-programming-editor-worker-babylonian-worker.js,AUTO-COMMIT-src-components-widgets-lively-window.js,AUTO-COMMIT-src-worker-livelyworker.js,AUTO-COMMIT-src-worker-meta-worker.js,AUTO-COMMIT-src-worker-systemjs-worker.js,
  • Loading branch information
JensLincke committed Nov 13, 2023
1 parent d85a39d commit f86b85a
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Getting Started



<lively-import src="https://lively-kernel.org/lively4/lively4-petrinet/doc/_navigation.html" alt=""></lively-import>

Directly start developing in your Chrome by visiting [lively4](https://lively-kernel.org/lively4/lively4-core/start.html) and follow the [Getting Started Guide](./doc/tutorial/index.md). Through checking out and serving git repositories with the [lively4-server](doc/lively4-server.md), we can directly edit and use the environment in a self-supporting way.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export default class BabylonianProgrammingEditor extends Morph {
this.livelyEditor().setText(this._text);
return
}
console.log("AST for code ", this._text)
// console.log("AST for code ", this._text)

this.collectAnnotationAndRemoveComments()
this.addContext()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import SystemjsWorker from "src/worker/systemjs-worker.js";

let globalMsgId = 0;

export default class ASTWorkerPromiseWrapper {

constructor() {
this._worker = new Worker("src/babylonian-programming-editor/worker/ast-worker-babel-wrapper.js");
// this._worker = new Worker("src/babylonian-programming-editor/worker/ast-worker-babel-wrapper.js");

this._worker = new SystemjsWorker("src/babylonian-programming-editor/worker/ast-worker.js");
}

async process(code, annotations, customInstances, sourceUrl, replacementUrls) {
console.log("ast-worker-promise-wrapper.js process" )

const msgId = globalMsgId++;
const msg = {
id: msgId,
Expand All @@ -19,10 +25,15 @@ export default class ASTWorkerPromiseWrapper {
})
};

return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {

await this.loaded
// TODO
this._worker.onmessage = (result) => {
console.log("ast-worker-promise-wrapper.js onmessage" )
resolve(result.data.payload);
};
console.log("ast-worker-promise-wrapper.js postmessage" )
this._worker.postMessage(msg);
});
}
Expand Down
8 changes: 7 additions & 1 deletion src/babylonian-programming-editor/worker/ast-worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Custom imports

import {
deepCopy,
generateLocationMap,
Expand All @@ -15,10 +16,15 @@ import {
} from "../utils/ast.js";
import Performance from "../utils/performance.js";

console.log("ast-worker loaded")


/**
* Receive message from the main thread
*/
export default async function onmessage(msg) {
export async function onmessage(msg) {

console.log("ast-worker onmessage", msg)
// Performance
Performance.step("parse");
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class BabylonianWorker {
MD*/
// #important
async evaluateEditor(editor, execute = true) {
console.log("BabylonianWorker>>evaluateEditor")
// lively.notify("BabylonianWorker>>evaluateEditor")


// Serialize annotations
let serializedAnnotations = {};
Expand Down
2 changes: 0 additions & 2 deletions src/components/widgets/lively-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,6 @@ export default class Window extends Morph {
}

onExtentChanged(evt) {
console.log(evt);
debugger;
// console.log(evt); // evt has no content? => current bounds must already have been refreshed
if (this.target) {
this.target.dispatchEvent(new CustomEvent("extent-changed", evt));
Expand Down
6 changes: 5 additions & 1 deletion src/worker/meta-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ self.lively4url = self.location.origin + path.join("/");
importScripts("./livelyworker.js")

onmessage = function(evt) {
console.log("metaworker initial onmessage", evt)
if (evt.data.message == "load") {
console.log("meta worker load " + evt.data.url)
System.import("src/plugin-babel.js").then(() => {
Expand All @@ -20,7 +21,10 @@ onmessage = function(evt) {

System.import(evt.data.url).then((m) => {
postMessage({message: "loaded"})
self.onmessage = m.onmessage
self.onmessage = (...args) => {
console.log("metaworker custom onmessage", args)
m.onmessage(...args)
}
}).catch((err) => {
console.log("meta worker error ", err)
postMessage({message: "error", value: err})
Expand Down
22 changes: 18 additions & 4 deletions src/worker/systemjs-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,36 @@ export default class SystemjsWorker {
constructor(url) {
this.metaworker = new Worker("src/worker/meta-worker.js");
// bootstrap onmessage
this.loaded = new Promise(resolve => {
console.log("sytemjs-worker new: " + url)
var isLoaded = false
this.loaded = new Promise((resolve, reject) => {


setTimeout(() => {
if (!isLoaded) reject("timeout")
}, 10000) // 10s then timeout?


this.metaworker.onmessage = (evt) => {
var msg = evt.data
console.log("bootstrap onmessage", msg)
console.log(`bootstrap onmessage (${url})` , msg)
if (msg.message == "error") {
lively.error("[systemjs-worker]", msg.error || msg.value)
}
if (msg.message == "loaded") {
console.log("worker loaded", url)
this.metaworker.onmessage = (msg) => {
// console.log("new onmessage")
console.log(`systemjs-worker.js metaworker.onmessage (${url})` )
this.onmessage(msg)
}
resolve() // worker should accept postMessages now...
isLoaded = true
resolve(true) // worker should accept postMessages now...
}
}
})
this.loaded.then(() => {
console.log("systemjs loading finished: " + url)
})
this.metaworker.postMessage({message: "load", url: url, preferences: Preferences.config })
SystemjsWorker.workers.add(this)
}
Expand All @@ -46,6 +59,7 @@ export default class SystemjsWorker {

async postMessage(msg) {
await this.loaded
console.log("systemjs-worker.js post message", msg)
this.metaworker.postMessage(msg)
}

Expand Down

0 comments on commit f86b85a

Please sign in to comment.