Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5520b33

Browse files
committed
Simplify lib
1 parent 8e1f797 commit 5520b33

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/docs/index.js*
22
/head-wasm32-unknown-wasi-full-js/
3-
/lib/lib/
3+
/lib/
44
/node_modules/
55
/ruby.wasm
66
/src/app.wasm
77
/vendor/
88
/wasi-vfs
9-
/wasmtime
109
/yarn-error.log

Rakefile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ file "wasi-vfs" do
1414
rm filename
1515
end
1616

17-
file "wasmtime" do
18-
`curl https://wasmtime.dev/install.sh -sSf | bash`
19-
cp "#{ENV["HOME"]}/.wasmtime/bin/wasmtime", "wasmtime"
20-
end
21-
2217
file "head-wasm32-unknown-wasi-full-js" do
2318
require "json"
2419
version = JSON.parse(File.read("package.json"))["dependencies"]["ruby-head-wasm-wasi"][1..]
@@ -30,15 +25,15 @@ file "head-wasm32-unknown-wasi-full-js" do
3025
end
3126

3227
file "ruby.wasm" => ["head-wasm32-unknown-wasi-full-js"] do
33-
mv "head-wasm32-unknown-wasi-full-js/usr/local/bin/ruby", "ruby.wasm"
28+
cp "head-wasm32-unknown-wasi-full-js/usr/local/bin/ruby", "ruby.wasm"
3429
end
3530

36-
file "src/app.wasm" => ["wasi-vfs", "wasmtime", "ruby.wasm", "lib/app.rb"] do
31+
file "src/app.wasm" => ["Gemfile.lock", "wasi-vfs", "ruby.wasm"] do
3732
require "bundler/setup"
38-
cp_r $:.find { _1.include?("syntax_tree") }, "lib/lib"
33+
cp_r $:.find { _1.include?("syntax_tree") }, "lib"
3934

4035
`./wasi-vfs pack ruby.wasm --mapdir /lib::./lib --mapdir /usr::./head-wasm32-unknown-wasi-full-js/usr -o src/app.wasm`
41-
rm_rf "lib/lib"
36+
rm_rf "lib"
4237
end
4338

4439
task default: ["src/app.wasm"]

lib/app.rb

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/createRuby.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ export default async function createRuby() {
6565
// Once our virtual machine is booted, we're going to require the necessary
6666
// files to make it work. I'm not sure why I need to explicitly require
6767
// did_you_mean here, but it doesn't work without it.
68-
ruby.eval(`require "did_you_mean"; require "json"; require_relative "/lib/app"`);
68+
ruby.eval(`
69+
require "did_you_mean"
70+
require "json"
71+
$:.unshift("/lib")
72+
require_relative "/lib/syntax_tree"
73+
`);
6974

7075
return {
7176
// A function that calls through to PP to get the pretty-printed version of

src/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const initialState: State = {
1919

2020
type Action = (
2121
| { type: "changeSource", source: string }
22-
| { type: "createRuby", ruby: Ruby }
22+
| { type: "createRuby", ruby: Ruby, output: string }
2323
| { type: "evaluateSource", output: string }
2424
| { type: "syntaxErrorSource" }
2525
);
@@ -29,7 +29,7 @@ function reducer(state: State, action: Action): State {
2929
case "changeSource":
3030
return { ...state, state: "evaluating", source: action.source };
3131
case "createRuby":
32-
return { ...state, state: "ready", ruby: action.ruby };
32+
return { ...state, state: "ready", ruby: action.ruby, output: action.output };
3333
case "evaluateSource":
3434
return { ...state, state: "ready", output: action.output };
3535
case "syntaxErrorSource":
@@ -48,7 +48,7 @@ const App: React.FC = () => {
4848
switch (state.state) {
4949
case "initializing":
5050
createRuby().then((ruby) => {
51-
dispatch({ type: "createRuby", ruby });
51+
dispatch({ type: "createRuby", ruby, output: ruby.prettyPrint(state.source) });
5252
});
5353
return;
5454
case "evaluating":

0 commit comments

Comments
 (0)