-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add executables from file system (require store)
- Loading branch information
Showing
7 changed files
with
211 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const bs = new BroadcastChannel('rpc'); | ||
|
||
let rprc_id = 0; | ||
|
||
const modules = new Proxy({}, { | ||
get(target, namespace) { | ||
return new Proxy({}, { | ||
get(target, name) { | ||
return (...args) => { | ||
return new Promise((resolve, reject) => { | ||
const id = ++rprc_id; | ||
const method = name; | ||
bs.addEventListener('message', function handler({data}) { | ||
if (data.id === id) { | ||
if (data.error) { | ||
reject(data.error); | ||
} else { | ||
resolve(data.result); | ||
} | ||
bs.removeEventListener('message', handler); | ||
} | ||
}); | ||
bs.postMessage({ | ||
id, | ||
namespace, | ||
method, | ||
args | ||
}); | ||
}); | ||
}; | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
let handler_id = 0; | ||
const handlers = {}; | ||
|
||
function open(filename) { | ||
return new Promise((resolve, reject) => { | ||
fs.stat(filename).then(() => { | ||
const id = ++handler_id; | ||
handlers[id] = filename; | ||
resolve(id); | ||
}).catch(err => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
const kernel_bs = new BroadcastChannel('rpc'); | ||
|
||
const kernel = { | ||
exec(program) { | ||
return fs.readFile(program).then(code => { | ||
eval(code); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
importScripts(location.href.replace(/__fs__.*/, 'kernel.js')); | ||
|
||
modules.term.resume().then(() => { | ||
return main(); | ||
}).then(code => { | ||
self.postMessage({exit: code}); | ||
self.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
async function main() { | ||
const name = await modules.term.read('name: '); | ||
await modules.term.pause(); | ||
await modules.term.echo(`Hello ${name}`); | ||
await modules.term.resume(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
importScripts( | ||
'https://cdn.jsdelivr.net/npm/@jcubic/wayne/index.umd.min.js', | ||
'https://cdn.jsdelivr.net/npm/@isomorphic-git/lightning-fs/dist/lightning-fs.min.js', | ||
'https://cdn.jsdelivr.net/gh/jcubic/static@master/js/mime.min.js', | ||
'https://cdn.jsdelivr.net/gh/jcubic/static@master/js/path.js' | ||
); | ||
|
||
const { Wayne, FileSystem } = wayne; | ||
|
||
const { promises: fs } = new LightningFS('__fs__'); | ||
|
||
fetch('./process_postfix.js') | ||
.then(res => res.text()) | ||
.then(postfix => { | ||
const readFile = fs.readFile; | ||
fs.readFile = async function(...args) { | ||
const output = await readFile(...args); | ||
return `${output}\n${postfix}`; | ||
}; | ||
}); | ||
|
||
const app = new Wayne(); | ||
|
||
app.use(FileSystem({ path, fs, mime, prefix: '__fs__' })); |