Skip to content

Commit

Permalink
Improve wasmer-sh
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Oct 7, 2024
1 parent 80fe4b0 commit 0ec1960
Show file tree
Hide file tree
Showing 4 changed files with 524 additions and 17 deletions.
10 changes: 7 additions & 3 deletions examples/wasmer.sh/app.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---
kind: wasmer.io/App.v0
name: wasmer-examples-wasmer-sh
package: wasmer-examples/wasmer-sh
app_id: da_bRbxI9tgUaQK
owner: wasmer
package: .
domains:
- wasmer-examples-wasmer-sh.wasmer.app
- wasmer-sh.wasmer.app
kind: wasmer.io/App.v0
45 changes: 41 additions & 4 deletions examples/wasmer.sh/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ const encoder = new TextEncoder();
const params = new URLSearchParams(window.location.search);

const packageName = params.get("package") || "sharrattj/bash";
const uses = params.getAll("use");
const uses = packageName == "sharrattj/bash" ? ["wasmer/neatvi"] : params.getAll("use");

const args = params.getAll("arg");
const logFilter = params.get("log") || "warn";
const logFilter = params.get("log") || "trace";

async function main() {
// Note: We dynamically import the Wasmer SDK to make sure the bundler puts
Expand All @@ -19,7 +20,7 @@ async function main() {
// same chunk as @wasmer/sdk, each Web Worker will try to run this code and
// crash.
// See https://github.com/wasmerio/wasmer-js/issues/373
const { Wasmer, init } = await import("@wasmer/sdk");
const { Wasmer, init, Directory } = await import("@wasmer/sdk");

await init({log: logFilter});

Expand All @@ -32,7 +33,43 @@ async function main() {
term.writeln("Starting...");
const pkg = await Wasmer.fromRegistry(packageName);
term.reset();
const instance = await pkg.entrypoint!.run({ args, uses });
const home = new Directory();
await home.writeFile("example.c",
`#include<stdio.h>
int main() {
printf("Hello World from WebAssembly!\\n");
return 0;
}
`);
await home.writeFile("donut.c", `
#include <stdio.h>
#include <string.h>
k;double sin()
,cos();main(){float A=
0,B=0,i,j,z[1760];char b[
1760];printf("\x1b[2J");for(;;
){memset(b,32,1760);memset(z,0,7040)
;for(j=0;6.28>j;j+=0.07)for(i=0;6.28
>i;i+=0.02){float c=sin(i),d=cos(j),e=
sin(A),f=sin(j),g=cos(A),h=d+2,D=1/(c*
h*e+f*g+5),l=cos (i),m=cos(B),n=s\
in(B),t=c*h*g-f* e;int x=40+30*D*
(l*h*m-t*n),y= 12+15*D*(l*h*n
+t*m),o=x+80*y, N=8*((f*e-c*d*g
)*m-c*d*e-f*g-l *d*n);if(22>y&&
y>0&&x>0&&80>x&&D>z[o]){z[o]=D;;;b[o]=
".,-~:;=!*#$@"[N>0?N:0];}}/*#****!!-*/
printf("\x1b[H");for(k=0;1761>k;k++)
putchar(k%80?b[k]:10);A+=0.04;B+=
0.02;}}/*****####*******!!=;:~
~::==!!!**********!!!==::-
.,~~;;;========;;;:~-.
..,--------,*/
`);

const instance = await pkg.entrypoint!.run({ args, uses, mount: { "/home": home }, cwd: "/home"});
connectStreams(instance, term);
}

Expand Down
Loading

0 comments on commit 0ec1960

Please sign in to comment.