Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
Signed-off-by: Shaw Summa <[email protected]>
  • Loading branch information
ShawSumma committed Feb 13, 2024
1 parent 18d56c2 commit 4646fb3
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 37 deletions.
5 changes: 5 additions & 0 deletions web/empty.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh

cd $(dirname "$0")

emcc src/empty/empty.c -o src/empty/empty.js -O3 -flto -s EXPORT_ES6=1 -s EXPORTED_RUNTIME_METHODS=FS,PROXYFS,ERRNO_CODES,allocateUTF8 -s FORCE_FILESYSTEM=1 -s ALLOW_MEMORY_GROWTH=1 --no-entry -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE='$ERRNO_CODES' -s EXPORTED_FUNCTIONS=_main,_free,_malloc -s --js-library=src/empty/fsroot.js -lproxyfs.js
4 changes: 4 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
"webpack-node": "^0.0.0",
"worker-loader": "^3.0.8"
},
"scripts": {
"build": "sh empty.sh && npx webpack",
"serve": "sh empty.sh && npx webpack serve"
},
"type": "module"
}
10 changes: 4 additions & 6 deletions web/src/app/NewTerm.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import { onMount } from "svelte";
import { repl } from '../lib/repl.js';
import { onMount } from 'svelte';
let data = '';
let src = '';
Expand All @@ -18,9 +18,7 @@
}
};
onMount(() => {
obj.start();
});
obj.start();
</script>

<style>
Expand All @@ -46,18 +44,18 @@
padding: 1em;
padding-top: 0em;
outline: none;
height: min-content;
flex-grow: 1;
}
.term {
display: flex;
flex-direction: column;
background-color: #111;
width: 100%;
padding: 0em;
border: 0em;
width: 100%;
height: 100%;
overflow: auto;
}
</style>

Expand Down
1 change: 1 addition & 0 deletions web/src/empty/empty.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int main() {}
63 changes: 63 additions & 0 deletions web/src/empty/fsroot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @license
* Copyright 2013 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/

mergeInto(LibraryManager.library, {
$FSROOT__deps: ["$FS"],
$FSROOT__postset: "FSROOT.staticInit();",
$FSROOT: {
staticInit: () => {
FS.root = null;

let opts = (Module.ROOT && Module.ROOT.opts) || {};
let type = (Module.ROOT && Module.ROOT.type) || "MEMFS";
if (typeof type === "string") {
type = FS.filesystems[type] || eval(type);
} else if (typeof type === "function") {
type = type(Module);
}
FS.mount(type, opts, '/');

FSROOT.createDefaultMountPoints();

// We need to ignore errors in mkdir
// since we are pre-creation mountpoints
// for directories otherwise created by the
// FS.create* functions
const restore_mkdir = FSROOT.safeMkdir();

FS.createDefaultDirectories();
FS.createDefaultDevices();
FS.createSpecialDirectories();

restore_mkdir();
},
createDefaultMountPoints: () => {
// Mount a new MEMFS for /dev
FS.mkdirTree("/dev");
FS.mount(MEMFS, {}, "/dev");

// Mount a new MEMFS for /proc/self
FS.mkdirTree('/proc/self');
FS.mount(MEMFS, {}, '/proc/self');
},
safeMkdir: () => {
const mkdir = FS.mkdir;
FS.mkdir = (path, mode) => {
try {
return mkdir(path, mode);
} catch {
// ignore errors
return FS.lookupPath(path, { follow: true }).node;
}
};
return () => {
FS.mkdir = mkdir;
};
},
},
});

DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.push('$FSROOT');
16 changes: 15 additions & 1 deletion web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@
<meta charset="utf-8">
<title>MiniVM</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="minivm.css">
<link rel="icon" href="data://">
<style>
html {
height: 100%;
}

body {
margin: 0;
height: 100%;
background-color: black;
}
</style>
</head>

<body>
<link rel="prefetch" as="wasm-package" href="wasm/minivm.wasm">
<link rel="prefetch" as="wasm-package" href="wasm/wasm-package.wasm">
<link rel="prefetch" as="wasm-package" href="wasm/empty.wasm">
<script type="module" src="minivm.js"></script>
</body>

Expand Down
6 changes: 4 additions & 2 deletions web/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import './app/global.css';
// import {load} from 'fengari-web';
import App from './app/App.svelte';

new App({
target: document.body,
document.addEventListener('DOMContentLoaded', () => {
new App({
target: document.body,
});
});

// const fengari = (str) => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/emception.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import FileSystem from "emception/FileSystem.mjs";

import LlvmBoxProcess from "emception/LlvmBoxProcess.mjs";

import wasm from "emception/packages/wasm.pack.br";
import wasm from "emception/packages/wasm.pack";

const packs = {
"wasm": wasm,
Expand Down
38 changes: 21 additions & 17 deletions web/src/lib/repl.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@

const comp = new Worker(new URL('../lib/wcomp.js', import.meta.url));
let comp;

const thens = [];

const waitForComp = await new Promise((ok, err) => {
comp.onmessage = ({data}) => {
switch (data.type) {
case 'result': {
if (data.number != null) {
thens[data.number](data.output);
const waitForComp = () => {
comp = new Worker(new URL(/* webpackChunkName: "wcomp" */ '../lib/wcomp.js', import.meta.url));
return new Promise((ok, err) => {
comp.onmessage = ({data}) => {
switch (data.type) {
case 'result': {
if (data.number != null) {
thens[data.number](data.output);
}
break;
}
case 'ready': {
ok();
break;
}
break;
}
case 'ready': {
ok();
break;
}
}
};
});
};
});
};

const unmap = (c) => {
if (c === '\n') {
Expand All @@ -29,6 +32,7 @@ const unmap = (c) => {
};

export const repl = ({putchar}) => {
const hasComp = waitForComp();
const obj = {};
obj.putchar = putchar;
const want = new SharedArrayBuffer(4);
Expand All @@ -44,9 +48,9 @@ export const repl = ({putchar}) => {
}
};
obj.start = async() => {
const worker = new Worker(new URL(/* webpackChunkName: "wlua" */ '../lib/wlua.js', import.meta.url));
const wait = new SharedArrayBuffer(4);
const ret = new SharedArrayBuffer(65536);
const worker = new Worker(new URL('../lib/wlua.js', import.meta.url));
const number = thens.length;
thens.push((buf) => {
const len = buf.byteLength;
Expand Down Expand Up @@ -74,7 +78,7 @@ export const repl = ({putchar}) => {
break;
}
case 'comp': {
await waitForComp;
await hasComp;
comp.postMessage({
type: 'comp',
number: number,
Expand Down
17 changes: 7 additions & 10 deletions web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';
import { fileURLToPath } from 'url';
import webpack from 'webpack';

const dev = true;
const dev = false;

export default {
mode: dev ? 'development' : 'production',
Expand All @@ -31,10 +31,6 @@ export default {
process: false,
},
},
externals: {
'brotli.mjs': false,
'brotli.wasm': false,
},
module: {
rules: [
{
Expand All @@ -45,7 +41,7 @@ export default {
compilerOptions: {
dev: dev,
},
hotReload: dev,
hotReload: false,
},
},
},
Expand Down Expand Up @@ -99,13 +95,13 @@ export default {
{ from: "src/index.html", to: "index.html" },
],
}),
new webpack.NormalModuleReplacementPlugin(
/emception\/brotli\/brotli\.mjs$/,
path.resolve(fileURLToPath(new URL('.', import.meta.url)), './src/empty.js'),
),
// new CompressionPlugin({
// exclude: /\.br$/,
// }),
new webpack.NormalModuleReplacementPlugin(
/brotli\.m?js$/,
fileURLToPath(new URL('./src/empty/empty.js', import.meta.url)),
),
],
devServer: {
headers: {
Expand All @@ -115,6 +111,7 @@ export default {
client: {
logging: 'warn',
},
hot: dev,
},
experiments: {
topLevelAwait: true,
Expand Down

0 comments on commit 4646fb3

Please sign in to comment.