-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from ZakFarmer/feature/wasm
Feature/wasm
- Loading branch information
Showing
10 changed files
with
7,718 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[workspace] | ||
members = [ "opcode", "compiler", "lexer", "parser", "evaluator", "object", "interpreter", "vm"] | ||
members = [ "opcode", "compiler", "lexer", "parser", "evaluator", "object", "interpreter", "vm", "wasm"] |
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,3 @@ | ||
/dist | ||
/node_modules | ||
/pkg |
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,47 @@ | ||
[package] | ||
name = "wasm" | ||
version = "0.1.0" | ||
description = "WASM implementation of php-rs" | ||
homepage = "https://github.com/ZakFarmer/php-rs" | ||
repository = "https://github.com/ZakFarmer/php-rs" | ||
edition = "2021" | ||
license = "MIT" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
default = ["console_error_panic_hook"] | ||
|
||
[dependencies] | ||
compiler = { path = "../compiler" } | ||
lexer = { path = "../lexer" } | ||
object = { path = "../object" } | ||
parser = { path = "../parser" } | ||
vm = { path = "../vm" } | ||
|
||
wasm-bindgen = "0.2.80" | ||
|
||
# The `console_error_panic_hook` crate provides better debugging of panics by | ||
# logging them with `console.error`. This is great for development, but requires | ||
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for | ||
# code size when deploying. | ||
console_error_panic_hook = { version = "0.1.7", optional = true } | ||
|
||
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size | ||
# compared to the default allocator's ~10K. It is slower than the default | ||
# allocator, however. | ||
# | ||
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now. | ||
wee_alloc = { version = "0.4.5", optional = true } | ||
web-sys = { version = "0.3.64", features = ["console"] } | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3.24" | ||
|
||
[profile.release] | ||
# Tell `rustc` to optimize for small code size. | ||
opt-level = "s" | ||
|
||
[package.metadata.wasm-pack.profile.release] | ||
wasm-opt = false |
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,23 @@ | ||
import("../pkg/index.js") | ||
.then((wasm) => { | ||
wasm.init_state(); | ||
|
||
const inputElement = document.getElementById("input"); | ||
const outputElement = document.getElementById("output"); | ||
|
||
outputElement.innerHTML += `> php-rs interpreter 0.1.0\n`; | ||
outputElement.innerHTML += `Loaded WASM bundle.\n\n`; | ||
|
||
inputElement.addEventListener("keydown", (event) => { | ||
if (event.key === "Enter" && !event.shiftKey) { | ||
event.preventDefault(); | ||
|
||
const input = inputElement.value; | ||
const output = wasm.parse(input); | ||
|
||
outputElement.innerHTML += `> ${input}\n${output}\n`; | ||
inputElement.value = ""; // Clear the input | ||
} | ||
}); | ||
}) | ||
.catch(console.error); |
Oops, something went wrong.