Skip to content

Commit

Permalink
feat: memory opcodes + tests
Browse files Browse the repository at this point in the history
Signed-off-by: nerodesu017 <[email protected]>
  • Loading branch information
nerodesu017 committed Nov 18, 2024
1 parent 09c3435 commit 47e413b
Show file tree
Hide file tree
Showing 49 changed files with 6,322 additions and 633 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/requirements/export
/target
result
whitepaper/main.pdf
145 changes: 83 additions & 62 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 54 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
description = "a minimal WASM interpreter";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
typst-packages = {
url = "github:typst/packages";
flake = false;
};
typix = {
url = "github:loqusion/typix";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
utils.url = "git+https://github.com/numtide/flake-utils.git";
devshell.url = "github:numtide/devshell";
fenix = {
Expand All @@ -24,43 +33,66 @@
lib = nixpkgs.lib;
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlays.default ];
overlays = [
devshell.overlays.default

# We unfortunately need the most up-to-date typst
(final: prev: {
typst = inputs.nixpkgs-unstable.legacyPackages.${pkgs.hostPlatform.system}.typst;
})
];
};

# universal formatter
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;

# rust target name of the `system`
rust-target = pkgs.rust.toRustTarget pkgs.pkgsStatic.targetPlatform;
rust-target = pkgs.pkgsStatic.targetPlatform.rust.rustcTarget;

# Rust distribution for our hostSystem
fenix = inputs.fenix.packages.${system};

rust-toolchain = with fenix;
combine [
latest.rustc
latest.cargo
latest.clippy
latest.rustfmt
targets.${rust-target}.latest.rust-std
targets.thumbv6m-none-eabi.latest.rust-std # for no_std test
targets.wasm32-unknown-unknown.latest.rust-std
];
rust-toolchain = with fenix; combine [
latest.rustc
latest.cargo
latest.clippy
latest.rustfmt
targets.${rust-target}.latest.rust-std
targets.thumbv6m-none-eabi.latest.rust-std # for no_std test
targets.wasm32-unknown-unknown.latest.rust-std
];

# overrides a naersk-lib which uses the stable toolchain expressed above
naersk-lib = (naersk.lib.${system}.override {
cargo = rust-toolchain;
rustc = rust-toolchain;
});

typstPackagesCache = pkgs.stdenv.mkDerivation {
name = "typst-packages-cache";
src = inputs.typst-packages;
dontBuild = true;
installPhase = ''
mkdir -p "$out/typst/packages"
cp --dereference --no-preserve=mode --recursive --reflink=auto \
--target-directory="$out/typst/packages" -- "$src"/packages/*
'';
};
in
{
# packages
packages.wasm-interpreter = pkgs.callPackage pkgs/wasm-interpreter.nix { };
packages.whitepaper = inputs.typix.lib.${system}.buildTypstProject {
name = "whitepaper.pdf";
src = ./whitepaper;
XDG_CACHE_HOME = typstPackagesCache;
};

packages.report = pkgs.callPackage pkgs/report.nix {
inherit (self.packages.${system}) wasm-interpreter;
inherit (self.packages.${system}) wasm-interpreter whitepaper;
};


# a devshell with all the necessary bells and whistles
devShells.default = (pkgs.devshell.mkShell {
imports = [ "${devshell}/extra/git/hooks.nix" ];
Expand All @@ -84,6 +116,7 @@
nixpkgs-fmt
nodePackages.prettier
treefmtEval.config.build.wrapper
typst # for the whitepaper
];
env = [
{
Expand Down Expand Up @@ -132,6 +165,13 @@
'';
help = "start cargo watch loop for documentation";
}
{
name = "whitepaper-watch";
command = ''
typst watch --root "$PRJ_ROOT/whitepaper" "$PRJ_ROOT/whitepaper/main.typ"
'';
help = "start typst watch loop for the whitepaper";
}
];
});

Expand Down
3 changes: 2 additions & 1 deletion pkgs/report.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, stdenvNoCC, python3Packages, strictdoc, wasm-interpreter }:
{ lib, stdenvNoCC, python3Packages, strictdoc, wasm-interpreter, whitepaper }:

let
evidenceRoot = lib.strings.escapeShellArg wasm-interpreter;
Expand All @@ -22,6 +22,7 @@ stdenvNoCC.mkDerivation {
cp --recursive -- ${evidenceRoot}/bench-html bench
cp --recursive -- ${evidenceRoot}/lcov-html coverage
cp --recursive -- ${evidenceRoot}/share/doc/ rustdoc
cp --dereference -- ${whitepaper} whitepaper.pdf
mkdir test
junit2html ${evidenceRoot}/junit.xml test/index.html
Expand Down
1 change: 1 addition & 0 deletions pkgs/report_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@
<a href="test/index.html">Tests</a>
<a href="coverage/html/index.html">Coverage</a>
<a href="bench/report/index.html">Benchmark</a>
<a href="whitepaper.pdf">Whitepaper</a>
</body>
</html>
Loading

0 comments on commit 47e413b

Please sign in to comment.