Skip to content

Mega rewrite #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 98 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
9f15783
initial commit of rewrite
pufferfish101007 Dec 27, 2024
4737e34
commit number 2: full testing support for validity of wasm instructions
pufferfish101007 Dec 28, 2024
f8df9bc
commit 3: auto-generate opcode enum & related functions
pufferfish101007 Dec 28, 2024
7946cad
basic looks_say, js type checking, and Other Things
pufferfish101007 Jan 1, 2025
0146d53
start implementing IR
pufferfish101007 Jan 2, 2025
5462a0c
format and add remaining primitive number blocks
pufferfish101007 Jan 3, 2025
75fe2a1
getting closer
pufferfish101007 Jan 3, 2025
02290b0
try to avoid circular strong references
pufferfish101007 Jan 4, 2025
b2671ae
mostly finish putting everything together
pufferfish101007 Jan 4, 2025
c7f0729
make things work(ish) in the playground
pufferfish101007 Jan 4, 2025
9ae58b1
wasm almost functioning correctly
pufferfish101007 Jan 5, 2025
6dad059
ensure finished threads exit successfully
pufferfish101007 Jan 5, 2025
ec72b12
fix things (incl. use i32 rather than i64)
pufferfish101007 Jan 8, 2025
c78d090
start implementing strings; expose settings/flags to js; generalise r…
pufferfish101007 Jan 12, 2025
9c3f55d
start implementing casts
pufferfish101007 Jan 19, 2025
3b22e82
(hopefully) fix casts
pufferfish101007 Jan 25, 2025
7c2e1c6
update casting system to work properly
pufferfish101007 Feb 17, 2025
f61bdb6
add instructions on adding new blocks
pufferfish101007 Feb 17, 2025
d140faf
CI overhaul
pufferfish101007 Feb 18, 2025
753e2a2
auto-track implemented blocks
pufferfish101007 Feb 18, 2025
c0ee513
don't specify an absolute href for example links
pufferfish101007 Feb 18, 2025
52b88ee
use hash history
pufferfish101007 Feb 18, 2025
51b56c1
fix some bits and bobs
pufferfish101007 Feb 18, 2025
aaceeb6
convert nans to 0 (resolves hyperquark/hyperquark#17)
pufferfish101007 Feb 19, 2025
f553727
remove unused files
pufferfish101007 Feb 19, 2025
d0b0011
tighten bounds on output type of operator_add
pufferfish101007 Feb 19, 2025
e58af33
update internal documentation and internal imports + README
pufferfish101007 Feb 19, 2025
f441e7e
operator_divide
pufferfish101007 Feb 19, 2025
795beab
consider that addition can be nan for inf+(-inf)
pufferfish101007 Feb 19, 2025
b95add0
operator_subtract
pufferfish101007 Feb 19, 2025
e851117
bad input type is a bug not a todo
pufferfish101007 Feb 19, 2025
5abf1de
operator_multiply and sensing_dayssince2000
pufferfish101007 Feb 19, 2025
f0ec59e
begin implementing variables
pufferfish101007 Feb 21, 2025
e00e465
allow strings in variables
pufferfish101007 Feb 21, 2025
fcaa82b
implement operator_lt
pufferfish101007 Feb 22, 2025
79096e7
implement control_if
pufferfish101007 Feb 22, 2025
88340d0
remove unused file
pufferfish101007 Feb 22, 2025
4f686a0
allow for empty substacks or (predicate) inputs
pufferfish101007 Feb 22, 2025
7f0afc6
update CI
pufferfish101007 Feb 22, 2025
3632137
lint
pufferfish101007 Feb 22, 2025
9183571
`enum-field-getter`: fix typo in `repository` field
pufferfish101007 Feb 22, 2025
30577b4
implement operator_not
pufferfish101007 Feb 22, 2025
43b854d
control_repeat
pufferfish101007 Feb 22, 2025
2a3378c
remove unnecessary logs
pufferfish101007 Feb 22, 2025
9794eec
don't track generated files
pufferfish101007 Feb 23, 2025
a43e43b
ci: run tests
pufferfish101007 Feb 23, 2025
ee6908b
update operator_join test
pufferfish101007 Feb 23, 2025
32c686d
implement string -> int cast
pufferfish101007 Feb 24, 2025
c26118a
ensure that int->int cast works
pufferfish101007 Feb 24, 2025
ef99a11
ignore doctest
pufferfish101007 Feb 24, 2025
758671f
tests: update input tyoe filtering order
pufferfish101007 Feb 24, 2025
6adaff7
properly initialise loop counter variables
pufferfish101007 Feb 25, 2025
c352ac4
fix wrapped casting
pufferfish101007 Feb 24, 2025
5733b19
don't error on top-level special block
pufferfish101007 Feb 26, 2025
962a457
sort of variable type specialisation
pufferfish101007 Mar 1, 2025
b7dbc9c
update ci
pufferfish101007 Mar 1, 2025
0222ae5
use typed function references for threads
pufferfish101007 Mar 16, 2025
e6033a1
remove unneeded test
pufferfish101007 Mar 17, 2025
85d94f5
add operator_gt
pufferfish101007 Mar 23, 2025
72a4417
fix operator_gt
pufferfish101007 Mar 23, 2025
06cd8b0
implement yielding
pufferfish101007 Apr 9, 2025
13aaeeb
handle project id input properly
pufferfish101007 Apr 10, 2025
7be5480
lint
pufferfish101007 Apr 10, 2025
ab6eaf4
mostly implement warped procedures
pufferfish101007 Apr 12, 2025
d1299c6
run control_repeat correct amount of times
pufferfish101007 Apr 13, 2025
d6b80dc
fix logic for determining whether to produce wasm func for step
pufferfish101007 Apr 13, 2025
3aedbec
allow for empty argumentids/argumentnames arrays
pufferfish101007 Apr 13, 2025
3d3a572
support global variables
pufferfish101007 Apr 13, 2025
7463de9
fix stop function
pufferfish101007 Apr 14, 2025
423f517
fix some nested loops
pufferfish101007 Apr 14, 2025
8063c13
fix scheduler
pufferfish101007 Apr 14, 2025
1a3adfb
use locals for loops
pufferfish101007 Apr 14, 2025
f59dcdc
use bubbles; start playing around with binaryen
pufferfish101007 Apr 18, 2025
f21b518
update ignored tests
pufferfish101007 Apr 18, 2025
07df55e
add looks_think
pufferfish101007 Apr 18, 2025
ee440c8
fix loops (again)
pufferfish101007 Apr 19, 2025
6889c2f
implement control_if_else
pufferfish101007 Apr 19, 2025
ef12803
implement data_changevariableby
pufferfish101007 Apr 20, 2025
cdeb04a
implement operator_and & operator_or
pufferfish101007 Apr 20, 2025
53697e6
use js string builtins for concat
pufferfish101007 Apr 20, 2025
195f554
implement more string operations
pufferfish101007 Apr 20, 2025
c5af91f
more strings
pufferfish101007 Apr 20, 2025
8fddc73
update block list colours for procedures
pufferfish101007 Apr 20, 2025
7ee5ac7
skip failing test
pufferfish101007 Apr 20, 2025
42f900a
optimise wasm module with binaryen
pufferfish101007 Apr 20, 2025
e97a83f
implement operator_equals
pufferfish101007 Apr 21, 2025
4de2f7d
implement control_repeat_until
pufferfish101007 Apr 21, 2025
8f425e7
condense loop generation into one function
pufferfish101007 Apr 21, 2025
3f134d4
improve binaryen opts; make wasm-opt optional
pufferfish101007 Apr 21, 2025
b6ae18b
fix warped control_repeat_until
pufferfish101007 Apr 21, 2025
55c712b
don't use colons in directory names
pufferfish101007 Apr 23, 2025
a32d96f
move more flag logic to rust
pufferfish101007 Apr 23, 2025
7e8a61d
run wasm-opt in deploy with latest binaryen
pufferfish101007 Apr 24, 2025
43a1949
actually use call_ref when using typed_function references
pufferfish101007 Apr 28, 2025
0b6587f
add option to use old call_indirect scheduler, and fix binaryen better
pufferfish101007 May 2, 2025
03000d1
fix binaryen dependency name
pufferfish101007 May 3, 2025
0b32a4a
add rust-toolchain.toml
pufferfish101007 May 3, 2025
c52ee5d
mega lint
pufferfish101007 May 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 30 additions & 38 deletions .github/workflows/ci.yaml → .github/workflows/ci-checks.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
on: [push, workflow_dispatch]
on: [push, workflow_dispatch, pull_request]

name: CI
name: CI checks

jobs:
build:
Expand All @@ -16,18 +16,20 @@ jobs:
profile: minimal
toolchain: nightly
override: true
target: wasm32-unknown-unknown

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --target=wasm32-unknown-unknown

clippy:
name: Lint (clippy)
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install nightly toolchain with clippy available
uses: actions-rs/toolchain@v1
Expand All @@ -48,7 +50,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install nightly toolchain with rustfmt available
uses: actions-rs/toolchain@v1
Expand All @@ -60,14 +62,12 @@ jobs:

- name: Run cargo fmt
uses: actions-rs/cargo@v1
continue-on-error: true # WARNING: only for this example, remove it!
with:
command: fmt
args: --all -- --check

buildwasm:
name: Build WASM & website
if: github.ref_name == 'main'

test:
name: Run unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand All @@ -79,34 +79,26 @@ jobs:
profile: minimal
toolchain: nightly
override: true
target: wasm32-unknown-unknown

- name: Install wasm-bindgen

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: install
args: -f wasm-bindgen-cli

- name: Install binaryen
run: sudo apt-get install binaryen

- name: Install node
uses: actions/setup-node@v3
with:
node-version: "20.x"

- name: Run npm install
run: npm install

- name: Build
run: chmod +x build.sh && ./build.sh -pWV

- name: Move files for gh pages
run: mv ./playground/dist docs && cp docs/index.html docs/404.html

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: gh-pages
create_branch: true
push_options: '--force'
command: test
args: >-
--
--skip cast::float::js_functions_match_declared_types
--skip cast::int::js_functions_match_declared_types
--skip cast::string::js_functions_match_declared_types
--skip join::tests::js_functions_match_declared_types
--skip lt::tests::js_functions_match_declared_types
--skip gt::tests::js_functions_match_declared_types
--skip equals::tests::js_functions_match_declared_types
--skip length::tests::js_functions_match_declared_types
--skip letter_of::tests::js_functions_match_declared_types
--skip contains::tests::js_functions_match_declared_types
--skip dayssince2000::tests::js_functions_match_declared_types
--skip looks::say::tests_debug::js_functions_match_declared_types
--skip looks::say::tests_non_debug::js_functions_match_declared_types
--skip looks::think::tests_debug::js_functions_match_declared_types
--skip looks::think::tests_non_debug::js_functions_match_declared_types

76 changes: 76 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
on: [push, workflow_dispatch]

name: Deploy

jobs:
deploy:
name: Build WASM & website
runs-on: ubuntu-latest
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
permissions:
contents: write
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
target: wasm32-unknown-unknown

- name: Install wasm-bindgen
uses: actions-rs/cargo@v1
with:
command: install
args: -f wasm-bindgen-cli

- name: Install cargo-outdir
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-outdir

- name: Install binaryen
run: sudo apt-get install binaryen

- name: Install node
uses: actions/setup-node@v3
with:
node-version: "20.x"

- name: Run npm install
run: |
npm install
npm i -g vite
npm i -g binaryen@nightly

- name: Build
env:
VITE_HASH_HISTORY: true
run: |
chmod +x build.sh && ./build.sh -Wpz
vite build --base=/hyperquark/$BRANCH_NAME/

- name: Move files to tmp
run: mv ./playground/dist /tmp/hq-dist

- name: checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages

- name: move file to gh-pages
run: |
rm -rf ./$BRANCH_NAME
mv /tmp/hq-dist ./$BRANCH_NAME
#mv ./main/* ./

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: gh-pages
push_options: '--force-with-lease'
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
/bad.mjs
/bad.wat
/wabt*
/js/
/js/compiler
/js/no-compiler
/js/imports.ts
/js/opcodes.js
/node_modules/
/package-lock.json
/playground/dist/
/.vite/
/.vite/
/.vscode/
23 changes: 20 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,37 @@ publish = false
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
enum-field-getter = { path = "enum-field-getter" }
wasm-encoder = "0.214.0"
wasm-bindgen = "0.2.92"
wasm-encoder = "0.226.0"
indexmap = { version = "2.0.0", default-features = false }
hashers = "1.0.1"
uuid = { version = "1.4.1", default-features = false, features = ["v4", "js"] }
regex = "1.10.5"
lazy-regex = "3.2.0"
bitmask-enum = "2.2.5"
itertools = { version = "0.13.0", default-features = false, features = ["use_alloc"] }
split_exact = "1.1.0"
wasm-bindgen = "0.2.92"
serde-wasm-bindgen = "0.6.5"
wasm-gen = { path = "wasm-gen" }

#[dev-dependencies]
[dev-dependencies]
wasmparser = "0.226.0"
wasmprinter = "0.226.0"
#reqwest = { version = "0.11", features = ["blocking"] }

[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
ezno-checker = { git = "https://github.com/kaleidawave/ezno.git", rev = "96d5058bdbb0cde924be008ca1e5a67fe39f46b9" }

[lib]
crate-type = ["cdylib", "rlib"]

[profile.release]
lto = true
opt-level = "z"

[build-dependencies]
convert_case = "0.6.0"

[features]
compiler = [] # if we only want to access flags, we don't want to additionally have all the compiler machinery
default = ["compiler"]
26 changes: 23 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,42 @@ Compile scratch projects to WASM

## Prerequisites

- [Rust](https://rust-lang.org) (v1.65.0 or later)
- [Rust](https://rust-lang.org) v1.65.0 or later
- the `wasm32-unknown-unknown` target (`rustup target add wasm32-unknown-unknown`)
- wasm-bindgen-cli (`cargo install -f wasm-bindgen-cli`)
- wasm-opt (install binaryen using whatever package manager you use)
- `cargo-outdir` (`cargo install cargo-outdir`)

## Building

```bash
./build.sh -pVW # use -dVW for a debug build without optimisation
./build.sh -Wp # use -Wd for a debug build without optimisation
```

You may need to run `chmod +x build.sh` if it says it doesn't have permission.

The build script has additonal configuration options; run `./build.sh -h` for info on these.

If you experience runtime stack overflow errors in debug mode, try using the `-O` option to enable wasm-opt.
If you experience runtime stack overflow errors in debug mode, try using the `-s` or `-z` options to enable wasm-opt; weird wasm errors in production mode may conversely be solved by *disabling* wasm-opt using the `-o` flag.

## Adding a new block

To add a new block named `category_opcode`, if it cannot be reduced to simpler blocks:
1. create `src/instructions/category/opcode.rs`. Make sure to `use super::super::prelude::*` and create the relevant `pub` items:
- (optional) `pub struct Fields` (must be `Debug` and `Clone`)
- `pub fn wasm(func: &StepFunc, inputs: Rc<[IrType]>, (fields: &Fields)?) -> HQResult<Vec<InternalInstruction>>;`
- - wasm is generated using the `wasm_gen::wasm` macro. See [its README](./wasm-gen/README.md) for usage instructions, or e.g. [say.rs](./src/instructions/looks/say.rs) for an example.
- `pub fn acceptable_inputs() -> Rc<[IrType]>;`
- - these should really be base types (see BASE_TYPES in [types.rs](./src/ir/types.rs))
- `pub fn output_type(inputs: Rc<[IrType]>, (fields: &Fields)?) -> HQResult<Option<IrType>>;`
- - the output type should be as restrictive as possible; loose output types can cause us to lose out on some optimisations
- ensure to add relevant `instructions_test!`s - see [instructions/tests.rs](./src/instructions/tests.rs) for usage
2. add `pub mod opcode;` to `src/instructions/category.rs`, creating the file if needed
- if you're creating the category file, add `mod category;` to `src/instructions.rs`
3. add the block to `from_normal_block` in `src/ir/blocks.rs`; in most cases this should be a direct mapping of `BlockOpcode::category_opcode => IrOpcode::category_opcode`
4. add the block's input names to `input_names` in `src/ir/blocks.rs`

If the block *can* be reduced to simpler steps, only carry out steps 3 and 4 above.

## generared WASM module memory layout

Expand Down
Loading
Loading