diff --git a/.gitignore b/.gitignore
index 08b7716..ba13579 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
/target
osmarkscalculator.zip
osmarkscalculator.tar
-src.zip
\ No newline at end of file
+src.zip
+dist
+vgcore*
\ No newline at end of file
diff --git a/Cargo.lock b/Cargo.lock
index c2f2556..ad1ea11 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9,10 +9,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1"
[[package]]
-name = "autocfg"
-version = "1.0.1"
+name = "bumpalo"
+version = "3.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
+checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"
+
+[[package]]
+name = "cfg-if"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
@@ -20,65 +26,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
-[[package]]
-name = "crossbeam-channel"
-version = "0.5.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa"
-dependencies = [
- "cfg-if",
- "crossbeam-utils",
-]
-
-[[package]]
-name = "crossbeam-deque"
-version = "0.8.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
-dependencies = [
- "cfg-if",
- "crossbeam-epoch",
- "crossbeam-utils",
-]
-
-[[package]]
-name = "crossbeam-epoch"
-version = "0.9.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762"
-dependencies = [
- "cfg-if",
- "crossbeam-utils",
- "lazy_static",
- "memoffset",
- "scopeguard",
-]
-
-[[package]]
-name = "crossbeam-utils"
-version = "0.8.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120"
-dependencies = [
- "cfg-if",
- "lazy_static",
-]
-
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
-[[package]]
-name = "hermit-abi"
-version = "0.1.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
-dependencies = [
- "libc",
-]
-
[[package]]
name = "inlinable_string"
version = "0.1.14"
@@ -94,36 +47,32 @@ dependencies = [
"either",
]
-[[package]]
-name = "lazy_static"
-version = "1.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
-
[[package]]
name = "libc"
-version = "0.2.114"
+version = "0.2.137"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b0005d08a8f7b65fb8073cb697aa0b12b631ed251ce73d862ce50eeb52ce3b50"
+checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
[[package]]
-name = "memoffset"
-version = "0.6.5"
+name = "log"
+version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
+checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
- "autocfg",
+ "cfg-if 1.0.0",
]
[[package]]
-name = "num_cpus"
-version = "1.13.1"
+name = "memory_units"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
-dependencies = [
- "hermit-abi",
- "libc",
-]
+checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3"
+
+[[package]]
+name = "once_cell"
+version = "1.16.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
[[package]]
name = "osmarkscalculator"
@@ -132,36 +81,129 @@ dependencies = [
"anyhow",
"inlinable_string",
"itertools",
- "rayon",
+ "wasm-bindgen",
+ "wee_alloc",
]
[[package]]
-name = "rayon"
-version = "1.5.1"
+name = "proc-macro2"
+version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90"
+checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
dependencies = [
- "autocfg",
- "crossbeam-deque",
- "either",
- "rayon-core",
+ "unicode-ident",
]
[[package]]
-name = "rayon-core"
-version = "1.9.1"
+name = "quote"
+version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e"
+checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [
- "crossbeam-channel",
- "crossbeam-deque",
- "crossbeam-utils",
- "lazy_static",
- "num_cpus",
+ "proc-macro2",
]
[[package]]
-name = "scopeguard"
-version = "1.1.0"
+name = "syn"
+version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
+checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
+
+[[package]]
+name = "wasm-bindgen"
+version = "0.2.83"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
+dependencies = [
+ "cfg-if 1.0.0",
+ "wasm-bindgen-macro",
+]
+
+[[package]]
+name = "wasm-bindgen-backend"
+version = "0.2.83"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"
+dependencies = [
+ "bumpalo",
+ "log",
+ "once_cell",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.83"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.83"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-backend",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.83"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
+
+[[package]]
+name = "wee_alloc"
+version = "0.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e"
+dependencies = [
+ "cfg-if 0.1.10",
+ "libc",
+ "memory_units",
+ "winapi",
+]
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/Cargo.toml b/Cargo.toml
index dc28a8d..a2a9cae 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,10 +3,23 @@ name = "osmarkscalculator"
version = "0.1.0"
edition = "2018"
+[lib]
+crate-type = ["cdylib", "rlib"]
+name = "osmarkscalculator"
+
+[[bin]]
+name = "osmarkscalculator"
+path = "src/main.rs"
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1"
inlinable_string = "0.1"
-rayon = "1.5"
-itertools = "0.10"
\ No newline at end of file
+itertools = "0.10"
+wasm-bindgen = "0.2.63"
+wee_alloc = "0.4.5"
+
+[profile.release]
+opt-level = "s"
+lto = true
\ No newline at end of file
diff --git a/buildcalc.py b/buildcalc.py
new file mode 100644
index 0000000..8c1c4f5
--- /dev/null
+++ b/buildcalc.py
@@ -0,0 +1,44 @@
+BINDING = """
+let loaded = false
+onmessage = async ev => {
+ if (!loaded) {
+ await wasm_bindgen("./osmarkscalculator.wasm")
+ loaded = true
+ }
+ var [fn, ...args] = ev.data
+ let init = false
+ if (fn === "deinit") {
+ wasm_bindgen.deinit_context()
+ init = false
+ } else if (fn === "run") {
+ const start = performance.now()
+ try {
+ if (!init) {
+ wasm_bindgen.init_context()
+ wasm_bindgen.load_defaults()
+ init = true;
+ }
+ postMessage(["ok", wasm_bindgen.run_program(args[0]), performance.now() - start])
+ } catch(e) {
+ postMessage(["error", e.toString(), performance.now() - start])
+ }
+ }
+}
+"""
+HEADER = """
+---
+title: osmarkscalculator
+description: Unholy horrors moved from the depths of my projects directory to your browser. Theoretically, this is a calculator. Good luck using it.
+---
+""".strip()
+import subprocess, rjsmin, os, shutil
+subprocess.run(["wasm-pack", "build", "--target=no-modules"])
+minified = rjsmin.jsmin(open("pkg/osmarkscalculator.js", "r").read() + BINDING)
+os.makedirs("dist", exist_ok=True)
+subprocess.run(["wasm-opt", "-Oz", "pkg/osmarkscalculator_bg.wasm", "-o", "dist/osmarkscalculator.wasm"])
+open("dist/osmarkscalculator.js", "w").write(minified)
+with open("index.html") as f:
+ g = HEADER + f.read().replace("""""", "")
+with open("dist/index.html", "w") as h:
+ h.write(g)
+shutil.copytree("dist/.", "../website/experiments/osmarkscalculator", dirs_exist_ok=True)
\ No newline at end of file
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..5f8d8ee
--- /dev/null
+++ b/index.html
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..6dfbc2a
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,658 @@
+use anyhow::{Result, Context, bail};
+use inlinable_string::InlinableString;
+use std::collections::HashMap;
+use std::borrow::Cow;
+use std::convert::TryInto;
+use std::sync::Arc;
+use wasm_bindgen::prelude::*;
+
+#[global_allocator]
+static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
+
+mod parse;
+mod value;
+mod util;
+mod env;
+
+use value::Value;
+use env::{Rule, Ruleset, Env, Bindings, RuleResult, Operation};
+
+// Main pattern matcher function;
+fn match_and_bind(expr: &Value, rule: &Rule, env: &Env) -> Result