Compare commits
67 Commits
29a0266c67
...
partially_
| Author | SHA1 | Date | |
|---|---|---|---|
| 92bcb6f358 | |||
| 48de9517c9 | |||
| 9162b456d2 | |||
| 1df3acccd7 | |||
| 7b334e96df | |||
| 04bf1c6249 | |||
| d4920ec4b6 | |||
| 865fc1b4b6 | |||
| 46e6e27f88 | |||
| d836a66e66 | |||
| 3df2d02286 | |||
| 3d6082503c | |||
| af2fb537c7 | |||
| 4752dde4af | |||
| abddf1db06 | |||
| 6357297cd1 | |||
| bb6b15c156 | |||
| e327ed7314 | |||
| bde04e94df | |||
| 45a869b09b | |||
| 21fb47470a | |||
| 67feab10bc | |||
| 76b68e28d8 | |||
| 7f10d111ac | |||
| 5107c1d7e4 | |||
| 4d251964a2 | |||
| 5df87a53cf | |||
| 71326738fa | |||
| 91e0641045 | |||
| 283c0232b0 | |||
| fdaca7f807 | |||
| c5f7a52a38 | |||
| b893787a1b | |||
| 8b59d5a16a | |||
| 520e473415 | |||
| f568ee3d50 | |||
| 66fc1db606 | |||
| ad3c251ba9 | |||
| 3df7d6e0ec | |||
| e9b8f636cf | |||
| 5838cf0bdd | |||
| 5512ab8804 | |||
| 30964bf4ec | |||
| c028e975d4 | |||
| 1b813e39fb | |||
| 606972a38b | |||
| 3c2dfbf8a7 | |||
| ba67b8c67b | |||
| 3b5cc2c506 | |||
| 02e359f42d | |||
| d861d91397 | |||
| c801f604c2 | |||
| 60dad101f8 | |||
| 3807381ceb | |||
| bea48eb18b | |||
| a038a8cebf | |||
| 967ec0feb4 | |||
| c20ba09179 | |||
| 7f9f419a23 | |||
| 5a4cb4b40b | |||
| dff6730dd9 | |||
| 0ed097b5b0 | |||
| 95f6dd867c | |||
| 94ae60f9d1 | |||
| b2f0b5f1dd | |||
| 18b901b2f1 | |||
| 54f1092a2a |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@ build-ninja
|
||||
.*.un~
|
||||
callgrind*
|
||||
.stfolder
|
||||
*.wasm
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2020-2022 Nathan Braswell
|
||||
Copyright Nathan Braswell
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ with partial evaluation during compilation to make it efficient.
|
||||
|
||||
koka_bench: Licensed under Apache-2.0, as they are derived from the benchmarks of the Koka project, see the readme and license in koka_bench for more, or https://github.com/koka-lang/koka for the source project.
|
||||
|
||||
Kraken (everything else besides the benchmarks in koka_bench) Licensed under
|
||||
Kraken (everything else besides the benchmarks in koka_bench, and Recursive/CodeJar/Highlight.js in website/) Licensed under
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
Note: This license is designed to provide: a) a simple permissive license; b) that is compatible with the GNU General Public License (GPL), version 2; and c) which also has an express patent grant included.
|
||||
|
||||
88
basic_dyns
Normal file
88
basic_dyns
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RB-TREE
|
||||
|
||||
evals all_evals evaled_wrap_1 evaled_wrap_0 compiled_dyn_1 compiled_dyn_0
|
||||
non-PE10 114_170 5_032_297 1_291_489 398_104 1 0
|
||||
PE10 0 0 0 0 10 0
|
||||
nonPE9 97087 4278001 1097965 338383 1 0
|
||||
PE9 0 0 0 0 9 0
|
||||
nonPE8 80160 3532131 906548 279379 1 0
|
||||
PE8 0 0 0 0 8 0
|
||||
nonPE7 67050 2952848 757932 233513 1 0
|
||||
PE7 0 0 0 0 7 0
|
||||
nonPE6 50361 2219792 569723 175593 1 0
|
||||
PE6 0 0 0 0 6 0
|
||||
nonPE5 37299 1643049 421745 129938 1 0
|
||||
PE5 0 0 0 0 5 0
|
||||
nonPE4 24393 1074730 275873 85000 1 0
|
||||
PE4 0 0 0 0 4 0
|
||||
nonPE3 15304 672998 172802 53200 1 0
|
||||
PE3 0 0 0 0 3 0
|
||||
nonPE2 6453 284080 72939 22484 1 0
|
||||
PE2 0 0 0 0 2 0
|
||||
nonPE1 1385 59899 15413 4750 1 0
|
||||
PE1 0 0 0 0 1 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Fib
|
||||
|
||||
evals all_evals evaled_wrap_1 evaled_wrap_0 compiled_dyn_1 compiled_dyn_0
|
||||
non-PE35 29860726 1320920726 337695363 119442881 1 0
|
||||
non-PE30 2692560 119107888 30450112 10770217 1 0
|
||||
non-PE25 242808 10740492 2745825 971209 1 0
|
||||
non-PE20 21914 969010 247731 87633 1 0
|
||||
non-PE15 1996 87916 22478 7961 1 0
|
||||
non-PE10 200 8468 2167 777 1 0
|
||||
|
||||
PE10 0 0 0 0 0 0
|
||||
PE15 0 0 0 0 0 0
|
||||
PE20 0 0 0 0 0 0
|
||||
PE25 0 0 0 0 0 0
|
||||
PE30 0 0 0 0 0 0
|
||||
PE35 0 0 0 0 0 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cfold
|
||||
evals all_evals evaled_wrap_1 evaled_wrap_0 compiled_dyn_1 compiled_dyn_0
|
||||
non-PE5 239660 10897376 2784275 879066 1 0
|
||||
PE5 0 0 0 0 0 0
|
||||
|
||||
|
||||
deriv
|
||||
evals all_evals evaled_wrap_1 evaled_wrap_0 compiled_dyn_1 compiled_dyn_0
|
||||
non-PE2 257693 11708558 2990090 946500 1 0
|
||||
PE2 0 0 0 0 2 0
|
||||
|
||||
|
||||
nqueens
|
||||
evals all_evals evaled_wrap_1 evaled_wrap_0 compiled_dyn_1 compiled_dyn_0
|
||||
non-PE7 271720 13530241 3429161 1108393 1 0
|
||||
PE7 0 0 0 0 0 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
scheme --script ../../partial_eval.scm rbtree-opt.kp no_partial_eval && mv csc_out.wasm rbtree-opt.wasm && time wasmtime ./rbtree-opt.wasm 10
|
||||
scheme --script ../../partial_eval.scm rbtree-opt.kp && mv csc_out.wasm rbtree-opt.wasm && time wasmtime ./rbtree-opt.wasm 10
|
||||
|
||||
|
||||
66
flake.lock
generated
66
flake.lock
generated
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1649676176,
|
||||
"narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=",
|
||||
"lastModified": 1676283394,
|
||||
"narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678",
|
||||
"rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -17,11 +17,11 @@
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"locked": {
|
||||
"lastModified": 1649676176,
|
||||
"narHash": "sha256-OWKJratjt2RW151VUlJPRALb7OU2S5s+f0vLj4o1bHM=",
|
||||
"lastModified": 1659877975,
|
||||
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "a4b154ebbdc88c8498a5c7b01589addc9e9cb678",
|
||||
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -36,11 +36,11 @@
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1652149774,
|
||||
"narHash": "sha256-rms5yNnnlmaqzEnI/9Log+5k/yVz4fB1BUVx5HXf8i8=",
|
||||
"lastModified": 1678760344,
|
||||
"narHash": "sha256-N8u9/O0NWt3PUQc9xmCeod1SFilOFicALjtYtslib2g=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "1dcdd08fcd39e4e053f58f9959be801399c5211e",
|
||||
"rev": "d907affef544f64bd6886fe6bcc5fa2495a82373",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -51,11 +51,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1652133925,
|
||||
"narHash": "sha256-kfATGChLe9/fQVZkXN9G71JAVMlhePv1qDbaRKklkQs=",
|
||||
"lastModified": 1665296151,
|
||||
"narHash": "sha256-uOB0oxqxN9K7XGF1hcnY+PQnlQJ+3bP2vCn/+Ru/bbc=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "51d859cdab1ef58755bd342d45352fc607f5e59b",
|
||||
"rev": "14ccaaedd95a488dd7ae142757884d8e125b3363",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -65,13 +65,28 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"nixpkgs_stable_new": {
|
||||
"locked": {
|
||||
"lastModified": 1652020977,
|
||||
"narHash": "sha256-V6VYIwTeI5BCfYK9f5EsMbjsjsis1rUDHMsaDbTvt+A=",
|
||||
"lastModified": 1678703398,
|
||||
"narHash": "sha256-Y1mW3dBsoWLHpYm+UIHb5VZ7rx024NNHaF16oZBx++o=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "715dc137b08213aabbbe0965b78ab938e5d8d3b7",
|
||||
"rev": "67f26c1cfc5d5783628231e776a81c1ade623e0b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-22.11",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nixpkgs_stable_old": {
|
||||
"locked": {
|
||||
"lastModified": 1659446231,
|
||||
"narHash": "sha256-hekabNdTdgR/iLsgce5TGWmfIDZ86qjPhxDg/8TlzhE=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "eabc38219184cc3e04a974fe31857d8e0eac098d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -80,11 +95,28 @@
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nixpkgs_unstable": {
|
||||
"locked": {
|
||||
"lastModified": 1678838343,
|
||||
"narHash": "sha256-aA48yVAUyppdlVHhMStlWjB8u9uzA5iel3C47xlbkrw=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "b16f2a75619fe8e6adf4583f5fc6448bc967d482",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"moz_overlay": "moz_overlay",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
"nixpkgs_stable_new": "nixpkgs_stable_new",
|
||||
"nixpkgs_stable_old": "nixpkgs_stable_old",
|
||||
"nixpkgs_unstable": "nixpkgs_unstable"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
173
flake.nix
173
flake.nix
@@ -1,119 +1,110 @@
|
||||
{
|
||||
description = "Env for Kraken and the extacted Koka bencmarks";
|
||||
inputs = {
|
||||
|
||||
#flake.lock pins a particular version of 21.11 that has non-broken Swift
|
||||
nixpkgs.url = "nixpkgs/nixos-21.11";
|
||||
#nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
|
||||
# Pure-er, so we don't have to mess with the --impure flag
|
||||
# For some reason the newer one has broken koka/emscripten (probs same change)
|
||||
nixpkgs_stable_new.url = "nixpkgs/nixos-22.11";
|
||||
nixpkgs_stable_old.url = "nixpkgs/nixos-21.11";
|
||||
nixpkgs_unstable.url = "github:NixOS/nixpkgs";
|
||||
moz_overlay.url = "github:oxalica/rust-overlay";
|
||||
#moz_overlay.url = "github:mozilla/nixpkgs-mozilla";
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
outputs = { self, nixpkgs, moz_overlay, flake-utils }:
|
||||
outputs = { self, nixpkgs_stable_new, nixpkgs_stable_old, nixpkgs_unstable, moz_overlay, flake-utils }:
|
||||
(flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
pkgs_new = import nixpkgs_unstable {
|
||||
inherit system;
|
||||
overlays = [ moz_overlay.overlay ];
|
||||
};
|
||||
newlisp = pkgs.stdenv.mkDerivation rec {
|
||||
pname = "newLisp";
|
||||
version = "10.7.5";
|
||||
|
||||
src = pkgs.fetchurl {
|
||||
url = "http://www.newlisp.org/downloads/newlisp-10.7.5.tgz";
|
||||
sha256 = "sha256-3C0P9lHCsnW8SvOvi6WYUab7bh6t3CCudftgsekBJuw=";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkgs.autoPatchelfHook
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
pkgs.stdenv.cc.cc.lib
|
||||
pkgs.libffi
|
||||
pkgs.readline
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp newlisp $out/bin
|
||||
'';
|
||||
|
||||
meta = with pkgs.lib; {
|
||||
homepage = "http://www.newlisp.org/index.cgi";
|
||||
description = "A Lisp-like, general-purpose scripting language";
|
||||
platforms = platforms.linux;
|
||||
};
|
||||
pkgs_old = import nixpkgs_stable_old {
|
||||
inherit system;
|
||||
overlays = [ moz_overlay.overlay ];
|
||||
};
|
||||
wavm = pkgs.stdenv.mkDerivation rec {
|
||||
pname = "wavm";
|
||||
version = "0.0.0";
|
||||
#newlisp = pkgs.stdenv.mkDerivation rec {
|
||||
#pname = "newLisp";
|
||||
#version = "10.7.5";
|
||||
|
||||
src = pkgs.fetchurl {
|
||||
url = "https://github.com/WAVM/WAVM/releases/download/nightly%2F2022-05-14/wavm-0.0.0-prerelease-linux.tar.gz";
|
||||
sha256 = "sha256-+PpnwPJDty6XCjjuHVFwiHc1q+k0zPF11EbRpqSKfyY=";
|
||||
};
|
||||
#src = pkgs.fetchurl {
|
||||
#url = "http://www.newlisp.org/downloads/newlisp-10.7.5.tgz";
|
||||
#sha256 = "sha256-3C0P9lHCsnW8SvOvi6WYUab7bh6t3CCudftgsekBJuw=";
|
||||
#};
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkgs.autoPatchelfHook
|
||||
];
|
||||
#nativeBuildInputs = [
|
||||
#pkgs.autoPatchelfHook
|
||||
#];
|
||||
|
||||
buildInputs = [
|
||||
pkgs.stdenv.cc.cc.lib
|
||||
];
|
||||
#buildInputs = [
|
||||
#pkgs.stdenv.cc.cc.lib
|
||||
#pkgs.libffi
|
||||
#pkgs.readline
|
||||
#];
|
||||
|
||||
sourceRoot = ".";
|
||||
#installPhase = ''
|
||||
#mkdir -p $out/bin
|
||||
#cp newlisp $out/bin
|
||||
#'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp -r bin/wavm $out/bin/
|
||||
cp -r include/ $out
|
||||
cp -r lib64/ $out
|
||||
cp -r share/ $out
|
||||
#install -m755 -D studio-link-standalone-v${version} $out/bin/studio-link
|
||||
'';
|
||||
#meta = with pkgs.lib; {
|
||||
#homepage = "http://www.newlisp.org/index.cgi";
|
||||
#description = "A Lisp-like, general-purpose scripting language";
|
||||
#platforms = platforms.linux;
|
||||
#};
|
||||
#};
|
||||
#wavm = pkgs.stdenv.mkDerivation rec {
|
||||
#pname = "wavm";
|
||||
#version = "0.0.0";
|
||||
|
||||
meta = with pkgs.lib; {
|
||||
homepage = "https://wavm.github.io/";
|
||||
description = "WAVM WebAssembly Engine";
|
||||
platforms = platforms.linux;
|
||||
};
|
||||
};
|
||||
#src = pkgs.fetchurl {
|
||||
#url = "https://github.com/WAVM/WAVM/releases/download/nightly%2F2022-05-14/wavm-0.0.0-prerelease-linux.tar.gz";
|
||||
#sha256 = "sha256-+PpnwPJDty6XCjjuHVFwiHc1q+k0zPF11EbRpqSKfyY=";
|
||||
#};
|
||||
|
||||
#nativeBuildInputs = [
|
||||
#pkgs.autoPatchelfHook
|
||||
#];
|
||||
|
||||
#buildInputs = [
|
||||
#pkgs.stdenv.cc.cc.lib
|
||||
#];
|
||||
|
||||
#sourceRoot = ".";
|
||||
|
||||
#installPhase = ''
|
||||
#mkdir -p $out/bin
|
||||
#cp -r bin/wavm $out/bin/
|
||||
#cp -r include/ $out
|
||||
#cp -r lib64/ $out
|
||||
#cp -r share/ $out
|
||||
##install -m755 -D studio-link-standalone-v${version} $out/bin/studio-link
|
||||
#'';
|
||||
|
||||
#meta = with pkgs.lib; {
|
||||
#homepage = "https://wavm.github.io/";
|
||||
#description = "WAVM WebAssembly Engine";
|
||||
#platforms = platforms.linux;
|
||||
#};
|
||||
#};
|
||||
in {
|
||||
devShell = pkgs.mkShell {
|
||||
buildInputs = with pkgs; [
|
||||
devShell = pkgs_new.mkShell {
|
||||
buildInputs = with pkgs_new; [
|
||||
which # used for shell stuff when inside pure env
|
||||
|
||||
chicken
|
||||
hyperfine
|
||||
graph-cli # is this just for python?!
|
||||
|
||||
chicken gambit-unstable chez
|
||||
#gambit
|
||||
gambit-unstable
|
||||
chez
|
||||
wabt
|
||||
wasmtime
|
||||
wasm3
|
||||
wasmer
|
||||
leiningen
|
||||
clang
|
||||
kakoune
|
||||
|
||||
wavm
|
||||
wabt wasmtime #wavm
|
||||
#wasm3
|
||||
|
||||
hyperfine graph-cli
|
||||
(rust-bin.stable.latest.default.override {
|
||||
targets = [ "wasm32-wasi" ];
|
||||
})
|
||||
cmake
|
||||
stack (haskellPackages.ghcWithPackages (p: [p.parallel]))
|
||||
clang cmake
|
||||
(rust-bin.stable.latest.default.override { targets = [ "wasm32-wasi" ]; })
|
||||
#stack (haskellPackages.ghcWithPackages (p: [p.parallel]))
|
||||
koka
|
||||
ocaml
|
||||
jdk
|
||||
swift
|
||||
pkgs_old.emscripten
|
||||
|
||||
picolisp
|
||||
newlisp
|
||||
#picolisp
|
||||
#newlisp
|
||||
];
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
# Benchmarks
|
||||
|
||||
## cfold_table.md
|
||||
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `build/kraken/out/bench/kraken-cfold-wavm 20` | 1.262 ± 0.009 | 1.255 | 1.285 | 9.52 ± 0.21 |
|
||||
| `build/java/out/bench/cfold 20` | 0.357 ± 0.006 | 0.346 | 0.364 | 2.69 ± 0.07 |
|
||||
| `build/ocaml/ml-cfold 20` | 0.539 ± 0.002 | 0.536 | 0.540 | 4.06 ± 0.09 |
|
||||
| `build/swift/sw-cfold 20` | 0.864 ± 0.004 | 0.855 | 0.871 | 6.52 ± 0.14 |
|
||||
| `build/cpp/cpp-cfold 20` | 0.306 ± 0.002 | 0.303 | 0.311 | 2.31 ± 0.05 |
|
||||
| `build/haskell/hs-cfold 20` | 0.504 ± 0.001 | 0.502 | 0.505 | 3.80 ± 0.08 |
|
||||
| `build/koka/out/bench/kk-cfold 20` | 0.133 ± 0.003 | 0.129 | 0.139 | 1.00 |
|
||||
|
||||
|
||||
|
||||
## deriv_table.md
|
||||
|
||||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `build/kraken/out/bench/kraken-deriv 8` | 592.7 ± 15.7 | 579.7 | 622.1 | 41.04 ± 2.42 |
|
||||
| `build/kraken/out/bench/kraken-deriv-wavm 8` | 407.3 ± 1.0 | 405.6 | 408.8 | 28.21 ± 1.49 |
|
||||
| `build/java/out/bench/deriv 8` | 120.7 ± 17.4 | 86.7 | 130.2 | 8.36 ± 1.28 |
|
||||
| `build/ocaml/ml-deriv 8` | 14.4 ± 0.8 | 13.1 | 16.5 | 1.00 |
|
||||
| `build/swift/sw-deriv 8` | 37.3 ± 0.7 | 35.6 | 39.6 | 2.58 ± 0.15 |
|
||||
| `build/cpp/cpp-deriv 8` | 20.3 ± 0.7 | 19.4 | 22.2 | 1.41 ± 0.09 |
|
||||
| `build/haskell/hs-deriv 8` | 35.4 ± 0.8 | 34.1 | 37.1 | 2.45 ± 0.14 |
|
||||
| `build/koka/out/bench/kk-deriv 8` | 16.6 ± 0.8 | 15.7 | 18.7 | 1.15 ± 0.08 |
|
||||
|
||||
|
||||
|
||||
## fib_table.md
|
||||
|
||||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `build/kraken/out/bench/kraken-fib-let-wavm 30` | 31.8 ± 1.1 | 30.4 | 38.0 | 12.68 ± 3.23 |
|
||||
| `build/kraken/out/bench/kraken-fib-wavm 30` | 30.9 ± 0.9 | 29.3 | 34.4 | 12.32 ± 3.13 |
|
||||
| `build/kraken/out/bench/kraken-fib 30` | 38.9 ± 1.1 | 37.0 | 40.9 | 15.51 ± 3.93 |
|
||||
| `build/kraken/out/bench/kraken-fib-let 30` | 42.8 ± 0.8 | 40.6 | 44.9 | 17.07 ± 4.32 |
|
||||
| `build/cpp/cpp-fib 30` | 2.5 ± 0.6 | 2.1 | 5.2 | 1.00 |
|
||||
| `build/picolisp/out/bench/picolisp-fib-let 30` | 107.8 ± 0.9 | 105.7 | 109.3 | 42.94 ± 10.83 |
|
||||
| `build/picolisp/out/bench/picolisp-fib 30` | 88.7 ± 1.2 | 86.7 | 91.3 | 35.33 ± 8.92 |
|
||||
| `build/koka/out/bench/kk-fib 30` | 5.9 ± 0.5 | 5.4 | 8.1 | 2.34 ± 0.62 |
|
||||
| `build/python/out/bench/python-fib-let 30` | 295.5 ± 11.2 | 278.8 | 306.8 | 117.74 ± 30.03 |
|
||||
| `build/python/out/bench/python-fib 30` | 284.4 ± 9.8 | 266.3 | 295.7 | 113.32 ± 28.84 |
|
||||
| `build/scheme/out/bench/scheme-fib 30` | 52.1 ± 1.1 | 50.6 | 55.3 | 20.76 ± 5.25 |
|
||||
| `build/scheme/out/bench/scheme-fib-let 30` | 53.0 ± 0.9 | 51.4 | 55.2 | 21.11 ± 5.34 |
|
||||
|
||||
|
||||
|
||||
## nqueens_table.md
|
||||
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `build/kraken/out/bench/kraken-nqueens 10` | 1.196 ± 0.013 | 1.185 | 1.230 | 272.10 ± 37.86 |
|
||||
| `build/kraken/out/bench/kraken-nqueens-wavm 10` | 0.863 ± 0.010 | 0.850 | 0.880 | 196.39 ± 27.33 |
|
||||
| `build/java/out/bench/nqueens 10` | 0.058 ± 0.005 | 0.053 | 0.071 | 13.28 ± 2.20 |
|
||||
| `build/ocaml/ml-nqueens 10` | 0.005 ± 0.001 | 0.004 | 0.007 | 1.05 ± 0.20 |
|
||||
| `build/swift/sw-nqueens 10` | 0.016 ± 0.001 | 0.015 | 0.018 | 3.61 ± 0.53 |
|
||||
| `build/cpp/cpp-nqueens 10` | 0.006 ± 0.000 | 0.005 | 0.008 | 1.34 ± 0.22 |
|
||||
| `build/haskell/hs-nqueens 10` | 0.036 ± 0.001 | 0.035 | 0.037 | 8.18 ± 1.15 |
|
||||
| `build/koka/out/bench/kk-nqueens 10` | 0.004 ± 0.001 | 0.004 | 0.007 | 1.00 |
|
||||
| `build/koka/out/bench/kk-nqueens-int 10` | 0.006 ± 0.001 | 0.006 | 0.008 | 1.47 ± 0.24 |
|
||||
|
||||
|
||||
|
||||
## rbtree_table.md
|
||||
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `build/kraken/out/bench/kraken-rbtree-opt 420000` | 5.319 ± 0.335 | 5.120 | 6.119 | 110.82 ± 7.71 |
|
||||
| `build/kraken/out/bench/kraken-rbtree-wavm 420000` | 7.603 ± 0.085 | 7.545 | 7.826 | 158.41 ± 5.00 |
|
||||
| `build/kraken/out/bench/kraken-rbtree-opt-wavm 420000` | 2.388 ± 0.024 | 2.370 | 2.427 | 49.75 ± 1.55 |
|
||||
| `build/kraken/out/bench/kraken-rbtree 420000` | 14.104 ± 0.672 | 13.574 | 15.735 | 293.85 ± 16.47 |
|
||||
| `build/java/out/bench/rbtree 420000` | 0.205 ± 0.005 | 0.201 | 0.215 | 4.26 ± 0.17 |
|
||||
| `build/ocaml/ml-rbtree 420000` | 0.084 ± 0.000 | 0.083 | 0.086 | 1.75 ± 0.05 |
|
||||
| `build/swift/sw-rbtree 420000` | 0.481 ± 0.002 | 0.478 | 0.487 | 10.03 ± 0.30 |
|
||||
| `build/cpp/cpp-rbtree 420000` | 0.062 ± 0.003 | 0.058 | 0.070 | 1.28 ± 0.07 |
|
||||
| `build/haskell/hs-rbtree 420000` | 0.165 ± 0.001 | 0.164 | 0.166 | 3.44 ± 0.10 |
|
||||
| `build/koka/out/bench/kk-rbtree 420000` | 0.048 ± 0.001 | 0.045 | 0.052 | 1.00 |
|
||||
|
||||
|
||||
|
||||
## slow_fib_table.md
|
||||
|
||||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `slow/newlisp-fib-let 30` | 352.8 ± 3.6 | 345.0 | 356.9 | 11.44 ± 0.38 |
|
||||
| `slow/kraken-fib-let-slow-wavm 30` | 8754.9 ± 79.1 | 8635.3 | 8940.4 | 283.97 ± 9.38 |
|
||||
| `slow/kraken-fib-slow-wavm 30` | 3154.1 ± 31.8 | 3112.0 | 3204.9 | 102.31 ± 3.41 |
|
||||
| `slow/kraken-fib-let-wavm 30` | 31.8 ± 0.8 | 30.1 | 34.5 | 1.03 ± 0.04 |
|
||||
| `slow/newlisp-fib 30` | 308.3 ± 3.1 | 304.0 | 313.0 | 10.00 ± 0.33 |
|
||||
| `slow/kraken-fib-wavm 30` | 30.8 ± 1.0 | 29.6 | 33.8 | 1.00 |
|
||||
| `slow/kraken-fib 30` | 38.7 ± 0.9 | 37.2 | 41.1 | 1.25 ± 0.05 |
|
||||
| `slow/kraken-fib-let 30` | 42.7 ± 1.0 | 40.8 | 45.5 | 1.38 ± 0.05 |
|
||||
|
||||
|
||||
|
||||
## slow_ish_rbtree_table.md
|
||||
|
||||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `./slow/kraken-rbtree-opt 890` | 28.9 ± 1.1 | 26.9 | 32.8 | 1.00 |
|
||||
| `./slow/kraken-rbtree-opt-wavm 890` | 35.9 ± 0.7 | 34.7 | 37.8 | 1.24 ± 0.05 |
|
||||
| `./slow/newlisp-slow-fexpr-rbtree 890` | 6516.8 ± 15.4 | 6491.3 | 6537.4 | 225.82 ± 8.46 |
|
||||
| `./slow/newlisp-macro-rbtree 890` | 1003.7 ± 2.4 | 1000.1 | 1008.9 | 34.78 ± 1.30 |
|
||||
|
||||
|
||||
|
||||
## slow_rbtree_table.md
|
||||
|
||||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `./slow/kraken-rbtree-opt 100` | 24.1 ± 1.0 | 22.2 | 26.7 | 1.88 ± 0.12 |
|
||||
| `./slow/kraken-rbtree-opt-wavm 100` | 34.7 ± 7.8 | 32.5 | 104.4 | 2.71 ± 0.63 |
|
||||
| `./slow/newlisp-slow-fexpr-rbtree 100` | 334.7 ± 1.7 | 331.3 | 337.2 | 26.13 ± 1.27 |
|
||||
| `./slow/newlisp-macro-rbtree 100` | 12.8 ± 0.6 | 12.1 | 15.0 | 1.00 |
|
||||
| `./slow/kraken-rbtree-slow-wavm 100` | 2501167.5 ± 26231.6 | 2428798.0 | 2514951.4 | 195272.93 ± 9651.02 |
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max
|
||||
build/kraken/out/bench/kraken-cfold-wavm 20,1.2621564595800003,0.008640411915661495,1.2593907364799999,1.13313784,0.118044,1.25479187498,1.28487568498
|
||||
build/java/out/bench/cfold 20,0.35657448718000007,0.00558577826352044,0.35739406448000005,0.40431914,0.1469187,0.34625631998000006,0.36395965198
|
||||
build/ocaml/ml-cfold 20,0.5385355318800001,0.001566527327571848,0.53853815098,0.50224824,0.036017,0.53558768298,0.54036365198
|
||||
build/swift/sw-cfold 20,0.8642314439800002,0.0044482895786414275,0.8649492004800001,0.80760954,0.05612069999999999,0.85469952498,0.8705609119800001
|
||||
build/cpp/cpp-cfold 20,0.30622296198,0.0024784149826698612,0.30592687648000005,0.21424323999999997,0.0918147,0.30293893898,0.31113143098
|
||||
build/haskell/hs-cfold 20,0.5037699929799999,0.001091585403056106,0.50399623548,0.4556685399999999,0.04782399999999999,0.50162550498,0.5051531599800001
|
||||
build/koka/out/bench/kk-cfold 20,0.1326358102981818,0.002816643075142655,0.13199419048,0.09420199454545455,0.03824613636363636,0.12888567098,0.13929317298
|
||||
|
@@ -1,8 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max,relative
|
||||
build/koka/out/bench/kk-cfold 20,0.1326358102981818,0.002816643075142655,0.13199419048,0.09420199454545455,0.03824613636363636,0.12888567098,0.13929317298,1.0
|
||||
build/cpp/cpp-cfold 20,0.30622296198,0.0024784149826698612,0.30592687648000005,0.21424323999999997,0.0918147,0.30293893898,0.31113143098,2.3087502635342045
|
||||
build/java/out/bench/cfold 20,0.35657448718000007,0.00558577826352044,0.35739406448000005,0.40431914,0.1469187,0.34625631998000006,0.36395965198,2.6883726678215805
|
||||
build/haskell/hs-cfold 20,0.5037699929799999,0.001091585403056106,0.50399623548,0.4556685399999999,0.04782399999999999,0.50162550498,0.5051531599800001,3.798144647719664
|
||||
build/ocaml/ml-cfold 20,0.5385355318800001,0.001566527327571848,0.53853815098,0.50224824,0.036017,0.53558768298,0.54036365198,4.060257412152158
|
||||
build/swift/sw-cfold 20,0.8642314439800002,0.0044482895786414275,0.8649492004800001,0.80760954,0.05612069999999999,0.85469952498,0.8705609119800001,6.515822853851462
|
||||
build/kraken/out/bench/kraken-cfold-wavm 20,1.2621564595800003,0.008640411915661495,1.2593907364799999,1.13313784,0.118044,1.25479187498,1.28487568498,9.515955432718476
|
||||
|
@@ -1,9 +0,0 @@
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `build/kraken/out/bench/kraken-cfold-wavm 20` | 1.262 ± 0.009 | 1.255 | 1.285 | 9.52 ± 0.21 |
|
||||
| `build/java/out/bench/cfold 20` | 0.357 ± 0.006 | 0.346 | 0.364 | 2.69 ± 0.07 |
|
||||
| `build/ocaml/ml-cfold 20` | 0.539 ± 0.002 | 0.536 | 0.540 | 4.06 ± 0.09 |
|
||||
| `build/swift/sw-cfold 20` | 0.864 ± 0.004 | 0.855 | 0.871 | 6.52 ± 0.14 |
|
||||
| `build/cpp/cpp-cfold 20` | 0.306 ± 0.002 | 0.303 | 0.311 | 2.31 ± 0.05 |
|
||||
| `build/haskell/hs-cfold 20` | 0.504 ± 0.001 | 0.502 | 0.505 | 3.80 ± 0.08 |
|
||||
| `build/koka/out/bench/kk-cfold 20` | 0.133 ± 0.003 | 0.129 | 0.139 | 1.00 |
|
||||
@@ -1,9 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max
|
||||
build/kraken/out/bench/kraken-deriv 8,0.5926659240600001,0.015671919009291355,0.58672073846,0.56475258,0.02802132,0.57974311646,0.62213955046
|
||||
build/kraken/out/bench/kraken-deriv-wavm 8,0.40733756365999996,0.0009821282489247262,0.40737392896,0.36970888,0.025605619999999996,0.40555148046,0.40877450746
|
||||
build/java/out/bench/deriv 8,0.12067052941454541,0.017361764256886632,0.12979169095999998,0.10848297090909093,0.032761456363636365,0.08669823646000001,0.13022292646
|
||||
build/ocaml/ml-deriv 8,0.01444019793904192,0.0007600945529711628,0.014232565459999999,0.011388068622754495,0.0029253649101796393,0.01311326646,0.01648827546
|
||||
build/swift/sw-deriv 8,0.03732575823333334,0.0007290788778458855,0.03737861746,0.03111240666666666,0.006054553333333333,0.03556797346,0.03963244146
|
||||
build/cpp/cpp-deriv 8,0.020339155069374996,0.0007414278246101117,0.02017742246,0.0148340284375,0.005368085624999999,0.01940543846,0.02215189446
|
||||
build/haskell/hs-deriv 8,0.035425201109350636,0.0007980342646148488,0.03550050246,0.029785626753246742,0.0054718719480519465,0.034088684460000004,0.03711976646
|
||||
build/koka/out/bench/kk-deriv 8,0.016569307715172413,0.0007517508455226539,0.01611368746,0.013344717931034483,0.003070199310344828,0.01573686246,0.01865933346
|
||||
|
@@ -1,9 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max,relative
|
||||
build/ocaml/ml-deriv 8,0.01444019793904192,0.0007600945529711628,0.014232565459999999,0.011388068622754495,0.0029253649101796393,0.01311326646,0.01648827546,1.0
|
||||
build/koka/out/bench/kk-deriv 8,0.016569307715172413,0.0007517508455226539,0.01611368746,0.013344717931034483,0.003070199310344828,0.01573686246,0.01865933346,1.1474432542488926
|
||||
build/cpp/cpp-deriv 8,0.020339155069374996,0.0007414278246101117,0.02017742246,0.0148340284375,0.005368085624999999,0.01940543846,0.02215189446,1.4085094370059903
|
||||
build/haskell/hs-deriv 8,0.035425201109350636,0.0007980342646148488,0.03550050246,0.029785626753246742,0.0054718719480519465,0.034088684460000004,0.03711976646,2.4532351466991753
|
||||
build/swift/sw-deriv 8,0.03732575823333334,0.0007290788778458855,0.03737861746,0.03111240666666666,0.006054553333333333,0.03556797346,0.03963244146,2.5848508719133134
|
||||
build/java/out/bench/deriv 8,0.12067052941454541,0.017361764256886632,0.12979169095999998,0.10848297090909093,0.032761456363636365,0.08669823646000001,0.13022292646,8.356570313228799
|
||||
build/kraken/out/bench/kraken-deriv-wavm 8,0.40733756365999996,0.0009821282489247262,0.40737392896,0.36970888,0.025605619999999996,0.40555148046,0.40877450746,28.2085858780843
|
||||
build/kraken/out/bench/kraken-deriv 8,0.5926659240600001,0.015671919009291355,0.58672073846,0.56475258,0.02802132,0.57974311646,0.62213955046,41.04278393979704
|
||||
|
@@ -1,10 +0,0 @@
|
||||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `build/kraken/out/bench/kraken-deriv 8` | 592.7 ± 15.7 | 579.7 | 622.1 | 41.04 ± 2.42 |
|
||||
| `build/kraken/out/bench/kraken-deriv-wavm 8` | 407.3 ± 1.0 | 405.6 | 408.8 | 28.21 ± 1.49 |
|
||||
| `build/java/out/bench/deriv 8` | 120.7 ± 17.4 | 86.7 | 130.2 | 8.36 ± 1.28 |
|
||||
| `build/ocaml/ml-deriv 8` | 14.4 ± 0.8 | 13.1 | 16.5 | 1.00 |
|
||||
| `build/swift/sw-deriv 8` | 37.3 ± 0.7 | 35.6 | 39.6 | 2.58 ± 0.15 |
|
||||
| `build/cpp/cpp-deriv 8` | 20.3 ± 0.7 | 19.4 | 22.2 | 1.41 ± 0.09 |
|
||||
| `build/haskell/hs-deriv 8` | 35.4 ± 0.8 | 34.1 | 37.1 | 2.45 ± 0.14 |
|
||||
| `build/koka/out/bench/kk-deriv 8` | 16.6 ± 0.8 | 15.7 | 18.7 | 1.15 ± 0.08 |
|
||||
@@ -1,13 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max
|
||||
build/kraken/out/bench/kraken-fib-let-wavm 30,0.03181960762551724,0.0011452651359248392,0.031557890660000004,0.023700833793103452,0.007047057011494251,0.030398782660000005,0.03803639566
|
||||
build/kraken/out/bench/kraken-fib-wavm 30,0.030918793326666673,0.000928676328145603,0.03077728466,0.02248509777777778,0.007249324444444445,0.029288149660000005,0.03444836666
|
||||
build/kraken/out/bench/kraken-fib 30,0.03893658151915494,0.0010515681229527139,0.03883635966,0.03277791295774647,0.007673601126760562,0.03701147266,0.04091842666
|
||||
build/kraken/out/bench/kraken-fib-let 30,0.042836191326666676,0.000824112628331353,0.042713493660000004,0.03617710181818181,0.008130216363636363,0.04063806366,0.044874553660000004
|
||||
build/cpp/cpp-fib 30,0.002509718753235833,0.0006329242444390252,0.0022614686600000004,0.0018724126873857386,0.0006322106764168192,0.0020580746600000004,0.005170380660000001
|
||||
build/picolisp/out/bench/picolisp-fib-let 30,0.10776150032666665,0.0009226815402447703,0.10776881466,0.10382312370370368,0.0037123022222222226,0.10565573666,0.10932584666
|
||||
build/picolisp/out/bench/picolisp-fib 30,0.08865807719125,0.0012121985922940507,0.08852848766,0.08488813875000001,0.0035180487500000002,0.08672793966,0.09133525566
|
||||
build/koka/out/bench/kk-fib 30,0.0058831122724260386,0.0004593408247992408,0.005689903660000001,0.005364798698224853,0.0004990137278106509,0.005406744660000001,0.008101926660000001
|
||||
build/python/out/bench/python-fib-let 30,0.29550229916,0.01117655962350306,0.30074413116,0.29035832000000006,0.00468668,0.27876866566,0.30682154066
|
||||
build/python/out/bench/python-fib 30,0.28439971895999994,0.00979890901848185,0.28642411016,0.27906482,0.00498138,0.26628892266,0.29565501166
|
||||
build/scheme/out/bench/scheme-fib 30,0.05209390788222225,0.001142581920387094,0.051942426160000006,0.03786001259259259,0.014038524444444443,0.05063031766000001,0.055315788660000004
|
||||
build/scheme/out/bench/scheme-fib-let 30,0.05298147327538462,0.0009319879115699704,0.053112924660000005,0.03899324692307692,0.01375221461538461,0.05143635666,0.055183640660000005
|
||||
|
@@ -1,13 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max,relative
|
||||
build/cpp/cpp-fib 30,0.002509718753235833,0.0006329242444390252,0.0022614686600000004,0.0018724126873857386,0.0006322106764168192,0.0020580746600000004,0.005170380660000001,1.0
|
||||
build/koka/out/bench/kk-fib 30,0.0058831122724260386,0.0004593408247992408,0.005689903660000001,0.005364798698224853,0.0004990137278106509,0.005406744660000001,0.008101926660000001,2.3441320924270177
|
||||
build/kraken/out/bench/kraken-fib-wavm 30,0.030918793326666673,0.000928676328145603,0.03077728466,0.02248509777777778,0.007249324444444445,0.029288149660000005,0.03444836666,12.319624773414322
|
||||
build/kraken/out/bench/kraken-fib-let-wavm 30,0.03181960762551724,0.0011452651359248392,0.031557890660000004,0.023700833793103452,0.007047057011494251,0.030398782660000005,0.03803639566,12.678555150648476
|
||||
build/kraken/out/bench/kraken-fib 30,0.03893658151915494,0.0010515681229527139,0.03883635966,0.03277791295774647,0.007673601126760562,0.03701147266,0.04091842666,15.514320665992232
|
||||
build/kraken/out/bench/kraken-fib-let 30,0.042836191326666676,0.000824112628331353,0.042713493660000004,0.03617710181818181,0.008130216363636363,0.04063806366,0.044874553660000004,17.06812417584125
|
||||
build/scheme/out/bench/scheme-fib 30,0.05209390788222225,0.001142581920387094,0.051942426160000006,0.03786001259259259,0.014038524444444443,0.05063031766000001,0.055315788660000004,20.756870790823267
|
||||
build/scheme/out/bench/scheme-fib-let 30,0.05298147327538462,0.0009319879115699704,0.053112924660000005,0.03899324692307692,0.01375221461538461,0.05143635666,0.055183640660000005,21.110522128056978
|
||||
build/picolisp/out/bench/picolisp-fib 30,0.08865807719125,0.0012121985922940507,0.08852848766,0.08488813875000001,0.0035180487500000002,0.08672793966,0.09133525566,35.32590138912629
|
||||
build/picolisp/out/bench/picolisp-fib-let 30,0.10776150032666665,0.0009226815402447703,0.10776881466,0.10382312370370368,0.0037123022222222226,0.10565573666,0.10932584666,42.93767984469475
|
||||
build/python/out/bench/python-fib 30,0.28439971895999994,0.00979890901848185,0.28642411016,0.27906482,0.00498138,0.26628892266,0.29565501166,113.31935843142482
|
||||
build/python/out/bench/python-fib-let 30,0.29550229916,0.01117655962350306,0.30074413116,0.29035832000000006,0.00468668,0.27876866566,0.30682154066,117.74319284939904
|
||||
|
@@ -1,14 +0,0 @@
|
||||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `build/kraken/out/bench/kraken-fib-let-wavm 30` | 31.8 ± 1.1 | 30.4 | 38.0 | 12.68 ± 3.23 |
|
||||
| `build/kraken/out/bench/kraken-fib-wavm 30` | 30.9 ± 0.9 | 29.3 | 34.4 | 12.32 ± 3.13 |
|
||||
| `build/kraken/out/bench/kraken-fib 30` | 38.9 ± 1.1 | 37.0 | 40.9 | 15.51 ± 3.93 |
|
||||
| `build/kraken/out/bench/kraken-fib-let 30` | 42.8 ± 0.8 | 40.6 | 44.9 | 17.07 ± 4.32 |
|
||||
| `build/cpp/cpp-fib 30` | 2.5 ± 0.6 | 2.1 | 5.2 | 1.00 |
|
||||
| `build/picolisp/out/bench/picolisp-fib-let 30` | 107.8 ± 0.9 | 105.7 | 109.3 | 42.94 ± 10.83 |
|
||||
| `build/picolisp/out/bench/picolisp-fib 30` | 88.7 ± 1.2 | 86.7 | 91.3 | 35.33 ± 8.92 |
|
||||
| `build/koka/out/bench/kk-fib 30` | 5.9 ± 0.5 | 5.4 | 8.1 | 2.34 ± 0.62 |
|
||||
| `build/python/out/bench/python-fib-let 30` | 295.5 ± 11.2 | 278.8 | 306.8 | 117.74 ± 30.03 |
|
||||
| `build/python/out/bench/python-fib 30` | 284.4 ± 9.8 | 266.3 | 295.7 | 113.32 ± 28.84 |
|
||||
| `build/scheme/out/bench/scheme-fib 30` | 52.1 ± 1.1 | 50.6 | 55.3 | 20.76 ± 5.25 |
|
||||
| `build/scheme/out/bench/scheme-fib-let 30` | 53.0 ± 0.9 | 51.4 | 55.2 | 21.11 ± 5.34 |
|
||||
@@ -27,7 +27,7 @@
|
||||
(f4 (idx l4 (+ i4 2)))
|
||||
(f4 (idx l4 (+ i4 3)))
|
||||
)) (+ i4 4))
|
||||
true (recurse f4 l4 (concat n4 (array (f4 (idx l4 i4)))) (+ i4 1)))))
|
||||
true (recurse f4 l4 (concat n4 (array (f4 (idx l4 i4)))) (+ 1 i4)))))
|
||||
(helper f5 l5 (array) 0)))
|
||||
|
||||
|
||||
|
||||
18
koka_bench/kraken/test.sh
Executable file
18
koka_bench/kraken/test.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
NUMBER=42000
|
||||
|
||||
#rm rbtree.wasm || true
|
||||
#scheme --script ../../partial_eval.scm rbtree.kp && mv csc_out.wasm rbtree.wasm
|
||||
#hyperfine --warmup 2 "wasmtime ./rbtree.wasm $NUMBER" "wasmtime ./old_rbtree.wasm $NUMBER"
|
||||
|
||||
rm rbtree-opt.wasm || true
|
||||
scheme --script ../../partial_eval.scm rbtree-opt.kp && mv csc_out.wasm rbtree-opt.wasm
|
||||
hyperfine --warmup 2 "wasmtime ./rbtree-opt.wasm $NUMBER" "wasmtime ./old_rbtree-opt.wasm $NUMBER"
|
||||
|
||||
#rm rbtree.wasm || true
|
||||
#rm rbtree-opt.wasm || true
|
||||
#scheme --script ../../partial_eval.scm rbtree.kp && mv csc_out.wasm rbtree.wasm
|
||||
#scheme --script ../../partial_eval.scm rbtree-opt.kp && mv csc_out.wasm rbtree-opt.wasm
|
||||
#hyperfine --warmup 2 "wasmtime ./rbtree.wasm $NUMBER" "wasmtime ./rbtree-opt.wasm $NUMBER" "wasmtime ./old_rbtree.wasm $NUMBER" "wasmtime ./old_rbtree-opt.wasm $NUMBER"
|
||||
|
||||
66
koka_bench/new_test.sh
Executable file
66
koka_bench/new_test.sh
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
pushd "$SCRIPT_DIR"
|
||||
|
||||
# Yeet ourselves inside a pure flake shell (-i for ignore-environment)
|
||||
if [[ -z "${INSIDE_FLAKE}" ]]; then
|
||||
echo "Not inside flake, entering"
|
||||
# thanks to https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
|
||||
echo "about to run nix develop"
|
||||
nix develop -i -c env INSIDE_FLAKE=true bash -c "$SCRIPT_DIR/new_test.sh"
|
||||
exit
|
||||
else
|
||||
echo "Inside flake, running!"
|
||||
fi
|
||||
|
||||
rm -rf build || true
|
||||
mkdir build
|
||||
|
||||
pushd build
|
||||
# workaround thanks to https://github.com/NixOS/nixpkgs/issues/139943
|
||||
cp -r "$(dirname $(dirname $(which emcc)))/share/emscripten/cache" ./emcache
|
||||
chmod u+rwX -R emcache
|
||||
export EM_CACHE="$(pwd)/emcache"
|
||||
|
||||
#no_compile
|
||||
#no_lazy_env
|
||||
#no_y_comb
|
||||
#no_prim_inline
|
||||
#no_closure_inline
|
||||
|
||||
echo "RB-Tree"
|
||||
ITERS=420000
|
||||
scheme --script ../../partial_eval.scm ../kraken/rbtree-opt.kp && mv csc_out.wasm kraken-rbtree-opt.wasm
|
||||
koka --target=wasm -v -O2 ../koka/rbtree.kk && mv ./.koka/v*/emcc-wasm32-drelease/koka_rbtree.wasm ./
|
||||
#koka --target=c -v -O2 ../koka/rbtree.kk && mv ./.koka/v*/cc-drelease/koka_rbtree ./
|
||||
|
||||
hyperfine --warmup 2 "wasmtime ./koka_rbtree.wasm $ITERS" "wasmtime ./kraken-rbtree-opt.wasm $ITERS" --export-markdown rbtree_table.md --export-csv rbtree_table.csv
|
||||
|
||||
echo "Fib"
|
||||
ITERS=40
|
||||
scheme --script ../../partial_eval.scm ../kraken/fib.kp && mv csc_out.wasm kraken-fib.wasm
|
||||
koka --target=wasm -v -O2 ../koka/fib.kk && mv ./.koka/v*/emcc-wasm32-drelease/koka_fib.wasm ./
|
||||
hyperfine --warmup 2 "wasmtime ./koka_fib.wasm $ITERS" "wasmtime ./kraken-fib.wasm $ITERS" --export-markdown fib_table.md --export-csv fib_table.csv
|
||||
|
||||
|
||||
echo "CFold"
|
||||
ITERS=9
|
||||
scheme --script ../../partial_eval.scm ../kraken/cfold.kp && mv csc_out.wasm kraken-cfold.wasm
|
||||
koka --target=wasm -v -O2 ../koka/cfold.kk && mv ./.koka/v*/emcc-wasm32-drelease/koka_cfold.wasm ./
|
||||
hyperfine --warmup 2 "wasmtime ./koka_cfold.wasm $ITERS" "wasmtime ./kraken-cfold.wasm $ITERS" --export-markdown cfold_table.md --export-csv cfold_table.csv
|
||||
|
||||
echo "N-Queens"
|
||||
ITERS=10
|
||||
scheme --script ../../partial_eval.scm ../kraken/nqueens.kp && mv csc_out.wasm kraken-nqueens.wasm
|
||||
koka --target=wasm -v -O2 ../koka/nqueens.kk && mv ./.koka/v*/emcc-wasm32-drelease/koka_nqueens.wasm ./
|
||||
hyperfine --warmup 2 "wasmtime ./koka_nqueens.wasm $ITERS" "wasmtime ./kraken-nqueens.wasm $ITERS" --export-markdown nqueens_table.md --export-csv nqueens_table.csv
|
||||
|
||||
echo "Deriv"
|
||||
ITERS=9
|
||||
scheme --script ../../partial_eval.scm ../kraken/deriv.kp && mv csc_out.wasm kraken-deriv.wasm
|
||||
koka --target=wasm -v -O2 ../koka/deriv.kk && mv ./.koka/v*/emcc-wasm32-drelease/koka_deriv.wasm ./
|
||||
hyperfine --warmup 2 "wasmtime ./koka_deriv.wasm $ITERS" "wasmtime ./kraken-deriv.wasm $ITERS" --export-markdown deriv_table.md --export-csv deriv_table.csv
|
||||
popd
|
||||
popd
|
||||
@@ -1,10 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max
|
||||
build/kraken/out/bench/kraken-nqueens 10,1.19636121408,0.013016063885035612,1.19335900808,1.17315286,0.023507419999999998,1.18544050258,1.2302624585800002
|
||||
build/kraken/out/bench/kraken-nqueens-wavm 10,0.8634745450799999,0.009705372714724447,0.86542838008,0.83359416,0.021065220000000003,0.84952514358,0.8802923365800001
|
||||
build/java/out/bench/nqueens 10,0.05836687064976744,0.005330936257647592,0.05591865258,0.039822490232558135,0.024053552558139537,0.05310179458,0.07067794158000001
|
||||
build/ocaml/ml-nqueens 10,0.004601735168555858,0.000577630460392379,0.00431815858,0.003810435858310624,0.0008569992370572217,0.00412929358,0.006851159580000001
|
||||
build/swift/sw-nqueens 10,0.015856361522307693,0.0007476976679558368,0.015368299080000002,0.014388534358974359,0.0014337138461538472,0.015108747580000002,0.017575813580000002
|
||||
build/cpp/cpp-nqueens 10,0.005897589116741212,0.0004970463127740206,0.00566404158,0.004994850734824281,0.0009119492651757191,0.0054777585799999995,0.00770937058
|
||||
build/haskell/hs-nqueens 10,0.035982979982597384,0.000676971490027155,0.03615113058,0.03319600155844155,0.002702796883116884,0.03459675658,0.03722873058
|
||||
build/koka/out/bench/kk-nqueens 10,0.0043967425472897234,0.0006098432797481458,0.00415873458,0.0038578263551401868,0.0006252028971962618,0.003935189580000001,0.00726332758
|
||||
build/koka/out/bench/kk-nqueens-int 10,0.006476511649930072,0.0005270082893349759,0.0062184525800000005,0.005904727832167832,0.0006367033566433565,0.005995675580000001,0.008241744580000002
|
||||
|
@@ -1,10 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max,relative
|
||||
build/koka/out/bench/kk-nqueens 10,0.0043967425472897234,0.0006098432797481458,0.00415873458,0.0038578263551401868,0.0006252028971962618,0.003935189580000001,0.00726332758,1.0
|
||||
build/ocaml/ml-nqueens 10,0.004601735168555858,0.000577630460392379,0.00431815858,0.003810435858310624,0.0008569992370572217,0.00412929358,0.006851159580000001,1.0466237490736177
|
||||
build/cpp/cpp-nqueens 10,0.005897589116741212,0.0004970463127740206,0.00566404158,0.004994850734824281,0.0009119492651757191,0.0054777585799999995,0.00770937058,1.3413542078729748
|
||||
build/koka/out/bench/kk-nqueens-int 10,0.006476511649930072,0.0005270082893349759,0.0062184525800000005,0.005904727832167832,0.0006367033566433565,0.005995675580000001,0.008241744580000002,1.473024990722365
|
||||
build/swift/sw-nqueens 10,0.015856361522307693,0.0007476976679558368,0.015368299080000002,0.014388534358974359,0.0014337138461538472,0.015108747580000002,0.017575813580000002,3.6063884459375504
|
||||
build/haskell/hs-nqueens 10,0.035982979982597384,0.000676971490027155,0.03615113058,0.03319600155844155,0.002702796883116884,0.03459675658,0.03722873058,8.18400886464874
|
||||
build/java/out/bench/nqueens 10,0.05836687064976744,0.005330936257647592,0.05591865258,0.039822490232558135,0.024053552558139537,0.05310179458,0.07067794158000001,13.275025776923517
|
||||
build/kraken/out/bench/kraken-nqueens-wavm 10,0.8634745450799999,0.009705372714724447,0.86542838008,0.83359416,0.021065220000000003,0.84952514358,0.8802923365800001,196.38960794105856
|
||||
build/kraken/out/bench/kraken-nqueens 10,1.19636121408,0.013016063885035612,1.19335900808,1.17315286,0.023507419999999998,1.18544050258,1.2302624585800002,272.10172103833344
|
||||
|
@@ -1,11 +0,0 @@
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `build/kraken/out/bench/kraken-nqueens 10` | 1.196 ± 0.013 | 1.185 | 1.230 | 272.10 ± 37.86 |
|
||||
| `build/kraken/out/bench/kraken-nqueens-wavm 10` | 0.863 ± 0.010 | 0.850 | 0.880 | 196.39 ± 27.33 |
|
||||
| `build/java/out/bench/nqueens 10` | 0.058 ± 0.005 | 0.053 | 0.071 | 13.28 ± 2.20 |
|
||||
| `build/ocaml/ml-nqueens 10` | 0.005 ± 0.001 | 0.004 | 0.007 | 1.05 ± 0.20 |
|
||||
| `build/swift/sw-nqueens 10` | 0.016 ± 0.001 | 0.015 | 0.018 | 3.61 ± 0.53 |
|
||||
| `build/cpp/cpp-nqueens 10` | 0.006 ± 0.000 | 0.005 | 0.008 | 1.34 ± 0.22 |
|
||||
| `build/haskell/hs-nqueens 10` | 0.036 ± 0.001 | 0.035 | 0.037 | 8.18 ± 1.15 |
|
||||
| `build/koka/out/bench/kk-nqueens 10` | 0.004 ± 0.001 | 0.004 | 0.007 | 1.00 |
|
||||
| `build/koka/out/bench/kk-nqueens-int 10` | 0.006 ± 0.001 | 0.006 | 0.008 | 1.47 ± 0.24 |
|
||||
@@ -1,6 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max
|
||||
./slow/kraken-rbtree-opt 100,0.024073812766902663,0.00101568872666385,0.023981108820000003,0.013964058938053093,0.010416836283185843,0.022171882820000002,0.026677836820000002
|
||||
./slow/kraken-rbtree-opt-wavm 100,0.034688892393170745,0.007841371606363657,0.033655831319999996,0.02159911268292682,0.01100518292682927,0.03249684882,0.10438634682000002
|
||||
./slow/newlisp-slow-fexpr-rbtree 100,0.33467720061999995,0.0017169909863666642,0.33419976582,0.33144182000000005,0.0029782,0.33133876282,0.33724592082
|
||||
./slow/newlisp-macro-rbtree 100,0.012808572662105267,0.0006186239065595693,0.01251284132,0.009985556842105265,0.0026657263157894733,0.012097865820000001,0.014971716820000001
|
||||
./slow/kraken-rbtree-slow-wavm 100,2501.1674679941198,26.23156008638233,2511.02493639732,2500.37616872,0.5680571000000001,2428.79803291582,2514.95137303882
|
||||
|
@@ -1,6 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max,relative
|
||||
./slow/newlisp-macro-rbtree 100,0.012808572662105267,0.0006186239065595693,0.01251284132,0.009985556842105265,0.0026657263157894733,0.012097865820000001,0.014971716820000001,1.0
|
||||
./slow/kraken-rbtree-opt 100,0.024073812766902663,0.00101568872666385,0.023981108820000003,0.013964058938053093,0.010416836283185843,0.022171882820000002,0.026677836820000002,1.879507842284887
|
||||
./slow/kraken-rbtree-opt-wavm 100,0.034688892393170745,0.007841371606363657,0.033655831319999996,0.02159911268292682,0.01100518292682927,0.03249684882,0.10438634682000002,2.7082558930082334
|
||||
./slow/newlisp-slow-fexpr-rbtree 100,0.33467720061999995,0.0017169909863666642,0.33419976582,0.33144182000000005,0.0029782,0.33133876282,0.33724592082,26.129156577309924
|
||||
./slow/kraken-rbtree-slow-wavm 100,2501.1674679941198,26.23156008638233,2511.02493639732,2500.37616872,0.5680571000000001,2428.79803291582,2514.95137303882,195272.92649819877
|
||||
|
@@ -1,7 +0,0 @@
|
||||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `./slow/kraken-rbtree-opt 100` | 24.1 ± 1.0 | 22.2 | 26.7 | 1.88 ± 0.12 |
|
||||
| `./slow/kraken-rbtree-opt-wavm 100` | 34.7 ± 7.8 | 32.5 | 104.4 | 2.71 ± 0.63 |
|
||||
| `./slow/newlisp-slow-fexpr-rbtree 100` | 334.7 ± 1.7 | 331.3 | 337.2 | 26.13 ± 1.27 |
|
||||
| `./slow/newlisp-macro-rbtree 100` | 12.8 ± 0.6 | 12.1 | 15.0 | 1.00 |
|
||||
| `./slow/kraken-rbtree-slow-wavm 100` | 2501167.5 ± 26231.6 | 2428798.0 | 2514951.4 | 195272.93 ± 9651.02 |
|
||||
@@ -1,11 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max
|
||||
build/kraken/out/bench/kraken-rbtree-opt 420000,5.31925239708,0.3349988125683587,5.14052044018,5.1289582199999995,0.19030451999999998,5.119997754180001,6.1186545401800005
|
||||
build/kraken/out/bench/kraken-rbtree-wavm 420000,7.603207084680001,0.08532599178431961,7.56256009118,7.364062819999999,0.19609051999999996,7.54500121418,7.82634368618
|
||||
build/kraken/out/bench/kraken-rbtree-opt-wavm 420000,2.38786697048,0.024027067473493164,2.37399108918,2.18655812,0.17421282,2.37013181018,2.42730367318
|
||||
build/kraken/out/bench/kraken-rbtree 420000,14.103996714480001,0.6716953370649333,13.862458608179999,13.879761419999998,0.22387711999999996,13.57410318018,15.734669132179999
|
||||
build/java/out/bench/rbtree 420000,0.20452481833384614,0.005494893712175741,0.20184439718000002,0.1633610507692308,0.08549068153846152,0.20064960218,0.21500799618000002
|
||||
build/ocaml/ml-rbtree 420000,0.08404845703294117,0.0004965078984563921,0.08389702468000002,0.07837808470588233,0.005522072941176472,0.08343194518000001,0.08558860818
|
||||
build/swift/sw-rbtree 420000,0.48127939458,0.002468656281248806,0.48110524718000003,0.47217482000000005,0.00883322,0.47831013518000004,0.48734295218000007
|
||||
build/cpp/cpp-rbtree 420000,0.06167631024249998,0.002866280729154884,0.06073653918,0.056175653333333325,0.005363282499999998,0.05818080818,0.07026982618000001
|
||||
build/haskell/hs-rbtree 420000,0.1650659297682353,0.0007316071227665543,0.16494317018000001,0.1528258788235294,0.012111984705882354,0.16393611218,0.16621976618
|
||||
build/koka/out/bench/kk-rbtree 420000,0.04799795884666668,0.0014174284429626085,0.04771546118,0.042882170877192975,0.005030605964912281,0.04521208018,0.052173015180000004
|
||||
|
@@ -1,11 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max,relative
|
||||
build/koka/out/bench/kk-rbtree 420000,0.04799795884666668,0.0014174284429626085,0.04771546118,0.042882170877192975,0.005030605964912281,0.04521208018,0.052173015180000004,1.0
|
||||
build/cpp/cpp-rbtree 420000,0.06167631024249998,0.002866280729154884,0.06073653918,0.056175653333333325,0.005363282499999998,0.05818080818,0.07026982618000001,1.2849777724825735
|
||||
build/ocaml/ml-rbtree 420000,0.08404845703294117,0.0004965078984563921,0.08389702468000002,0.07837808470588233,0.005522072941176472,0.08343194518000001,0.08558860818,1.7510839846636121
|
||||
build/haskell/hs-rbtree 420000,0.1650659297682353,0.0007316071227665543,0.16494317018000001,0.1528258788235294,0.012111984705882354,0.16393611218,0.16621976618,3.4390197778107945
|
||||
build/java/out/bench/rbtree 420000,0.20452481833384614,0.005494893712175741,0.20184439718000002,0.1633610507692308,0.08549068153846152,0.20064960218,0.21500799618000002,4.2611149150574725
|
||||
build/swift/sw-rbtree 420000,0.48127939458,0.002468656281248806,0.48110524718000003,0.47217482000000005,0.00883322,0.47831013518000004,0.48734295218000007,10.027080445597395
|
||||
build/kraken/out/bench/kraken-rbtree-opt-wavm 420000,2.38786697048,0.024027067473493164,2.37399108918,2.18655812,0.17421282,2.37013181018,2.42730367318,49.74934409415684
|
||||
build/kraken/out/bench/kraken-rbtree-opt 420000,5.31925239708,0.3349988125683587,5.14052044018,5.1289582199999995,0.19030451999999998,5.119997754180001,6.1186545401800005,110.82247089033051
|
||||
build/kraken/out/bench/kraken-rbtree-wavm 420000,7.603207084680001,0.08532599178431961,7.56256009118,7.364062819999999,0.19609051999999996,7.54500121418,7.82634368618,158.40688369622245
|
||||
build/kraken/out/bench/kraken-rbtree 420000,14.103996714480001,0.6716953370649333,13.862458608179999,13.879761419999998,0.22387711999999996,13.57410318018,15.734669132179999,293.8457603902771
|
||||
|
@@ -1,12 +0,0 @@
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `build/kraken/out/bench/kraken-rbtree-opt 420000` | 5.319 ± 0.335 | 5.120 | 6.119 | 110.82 ± 7.71 |
|
||||
| `build/kraken/out/bench/kraken-rbtree-wavm 420000` | 7.603 ± 0.085 | 7.545 | 7.826 | 158.41 ± 5.00 |
|
||||
| `build/kraken/out/bench/kraken-rbtree-opt-wavm 420000` | 2.388 ± 0.024 | 2.370 | 2.427 | 49.75 ± 1.55 |
|
||||
| `build/kraken/out/bench/kraken-rbtree 420000` | 14.104 ± 0.672 | 13.574 | 15.735 | 293.85 ± 16.47 |
|
||||
| `build/java/out/bench/rbtree 420000` | 0.205 ± 0.005 | 0.201 | 0.215 | 4.26 ± 0.17 |
|
||||
| `build/ocaml/ml-rbtree 420000` | 0.084 ± 0.000 | 0.083 | 0.086 | 1.75 ± 0.05 |
|
||||
| `build/swift/sw-rbtree 420000` | 0.481 ± 0.002 | 0.478 | 0.487 | 10.03 ± 0.30 |
|
||||
| `build/cpp/cpp-rbtree 420000` | 0.062 ± 0.003 | 0.058 | 0.070 | 1.28 ± 0.07 |
|
||||
| `build/haskell/hs-rbtree 420000` | 0.165 ± 0.001 | 0.164 | 0.166 | 3.44 ± 0.10 |
|
||||
| `build/koka/out/bench/kk-rbtree 420000` | 0.048 ± 0.001 | 0.045 | 0.052 | 1.00 |
|
||||
@@ -1,9 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max
|
||||
slow/newlisp-fib-let 30,0.35278714856,0.003582673299334197,0.35351408886,0.34983320000000007,0.0027236399999999994,0.34496016636,0.35693083636
|
||||
slow/kraken-fib-let-slow-wavm 30,8.754898901459999,0.07909160701917145,8.745499961859998,8.698452499999998,0.00766424,8.63531548136,8.94044194336
|
||||
slow/kraken-fib-slow-wavm 30,3.1541494835600004,0.03184683066376855,3.15320478736,3.1101357,0.005756239999999998,3.11203098636,3.2048651933600003
|
||||
slow/kraken-fib-let-wavm 30,0.031773318467142854,0.000840390301131736,0.031628002860000004,0.023603545238095235,0.007084359047619045,0.03006603536,0.03445624236
|
||||
slow/newlisp-fib 30,0.30830525255999996,0.0030724920421244676,0.30762596086,0.30525209999999997,0.00282474,0.30399827236,0.31303751135999996
|
||||
slow/kraken-fib-wavm 30,0.030830056166818196,0.000979772131088745,0.030573067860000004,0.022655052272727273,0.0069862627272727264,0.02959692136,0.033764539360000005
|
||||
slow/kraken-fib 30,0.038683845426666676,0.0008881692760578456,0.038567545360000004,0.03223380666666667,0.00796338,0.03720691336,0.041057437360000004
|
||||
slow/kraken-fib-let 30,0.042657774585806454,0.000996895260201283,0.042579403360000004,0.0362714258064516,0.007971127096774193,0.04082327436,0.04550403036
|
||||
|
@@ -1,9 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max,relative
|
||||
slow/kraken-fib-wavm 30,0.030830056166818196,0.000979772131088745,0.030573067860000004,0.022655052272727273,0.0069862627272727264,0.02959692136,0.033764539360000005,1.0
|
||||
slow/kraken-fib-let-wavm 30,0.031773318467142854,0.000840390301131736,0.031628002860000004,0.023603545238095235,0.007084359047619045,0.03006603536,0.03445624236,1.030595542713927
|
||||
slow/kraken-fib 30,0.038683845426666676,0.0008881692760578456,0.038567545360000004,0.03223380666666667,0.00796338,0.03720691336,0.041057437360000004,1.2547445654121565
|
||||
slow/kraken-fib-let 30,0.042657774585806454,0.000996895260201283,0.042579403360000004,0.0362714258064516,0.007971127096774193,0.04082327436,0.04550403036,1.3836424544603394
|
||||
slow/newlisp-fib 30,0.30830525255999996,0.0030724920421244676,0.30762596086,0.30525209999999997,0.00282474,0.30399827236,0.31303751135999996,10.000152153203764
|
||||
slow/newlisp-fib-let 30,0.35278714856,0.003582673299334197,0.35351408886,0.34983320000000007,0.0027236399999999994,0.34496016636,0.35693083636,11.442961590828956
|
||||
slow/kraken-fib-slow-wavm 30,3.1541494835600004,0.03184683066376855,3.15320478736,3.1101357,0.005756239999999998,3.11203098636,3.2048651933600003,102.30761392367334
|
||||
slow/kraken-fib-let-slow-wavm 30,8.754898901459999,0.07909160701917145,8.745499961859998,8.698452499999998,0.00766424,8.63531548136,8.94044194336,283.9728495494189
|
||||
|
@@ -1,10 +0,0 @@
|
||||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `slow/newlisp-fib-let 30` | 352.8 ± 3.6 | 345.0 | 356.9 | 11.44 ± 0.38 |
|
||||
| `slow/kraken-fib-let-slow-wavm 30` | 8754.9 ± 79.1 | 8635.3 | 8940.4 | 283.97 ± 9.38 |
|
||||
| `slow/kraken-fib-slow-wavm 30` | 3154.1 ± 31.8 | 3112.0 | 3204.9 | 102.31 ± 3.41 |
|
||||
| `slow/kraken-fib-let-wavm 30` | 31.8 ± 0.8 | 30.1 | 34.5 | 1.03 ± 0.04 |
|
||||
| `slow/newlisp-fib 30` | 308.3 ± 3.1 | 304.0 | 313.0 | 10.00 ± 0.33 |
|
||||
| `slow/kraken-fib-wavm 30` | 30.8 ± 1.0 | 29.6 | 33.8 | 1.00 |
|
||||
| `slow/kraken-fib 30` | 38.7 ± 0.9 | 37.2 | 41.1 | 1.25 ± 0.05 |
|
||||
| `slow/kraken-fib-let 30` | 42.7 ± 1.0 | 40.8 | 45.5 | 1.38 ± 0.05 |
|
||||
@@ -1,5 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max
|
||||
./slow/kraken-rbtree-opt 890,0.028858574056842112,0.0010792063880742354,0.02871603632,0.018728634736842102,0.010397546315789475,0.026890857320000003,0.03280110632
|
||||
./slow/kraken-rbtree-opt-wavm 890,0.0358968304238961,0.0007304344407639161,0.03579772732,0.02372153480519481,0.010858762857142858,0.03467246532,0.03778242732
|
||||
./slow/newlisp-slow-fexpr-rbtree 890,6.516844599920001,0.015387330949067515,6.519502710819999,6.477723739999999,0.038728519999999995,6.49131463232,6.53738309332
|
||||
./slow/newlisp-macro-rbtree 890,1.00366118492,0.002375809996798342,1.00352140382,0.9717198400000001,0.031717619999999995,1.00011486032,1.00887062132
|
||||
|
@@ -1,5 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max,relative
|
||||
./slow/kraken-rbtree-opt 890,0.028858574056842112,0.0010792063880742354,0.02871603632,0.018728634736842102,0.010397546315789475,0.026890857320000003,0.03280110632,1.0
|
||||
./slow/kraken-rbtree-opt-wavm 890,0.0358968304238961,0.0007304344407639161,0.03579772732,0.02372153480519481,0.010858762857142858,0.03467246532,0.03778242732,1.2438878772454554
|
||||
./slow/newlisp-macro-rbtree 890,1.00366118492,0.002375809996798342,1.00352140382,0.9717198400000001,0.031717619999999995,1.00011486032,1.00887062132,34.77861321017144
|
||||
./slow/newlisp-slow-fexpr-rbtree 890,6.516844599920001,0.015387330949067515,6.519502710819999,6.477723739999999,0.038728519999999995,6.49131463232,6.53738309332,225.8200487343523
|
||||
|
@@ -1,6 +0,0 @@
|
||||
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `./slow/kraken-rbtree-opt 890` | 28.9 ± 1.1 | 26.9 | 32.8 | 1.00 |
|
||||
| `./slow/kraken-rbtree-opt-wavm 890` | 35.9 ± 0.7 | 34.7 | 37.8 | 1.24 ± 0.05 |
|
||||
| `./slow/newlisp-slow-fexpr-rbtree 890` | 6516.8 ± 15.4 | 6491.3 | 6537.4 | 225.82 ± 8.46 |
|
||||
| `./slow/newlisp-macro-rbtree 890` | 1003.7 ± 2.4 | 1000.1 | 1008.9 | 34.78 ± 1.30 |
|
||||
@@ -1,4 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max
|
||||
./slow/kraken-rbtree-opt 100,0.024073812766902663,0.00101568872666385,0.023981108820000003,0.013964058938053093,0.010416836283185843,0.022171882820000002,0.026677836820000002
|
||||
./slow/kraken-rbtree-opt-wavm 100,0.034688892393170745,0.007841371606363657,0.033655831319999996,0.02159911268292682,0.01100518292682927,0.03249684882,0.10438634682000002
|
||||
./slow/kraken-rbtree-slow-wavm 100,2501.1674679941198,26.23156008638233,2511.02493639732,2500.37616872,0.5680571000000001,2428.79803291582,2514.95137303882
|
||||
|
@@ -1,4 +0,0 @@
|
||||
command,mean,stddev,median,user,system,min,max,relative
|
||||
./slow/kraken-rbtree-opt 100,0.024073812766902663,0.00101568872666385,0.023981108820000003,0.013964058938053093,0.010416836283185843,0.022171882820000002,0.026677836820000002,1.0
|
||||
./slow/kraken-rbtree-opt-wavm 100,0.034688892393170745,0.007841371606363657,0.033655831319999996,0.02159911268292682,0.01100518292682927,0.03249684882,0.10438634682000002,1.440938862865212
|
||||
./slow/kraken-rbtree-slow-wavm 100,2501.1674679941198,26.23156008638233,2511.02493639732,2500.37616872,0.5680571000000001,2428.79803291582,2514.95137303882,103895.77638623131
|
||||
|
1
kr/.gitignore
vendored
Normal file
1
kr/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target
|
||||
559
kr/Cargo.lock
generated
Normal file
559
kr/Cargo.lock
generated
Normal file
@@ -0,0 +1,559 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
|
||||
|
||||
[[package]]
|
||||
name = "ascii-canvas"
|
||||
version = "3.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6"
|
||||
dependencies = [
|
||||
"term",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1"
|
||||
dependencies = [
|
||||
"bit-vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||
|
||||
[[package]]
|
||||
name = "dirs-next"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"dirs-sys-next",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys-next"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"redox_users",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||
|
||||
[[package]]
|
||||
name = "ena"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fixedbitset"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kr"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"lalrpop",
|
||||
"lalrpop-util",
|
||||
"once_cell",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lalrpop"
|
||||
version = "0.19.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b30455341b0e18f276fa64540aff54deafb54c589de6aca68659c63dd2d5d823"
|
||||
dependencies = [
|
||||
"ascii-canvas",
|
||||
"atty",
|
||||
"bit-set",
|
||||
"diff",
|
||||
"ena",
|
||||
"itertools",
|
||||
"lalrpop-util",
|
||||
"petgraph",
|
||||
"pico-args",
|
||||
"regex",
|
||||
"regex-syntax",
|
||||
"string_cache",
|
||||
"term",
|
||||
"tiny-keccak",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lalrpop-util"
|
||||
version = "0.19.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bcf796c978e9b4d983414f4caedc9273aa33ee214c5b887bd55fde84c85d2dc4"
|
||||
dependencies = [
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.139"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "new_debug_unreachable"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
"parking_lot_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.9.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "petgraph"
|
||||
version = "0.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4"
|
||||
dependencies = [
|
||||
"fixedbitset",
|
||||
"indexmap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
|
||||
dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pico-args"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468"
|
||||
|
||||
[[package]]
|
||||
name = "precomputed-hash"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"redox_syscall",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "0.3.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
|
||||
|
||||
[[package]]
|
||||
name = "string_cache"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "213494b7a2b503146286049378ce02b482200519accc31872ee8be91fa820a08"
|
||||
dependencies = [
|
||||
"new_debug_unreachable",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"phf_shared",
|
||||
"precomputed-hash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "term"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f"
|
||||
dependencies = [
|
||||
"dirs-next",
|
||||
"rustversion",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-keccak"
|
||||
version = "2.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
|
||||
dependencies = [
|
||||
"crunchy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[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"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.45.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.42.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd"
|
||||
16
kr/Cargo.toml
Normal file
16
kr/Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "kr"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
build = "build.rs"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
lalrpop-util = {version="0.19.7", features=["lexer"]}
|
||||
regex = "1"
|
||||
once_cell = "1.17.0"
|
||||
anyhow = "1"
|
||||
|
||||
[build-dependencies]
|
||||
lalrpop = "0.19.7"
|
||||
5
kr/build.rs
Normal file
5
kr/build.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
extern crate lalrpop;
|
||||
|
||||
fn main() {
|
||||
lalrpop::process_root().unwrap();
|
||||
}
|
||||
338
kr/src/ast.rs
Normal file
338
kr/src/ast.rs
Normal file
@@ -0,0 +1,338 @@
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
use std::convert::From;
|
||||
|
||||
// TODO:
|
||||
// -extend vau & env logic and SuspendedPair PE with sequence_params & wrap_level
|
||||
// -add current-hashes to if
|
||||
// -expand combiner_Return_ok with (func ...params) | func doesn't take de and func+params are return ok
|
||||
// -add recursive drop redundent veval
|
||||
// -mark rec-hash on DeriComb
|
||||
// -add compiler
|
||||
//
|
||||
// -use current fake comb ids instead of hashes
|
||||
// -do they have to be added to not-under thing like hashes
|
||||
// -make cons work only for SuspendedParam/Env
|
||||
|
||||
impl From<i32> for Form { fn from(item: i32) -> Self { Form::Int(item) } }
|
||||
impl From<bool> for Form { fn from(item: bool) -> Self { Form::Bool(item) } }
|
||||
// todo, strings not symbols?
|
||||
impl From<String> for Form { fn from(item: String) -> Self { Form::Symbol(item) } }
|
||||
impl From<&str> for Form { fn from(item: &str) -> Self { Form::Symbol(item.to_owned()) } }
|
||||
|
||||
impl<A: Into<Form>, B: Into<Form>> From<(A, B)> for Form {
|
||||
fn from(item: (A, B)) -> Self {
|
||||
Form::Pair(Rc::new(item.0.into()), Rc::new(item.1.into()))
|
||||
}
|
||||
}
|
||||
|
||||
pub enum PossibleTailCall {
|
||||
Result(Rc<Form>),
|
||||
TailCall(Rc<Form>, Rc<Form>),
|
||||
}
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum Form {
|
||||
Nil,
|
||||
Int(i32),
|
||||
Bool(bool),
|
||||
Symbol(String),
|
||||
Pair(Rc<Form>,Rc<Form>),
|
||||
PrimComb(String, fn(Rc<Form>, Rc<Form>) -> PossibleTailCall),
|
||||
DeriComb { se: Rc<Form>, de: Option<String>, params: String, body: Rc<Form> },
|
||||
}
|
||||
impl Form {
|
||||
pub fn truthy(&self) -> bool {
|
||||
match self {
|
||||
Form::Bool(b) => *b,
|
||||
Form::Nil => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
pub fn int(&self) -> Option<i32> {
|
||||
match self {
|
||||
Form::Int(i) => Some(*i),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn sym(&self) -> Option<&str> {
|
||||
match self {
|
||||
Form::Symbol(s) => Some(s),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn car(&self) -> Option<Rc<Form>> {
|
||||
match self {
|
||||
Form::Pair(car, _cdr) => Some(Rc::clone(car)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn cdr(&self) -> Option<Rc<Form>> {
|
||||
match self {
|
||||
Form::Pair(_car, cdr) => Some(Rc::clone(cdr)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
pub fn append(&self, x: Rc<Form>) -> Option<Form> {
|
||||
match self {
|
||||
Form::Pair(car, cdr) => cdr.append(x).map(|x| Form::Pair(Rc::clone(car), Rc::new(x))),
|
||||
Form::Nil => Some(Form::Pair(x, Rc::new(Form::Nil))),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl fmt::Display for Form {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Form::Nil => write!(f, "nil"),
|
||||
Form::Int(i) => write!(f, "{}", i),
|
||||
Form::Bool(b) => write!(f, "{}", b),
|
||||
Form::Symbol(s) => write!(f, "{}", s),
|
||||
Form::Pair(car, cdr) => {
|
||||
write!(f, "({}", car)?;
|
||||
let mut traverse: Rc<Form> = Rc::clone(cdr);
|
||||
loop {
|
||||
match &*traverse {
|
||||
Form::Pair(ref carp, ref cdrp) => {
|
||||
write!(f, " {}", carp)?;
|
||||
traverse = Rc::clone(cdrp);
|
||||
},
|
||||
Form::Nil => {
|
||||
write!(f, ")")?;
|
||||
return Ok(());
|
||||
},
|
||||
x => {
|
||||
write!(f, ". {})", x)?;
|
||||
return Ok(());
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
Form::PrimComb(name, _f) => write!(f, "<{}>", name),
|
||||
Form::DeriComb { se, de, params, body } => {
|
||||
write!(f, "<{} {} {}>", de.as_ref().unwrap_or(&"".to_string()), params, body)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eval(e: Rc<Form>, f: Rc<Form>) -> Rc<Form> {
|
||||
let mut e = e;
|
||||
let mut x = Option::Some(f);
|
||||
loop {
|
||||
let cur = x.take().unwrap();
|
||||
//println!("Evaluating {:?} in {:?}", cur, e);
|
||||
match *cur {
|
||||
Form::Symbol(ref s) => {
|
||||
let mut t = e;
|
||||
//println!("Looking up {} in {:?}", s, t);
|
||||
//println!("Looking up {}", s);
|
||||
while s != t.car().unwrap().car().unwrap().sym().unwrap() {
|
||||
t = t.cdr().unwrap();
|
||||
}
|
||||
return t.car().unwrap().cdr().unwrap();
|
||||
},
|
||||
Form::Pair(ref c, ref p) => {
|
||||
let comb = eval(Rc::clone(&e), Rc::clone(c));
|
||||
match *comb {
|
||||
Form::PrimComb(ref _n, ref f) => match f(e, Rc::clone(p)) {
|
||||
PossibleTailCall::Result(r) => return r,
|
||||
PossibleTailCall::TailCall(ne, nx) => {
|
||||
e = ne;
|
||||
x = Some(nx);
|
||||
},
|
||||
},
|
||||
Form::DeriComb{ref se, ref de, ref params, ref body } => {
|
||||
let mut new_e = Rc::clone(se);
|
||||
if let Some(de) = de {
|
||||
new_e = assoc(de, Rc::clone(&e), new_e);
|
||||
}
|
||||
new_e = assoc(params, Rc::clone(p), new_e);
|
||||
// always a tail call
|
||||
e = new_e;
|
||||
x = Some(Rc::clone(body));
|
||||
},
|
||||
_ => panic!("Tried to call not a Prim/DeriComb {:?}", comb),
|
||||
}
|
||||
},
|
||||
_ => return cur,
|
||||
}
|
||||
}
|
||||
}
|
||||
fn assoc(k: &str, v: Rc<Form>, l: Rc<Form>) -> Rc<Form> {
|
||||
Rc::new(Form::Pair(
|
||||
Rc::new(Form::Pair(
|
||||
Rc::new(Form::Symbol(k.to_owned())),
|
||||
v)),
|
||||
l))
|
||||
}
|
||||
fn assoc_vec(kvs: Vec<(&str, Rc<Form>)>) -> Rc<Form> {
|
||||
let mut to_ret = Rc::new(Form::Nil);
|
||||
for (k, v) in kvs {
|
||||
to_ret = assoc(k, v, to_ret);
|
||||
}
|
||||
to_ret
|
||||
}
|
||||
|
||||
pub fn root_env() -> Rc<Form> {
|
||||
assoc_vec(vec![
|
||||
("eval", Rc::new(Form::PrimComb("eval".to_owned(), |e, p| {
|
||||
let b = eval(Rc::clone(&e), p.car().unwrap());
|
||||
let e = eval(e, p.cdr().unwrap().car().unwrap());
|
||||
PossibleTailCall::TailCall(e, b)
|
||||
}))),
|
||||
// (vau de params body)
|
||||
("vau", Rc::new(Form::PrimComb("vau".to_owned(), |e, p| {
|
||||
let de = p.car().unwrap().sym().map(|s| s.to_owned());
|
||||
let params = p.cdr().unwrap().car().unwrap().sym().unwrap().to_owned();
|
||||
let body = p.cdr().unwrap().cdr().unwrap().car().unwrap();
|
||||
|
||||
PossibleTailCall::Result(Rc::new(Form::DeriComb { se: e, de, params, body }))
|
||||
}))),
|
||||
("=", Rc::new(Form::PrimComb("=".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap());
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap());
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(a == b)))
|
||||
}))),
|
||||
("<", Rc::new(Form::PrimComb("<".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap());
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap());
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(a.int().unwrap() < b.int().unwrap())))
|
||||
}))),
|
||||
(">", Rc::new(Form::PrimComb(">".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap());
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap());
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(a.int().unwrap() > b.int().unwrap())))
|
||||
}))),
|
||||
("<=", Rc::new(Form::PrimComb("<=".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap());
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap());
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(a.int().unwrap() <= b.int().unwrap())))
|
||||
}))),
|
||||
(">=", Rc::new(Form::PrimComb(">=".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap());
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap());
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(a.int().unwrap() >= b.int().unwrap())))
|
||||
}))),
|
||||
("if", Rc::new(Form::PrimComb("if".to_owned(), |e, p| {
|
||||
if eval(Rc::clone(&e), p.car().unwrap()).truthy() {
|
||||
PossibleTailCall::TailCall(e, p.cdr().unwrap().car().unwrap())
|
||||
} else {
|
||||
PossibleTailCall::TailCall(e, p.cdr().unwrap().cdr().unwrap().car().unwrap())
|
||||
}
|
||||
}))),
|
||||
("cons", Rc::new(Form::PrimComb("cons".to_owned(), |e, p| {
|
||||
let h = eval(Rc::clone(&e), p.car().unwrap());
|
||||
let t = eval(e, p.cdr().unwrap().car().unwrap());
|
||||
PossibleTailCall::Result(Rc::new(Form::Pair(h, t)))
|
||||
}))),
|
||||
("car", Rc::new(Form::PrimComb("car".to_owned(), |e, p| {
|
||||
PossibleTailCall::Result(eval(Rc::clone(&e), p.car().unwrap()).car().unwrap())
|
||||
}))),
|
||||
("cdr", Rc::new(Form::PrimComb("cdr".to_owned(), |e, p| {
|
||||
PossibleTailCall::Result(eval(Rc::clone(&e), p.car().unwrap()).cdr().unwrap())
|
||||
}))),
|
||||
("quote", Rc::new(Form::PrimComb("quote".to_owned(), |_e, p| {
|
||||
PossibleTailCall::Result(p.car().unwrap())
|
||||
}))),
|
||||
|
||||
("debug", Rc::new(Form::PrimComb("debug".to_owned(), |e, p| {
|
||||
//println!("Debug: {:?}", eval(Rc::clone(&e), p.car().unwrap()));
|
||||
println!("Debug: {}", eval(Rc::clone(&e), p.car().unwrap()));
|
||||
PossibleTailCall::TailCall(e, p.cdr().unwrap().car().unwrap())
|
||||
}))),
|
||||
("assert", Rc::new(Form::PrimComb("assert".to_owned(), |e, p| {
|
||||
let thing = eval(Rc::clone(&e), p.car().unwrap());
|
||||
if !thing.truthy() {
|
||||
println!("Assert failed: {:?}", thing);
|
||||
}
|
||||
assert!(thing.truthy());
|
||||
PossibleTailCall::TailCall(e, p.cdr().unwrap().car().unwrap())
|
||||
}))),
|
||||
|
||||
("+", Rc::new(Form::PrimComb("+".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap()).int().unwrap();
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap()).int().unwrap();
|
||||
PossibleTailCall::Result(Rc::new(Form::Int(a + b)))
|
||||
}))),
|
||||
("-", Rc::new(Form::PrimComb("-".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap()).int().unwrap();
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap()).int().unwrap();
|
||||
PossibleTailCall::Result(Rc::new(Form::Int(a - b)))
|
||||
}))),
|
||||
("*", Rc::new(Form::PrimComb("*".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap()).int().unwrap();
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap()).int().unwrap();
|
||||
PossibleTailCall::Result(Rc::new(Form::Int(a * b)))
|
||||
}))),
|
||||
("/", Rc::new(Form::PrimComb("/".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap()).int().unwrap();
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap()).int().unwrap();
|
||||
PossibleTailCall::Result(Rc::new(Form::Int(a / b)))
|
||||
}))),
|
||||
("%", Rc::new(Form::PrimComb("%".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap()).int().unwrap();
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap()).int().unwrap();
|
||||
PossibleTailCall::Result(Rc::new(Form::Int(a % b)))
|
||||
}))),
|
||||
("&", Rc::new(Form::PrimComb("&".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap()).int().unwrap();
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap()).int().unwrap();
|
||||
PossibleTailCall::Result(Rc::new(Form::Int(a & b)))
|
||||
}))),
|
||||
("|", Rc::new(Form::PrimComb("|".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap()).int().unwrap();
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap()).int().unwrap();
|
||||
PossibleTailCall::Result(Rc::new(Form::Int(a | b)))
|
||||
}))),
|
||||
("^", Rc::new(Form::PrimComb("^".to_owned(), |e, p| {
|
||||
let a = eval(Rc::clone(&e), p.car().unwrap()).int().unwrap();
|
||||
let b = eval(e, p.cdr().unwrap().car().unwrap()).int().unwrap();
|
||||
PossibleTailCall::Result(Rc::new(Form::Int(a ^ b)))
|
||||
}))),
|
||||
|
||||
("comb?", Rc::new(Form::PrimComb("comb?".to_owned(), |e, p| {
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(match &*eval(e, p.car().unwrap()) {
|
||||
Form::PrimComb(_n, _f) => true,
|
||||
Form::DeriComb { .. } => true,
|
||||
_ => false,
|
||||
})))
|
||||
}))),
|
||||
("pair?", Rc::new(Form::PrimComb("pair?".to_owned(), |e, p| {
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(match &*eval(e, p.car().unwrap()) {
|
||||
Form::Pair(_a,_b) => true,
|
||||
_ => false,
|
||||
})))
|
||||
}))),
|
||||
("symbol?", Rc::new(Form::PrimComb("symbol?".to_owned(), |e, p| {
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(match &*eval(e, p.car().unwrap()) {
|
||||
Form::Symbol(_) => true,
|
||||
_ => false,
|
||||
})))
|
||||
}))),
|
||||
("int?", Rc::new(Form::PrimComb("int?".to_owned(), |e, p| {
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(match &*eval(e, p.car().unwrap()) {
|
||||
Form::Int(_) => true,
|
||||
_ => false,
|
||||
})))
|
||||
}))),
|
||||
// maybe bool? but also could be derived. Nil def
|
||||
("bool?", Rc::new(Form::PrimComb("bool?".to_owned(), |e, p| {
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(match &*eval(e, p.car().unwrap()) {
|
||||
Form::Bool(_) => true,
|
||||
_ => false,
|
||||
})))
|
||||
}))),
|
||||
("nil?", Rc::new(Form::PrimComb("nil?".to_owned(), |e, p| {
|
||||
PossibleTailCall::Result(Rc::new(Form::Bool(match &*eval(e, p.car().unwrap()) {
|
||||
Form::Nil => true,
|
||||
_ => false,
|
||||
})))
|
||||
}))),
|
||||
|
||||
// consts
|
||||
("true", Rc::new(Form::Bool(true))),
|
||||
("false", Rc::new(Form::Bool(false))),
|
||||
("nil", Rc::new(Form::Nil)),
|
||||
])
|
||||
}
|
||||
|
||||
31
kr/src/grammar.lalrpop
Normal file
31
kr/src/grammar.lalrpop
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::str::FromStr;
|
||||
use std::rc::Rc;
|
||||
use crate::ast::Form;
|
||||
|
||||
grammar;
|
||||
|
||||
pub Term: Form = {
|
||||
NUM => Form::Int(i32::from_str(<>).unwrap()),
|
||||
SYM => Form::Symbol(<>.to_owned()),
|
||||
"(" <ListInside?> ")" => <>.unwrap_or(Form::Nil),
|
||||
"'" <Term> => Form::Pair(Rc::new(Form::Symbol("quote".to_owned())), Rc::new(Form::Pair(Rc::new(<>), Rc::new(Form::Nil)))),
|
||||
"!" <h: Term> <t: Term> => {
|
||||
h.append(Rc::new(t)).unwrap()
|
||||
},
|
||||
};
|
||||
ListInside: Form = {
|
||||
<Term> => Form::Pair(Rc::new(<>), Rc::new(Form::Nil)),
|
||||
<h: Term> <t: ListInside> => Form::Pair(Rc::new(h), Rc::new(t)),
|
||||
<a: Term> "." <d: Term> => Form::Pair(Rc::new(a), Rc::new(d)),
|
||||
}
|
||||
match {
|
||||
"(",
|
||||
")",
|
||||
".",
|
||||
"'",
|
||||
"!",
|
||||
r"[0-9]+" => NUM,
|
||||
r"[a-zA-Z+*/_=?%&|^<>-][\w+*/=_?%&|^<>-]*" => SYM,
|
||||
r"(;[^\n]*\n)|\s+" => { }
|
||||
}
|
||||
|
||||
26
kr/src/main.rs
Normal file
26
kr/src/main.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
#[macro_use] extern crate lalrpop_util;
|
||||
lalrpop_mod!(pub grammar);
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
mod ast;
|
||||
use crate::ast::{eval,root_env};
|
||||
mod pe_ast;
|
||||
use crate::pe_ast::{mark,partial_eval,new_base_ctxs};
|
||||
|
||||
mod test;
|
||||
|
||||
|
||||
fn main() {
|
||||
let input = "(= 17 ((vau d p (+ (eval (car p) d) 13)) (+ 1 3)))";
|
||||
let parsed_input = Rc::new(grammar::TermParser::new().parse(input).unwrap());
|
||||
println!("Parsed input is {} - {:?}", parsed_input, parsed_input);
|
||||
let (bctx, dctx) = new_base_ctxs();
|
||||
let (bctx, marked) = mark(Rc::clone(&parsed_input),bctx);
|
||||
let unvaled = marked.unval().unwrap();
|
||||
println!("Parsed unvaled that is {}", unvaled);
|
||||
let (bctx, ped) = partial_eval(bctx, dctx, unvaled).unwrap();
|
||||
let result = eval(root_env(), parsed_input);
|
||||
println!("Result is {} - {:?}", result, result);
|
||||
}
|
||||
|
||||
1042
kr/src/pe_ast.rs
Normal file
1042
kr/src/pe_ast.rs
Normal file
File diff suppressed because it is too large
Load Diff
617
kr/src/test.rs
Normal file
617
kr/src/test.rs
Normal file
@@ -0,0 +1,617 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::grammar;
|
||||
use crate::ast::{eval,root_env,Form,PossibleTailCall};
|
||||
use crate::pe_ast::{mark,partial_eval,new_base_ctxs,MarkedForm};
|
||||
|
||||
#[test]
|
||||
fn parse_test() {
|
||||
let g = grammar::TermParser::new();
|
||||
for test in [
|
||||
"22", "(22)", "(((22)))",
|
||||
"(22 )", "()", "( )", "( 44)", "(44 )",
|
||||
"(22 44 (1) 33 (4 5 (6) 6))", "hello",
|
||||
"-", "+", "(+ 1 ;hi
|
||||
3)", "'13", "hello-world", "_",
|
||||
] {
|
||||
assert!(g.parse(test).is_ok());
|
||||
}
|
||||
assert!(g.parse("((22)").is_err());
|
||||
}
|
||||
|
||||
fn eval_test<T: Into<Form>>(also_pe: bool, gram: &grammar::TermParser, e: &Rc<Form>, code: &str, expected: T) {
|
||||
println!("Doing test {}", code);
|
||||
let parsed = Rc::new(gram.parse(code).unwrap());
|
||||
let basic_result = eval(Rc::clone(e), Rc::clone(&parsed));
|
||||
assert_eq!(*basic_result, expected.into());
|
||||
if also_pe {
|
||||
let (bctx, dctx) = new_base_ctxs();
|
||||
let (bctx, marked) = mark(parsed,bctx);
|
||||
let unvaled = marked.unval().unwrap();
|
||||
let (bctx, ped) = partial_eval(bctx, dctx, unvaled).unwrap();
|
||||
let (bctx, marked_basic_result) = mark(basic_result,bctx);
|
||||
println!("Final PE {}", ped);
|
||||
println!("wanted {}", marked_basic_result);
|
||||
assert_eq!(*ped, *marked_basic_result);
|
||||
}
|
||||
}
|
||||
fn partial_eval_test(gram: &grammar::TermParser, code: &str, expected: &str) {
|
||||
println!("Doing PE test {}", code);
|
||||
let parsed = Rc::new(gram.parse(code).unwrap());
|
||||
let (bctx, dctx) = new_base_ctxs();
|
||||
let (bctx, marked) = mark(parsed,bctx);
|
||||
let unvaled = marked.unval().unwrap();
|
||||
let (bctx, ped) = partial_eval(bctx, dctx, unvaled).unwrap();
|
||||
println!("Final PE {}", ped);
|
||||
println!("wanted {}", expected);
|
||||
assert_eq!(format!("{}", ped), expected);
|
||||
}
|
||||
#[test]
|
||||
fn basic_pe_test() {
|
||||
let g = grammar::TermParser::new();
|
||||
partial_eval_test(&g, "(+ 2 (car (cons 4 '(1 2))))", "6");
|
||||
partial_eval_test(&g, "(vau 0 p (+ 1 2))", "NeededIds { heads: {}, tails: {}, body_stopped: {}, if_stopped: {} }#[None/None/EnvID(1)/0/[]/Some(\"p\")/3]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, "(+ 2 (car (cons 4 '(1 2))))", 6);
|
||||
eval_test(true, &g, &e, "(= 17 ((vau d p (+ (eval (car p) d) 13)) (+ 1 3)))", true);
|
||||
eval_test(true, &g, &e, "(if (= 2 2) (+ 1 2) (+ 3 4))", 3);
|
||||
eval_test(true, &g, &e, "(quote a)", "a");
|
||||
eval_test(true, &g, &e, "'a", "a");
|
||||
eval_test(true, &g, &e, "'(1 . a)", (1, "a"));
|
||||
eval_test(true, &g, &e, "'(1 a)", (1, ("a", Form::Nil)));
|
||||
eval_test(true, &g, &e, "true", true);
|
||||
eval_test(true, &g, &e, "false", false);
|
||||
eval_test(true, &g, &e, "nil", Form::Nil);
|
||||
|
||||
eval_test(true, &g, &e, "(+ 1 2)", 3);
|
||||
eval_test(true, &g, &e, "(- 1 2)", -1);
|
||||
eval_test(true, &g, &e, "(* 1 2)", 2);
|
||||
eval_test(true, &g, &e, "(/ 4 2)", 2);
|
||||
eval_test(true, &g, &e, "(% 3 2)", 1);
|
||||
eval_test(true, &g, &e, "(& 3 2)", 2);
|
||||
eval_test(true, &g, &e, "(| 2 1)", 3);
|
||||
eval_test(true, &g, &e, "(^ 2 1)", 3);
|
||||
eval_test(true, &g, &e, "(^ 3 1)", 2);
|
||||
|
||||
eval_test(true, &g, &e, "(< 3 1)", false);
|
||||
eval_test(true, &g, &e, "(<= 3 1)", false);
|
||||
eval_test(true, &g, &e, "(> 3 1)", true);
|
||||
eval_test(true, &g, &e, "(>= 3 1)", true);
|
||||
|
||||
eval_test(true, &g, &e, "(comb? +)", true);
|
||||
eval_test(true, &g, &e, "(comb? (vau d p 1))", true);
|
||||
eval_test(true, &g, &e, "(comb? 1)", false);
|
||||
eval_test(true, &g, &e, "(pair? '(a))", true);
|
||||
//eval_test(true, &g, &e, "(pair? '())", true);
|
||||
eval_test(true, &g, &e, "(nil? nil)", true);
|
||||
eval_test(true, &g, &e, "(nil? 1)", false);
|
||||
eval_test(true, &g, &e, "(pair? 1)", false);
|
||||
eval_test(true, &g, &e, "(symbol? 'a)", true);
|
||||
eval_test(true, &g, &e, "(symbol? 1)", false);
|
||||
eval_test(true, &g, &e, "(int? 1)", true);
|
||||
eval_test(true, &g, &e, "(int? true)", false);
|
||||
eval_test(true, &g, &e, "(bool? true)", true);
|
||||
eval_test(true, &g, &e, "(bool? 1)", false);
|
||||
|
||||
eval_test(true, &g, &e, "!(bool?) 1", false);
|
||||
eval_test(true, &g, &e, "!(bool?) true", true);
|
||||
|
||||
eval_test(true, &g, &e, "((vau root_env _ (eval 'a (cons (cons 'a 2) root_env))))", 2);
|
||||
eval_test(true, &g, &e, "'name-dash", "name-dash");
|
||||
}
|
||||
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
static LET: Lazy<String> = Lazy::new(|| {
|
||||
"!((vau root_env p (eval (car p)
|
||||
(cons (cons 'let1
|
||||
(vau de p (eval (car (cdr (cdr p))) (cons (cons (car p) (eval (car (cdr p)) de)) de)))
|
||||
) root_env))))".to_owned()
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn let_pe_test() {
|
||||
let g = grammar::TermParser::new();
|
||||
partial_eval_test(&g, &format!("{} (let1 a 2 (+ a (car (cons 4 '(1 2)))))", *LET), "6");
|
||||
partial_eval_test(&g, &format!("{} (let1 a 2 (vau 0 p (+ 1 a)))", *LET),"NeededIds { heads: {}, tails: {}, body_stopped: {}, if_stopped: {} }#[None/None/EnvID(3)/0/[]/Some(\"p\")/3]");
|
||||
partial_eval_test(&g, &format!("{}
|
||||
!(let1 a 2)
|
||||
(vau 0 p (+ 1 a))
|
||||
", *LET), "NeededIds { heads: {}, tails: {}, body_stopped: {}, if_stopped: {} }#[None/None/EnvID(3)/0/[]/Some(\"p\")/3]");
|
||||
partial_eval_test(&g, &format!("{}
|
||||
!(let1 a 2)
|
||||
!(let1 b 5)
|
||||
(vau 0 p (+ b a))
|
||||
", *LET), "NeededIds { heads: {}, tails: {}, body_stopped: {}, if_stopped: {} }#[None/None/EnvID(3)/0/[]/Some(\"p\")/7]");
|
||||
/*
|
||||
partial_eval_test(&g, &format!("{}
|
||||
(vau 0 p
|
||||
!(let1 a 2)
|
||||
!(let1 b 5)
|
||||
(+ b a)
|
||||
)
|
||||
", *LET), "None({})#[None/None/EnvID(0)/0/[]/Some(\"p\")/7]");
|
||||
partial_eval_test(&g, &format!("{}
|
||||
(vau d p
|
||||
!(let1 a 2)
|
||||
(+ (eval (car p) d) a)
|
||||
)
|
||||
", *LET), "None({})#[None/None/EnvID(2)/0/[]/Some(\"p\")/7]");
|
||||
*/
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fib_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} (let1 x 10 (+ x 7))", *LET), 17);
|
||||
let def_fib = "
|
||||
!(let1 fib (vau de p
|
||||
!(let1 self (eval (car p) de))
|
||||
!(let1 n (eval (car (cdr p)) de))
|
||||
!(if (= 0 n) 0)
|
||||
!(if (= 1 n) 1)
|
||||
(+ (self self (- n 1)) (self self (- n 2)))
|
||||
))";
|
||||
eval_test(false, &g, &e, &format!("{} {} (fib fib 6)", *LET, def_fib), 8);
|
||||
}
|
||||
#[test]
|
||||
fn fact_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
let def_fact = "
|
||||
!(let1 fact (vau de p
|
||||
!(let1 self (eval (car p) de))
|
||||
!(let1 n (eval (car (cdr p)) de))
|
||||
!(if (= 0 n) 1)
|
||||
(* n (self self (- n 1)))
|
||||
))";
|
||||
eval_test(true, &g, &e, &format!("{} {} (fact fact 6)", *LET, def_fact), 720);
|
||||
}
|
||||
static VAPPLY: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 vapply (vau de p
|
||||
!(let1 f (eval (car p) de))
|
||||
!(let1 ip (eval (car (cdr p)) de))
|
||||
!(let1 nde (eval (car (cdr (cdr p))) de))
|
||||
(eval (cons f ip) nde)
|
||||
))", *LET)
|
||||
});
|
||||
#[test]
|
||||
fn vapply_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
// need the vapply to keep env in check because otherwise the env keeps growing
|
||||
// and the Rc::drop will overflow the stack lol
|
||||
let def_badid = format!("
|
||||
{}
|
||||
!(let1 badid (vau de p
|
||||
!(let1 inner (vau ide ip
|
||||
!(let1 self (car ip))
|
||||
!(let1 n (car (cdr ip)))
|
||||
!(let1 acc (car (cdr (cdr ip))))
|
||||
!(if (= 0 n) acc)
|
||||
(vapply self (cons self (cons (- n 1) (cons (+ acc 1) nil))) de)
|
||||
))
|
||||
(vapply inner (cons inner (cons (eval (car p) de) (cons 0 nil))) de)
|
||||
))", *VAPPLY);
|
||||
// Won't work unless tail calls work
|
||||
// so no PE?
|
||||
eval_test(false, &g, &e, &format!("{} (badid 1000)", def_badid), 1000);
|
||||
}
|
||||
|
||||
static VMAP: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 vmap (vau de p
|
||||
!(let1 vmap_inner (vau ide ip
|
||||
!(let1 self (car ip))
|
||||
!(let1 f (car (cdr ip)))
|
||||
!(let1 l (car (cdr (cdr ip))))
|
||||
!(if (= nil l) l)
|
||||
(cons (vapply f (cons (car l) nil) de) (vapply self (cons self (cons f (cons (cdr l) nil))) de))
|
||||
))
|
||||
(vapply vmap_inner (cons vmap_inner (cons (eval (car p) de) (cons (eval (car (cdr p)) de) nil))) de)
|
||||
))", *VAPPLY)
|
||||
});
|
||||
#[test]
|
||||
fn vmap_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
// Maybe define in terms of a right fold?
|
||||
//eval_test(true, &g, &e, &format!("{} (vmap (vau de p (+ 1 (car p))) '(1 2 3))", *VMAP), (2, (3, (4, Form::Nil))));
|
||||
eval_test(true, &g, &e, &format!("{} (vmap (vau de p (+ 1 (car p))) '(1))", *VMAP), (2, Form::Nil));
|
||||
}
|
||||
|
||||
static WRAP: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 wrap (vau de p
|
||||
!(let1 f (eval (car p) de))
|
||||
(vau ide p (vapply f (vmap (vau _ xp (eval (car xp) ide)) p) ide))
|
||||
))", *VMAP)
|
||||
});
|
||||
#[test]
|
||||
fn wrap_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
// Make sure (wrap (vau ...)) and internal style are optimized the same
|
||||
eval_test(true, &g, &e, &format!("{} ((wrap (vau _ p (+ (car p) 1))) (+ 1 2))", *WRAP), 4);
|
||||
}
|
||||
|
||||
static UNWRAP: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 unwrap (vau de p
|
||||
!(let1 f (eval (car p) de))
|
||||
(vau ide p (vapply f (vmap (vau _ xp (cons quote (cons (car xp) nil))) p) ide))
|
||||
))", *WRAP)
|
||||
});
|
||||
#[test]
|
||||
fn unwrap_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
// Can't represent prims in tests :( - they do work though, uncommenting and checking the
|
||||
// failed assert verifies
|
||||
//eval_test(true, &g, &e, &format!("{} ((unwrap (vau de p (car p))) (+ 1 2))", def_unwrap), ("quote", (("+", (1, (2, Form::Nil))), Form::Nil)));
|
||||
//eval_test(true, &g, &e, &format!("{} ((unwrap (vau de p (eval (car p) de))) (+ 1 2))", def_unwrap), (("+", (1, (2, Form::Nil))), Form::Nil));
|
||||
eval_test(true, &g, &e, &format!("{} ((unwrap (vau de p (eval (eval (car p) de) de))) (+ 1 2))", *UNWRAP), 3);
|
||||
eval_test(true, &g, &e, &format!("{} ((unwrap (vau de p (+ (eval (eval (car p) de) de) 1))) (+ 1 2))", *UNWRAP), 4);
|
||||
}
|
||||
|
||||
static LAPPLY: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 lapply (vau de p
|
||||
!(let1 f (eval (car p) de))
|
||||
!(let1 ip (eval (car (cdr p)) de))
|
||||
!(let1 nde (eval (car (cdr (cdr p))) de))
|
||||
(eval (cons (unwrap f) ip) nde)
|
||||
))", *UNWRAP)
|
||||
});
|
||||
#[test]
|
||||
fn lapply_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
// Should this allow envs at all? It technically can, but I feel like it kinda goes against the
|
||||
// sensible deriviation
|
||||
let def_lbadid = format!("
|
||||
{}
|
||||
!(let1 lbadid (vau de p
|
||||
!(let1 inner (wrap (vau ide ip
|
||||
!(let1 self (car ip))
|
||||
!(let1 n (car (cdr ip)))
|
||||
!(let1 acc (car (cdr (cdr ip))))
|
||||
!(if (= 0 n) acc)
|
||||
(lapply self (cons self (cons (- n 1) (cons (+ acc 1) nil))) de)
|
||||
)))
|
||||
(lapply inner (cons inner (cons (eval (car p) de) (cons 0 nil))) de)
|
||||
))", *LAPPLY);
|
||||
// Won't work unless tail calls work
|
||||
// takes a while though
|
||||
eval_test(false, &g, &e, &format!("{} (lbadid 1000)", def_lbadid), 1000);
|
||||
}
|
||||
|
||||
static VFOLDL: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 vfoldl (vau de p
|
||||
!(let1 vfoldl_inner (vau ide ip
|
||||
!(let1 self (car ip))
|
||||
!(let1 f (car (cdr ip)))
|
||||
!(let1 a (car (cdr (cdr ip))))
|
||||
!(let1 l (car (cdr (cdr (cdr ip)))))
|
||||
!(if (= nil l) a)
|
||||
(vapply self (cons self (cons f (cons (vapply f (cons a (cons (car l) nil)) de) (cons (cdr l) nil)))) de)
|
||||
))
|
||||
(vapply vfoldl_inner (cons vfoldl_inner (cons (eval (car p) de) (cons (eval (car (cdr p)) de) (cons (eval (car (cdr (cdr p))) de) nil)))) de)
|
||||
))", *LAPPLY)
|
||||
});
|
||||
#[test]
|
||||
fn vfoldl_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} (vfoldl (vau de p (+ (car p) (car (cdr p)))) 0 '(1 2 3))", *VFOLDL), 6);
|
||||
}
|
||||
static ZIPD: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 zipd (vau de p
|
||||
!(let1 zipd_inner (vau ide ip
|
||||
!(let1 self (car ip))
|
||||
!(let1 a (car (cdr ip)))
|
||||
!(let1 b (car (cdr (cdr ip))))
|
||||
!(if (= nil a) a)
|
||||
!(if (= nil b) b)
|
||||
(cons (cons (car a) (car b)) (vapply self (cons self (cons (cdr a) (cons (cdr b) nil))) de))
|
||||
))
|
||||
(vapply zipd_inner (cons zipd_inner (cons (eval (car p) de) (cons (eval (car (cdr p)) de) nil))) de)
|
||||
))", *VFOLDL)
|
||||
});
|
||||
#[test]
|
||||
fn zipd_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} (zipd '(1 2 3) '(4 5 6))", *ZIPD), ((1,4), ((2,5), ((3,6), Form::Nil))));
|
||||
}
|
||||
static CONCAT: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 concat (vau de p
|
||||
!(let1 concat_inner (vau ide ip
|
||||
!(let1 self (car ip))
|
||||
!(let1 a (car (cdr ip)))
|
||||
!(let1 b (car (cdr (cdr ip))))
|
||||
!(if (= nil a) b)
|
||||
(cons (car a) (vapply self (cons self (cons (cdr a) (cons b nil))) de))
|
||||
))
|
||||
(vapply concat_inner (cons concat_inner (cons (eval (car p) de) (cons (eval (car (cdr p)) de) nil))) de)
|
||||
))", *ZIPD)
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn concat_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} (concat '(1 2 3) '(4 5 6))", *CONCAT), (1, (2, (3, (4, (5, (6, Form::Nil)))))));
|
||||
}
|
||||
|
||||
static BVAU: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 match_params (wrap (vau 0 p
|
||||
!(let1 self (car p))
|
||||
!(let1 p_ls (car (cdr p)))
|
||||
!(let1 dp (car (cdr (cdr p))))
|
||||
!(let1 e (car (cdr (cdr (cdr p)))))
|
||||
!(if (= nil p_ls) (assert (= nil dp) e))
|
||||
!(if (symbol? p_ls) (cons (cons p_ls dp) e))
|
||||
(self self (cdr p_ls) (cdr dp) (self self (car p_ls) (car dp) e))
|
||||
)))
|
||||
!(let1 bvau (vau se p
|
||||
(if (= nil (cdr (cdr p)))
|
||||
; No de case
|
||||
!(let1 p_ls (car p))
|
||||
!(let1 b_v (car (cdr p)))
|
||||
(vau 0 dp
|
||||
(eval b_v (match_params match_params p_ls dp se))
|
||||
)
|
||||
|
||||
; de case
|
||||
!(let1 de_s (car p))
|
||||
!(let1 p_ls (car (cdr p)))
|
||||
!(let1 b_v (car (cdr (cdr p))))
|
||||
(vau dde dp
|
||||
(eval b_v (match_params match_params p_ls dp (cons (cons de_s dde) se)))
|
||||
)
|
||||
)
|
||||
))", *CONCAT)
|
||||
});
|
||||
#[test]
|
||||
fn bvau_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} ((bvau _ (a b c) (+ a (- b c))) 10 2 3)", *BVAU), 9);
|
||||
//eval_test(true, &g, &e, &format!("{} ((bvau (a b c) (+ a (- b c))) 10 2 3)", *BVAU), 9);
|
||||
|
||||
//eval_test(true, &g, &e, &format!("{} ((bvau (a b . c) c) 10 2 3)", *BVAU), (3, Form::Nil));
|
||||
//eval_test(true, &g, &e, &format!("{} ((bvau (a b . c) c) 10 2)", *BVAU), Form::Nil);
|
||||
//eval_test(true, &g, &e, &format!("{} ((bvau (a b . c) c) 10 2 3 4 5)", *BVAU), (3, (4, (5, Form::Nil))));
|
||||
//eval_test(true, &g, &e, &format!("{} ((bvau c c) 3 4 5)", *BVAU), (3, (4, (5, Form::Nil))));
|
||||
//eval_test(true, &g, &e, &format!("{} ((bvau c c))", *BVAU), Form::Nil);
|
||||
//eval_test(true, &g, &e, &format!("{} ((bvau ((a b) . c) c) (10 2) 3 4 5)", *BVAU), (3, (4, (5, Form::Nil))));
|
||||
//eval_test(true, &g, &e, &format!("{} ((bvau ((a b) . c) a) (10 2) 3 4 5)", *BVAU), 10);
|
||||
//eval_test(true, &g, &e, &format!("{} ((bvau ((a b) . c) b) (10 2) 3 4 5)", *BVAU), 2);
|
||||
|
||||
//eval_test(true, &g, &e, &format!("{} ((wrap (bvau _ (a b c) (+ a (- b c)))) (+ 10 1) (+ 2 2) (+ 5 3))", *BVAU), 7);
|
||||
//eval_test(true, &g, &e, &format!("{} ((wrap (bvau (a b c) (+ a (- b c)))) (+ 10 1) (+ 2 2) (+ 5 3))", *BVAU), 7);
|
||||
}
|
||||
|
||||
static LAMBDA: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 lambda (vau de p
|
||||
(wrap (vapply bvau p de))
|
||||
))", *BVAU)
|
||||
});
|
||||
#[test]
|
||||
fn lambda_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda (a b c) (+ a (- b c))) (+ 10 1) (+ 2 2) (+ 5 3))", *LAMBDA), 7);
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda (a b . c) c) 10 2 3)", *LAMBDA), (3, Form::Nil));
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda (a b . c) c) 10 2)", *LAMBDA), Form::Nil);
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda (a b . c) c) 10 2 3 4 5)", *LAMBDA), (3, (4, (5, Form::Nil))));
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda c c) 3 4 5)", *LAMBDA), (3, (4, (5, Form::Nil))));
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda c c))", *LAMBDA), Form::Nil);
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda ((a b) . c) c) '(10 2) 3 4 5)", *LAMBDA), (3, (4, (5, Form::Nil))));
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda ((a b) . c) a) '(10 2) 3 4 5)", *LAMBDA), 10);
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda ((a b) . c) b) '(10 2) 3 4 5)", *LAMBDA), 2);
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda ((a b . c) d) b) '(10 2 3 4) 3)", *LAMBDA), 2);
|
||||
eval_test(true, &g, &e, &format!("{} ((lambda ((a b . c) d) c) '(10 2 3 4) 3)", *LAMBDA), (3, (4, Form::Nil)));
|
||||
// should fail
|
||||
//eval_test(true, &g, &e, &format!("{} ((lambda (a b c) c) 10 2 3 4)", *LAMBDA), 3);
|
||||
}
|
||||
|
||||
static LET2: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 let1 (bvau dp (s v b)
|
||||
(eval b (match_params match_params s (eval v dp) dp))
|
||||
))
|
||||
", *LAMBDA)
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn let2_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
|
||||
eval_test(true, &g, &e, &format!("{} (let1 x (+ 10 1) (+ x 1))", *LET2), 12);
|
||||
eval_test(true, &g, &e, &format!("{} (let1 x '(10 1) x)", *LET2), (10, (1, Form::Nil)));
|
||||
eval_test(true, &g, &e, &format!("{} (let1 (a b) '(10 1) a)", *LET2), 10);
|
||||
eval_test(true, &g, &e, &format!("{} (let1 (a b) '(10 1) b)", *LET2), 1);
|
||||
eval_test(true, &g, &e, &format!("{} (let1 (a b . c) '(10 1) c)", *LET2), Form::Nil);
|
||||
eval_test(true, &g, &e, &format!("{} (let1 (a b . c) '(10 1 2 3) c)", *LET2), (2, (3, Form::Nil)));
|
||||
eval_test(true, &g, &e, &format!("{} (let1 ((a . b) . c) '((10 1) 2 3) a)", *LET2), 10);
|
||||
eval_test(true, &g, &e, &format!("{} (let1 ((a . b) . c) '((10 1) 2 3) b)", *LET2), (1, Form::Nil));
|
||||
// should fail
|
||||
//eval_test(true, &g, &e, &format!("{} (let1 (a b c) '(10 2 3 4) a)", *LET2), 10);
|
||||
}
|
||||
|
||||
static LIST: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 list (lambda args args))
|
||||
", *LET2)
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn list_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} (list 1 2 (+ 3 4))", *LIST), (1, (2, (7, Form::Nil))));
|
||||
}
|
||||
|
||||
static Y: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 Y (lambda (f3)
|
||||
((lambda (x1) (x1 x1))
|
||||
(lambda (x2) (f3 (wrap (vau app_env y (lapply (x2 x2) y app_env)))))))
|
||||
)
|
||||
", *LIST)
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn y_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
|
||||
eval_test(true, &g, &e, &format!("{} ((Y (lambda (recurse) (lambda (n) (if (= 0 n) 1 (* n (recurse (- n 1))))))) 5)", *Y), 120);
|
||||
|
||||
}
|
||||
|
||||
static RLAMBDA: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 rlambda (bvau se (n p b)
|
||||
(eval (list Y (list lambda (list n) (list lambda p b))) se)
|
||||
))
|
||||
", *Y)
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn rlambda_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} ((rlambda recurse (n) (if (= 0 n) 1 (* n (recurse (- n 1))))) 5)", *RLAMBDA), 120);
|
||||
}
|
||||
static AND_OR: Lazy<String> = Lazy::new(|| {
|
||||
// need to extend for varidac
|
||||
format!("
|
||||
{}
|
||||
!(let1 and (bvau se (a b)
|
||||
!(let1 ae (eval a se))
|
||||
(if ae (eval b se) ae)
|
||||
))
|
||||
!(let1 or (bvau se (a b)
|
||||
!(let1 ae (eval a se))
|
||||
(if ae ae (eval b se))
|
||||
))
|
||||
", *RLAMBDA)
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn and_or_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} (and true true)", *AND_OR), true);
|
||||
eval_test(true, &g, &e, &format!("{} (and false true)", *AND_OR), false);
|
||||
eval_test(true, &g, &e, &format!("{} (and true false)", *AND_OR), false);
|
||||
eval_test(true, &g, &e, &format!("{} (and false false)", *AND_OR), false);
|
||||
|
||||
eval_test(true, &g, &e, &format!("{} (or true true)", *AND_OR), true);
|
||||
eval_test(true, &g, &e, &format!("{} (or false true)", *AND_OR), true);
|
||||
eval_test(true, &g, &e, &format!("{} (or true false)", *AND_OR), true);
|
||||
eval_test(true, &g, &e, &format!("{} (or false false)", *AND_OR), false);
|
||||
}
|
||||
static LEN: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 len (lambda (l)
|
||||
!(let1 len_helper (rlambda len_helper (l a)
|
||||
(if (pair? l) (len_helper (cdr l) (+ 1 a))
|
||||
a)
|
||||
))
|
||||
(len_helper l 0)
|
||||
))
|
||||
", *AND_OR)
|
||||
});
|
||||
|
||||
#[test]
|
||||
fn len_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} (len '())", *LEN), 0);
|
||||
eval_test(true, &g, &e, &format!("{} (len '(1))", *LEN), 1);
|
||||
eval_test(true, &g, &e, &format!("{} (len '(1 2))", *LEN), 2);
|
||||
eval_test(true, &g, &e, &format!("{} (len '(1 2 3))", *LEN), 3);
|
||||
}
|
||||
static MATCH: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 match (bvau de (x . cases)
|
||||
!(let1 evaluate_case (rlambda evaluate_case (access c)
|
||||
!(if (symbol? c) (list true (lambda (b) (list let1 c access b))))
|
||||
!(if (and (pair? c) (= 'unquote (car c))) (list (list = access (car (cdr c))) (lambda (b) b)))
|
||||
!(if (and (pair? c) (= 'quote (car c))) (list (list = access c) (lambda (b) b)))
|
||||
!(if (pair? c)
|
||||
!(let1 tests (list and (list pair? access) (list = (len c) (list len access))))
|
||||
!(let1 (tests body_func) ((rlambda recurse (c tests access body_func) (if (pair? c)
|
||||
!(let1 (inner_test inner_body_func) (evaluate_case (list car access) (car c)))
|
||||
(recurse (cdr c)
|
||||
(list and tests inner_test)
|
||||
(list cdr access)
|
||||
(lambda (b) (body_func (inner_body_func b))))
|
||||
; else
|
||||
(list tests body_func)
|
||||
))
|
||||
c tests access (lambda (b) b)))
|
||||
(list tests body_func))
|
||||
(list (list = access c) (lambda (b) b))
|
||||
))
|
||||
!(let1 helper (rlambda helper (x_sym cases) (if (= nil cases) (list assert false)
|
||||
(let1 (test body_func) (evaluate_case x_sym (car cases))
|
||||
(concat (list if test (body_func (car (cdr cases)))) (list (helper x_sym (cdr (cdr cases)))))))))
|
||||
|
||||
(eval (list let1 '___MATCH_SYM x (helper '___MATCH_SYM cases)) de)
|
||||
;!(let1 expanded (list let1 '___MATCH_SYM x (helper '___MATCH_SYM cases)))
|
||||
;(debug expanded (eval expanded de))
|
||||
))
|
||||
", *LEN)
|
||||
});
|
||||
#[test]
|
||||
fn match_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(true, &g, &e, &format!("{} (match (+ 1 2) 1 2 2 3 3 4 _ 0)", *MATCH), 4);
|
||||
eval_test(true, &g, &e, &format!("{} (match '(1 2) 1 2 2 3 3 4 _ 0)", *MATCH), 0);
|
||||
eval_test(true, &g, &e, &format!("{} (match '(1 2) 1 2 2 3 (a b) (+ a (+ 2 b)) _ 0)", *MATCH), 5);
|
||||
eval_test(true, &g, &e, &format!("{} (match '(1 2) 1 2 2 3 '(1 2) 7 _ 0)", *MATCH), 7);
|
||||
eval_test(true, &g, &e, &format!("{} (let1 a 70 (match (+ 60 10) (unquote a) 100 2 3 _ 0))", *MATCH), 100);
|
||||
}
|
||||
static RBTREE: Lazy<String> = Lazy::new(|| {
|
||||
format!("
|
||||
{}
|
||||
!(let1 empty (list 'B nil nil nil))
|
||||
!(let1 E empty)
|
||||
!(let1 EE (list 'BB nil nil nil))
|
||||
|
||||
!(let1 generic-foldl (rlambda generic-foldl (f z t) (match t
|
||||
(unquote E) z
|
||||
|
||||
(c a x b) !(let1 new_left_result (generic-foldl f z a))
|
||||
!(let1 folded (f new_left_result x))
|
||||
(generic-foldl f folded b))))
|
||||
|
||||
!(let1 blacken (lambda (t) (match t
|
||||
('R a x b) (list 'B a x b)
|
||||
t t)))
|
||||
!(let1 balance (lambda (t) (match t
|
||||
; figures 1 and 2
|
||||
('B ('R ('R a x b) y c) z d) (list 'R (list 'B a x b) y (list 'B c z d))
|
||||
('B ('R a x ('R b y c)) z d) (list 'R (list 'B a x b) y (list 'B c z d))
|
||||
('B a x ('R ('R b y c) z d)) (list 'R (list 'B a x b) y (list 'B c z d))
|
||||
('B a x ('R b y ('R c z d))) (list 'R (list 'B a x b) y (list 'B c z d))
|
||||
; figure 8, double black cases
|
||||
('BB ('R a x ('R b y c)) z d) (list 'B (list 'B a x b) y (list 'B c z d))
|
||||
('BB a x ('R ('R b y c) z d)) (list 'B (list 'B a x b) y (list 'B c z d))
|
||||
; already balenced
|
||||
t t)))
|
||||
|
||||
!(let1 map-insert !(let1 ins (rlambda ins (t k v) (match t
|
||||
(unquote E) (list 'R t (list k v) t)
|
||||
(c a x b) !(if (< k (car x)) (balance (list c (ins a k v) x b)))
|
||||
!(if (= k (car x)) (list c a (list k v) b))
|
||||
(balance (list c a x (ins b k v))))))
|
||||
(lambda (t k v) (blacken (ins t k v))))
|
||||
|
||||
!(let1 map-empty empty)
|
||||
|
||||
!(let1 make-test-tree (rlambda make-test-tree (n t) (if (<= n 0) t
|
||||
(make-test-tree (- n 1) (map-insert t n (= 0 (% n 10)))))))
|
||||
!(let1 reduce-test-tree (lambda (tree) (generic-foldl (lambda (a x) (if (car (cdr x)) (+ a 1) a)) 0 tree)))
|
||||
", *MATCH)
|
||||
});
|
||||
#[test]
|
||||
fn rbtree_eval_test() { let g = grammar::TermParser::new(); let e = root_env();
|
||||
eval_test(false, &g, &e, &format!("{} (reduce-test-tree (make-test-tree 10 map-empty))", *RBTREE), 1);
|
||||
//eval_test(false, &g, &e, &format!("{} (reduce-test-tree (make-test-tree 20 map-empty))", *RBTREE), 2);
|
||||
}
|
||||
535
partial_eval.scm
535
partial_eval.scm
@@ -265,7 +265,6 @@
|
||||
(.comb_params (lambda (x) (idx x 7)))
|
||||
(.comb_body (lambda (x) (idx x 8)))
|
||||
(.comb_wrap_level (lambda (x) (idx x 2)))
|
||||
(.comb_rec_hashes (lambda (x) (idx x 9)))
|
||||
|
||||
(.prim_comb_sym (lambda (x) (idx x 3)))
|
||||
(.prim_comb_handler (lambda (x) (idx x 2)))
|
||||
@@ -276,7 +275,7 @@
|
||||
(.marked_env (lambda (x) (slice x 2 -1)))
|
||||
(.marked_env_has_vals (lambda (x) (idx x 2)))
|
||||
(.marked_env_needed_for_progress (lambda (x) (idx x 3)))
|
||||
(.marked_env_idx (lambda (x) (idx x 4)))
|
||||
(.marked_env_id (lambda (x) (idx x 4)))
|
||||
(.marked_env_upper (lambda (x) (idx (idx x 5) -1)))
|
||||
(.env_marked (lambda (x) (idx x 5)))
|
||||
(marked_env_real? (lambda (x) (= nil (idx (.marked_env_needed_for_progress x) 0))))
|
||||
@@ -431,22 +430,16 @@
|
||||
|
||||
|
||||
(marked_val (lambda (x) (array 'val (hash_val x) x)))
|
||||
(marked_comb (lambda (wrap_level env_id de? se variadic params body rec_hash) (array 'comb (hash_comb wrap_level env_id de? se variadic params body) wrap_level env_id de? se variadic params body rec_hash)))
|
||||
(marked_comb (lambda (wrap_level env_id de? se variadic params body) (array 'comb (hash_comb wrap_level env_id de? se variadic params body) wrap_level env_id de? se variadic params body)))
|
||||
(comb_w_body (dlambda ((_comb _hash wrap_level env_id de? se variadic params _body) new_body) (marked_comb wrap_level env_id de? se variadic params new_body)))
|
||||
(marked_prim_comb (lambda (handler_fun real_or_name wrap_level val_head_ok) (array 'prim_comb (hash_prim_comb handler_fun real_or_name wrap_level val_head_ok) handler_fun real_or_name wrap_level val_head_ok)))
|
||||
|
||||
(with_wrap_level (lambda (x new_wrap) (cond ((prim_comb? x) (dlet (((handler_fun real_or_name wrap_level val_head_ok) (.prim_comb x)))
|
||||
(marked_prim_comb handler_fun real_or_name new_wrap val_head_ok)))
|
||||
((comb? x) (dlet (((wrap_level env_id de? se variadic params body rec_hash) (.comb x)))
|
||||
(marked_comb new_wrap env_id de? se variadic params body rec_hash)))
|
||||
((comb? x) (dlet (((wrap_level env_id de? se variadic params body) (.comb x)))
|
||||
(marked_comb new_wrap env_id de? se variadic params body)))
|
||||
(true (error "bad with_wrap_level")))))
|
||||
|
||||
(add_hash_if_comb (lambda (new_hash x) (cond ((comb? x) (dlet (
|
||||
((wrap_level env_id de? se variadic params body rec_hash) (.comb x))
|
||||
) (marked_comb wrap_level env_id de? se variadic params body (cons (array new_hash wrap_level) rec_hash))))
|
||||
(true x))))
|
||||
|
||||
|
||||
|
||||
|
||||
(later_head? (rec-lambda recurse (x) (or (and (marked_array? x) (or (= false (.marked_array_is_val x)) (foldl (lambda (a x) (or a (recurse x))) false (.marked_array_values x))))
|
||||
(and (marked_symbol? x) (= false (.marked_symbol_is_val x)))
|
||||
@@ -496,13 +489,13 @@
|
||||
(array (true_str "<a" (.marked_array_is_attempted x) ",r" (needed_for_progress x) "~" (.marked_array_this_rec_stop x) "~*" (.hash x) "*>" stripped_values) done_envs))))
|
||||
((marked_symbol? x) (mif (.marked_symbol_is_val x) (array (true_str "'" (.marked_symbol_value x)) done_envs)
|
||||
(array (true_str (.marked_symbol_needed_for_progress x) "#" (.marked_symbol_value x)) done_envs)))
|
||||
((comb? x) (dlet (((wrap_level env_id de? se variadic params body rec_hash) (.comb x))
|
||||
((comb? x) (dlet (((wrap_level env_id de? se variadic params body) (.comb x))
|
||||
((se_s done_envs) (recurse se done_envs))
|
||||
((body_s done_envs) (recurse body done_envs)))
|
||||
(array (true_str "<n " (needed_for_progress x) " (comb " wrap_level " " env_id " " rec_hash " " se_s " " de? " " params " " body_s ")>") done_envs)))
|
||||
(array (true_str "<n " (needed_for_progress x) " (comb " wrap_level " " env_id " " se_s " " de? " " params " " body_s ")>") done_envs)))
|
||||
((prim_comb? x) (array (true_str "<wl=" (.prim_comb_wrap_level x) " " (.prim_comb_sym x) ">") done_envs))
|
||||
((marked_env? x) (dlet ((e (.env_marked x))
|
||||
(index (.marked_env_idx x))
|
||||
(index (.marked_env_id x))
|
||||
(u (idx e -1))
|
||||
(already (in_array index done_envs))
|
||||
(opening (true_str "{" (mif (marked_env_real? x) "real" "fake") (mif (.marked_env_has_vals x) " real vals" " fake vals") " ENV idx: " (true_str index) ", "))
|
||||
@@ -597,14 +590,14 @@
|
||||
((prim_comb? x) (array memo false))
|
||||
((val? x) (array memo false))
|
||||
((comb? x) (dlet (
|
||||
((wrap_level i_env_id de? se variadic params body rec_hash) (.comb x))
|
||||
((wrap_level i_env_id de? se variadic params body) (.comb x))
|
||||
((memo in_se) (check_for_env_id_in_result memo s_env_id se))
|
||||
((memo total) (if (and (not in_se) (!= s_env_id i_env_id)) (check_for_env_id_in_result memo s_env_id body)
|
||||
(array memo in_se)))
|
||||
;(memo (put memo hash total))
|
||||
) (array memo total)))
|
||||
|
||||
((marked_env? x) (if (and (not (marked_env_real? x)) (= s_env_id (.marked_env_idx x))) (array memo true)
|
||||
((marked_env? x) (if (and (not (marked_env_real? x)) (= s_env_id (.marked_env_id x))) (array memo true)
|
||||
(dlet (
|
||||
(values (slice (.env_marked x) 0 -2))
|
||||
(upper (idx (.env_marked x) -1))
|
||||
@@ -682,19 +675,18 @@
|
||||
))
|
||||
|
||||
(drop_redundent_veval (rec-lambda drop_redundent_veval (partial_eval_helper x de env_stack pectx indent) (dlet (
|
||||
(env_id (.marked_env_idx de))
|
||||
(env_id (.marked_env_id de))
|
||||
(r (if
|
||||
(and (marked_array? x)
|
||||
(not (.marked_array_is_val x)))
|
||||
(and (marked_array? x) (not (.marked_array_is_val x)))
|
||||
(if (and (prim_comb? (idx (.marked_array_values x) 0))
|
||||
(= 'veval (.prim_comb_sym (idx (.marked_array_values x) 0)))
|
||||
(= 3 (len (.marked_array_values x)))
|
||||
(not (marked_env_real? (idx (.marked_array_values x) 2)))
|
||||
(= env_id (.marked_env_idx (idx (.marked_array_values x) 2)))) (drop_redundent_veval partial_eval_helper (idx (.marked_array_values x) 1) de env_stack pectx (+ 1 indent))
|
||||
(= env_id (.marked_env_id (idx (.marked_array_values x) 2)))) (drop_redundent_veval partial_eval_helper (idx (.marked_array_values x) 1) de env_stack pectx (+ 1 indent))
|
||||
; wait, can it do this? will this mess with eval?
|
||||
|
||||
; basically making sure that this comb's params are still good to eval
|
||||
(if (and (or (prim_comb? (idx (.marked_array_values x) 0)) (comb? (idx (.marked_array_values x) 0)))
|
||||
; basically making sure that this comb's params are still good to eval
|
||||
(if (and (or (prim_comb? (idx (.marked_array_values x) 0)) (comb? (idx (.marked_array_values x) 0)))
|
||||
(!= -1 (.any_comb_wrap_level (idx (.marked_array_values x) 0))))
|
||||
(dlet (((pectx err ress changed) (foldl (dlambda ((c er ds changed) p) (dlet (
|
||||
(pre_hash (.hash p))
|
||||
@@ -729,10 +721,10 @@
|
||||
)
|
||||
(if (or force hashes_now (= for_progress true) (intset_intersection_nonempty for_progress (idx env_stack 0)))
|
||||
(cond ((val? x) (array pectx nil x))
|
||||
((marked_env? x) (dlet ((dbi (.marked_env_idx x)))
|
||||
((marked_env? x) (dlet ((dbi (.marked_env_id x)))
|
||||
; compiler calls with empty env stack
|
||||
(mif dbi (dlet ( (new_env ((rec-lambda rec (i len_env_stack) (cond ((= i len_env_stack) nil)
|
||||
((= dbi (.marked_env_idx (idx (idx env_stack 1) i))) (idx (idx env_stack 1) i))
|
||||
((= dbi (.marked_env_id (idx (idx env_stack 1) i))) (idx (idx env_stack 1) i))
|
||||
(true (rec (+ i 1) len_env_stack))))
|
||||
0 (len (idx env_stack 1))))
|
||||
(_ (println (str_strip "replacing " x) (str_strip " with (if nonnil) " new_env)))
|
||||
@@ -740,12 +732,12 @@
|
||||
(array pectx nil (if (!= nil new_env) new_env x)))
|
||||
(array pectx nil x))))
|
||||
|
||||
((comb? x) (dlet (((wrap_level env_id de? se variadic params body rec_hash) (.comb x)))
|
||||
((comb? x) (dlet (((wrap_level env_id de? se variadic params body) (.comb x)))
|
||||
(mif (or (and (not (marked_env_real? env)) (not (marked_env_real? se))) ; both aren't real, re-evaluation of creation site
|
||||
(and (marked_env_real? env) (not (marked_env_real? se)))) ; new env real, but se isn't - creation!
|
||||
(dlet ((inner_env (make_tmp_inner_env params de? env env_id))
|
||||
((pectx err evaled_body) (partial_eval_helper body false inner_env (array (idx env_stack 0) (cons inner_env (idx env_stack 1))) pectx (+ indent 1) false)))
|
||||
(array pectx err (mif err nil (marked_comb wrap_level env_id de? env variadic params evaled_body rec_hash))))
|
||||
(array pectx err (mif err nil (marked_comb wrap_level env_id de? env variadic params evaled_body))))
|
||||
(array pectx nil x))))
|
||||
((prim_comb? x) (array pectx nil x))
|
||||
((marked_symbol? x) (mif (.marked_symbol_is_val x) x
|
||||
@@ -775,7 +767,7 @@
|
||||
; (array pectx err comb)))
|
||||
(_ (println (indent_str indent) "Going to do an array call!"))
|
||||
(indent (+ 1 indent))
|
||||
(_ (print_strip (indent_str indent) "total (in env " (.marked_env_idx env) ") is (proceeding err " err ") " x))
|
||||
(_ (print_strip (indent_str indent) "total (in env " (.marked_env_id env) ") is (proceeding err " err ") " x))
|
||||
(map_rp_eval (lambda (pectx ps) (foldl (dlambda ((c er ds) p) (dlet ((_ (print_strip (indent_str indent) "rp_evaling " p)) ((c e d) (partial_eval_helper p false env env_stack c (+ 1 indent) false)) (_ (print_strip (indent_str indent) "result of rp_eval was err " e " and value " d))) (array c (mif er er e) (concat ds (array d)))))
|
||||
(array pectx nil (array))
|
||||
ps)))
|
||||
@@ -817,7 +809,7 @@
|
||||
) (if (= 'LATER err) (array pectx nil (l_later_call_array))
|
||||
(array pectx err result))))
|
||||
((comb? comb) (dlet (
|
||||
((wrap_level env_id de? se variadic params body rec_hash) (.comb comb))
|
||||
((wrap_level env_id de? se variadic params body) (.comb comb))
|
||||
|
||||
|
||||
(final_params (mif variadic (concat (slice evaled_params 0 (- (len params) 1))
|
||||
@@ -844,16 +836,16 @@
|
||||
(pectx (array env_counter memo))
|
||||
) (array pectx func_err func_result false))))
|
||||
|
||||
(_ (print_strip (indent_str indent) "evaled result of function call (in env " (.marked_env_idx env) ", with inner " env_id ") and err " func_err " is " func_result))
|
||||
(_ (print_strip (indent_str indent) "evaled result of function call (in env " (.marked_env_id env) ", with inner " env_id ") and err " func_err " is " func_result))
|
||||
(must_stop_maybe_id (and (= nil func_err)
|
||||
(or rec_stop (if (not (combiner_return_ok func_result env_id))
|
||||
(if (!= nil de?) (.marked_env_idx env) true)
|
||||
(if (!= nil de?) (.marked_env_id env) true)
|
||||
false))))
|
||||
) (if (!= nil func_err) (array pectx func_err nil)
|
||||
(if must_stop_maybe_id
|
||||
(array pectx nil (marked_array false must_stop_maybe_id (if rec_stop (array hash) nil) (cons (with_wrap_level comb remaining_wrap) evaled_params) (.marked_array_source x)))
|
||||
(dlet (((pectx err x) (drop_redundent_veval partial_eval_helper func_result env env_stack pectx indent)))
|
||||
(array pectx err (add_hash_if_comb hash x)))))))
|
||||
(array pectx err x))))))
|
||||
)))
|
||||
)))))
|
||||
|
||||
@@ -887,13 +879,13 @@
|
||||
((!= nil err) (begin (print (indent_str indent) "got err " err) (array pectx err nil)))
|
||||
; If our env was implicit, then our unval'd code can be inlined directly in our caller
|
||||
(implicit_env (drop_redundent_veval partial_eval_helper ebody de env_stack pectx indent))
|
||||
((combiner_return_ok ebody (.marked_env_idx eval_env)) (drop_redundent_veval partial_eval_helper ebody de env_stack pectx indent))
|
||||
((combiner_return_ok ebody (.marked_env_id eval_env)) (drop_redundent_veval partial_eval_helper ebody de env_stack pectx indent))
|
||||
(true (drop_redundent_veval partial_eval_helper (marked_array false true nil (array (marked_prim_comb recurse 'veval -1 true) ebody eval_env) nil) de env_stack pectx indent))
|
||||
))))
|
||||
|
||||
(env_id_start 1)
|
||||
(empty_env (marked_env true nil nil nil nil nil))
|
||||
(quote_internal (marked_comb 0 env_id_start nil empty_env false (array 'x) (marked_symbol env_id_start 'x) nil))
|
||||
(quote_internal (marked_comb 0 env_id_start nil empty_env false (array 'x) (marked_symbol env_id_start 'x)))
|
||||
(env_id_start (+ 1 env_id_start))
|
||||
|
||||
(root_marked_env (marked_env true nil nil nil nil (array
|
||||
@@ -951,7 +943,7 @@
|
||||
(cons inner_env (idx env_stack 1))) pectx (+ 1 indent) false))
|
||||
(_ (print_strip (indent_str indent) "in vau, result of evaluating body was " pe_body))
|
||||
) (array pectx err pe_body))))
|
||||
) (mif err (array pectx err nil) (array pectx nil (marked_comb 0 new_id de? de variadic vau_params pe_body nil)))
|
||||
) (mif err (array pectx err nil) (array pectx nil (marked_comb 0 new_id de? de variadic vau_params pe_body)))
|
||||
)) 'vau 0 true))
|
||||
|
||||
(array 'wrap (marked_prim_comb (dlambda (only_head de env_stack pectx (evaled) indent)
|
||||
@@ -983,7 +975,7 @@
|
||||
(this (marked_array false true nil (concat (array (marked_prim_comb (recurse false) 'cond 0 true)
|
||||
pred)
|
||||
sliced_params) nil))
|
||||
(hash (combine_hash (combine_hash 101 (.hash this)) (+ 103 (.marked_env_idx de))))
|
||||
(hash (combine_hash (combine_hash 101 (.hash this)) (+ 103 (.marked_env_id de))))
|
||||
((env_counter memo) pectx)
|
||||
(already_in (!= false (get-value-or-false memo hash)))
|
||||
(_ (if already_in (print_strip "ALREADY IN " this)
|
||||
@@ -1262,9 +1254,9 @@
|
||||
|
||||
(encode_function_section (lambda (x)
|
||||
(dlet ( ; nil functions are placeholders for improted functions
|
||||
;(_ (println "encoding function section " x))
|
||||
;(_ (true_print "encoding function section " x))
|
||||
(filtered (filter (lambda (i) (!= nil i)) x))
|
||||
;(_ (println "post filtered " filtered))
|
||||
;(_ (true_print "post filtered " filtered))
|
||||
(encoded (encode_vector encode_LEB128 filtered))
|
||||
) (concat (array #x03) (encode_LEB128 (len encoded)) encoded ))
|
||||
))
|
||||
@@ -1716,6 +1708,18 @@
|
||||
; <env____ptr32>|<func_idx26><usesde1><wrap1>y101 - both env-carrying values 1 bit different
|
||||
; <env____ptr32><28 0s> y001
|
||||
|
||||
; NOTE / TODO:
|
||||
; reduce sizes to 16 bits w/ saturation & include true size field/calculation in object header
|
||||
; to allow for 44 bit pointers for wasm64 (48 that could be used + minimum alignment of 16)
|
||||
; Biggest loser is func_idx which would become 14 bits, but can perhaps borrow from env pointer if we further align envs
|
||||
; currently aligning to 32 bytes, which is 8 word boundries or 4 kraken values (which I think is exactly what env requires, actually)
|
||||
; which allows pretty long strings or envs or arrays with 3 values
|
||||
; so that's 5 unused bits, to actually only require 43 bit pointers right now, I think
|
||||
; Honestly, going to 40 bits is 1024GB of RAM, -5 is 35 bits. If we allow a non-standard encoding for env-funcs, then
|
||||
; it leaves 23 bits for a function id, which is 8_388_608 possible functions, which isn't really terrible.
|
||||
; We could do this only for env-funcs, or actually for anything depending on the extra slow down vs the extra non-saturating size
|
||||
; Note that this does add an extra mask instruction for *everything* since the pointers aren't full width anymore
|
||||
|
||||
(to_hex_digit (lambda (x) (string (integer->char (if (< x 10) (+ x #x30)
|
||||
(+ x #x37))))))
|
||||
(le_hexify_helper (rec-lambda recurse (x i) (if (= i 0) ""
|
||||
@@ -1823,7 +1827,7 @@
|
||||
(nil_val array_tag) ; automatically 0 ptr, 0 size, 0 ref-counted
|
||||
(emptystr_val string_tag); ^ ditto
|
||||
|
||||
(compile (dlambda ((pectx partial_eval_err marked_code) needs_runtime_eval
|
||||
(compile (dlambda ((pectx partial_eval_err marked_code) dont_partial_eval
|
||||
dont_lazy_env
|
||||
dont_y_comb
|
||||
dont_prim_inline
|
||||
@@ -1858,6 +1862,13 @@
|
||||
(global '$num_sbrks '(mut i32) (i32.const 0))
|
||||
(global '$num_frees '(mut i32) (i32.const 0))
|
||||
|
||||
(global '$num_evals '(mut i32) (i32.const 0))
|
||||
(global '$num_all_evals '(mut i32) (i32.const 0))
|
||||
(global '$num_interp_dzero '(mut i32) (i32.const 0))
|
||||
(global '$num_interp_done '(mut i32) (i32.const 0))
|
||||
(global '$num_compiled_dzero '(mut i32) (i32.const 0))
|
||||
(global '$num_compiled_done '(mut i32) (i32.const 0))
|
||||
|
||||
(global '$num_array_innerdrops '(mut i32) (i32.const 0))
|
||||
(global '$num_env_innerdrops '(mut i32) (i32.const 0))
|
||||
(global '$num_array_subdrops '(mut i32) (i32.const 0))
|
||||
@@ -1903,6 +1914,7 @@
|
||||
|
||||
(_ (true_print "made true/false"))
|
||||
|
||||
((datasi memo bad_source_code_msg_val) (compile-string-val datasi memo "\nError: bad source code compile hit\n"))
|
||||
((datasi memo bad_params_number_msg_val) (compile-string-val datasi memo "\nError: passed a bad number of parameters\n"))
|
||||
((datasi memo bad_params_type_msg_val) (compile-string-val datasi memo "\nError: passed a bad type of parameters\n"))
|
||||
((datasi memo dropping_msg_val) (compile-string-val datasi memo "dropping "))
|
||||
@@ -4020,6 +4032,7 @@
|
||||
((k_eval_helper func_idx funcs) (array func_idx (+ 1 func_idx) (concat funcs (func '$eval_helper '(param $it i64) '(param $env i64) '(result i64) '(local $len i32) '(local $ptr i32) '(local $current_env i64) '(local $res i64) '(local $env_ptr i32) '(local $tmp_ptr i32) '(local $i i32) '(local $comb i64) '(local $params i64) '(local $wrap i32) '(local $tmp i64) '(local $rc_bytes i64) '(local $rc_ptr i32) '(local $rc_tmp i32)
|
||||
|
||||
|
||||
(global.set '$num_all_evals (i32.add (i32.const 1) (global.get '$num_all_evals)))
|
||||
; The cool thing about Vau calculus / Kernel / Kraken
|
||||
; is that everything is a value that evaluates to itself except symbols
|
||||
; and arrays.
|
||||
@@ -4103,6 +4116,17 @@
|
||||
)
|
||||
(local.set '$wrap (i32.wrap_i64 (extract_wrap_code (local.get '$comb))))
|
||||
(local.set '$params (call '$slice_impl (generate_dup (local.get '$it)) (i32.const 1) (local.get '$len)))
|
||||
|
||||
; Pure benchmarking
|
||||
(_if '$is_wrap_one
|
||||
(i32.eq (i32.const 1) (local.get '$wrap))
|
||||
(then (global.set '$num_interp_done (i32.add (i32.const 1) (global.get '$num_interp_done))))
|
||||
(else
|
||||
(_if '$is_wrap_zero
|
||||
(i32.eqz (local.get '$wrap))
|
||||
(then (global.set '$num_interp_dzero (i32.add (i32.const 1) (global.get '$num_interp_dzero))))
|
||||
(else (unreachable)))))
|
||||
|
||||
; we'll reuse len and ptr now for params
|
||||
(local.set '$len (extract_size_code (local.get '$params)))
|
||||
(local.set '$ptr (extract_ptr_code (local.get '$params)))
|
||||
@@ -4160,6 +4184,7 @@
|
||||
((k_eval func_idx funcs) (array func_idx (+ 1 func_idx) (concat funcs (func '$eval '(param $p i64) '(param $d i64) '(param $s i64) '(result i64) '(local $len i32) '(local $ptr i32) '(local $rc_bytes i64) '(local $rc_ptr i32) '(local $rc_tmp i32)
|
||||
|
||||
(ensure_not_op_n_params_set_ptr_len i32.lt_u 1)
|
||||
(global.set '$num_evals (i32.add (i32.const 1) (global.get '$num_evals)))
|
||||
(_if '$using_d_env '(result i64)
|
||||
(i32.eq (i32.const 1) (local.get '$len))
|
||||
(then
|
||||
@@ -4592,11 +4617,6 @@
|
||||
(if r (array r nil nil (array datasi funcs memo env pectx inline_locals)) #f))))
|
||||
|
||||
|
||||
(let_like_inline_closure (lambda (func_value containing_env_idx) (and (comb? func_value)
|
||||
(not (.comb_varadic func_value))
|
||||
(= containing_env_idx (.marked_env_idx (.comb_env func_value)))
|
||||
(= nil (.comb_des func_value)))))
|
||||
|
||||
; This is the second run at this, and is a little interesting
|
||||
; It can return a value OR code OR an error string. An error string should be propegated,
|
||||
; unless it was expected as a possiblity, which can happen when compling a call that may or
|
||||
@@ -4606,6 +4626,96 @@
|
||||
; ctx is (datasi funcs memo env pectx inline_locals)
|
||||
; return is (value? code? error? (datasi funcs memo env pectx inline_locals))
|
||||
|
||||
(let_like_inline_closure (lambda (func_value containing_env_idx) (and (comb? func_value)
|
||||
(not (.comb_varadic func_value))
|
||||
(= containing_env_idx (.marked_env_id (.comb_env func_value)))
|
||||
(= nil (.comb_des func_value)))))
|
||||
(is_prim_function_call (lambda (c s) (and (marked_array? c) (not (.marked_array_is_val c)) (<= 2 (len (.marked_array_values c)))
|
||||
(prim_comb? (idx (.marked_array_values c) 0)) (= s (.prim_comb_sym (idx (.marked_array_values c) 0))))))
|
||||
|
||||
; Ok, we're pulling out the call stuff out of compile
|
||||
; Wrapped vs unwrapped
|
||||
; Y combinator elimination
|
||||
; Eta reduction?
|
||||
; tail call elimination
|
||||
; dynamic call unval-partial-eval branch
|
||||
;
|
||||
; Rembember to account for (dont_compile dont_lazy_env dont_y_comb dont_prim_inline dont_closure_inline)
|
||||
|
||||
; (<this_data>... <sub_data>)
|
||||
|
||||
; call-info will be a fairly simple pre-order traversal (looking at caller before params)
|
||||
; infer-type has to walk though cond in pairs, special handle the (and ) case, and adjust parameters for veval
|
||||
; perceus is weird, as it has to look at the head to determine how to order/combine the children, as well as an extra sub-data for the call itself (though I guess this is just part of the node data)
|
||||
|
||||
; Starting with only dynamic call unval
|
||||
; TODO: tce-data
|
||||
|
||||
(call-info (rec-lambda call-info (c env pectx) (cond
|
||||
((val? c) (array nil nil pectx))
|
||||
((and (marked_symbol? c) (.marked_symbol_is_val c)) (array nil nil pectx))
|
||||
((marked_symbol? c) (array nil nil pectx))
|
||||
((marked_env? c) (array nil nil pectx))
|
||||
((prim_comb? c) (array nil nil pectx))
|
||||
((and (marked_array? c) (.marked_array_is_val c)) (array nil nil pectx))
|
||||
((comb? c) (array nil nil pectx))
|
||||
|
||||
((and (marked_array? c) (let_like_inline_closure (idx (.marked_array_values c) 0) (.marked_env_id env))) (dlet (
|
||||
(func_param_values (.marked_array_values c))
|
||||
(func (idx func_param_values 0))
|
||||
; TODO: pull errors out of here
|
||||
;(param_data (map (lambda (x) (call-info x env)) (slice func_param_values 1 -1)))
|
||||
; TODO: pull errors out of here
|
||||
; mk tmp env
|
||||
;(body_data (call-info (.comb_body func tmp_env)))
|
||||
) (array nil nil pectx))) ;(array nil (cons body_data param_data))))
|
||||
|
||||
((is_prim_function_call c 'veval) (dlet (
|
||||
(func_param_values (.marked_array_values c))
|
||||
(num_params (- (len func_param_values) 1))
|
||||
(params (slice func_param_values 1 -1))
|
||||
; These can't be fatal either
|
||||
;(_ (if (!= 2 num_params) (error "call to veval has != 2 params!")))
|
||||
;(_ (if (not (marked_env? (idx params 1))) (error "call to veval has not marked_env second param")))
|
||||
|
||||
; TODO: pull errors out of here
|
||||
;(sub_data (array nil (call-info (idx params 0) (idx params 1)) nil))
|
||||
) (array nil nil pectx))) ;(array nil sub_data)))
|
||||
|
||||
(true (dlet (
|
||||
; obv need to handle possible dynamic calls with an additional unval side, but also be careful of infinite recursion (as we had happen on compile before)
|
||||
; due to the interaction of partial eval and unval (previously in compile) here
|
||||
; might need to check for (is_prim_function_call c 'vcond) for recursion?
|
||||
|
||||
; the basic check is is this dynamic or not, and if so (and thus we don't know the wrap level)
|
||||
; we need to
|
||||
; if not dynamic, just recurse as normal
|
||||
; assert wrap-level == 0 or == -1
|
||||
|
||||
(func_param_values (.marked_array_values c))
|
||||
(func (idx func_param_values 0))
|
||||
; ; TODO: pull errors out of here
|
||||
; (sub_data (map (lambda (x) (call-info x env)) func_param_values))
|
||||
; ; TODO: pull errors out of here
|
||||
; (our_data (cond ((and (comb? func) ( = (.comb_wrap_level func) 0)) nil)
|
||||
; ((and (comb? func) (!= (.comb_wrap_level func) 1)) (error "bad wrap level call-info")) ; this is a tad tricky - I wanted to just have error here, but
|
||||
; ; *concievably this is the result of wrongly evaluted code based on this
|
||||
; ; very method of prediction. Instead, we need to error here,
|
||||
; ; and have that count as erroing out of the compile.
|
||||
; ; How best should we do that, I wonder?
|
||||
; ((prim_comb? func) nil)
|
||||
; (true (dlet (
|
||||
; ((ok x) (try_unval x (lambda (_) nil)))
|
||||
; (err (if (not ok) "couldn't unval in compile" err))
|
||||
; ((pectx e pex) (mif err (array pectx err nil))
|
||||
; ; x only_head env env_stack pectx indent force
|
||||
; (partial_eval_helper x false env (array nil nil) pectx 1 false))))
|
||||
; ) nil)
|
||||
; ))
|
||||
;) (array our_data sub_data))
|
||||
) (array nil nil pectx))) ;(array nil sub_data)))
|
||||
)))
|
||||
|
||||
; type is a bit generic, both the runtime types + length of arrays
|
||||
;
|
||||
; (array <symbol_identifier> maybe_rc <length or false for arrays/strings>)
|
||||
@@ -4631,8 +4741,6 @@
|
||||
(get-list-or (lambda (d k o) (dlet ((x (get-list d k)))
|
||||
(mif x (idx x 1)
|
||||
o))))
|
||||
(is_prim_function_call (lambda (c s) (and (marked_array? c) (not (.marked_array_is_val c)) (<= 2 (len (.marked_array_values c)))
|
||||
(prim_comb? (idx (.marked_array_values c) 0)) (= s (.prim_comb_sym (idx (.marked_array_values c) 0))))))
|
||||
(is_markable (lambda (x) (or (and (marked_symbol? x) (not (.marked_symbol_is_val x)))
|
||||
(and (marked_array? x) (not (.marked_array_is_val x)))
|
||||
)))
|
||||
@@ -4785,11 +4893,10 @@
|
||||
(_ (if (!= 2 num_params) (error "call to veval has != 2 params!")))
|
||||
(_ (if (not (marked_env? (idx params 1))) (error "call to veval has not marked_env second param")))
|
||||
|
||||
(new_env_id (.marked_env_idx (idx params 1)))
|
||||
((btyp bimpl b_assertion b_subdata) (infer_types (idx params 0) new_env_id empty_dict-list empty_dict-list))
|
||||
(new_env_id (.marked_env_id (idx params 1)))
|
||||
|
||||
(sub_data (array (infer_types func env_id implies guarentees)
|
||||
(array btyp bimpl b_assertion b_subdata)
|
||||
(infer_types (idx params 0) new_env_id empty_dict-list empty_dict-list)
|
||||
(infer_types (idx params 1) env_id implies guarentees)))
|
||||
) (array btyp false empty_dict-list sub_data)))
|
||||
|
||||
@@ -4799,6 +4906,7 @@
|
||||
;(_ (true_print " doing infer-types for random call "))
|
||||
(sub_results (map (lambda (x) (infer_types x env_id implies guarentees)) (.marked_array_values c)))
|
||||
;(_ (true_print " done infer-types for random call "))
|
||||
; I belive this .hash doesn't do anything
|
||||
) (array (get-list-or guarentees (.hash c) false) false empty_dict-list sub_results)))
|
||||
|
||||
; fallthrough
|
||||
@@ -4893,7 +5001,7 @@
|
||||
(_ (if (!= 2 num_params) (error "call to veval has != 2 params!")))
|
||||
(_ (if (not (marked_env? (idx params 1))) (error "call to veval has not marked_env second param")))
|
||||
|
||||
(new_env_id (.marked_env_idx (idx params 1)))
|
||||
(new_env_id (.marked_env_id (idx params 1)))
|
||||
(body_data (pseudo_perceus (idx params 0) new_env_id knot_memo empty_use_map))
|
||||
((used_map_pre_env env_sub_data) (pseudo_perceus (idx params 1) env_id knot_memo used_map_after))
|
||||
|
||||
@@ -4934,6 +5042,7 @@
|
||||
; YES remember to check for Y-combiner recursion knot tying - (and (!= nil (.marked_array_this_rec_stop c)) (get_passthrough (idx (.marked_array_this_rec_stop c) 0) ctx))
|
||||
; YES remember to check for let-like inlining (and (marked_array? c) (let_like_inline_closure (idx (.marked_array_values c) 0) env_id))
|
||||
; YES remember to properly handle crazy stuff like inlining inside of veval (does that mean we have to re-pick up inside veval after all?)
|
||||
; TODO: properly handle param usage based on wrap level if unknown (based on call-info)
|
||||
; remember to think (/modify appropriately) about TCE - I think it's fine to have it act like a normal call?
|
||||
((and (marked_array? c) (not (.marked_array_is_val c))) (dlet (
|
||||
; check func first for val or not & if val if it uses de (comb that uses de, prim_comb that takes it)
|
||||
@@ -4994,7 +5103,7 @@
|
||||
((and (marked_array? c) (.marked_array_is_val c)) (array b borrow_nil))
|
||||
; no matter if env is real or not, it's borrowed,
|
||||
; as it will be cached for the length of the function
|
||||
((marked_env? c) (array b borrow_nil))
|
||||
((marked_env? c) (array b borrow_nil)) ; I feel like all of these value ones but esp this one should be true instead of b? must-be-borrowed
|
||||
((and (marked_symbol? c) (not (.marked_symbol_is_val c))) (array (and b (not (cached_pseudo_perceus_sym_borrowed used_map_sub_data))) borrow_nil))
|
||||
; comb value just does its env
|
||||
((comb? c) (borrow? (.comb_env c) b env_id used_map_sub_data))
|
||||
@@ -5026,7 +5135,7 @@
|
||||
(_ (if (!= 2 num_params) (error "call to veval has != 2 params!")))
|
||||
(_ (if (not (marked_env? (idx params 1))) (error "call to veval has not marked_env second param")))
|
||||
|
||||
(new_env_id (.marked_env_idx (idx params 1)))
|
||||
(new_env_id (.marked_env_id (idx params 1)))
|
||||
((body_borrowed body_sub_data) (borrow? (idx params 0) b new_env_id (pseudo_perceus_just_sub_idx used_map_sub_data 1)))
|
||||
((env_borrowed env_sub_data) (borrow? (idx params 1) true env_id (pseudo_perceus_just_sub_idx used_map_sub_data 2)))
|
||||
) (array body_borrowed (array borrow_nil (array body_borrowed body_sub_data) (array env_borrowed env_sub_data)))))
|
||||
@@ -5046,6 +5155,7 @@
|
||||
) (array borrowed sub_data)))
|
||||
|
||||
; call taxonomy a bit simpler this time - if it's not already special cased, it's either an inline or it's owned
|
||||
; This also has to be adjusted based on possibly dynamic calls with unknown wrap level
|
||||
((and (marked_array? c) (not (.marked_array_is_val c))) (dlet (
|
||||
(func_param_values (.marked_array_values c))
|
||||
(num_params (- (len func_param_values) 1))
|
||||
@@ -5072,14 +5182,39 @@
|
||||
;(_ (true_print "done borrow!"))
|
||||
) r)))
|
||||
|
||||
(function-analysis (lambda (c memo pectx) (dlet (
|
||||
|
||||
((wrap_level env_id de? se variadic params body) (.comb c))
|
||||
(full_params (concat params (mif de? (array de?) (array))))
|
||||
|
||||
(inner_env (make_tmp_inner_env params de? se env_id))
|
||||
|
||||
((call_info call_err pectx) (call-info body inner_env pectx))
|
||||
(analysis_err call_err)
|
||||
|
||||
(inner_type_data (infer_types body env_id empty_dict-list empty_dict-list))
|
||||
((used_map_before used_map_sub_data) (pseudo_perceus body env_id memo (push_used_map empty_use_map full_params)))
|
||||
((borrowed borrow_sub_data) (borrow? body false env_id used_map_sub_data))
|
||||
(_ (mif borrowed (error "body hast to be borrowed? " borrowed " " (true_str_strip body))))
|
||||
|
||||
(inner_analysis_data (array inner_type_data used_map_sub_data call_info))
|
||||
|
||||
) (array inner_analysis_data analysis_err pectx))))
|
||||
|
||||
(cached_analysis_idx (lambda (c env_id cache i) (dlet (
|
||||
;(_ (true_print "doing infer-types-idx for " (true_str_strip c)))
|
||||
;(_ (true_print "doing infer-types-idx i " i))
|
||||
;(_ (true_print "doing infer-types-idx with " cache))
|
||||
;(_ (true_print "doing infer-types-idx, cache is real? " (mif cache true false)))
|
||||
( r (cached_infer_types_idx c env_id (mif cache (idx cache 0) type_data_nil) i))
|
||||
(_ (true_print "doing infer-types-idx, cache is real? " (mif cache true false)))
|
||||
|
||||
( t (cached_infer_types_idx c env_id (mif cache (idx cache 0) type_data_nil) i))
|
||||
;( t (cached_infer_types_idx c env_id (idx cache 0) i))
|
||||
;( p (mif cache (pseudo_perceus_just_sub_idx (idx cache 1) i) nil))
|
||||
( p nil )
|
||||
( c nil )
|
||||
|
||||
;(_ (true_print "done infer-types-idx"))
|
||||
) (array r))))
|
||||
) (array t p c))))
|
||||
|
||||
|
||||
(compile-inner (rec-lambda compile-inner (ctx c need_value inside_veval outer_s_env_access_code s_env_access_code inline_level tce_data analysis_data) (cond
|
||||
@@ -5146,7 +5281,6 @@
|
||||
; shape in that case which will cause compile to keep stepping.
|
||||
|
||||
((datasi funcs memo env pectx inline_locals) ctx)
|
||||
(hit_recursion (= 'RECURSE_FAIL (get-value-or-false memo (.hash c))))
|
||||
|
||||
(func_param_values (.marked_array_values c))
|
||||
(num_params (- (len func_param_values) 1))
|
||||
@@ -5154,7 +5288,7 @@
|
||||
(func_value (idx func_param_values 0))
|
||||
(_ (true_print "about to get cached_infer_types_idx for call before checking for 'idx"))
|
||||
;(_ (true_print " cache is " type_data))
|
||||
(parameter_subs (map (lambda (i) (cached_analysis_idx c (.marked_env_idx env) analysis_data i)) (range 1 (len func_param_values))))
|
||||
(parameter_subs (map (lambda (i) (cached_analysis_idx c (.marked_env_id env) analysis_data i)) (range 1 (len func_param_values))))
|
||||
(parameter_types (map just_type parameter_subs))
|
||||
; used_data HERE
|
||||
|
||||
@@ -5164,6 +5298,8 @@
|
||||
(compile_params (lambda (unval_and_eval ctx cond_tce)
|
||||
(foldr (dlambda (x (a err ctx i)) (dlet (
|
||||
|
||||
;(_ (true_print "compile param with unval?" unval_and_eval " " (true_str_strip x)))
|
||||
|
||||
((datasi funcs memo env pectx inline_locals) ctx)
|
||||
((x err ctx) (mif err (array nil err ctx)
|
||||
(if (not unval_and_eval) (array x err ctx)
|
||||
@@ -5172,7 +5308,6 @@
|
||||
(err (if (not ok) "couldn't unval in compile" err))
|
||||
|
||||
((pectx e pex) (cond ((!= nil err) (array pectx err nil))
|
||||
(hit_recursion (array pectx "blockrecursion" nil))
|
||||
(true (partial_eval_helper x false env (array nil nil) pectx 1 false))))
|
||||
|
||||
(ctx (array datasi funcs memo env pectx inline_locals))
|
||||
@@ -5386,7 +5521,7 @@
|
||||
|
||||
|
||||
; User inline
|
||||
((and (not dont_closure_inline) (let_like_inline_closure func_value (.marked_env_idx env))) (dlet (
|
||||
((and (not dont_closure_inline) (let_like_inline_closure func_value (.marked_env_id env))) (dlet (
|
||||
; To inline, we add all of the parameters + inline_level + 1 to the current functions additional symbols
|
||||
; as well as a new se + inline_level + 1 symbol
|
||||
; fill them with the result of evaling the parameters now
|
||||
@@ -5477,7 +5612,9 @@
|
||||
|
||||
((source_code ctx) (mif (.marked_array_source c) (dlet (((code _ _ ctx) (compile-inner ctx (.marked_array_source c) true inside_veval outer_s_env_access_code s_env_access_code inline_level nil analysis_nil))
|
||||
) (array code ctx))
|
||||
(array k_cond_msg_val ctx)))
|
||||
(array bad_source_code_msg_val ctx)))
|
||||
(_ (mif (nil? source_code) (error "nil source codepost compile! pre was " (.marked_array_source c))))
|
||||
;((source_code ctx) (mif (nil? source_code) (array bad_source_code_msg_val ctx) (array source_code ctx)))
|
||||
((result_code ctx) (mif func_val
|
||||
(dlet (
|
||||
(unwrapped (extract_unwrapped func_val))
|
||||
@@ -5553,11 +5690,17 @@
|
||||
(local.tee '$tmp)
|
||||
(_if '$is_wrap_0
|
||||
(is_wrap_code 0 (local.get '$tmp))
|
||||
(then wrap_0_param_code)
|
||||
(then
|
||||
(global.set '$num_compiled_dzero (i32.add (i32.const 1) (global.get '$num_compiled_dzero)))
|
||||
wrap_0_param_code
|
||||
)
|
||||
(else
|
||||
(_if '$is_wrap_1
|
||||
(is_wrap_code 1 (local.get '$tmp))
|
||||
(then wrap_1_param_code)
|
||||
(then
|
||||
(global.set '$num_compiled_done (i32.add (i32.const 1) (global.get '$num_compiled_done)))
|
||||
wrap_1_param_code
|
||||
)
|
||||
(else wrap_x_param_code)
|
||||
)
|
||||
)
|
||||
@@ -5592,7 +5735,7 @@
|
||||
|
||||
(generate_env_access (dlambda ((datasi funcs memo env pectx inline_locals) env_id reason) ((rec-lambda recurse (code this_env)
|
||||
(cond
|
||||
((= env_id (.marked_env_idx this_env)) (array nil (generate_dup code) nil (array datasi funcs memo env pectx inline_locals)))
|
||||
((= env_id (.marked_env_id this_env)) (array nil (generate_dup code) nil (array datasi funcs memo env pectx inline_locals)))
|
||||
((= nil (.marked_env_upper this_env)) (array nil nil (str "bad env, upper is nil and we haven't found " env_id ", (this is *possiblely* because we're not recreating val/notval chains?) maxing out at " (str_strip this_env) ", having started at " (str_strip env) ", we're generating because " reason) (array datasi funcs memo env pectx)))
|
||||
(true (recurse (i64.load 16 (extract_ptr_code code)) (.marked_env_upper this_env)))
|
||||
)
|
||||
@@ -5600,7 +5743,7 @@
|
||||
|
||||
) (if (not (marked_env_real? c)) (begin (print_strip "env wasn't real: " (marked_env_real? c) ", so generating access (env was) " c)
|
||||
(if need_value (array nil nil (str "marked env not real, though we need_value: " (str_strip c)) ctx)
|
||||
(generate_env_access ctx (.marked_env_idx c) "it wasn't real: " (str_strip c))))
|
||||
(generate_env_access ctx (.marked_env_id c) "it wasn't real: " (str_strip c))))
|
||||
(dlet (
|
||||
;(_ (true_print "gonna compile kvs vvs"))
|
||||
|
||||
@@ -5617,11 +5760,11 @@
|
||||
((uv ucode err ctx) (mif (idx e -1) (compile-inner ctx (idx e -1) need_value inside_veval outer_s_env_access_code s_env_access_code inline_level nil analysis_nil)
|
||||
(array nil_val nil nil ctx)))
|
||||
) (mif (or (= false kvs) (= nil uv) (!= nil err))
|
||||
(begin (print_strip "kvs " kvs " vvs " vvs " uv " uv " or err " err " based off of " c)
|
||||
(begin (true_print "kvs " kvs " vvs " vvs " uv " uv " or err " err " based off of " (true_str_strip c))
|
||||
(error "I DON'T LIKE IT - IMPOSSIBLE?")
|
||||
(if need_value
|
||||
(array nil nil (str "had to generate env access (course " need_value ") for " (str_strip c) "vvs is " vvs " err was " err) ctx)
|
||||
(generate_env_access ctx (.marked_env_idx c) (str " vvs " vvs " uv " uv " or err " err " based off of " (str_strip c)))))
|
||||
(generate_env_access ctx (.marked_env_id c) (str " vvs " vvs " uv " uv " or err " err " based off of " (str_strip c)))))
|
||||
(dlet (
|
||||
((datasi funcs memo env pectx inline_locals) ctx)
|
||||
;(_ (true_print "about to kvs_array"))
|
||||
@@ -5692,9 +5835,22 @@
|
||||
|
||||
|
||||
((comb? c) (dlet (
|
||||
((wrap_level env_id de? se variadic params body rec_hashes) (.comb c))
|
||||
((wrap_level env_id de? se variadic params body) (.comb c))
|
||||
(_ (mif (> wrap_level 1) (error "wrap level TOO DARN HIGH")))
|
||||
|
||||
; note that this is just the hash of the func, not the env
|
||||
(old_hash (.hash c))
|
||||
(maybe_func (get_passthrough old_hash ctx))
|
||||
((datasi funcs memo env pectx inline_locals) ctx)
|
||||
((pectx err evaled_body) (mif (or maybe_func dont_partial_eval)
|
||||
(array pectx "don't pe" body)
|
||||
(dlet ((inner_env (make_tmp_inner_env params de? env env_id)))
|
||||
(partial_eval_helper body false inner_env (array nil (array inner_env)) pectx 1 false))))
|
||||
(body (mif err body evaled_body))
|
||||
(c (comb_w_body c body))
|
||||
(new_hash (.hash c))
|
||||
(ctx (array datasi funcs memo env pectx inline_locals))
|
||||
|
||||
; Let's look and see if we can eta-reduce!
|
||||
; This is done here during code gen (when you would expect it earlier, like as part of partial eval)
|
||||
; because we currently only "tie the knot" for Y combinator based recursion here
|
||||
@@ -5702,85 +5858,38 @@
|
||||
; and so we can only tell here weather or not it will be safe to remove the level of lazyness (because we get a func value back instead of code)
|
||||
; and perform the eta reduction.
|
||||
|
||||
(attempt_reduction (and
|
||||
(not dont_y_comb)
|
||||
variadic
|
||||
(= 1 (len params))
|
||||
(marked_array? body)
|
||||
(= 4 (len (.marked_array_values body)))
|
||||
(prim_comb? (idx (.marked_array_values body) 0))
|
||||
(= 'lapply (.prim_comb_sym (idx (.marked_array_values body) 0)))
|
||||
(marked_symbol? (idx (.marked_array_values body) 2))
|
||||
(not (.marked_symbol_is_val (idx (.marked_array_values body) 2)))
|
||||
(= (idx params 0) (.marked_symbol_value (idx (.marked_array_values body) 2)))
|
||||
(marked_symbol? (idx (.marked_array_values body) 3))
|
||||
(not (.marked_symbol_is_val (idx (.marked_array_values body) 3)))
|
||||
(= de? (.marked_symbol_value (idx (.marked_array_values body) 3)))
|
||||
))
|
||||
|
||||
(full_params (concat params (mif de? (array de?) (array))))
|
||||
(normal_params_length (if variadic (- (len params) 1) (len params)))
|
||||
(compile_body_part (lambda (ctx body_part new_tce_data) (dlet (
|
||||
(inner_env (make_tmp_inner_env params de? se env_id))
|
||||
|
||||
((params_vec _ _ ctx) (compile-inner ctx (marked_array true false nil (map (lambda (k) (marked_symbol nil k)) full_params) nil) true false outer_s_env_access_code s_env_access_code 0 nil analysis_nil))
|
||||
(basic_get_s_env_code (local.get '$s_env))
|
||||
(generate_get_s_env_code (local.tee '$s_env (call '$env_alloc (i64.const params_vec)
|
||||
|
||||
(local.set '$tmp_ptr (call '$malloc (i32.const (* 8 (len full_params)))))
|
||||
(flat_map (lambda (i) (i64.store (* i 8) (local.get '$tmp_ptr)
|
||||
(generate_dup (local.get (idx full_params i)))))
|
||||
(range 0 (len full_params)))
|
||||
(mk_array_code_rc_const_len (len full_params) (local.get '$tmp_ptr))
|
||||
|
||||
(generate_dup (local.get '$outer_s_env)))))
|
||||
(lazy_get_s_env_code (_if '$have_s_env '(result i64)
|
||||
(i64.ne (i64.const nil_val) (local.get '$s_env))
|
||||
(then basic_get_s_env_code)
|
||||
(else generate_get_s_env_code
|
||||
;(call '$print (i64.const params_vec))
|
||||
;(call '$print (i64.const newline_msg_val))
|
||||
;(local.set '$outer_s_env (i64.const nil_val))
|
||||
)))
|
||||
(new_get_s_env_code (if dont_lazy_env basic_get_s_env_code lazy_get_s_env_code))
|
||||
((datasi funcs memo env pectx inline_locals) ctx)
|
||||
(inner_ctx (array datasi funcs memo inner_env pectx inline_locals))
|
||||
(_ (true_print "Doing infer_types for body part for " full_params))
|
||||
(inner_type_data (infer_types body_part (.marked_env_idx inner_env) empty_dict-list empty_dict-list))
|
||||
(_ (true_print "done infer_types, Doing pseudo perceus " full_params))
|
||||
((used_map_before used_map_sub_data) (pseudo_perceus body_part (.marked_env_idx inner_env) memo (push_used_map empty_use_map full_params)))
|
||||
(_ (true_print "done pseudo_perceus, Doing borrow? " full_params))
|
||||
((borrowed borrow_sub_data) (borrow? body_part false (.marked_env_idx inner_env) used_map_sub_data))
|
||||
(_ (mif borrowed (error "body hast to be borrowed? " borrowed " " (true_str_strip body_part))))
|
||||
(_ (true_print "done pseudo_perceus, Doing compile_body_part func def compile-inner " full_params))
|
||||
(inner_analysis_data (array inner_type_data))
|
||||
((inner_value inner_code err ctx) (compile-inner inner_ctx body_part false false (local.get '$outer_s_env) new_get_s_env_code 0 new_tce_data inner_analysis_data))
|
||||
(_ (true_print "Done compile_body_part func def compile-inner " full_params))
|
||||
; Don't overwrite env with what was our inner env! Env is returned as part of context to our caller!
|
||||
((datasi funcs memo _was_inner_env pectx inline_locals) ctx)
|
||||
) (array inner_value inner_code err (array datasi funcs memo env pectx inline_locals) generate_get_s_env_code))))
|
||||
|
||||
((early_quit err ctx) (mif attempt_reduction
|
||||
(dlet (
|
||||
((inner_value inner_code err ctx generate_get_s_env_code) (compile_body_part ctx (idx (.marked_array_values body) 1) nil))
|
||||
; set it's wrap level to our wrap level
|
||||
(inner_value (mif inner_value (set_wrap_val wrap_level inner_value)))
|
||||
) (array inner_value err ctx))
|
||||
(array nil nil ctx)))
|
||||
|
||||
) (mif (and (!= nil early_quit) (= nil err)) (array ;(mod_fval_to_wrap early_quit)
|
||||
early_quit
|
||||
nil nil ctx)
|
||||
(dlet (
|
||||
|
||||
((env_val env_code env_err ctx) (if (and need_value (not (marked_env_real? se)))
|
||||
(array nil nil "Env wasn't real when compiling comb, but need value" ctx)
|
||||
(compile-inner ctx se need_value inside_veval outer_s_env_access_code s_env_access_code inline_level nil analysis_nil)))
|
||||
(_ (if (not (or (= nil env_val) (int? env_val))) (error "BADBADBADenv_val")))
|
||||
(maybe_func (get_passthrough (.hash c) ctx))
|
||||
|
||||
) (mif (and
|
||||
(not dont_y_comb)
|
||||
variadic
|
||||
(= 1 (len params))
|
||||
(marked_array? body)
|
||||
(= 4 (len (.marked_array_values body)))
|
||||
(prim_comb? (idx (.marked_array_values body) 0))
|
||||
(= 'lapply (.prim_comb_sym (idx (.marked_array_values body) 0)))
|
||||
(int? (get-value-or-false memo (.hash (idx (.marked_array_values body) 1))))
|
||||
(marked_symbol? (idx (.marked_array_values body) 2))
|
||||
(not (.marked_symbol_is_val (idx (.marked_array_values body) 2)))
|
||||
(= (idx params 0) (.marked_symbol_value (idx (.marked_array_values body) 2)))
|
||||
(marked_symbol? (idx (.marked_array_values body) 3))
|
||||
(not (.marked_symbol_is_val (idx (.marked_array_values body) 3)))
|
||||
(= de? (.marked_symbol_value (idx (.marked_array_values body) 3)))
|
||||
env_val
|
||||
)
|
||||
(array (combine_env_comb_val env_val (set_wrap_val wrap_level (get-value-or-false memo (.hash (idx (.marked_array_values body) 1))))) nil err ctx)
|
||||
(dlet (
|
||||
|
||||
(maybe_func (or (get_passthrough old_hash ctx) (get_passthrough new_hash ctx)))
|
||||
((func_value _ func_err ctx) (mif maybe_func maybe_func
|
||||
(dlet (
|
||||
|
||||
(full_params (concat params (mif de? (array de?) (array))))
|
||||
(normal_params_length (if variadic (- (len params) 1) (len params)))
|
||||
|
||||
((datasi funcs memo env pectx outer_inline_locals) ctx)
|
||||
(old_funcs funcs)
|
||||
(funcs (concat funcs (array nil)))
|
||||
@@ -5791,15 +5900,50 @@
|
||||
(func_value (calculate_func_val wrap_level))
|
||||
; if variadic, we just use the wrapper func and don't expect callers to know that we're varidic
|
||||
(func_value (mif variadic (mod_fval_to_wrap func_value) func_value))
|
||||
; Is this the vau-tieer?
|
||||
(memo (mif env_val (foldl (dlambda (memo (hash wrap)) (put memo hash (combine_env_comb_val env_val (calculate_func_val wrap)))) memo rec_hashes)
|
||||
memo))
|
||||
|
||||
|
||||
; Put our eventual func_value in the memo before we actually compile for recursion etc
|
||||
(memo (put (put memo new_hash func_value) old_hash func_value))
|
||||
|
||||
((inner_analysis_data analysis_err pectx) (function-analysis c memo pectx))
|
||||
(ctx (array datasi funcs memo env pectx outer_inline_locals))
|
||||
; EARLY QUIT IF Analysis Error
|
||||
) (mif analysis_err (array nil nil analysis_err ctx) (dlet (
|
||||
(new_inline_locals (array))
|
||||
(ctx (array datasi funcs memo env pectx new_inline_locals))
|
||||
((inner_value inner_code err ctx generate_get_s_env_code) (compile_body_part ctx body (array our_func_idx full_params)))
|
||||
|
||||
|
||||
(new_tce_data (array our_func_idx full_params))
|
||||
(inner_env (make_tmp_inner_env params de? se env_id))
|
||||
|
||||
((params_vec _ _ ctx) (compile-inner ctx (marked_array true false nil (map (lambda (k) (marked_symbol nil k)) full_params) nil) true false outer_s_env_access_code s_env_access_code 0 nil analysis_nil))
|
||||
(basic_get_s_env_code (local.get '$s_env))
|
||||
(generate_get_s_env_code (local.tee '$s_env (call '$env_alloc (i64.const params_vec)
|
||||
|
||||
(local.set '$tmp_ptr (call '$malloc (i32.const (* 8 (len full_params)))))
|
||||
(flat_map (lambda (i) (i64.store (* i 8) (local.get '$tmp_ptr)
|
||||
(generate_dup (local.get (idx full_params i)))))
|
||||
(range 0 (len full_params)))
|
||||
(mk_array_code_rc_const_len (len full_params) (local.get '$tmp_ptr))
|
||||
|
||||
(generate_dup (local.get '$outer_s_env)))))
|
||||
(lazy_get_s_env_code (_if '$have_s_env '(result i64)
|
||||
(i64.ne (i64.const nil_val) (local.get '$s_env))
|
||||
(then basic_get_s_env_code)
|
||||
(else generate_get_s_env_code
|
||||
;(call '$print (i64.const params_vec))
|
||||
;(call '$print (i64.const newline_msg_val))
|
||||
;(local.set '$outer_s_env (i64.const nil_val))
|
||||
)))
|
||||
(new_get_s_env_code (if dont_lazy_env basic_get_s_env_code lazy_get_s_env_code))
|
||||
((datasi funcs memo env pectx inline_locals) ctx)
|
||||
(inner_ctx (array datasi funcs memo inner_env pectx inline_locals))
|
||||
|
||||
((inner_value inner_code err ctx) (compile-inner inner_ctx body false false (local.get '$outer_s_env) new_get_s_env_code 0 new_tce_data inner_analysis_data))
|
||||
(_ (true_print "Done compile_body func def compile-inner " full_params))
|
||||
; Don't overwrite env with what was our inner env! Env is returned as part of context to our caller!
|
||||
((datasi funcs memo _was_inner_env pectx inline_locals) ctx)
|
||||
(ctx (array datasi funcs memo env pectx inline_locals))
|
||||
|
||||
|
||||
(inner_code (mif inner_value (i64.const (mod_fval_to_wrap inner_value)) inner_code))
|
||||
(wrapper_func (func '$wrapper_func '(param $params i64) '(param $d_env i64) '(param $outer_s_env i64) '(result i64) '(local $param_ptr i32) '(local $rc_bytes i64) '(local $rc_ptr i32) '(local $rc_tmp i32)
|
||||
(_if '$params_len_good
|
||||
@@ -5850,16 +5994,17 @@
|
||||
))))
|
||||
; replace our placeholder with the real one
|
||||
(funcs (concat old_funcs wrapper_func our_func (drop funcs (+ 2 (len old_funcs)))))
|
||||
(memo (put memo (.hash c) func_value))
|
||||
|
||||
) (array func_value nil err (array datasi funcs memo env pectx outer_inline_locals)))
|
||||
))
|
||||
))))
|
||||
(_ (print_strip "returning " func_value " for " c))
|
||||
(_ (if (not (int? func_value)) (error "BADBADBADfunc")))
|
||||
(full_result (mif env_val
|
||||
(array (combine_env_comb_val env_val func_value) nil (mif func_err (str func_err ", from compiling comb body") (mif env_err (str env_err ", from compiling comb env") nil)) ctx)
|
||||
(array nil (combine_env_code_comb_val_code env_code (mod_fval_to_wrap func_value)) (mif func_err (str func_err ", from compiling comb body (env as code)") (mif env_err (str env_err ", from compiling comb env (as code)") nil)) ctx)))
|
||||
;(_ (mif env_val (true_print "total function " (idx full_result 0) " based on " env_val " and " func_value)))
|
||||
(_ (if (and (not func_err) (not (int? func_value))) (error "BADBADBADfunc")))
|
||||
|
||||
(full_result (cond
|
||||
((!= nil func_err) (array nil nil (str func_err ", from compiling comb body") ctx))
|
||||
((!= nil env_err) (array nil nil (str env_err ", from compiling env") ctx))
|
||||
((!= nil env_val) (array (combine_env_comb_val env_val func_value) nil nil ctx))
|
||||
(true (array nil (combine_env_code_comb_val_code env_code (mod_fval_to_wrap func_value)) nil ctx))))
|
||||
) full_result
|
||||
))))
|
||||
|
||||
@@ -5874,12 +6019,13 @@
|
||||
|
||||
(_ (true_print "About to compile a bunch of symbols & strings"))
|
||||
|
||||
((run_val _ _ ctx) (compile-inner ctx (marked_symbol nil 'run) true false (array) (array) 0 nil analysis_nil))
|
||||
((exit_val _ _ ctx) (compile-inner ctx (marked_symbol nil 'exit) true false (array) (array) 0 nil analysis_nil))
|
||||
((args_val _ _ ctx) (compile-inner ctx (marked_symbol nil 'args) true false (array) (array) 0 nil analysis_nil))
|
||||
((read_val _ _ ctx) (compile-inner ctx (marked_symbol nil 'read) true false (array) (array) 0 nil analysis_nil))
|
||||
((write_val _ _ ctx) (compile-inner ctx (marked_symbol nil 'write) true false (array) (array) 0 nil analysis_nil))
|
||||
((open_val _ _ ctx) (compile-inner ctx (marked_symbol nil 'open) true false (array) (array) 0 nil analysis_nil))
|
||||
((monad_error_msg_val _ _ ctx) (compile-inner ctx (marked_val "Not a legal monad ( ['args <cont (arg_array error?)>] / ['read fd len <cont(data error_no)>] / ['write fd data <cont(num_written error_no)>] / ['open fd path <cont(new_fd error_no)>] /['exit exit_code])") true false (array) (array) 0 nil analysis_nil))
|
||||
((monad_error_msg_val _ _ ctx) (compile-inner ctx (marked_val "Not a legal monad ( ['args <cont (arg_array error?)>] / ['read fd len <cont(data error_no)>] / ['write fd data <cont(num_written error_no)>] / ['open fd path <cont(new_fd error_no)>] / ['exit exit_code] / ['run <cont()>])") true false (array) (array) 0 nil analysis_nil))
|
||||
((bad_args_val _ _ ctx) (compile-inner ctx (marked_val "<error with args>") true false (array) (array) 0 nil analysis_nil))
|
||||
((bad_read_val _ _ ctx) (compile-inner ctx (marked_val "<error with read>") true false (array) (array) 0 nil analysis_nil))
|
||||
((exit_msg_val _ _ ctx) (compile-inner ctx (marked_val "Exiting with code: ") true false (array) (array) 0 nil analysis_nil))
|
||||
@@ -5909,8 +6055,7 @@
|
||||
; ineriting rights, fdflags
|
||||
|
||||
(start (func '$start '(local $it i64) '(local $tmp i64) '(local $ptr i32) '(local $monad_name i64) '(local $len i32) '(local $buf i32) '(local $traverse i32) '(local $x i32) '(local $y i32) '(local $code i32) '(local $str i64) '(local $result i64) '(local $debug_malloc_print i32) '(local $rc_bytes i64) '(local $rc_ptr i32) '(local $rc_tmp i32)
|
||||
(local.set '$it (if needs_runtime_eval (call '$eval_helper compiled_value_code (i64.const root_marked_env_val))
|
||||
compiled_value_code))
|
||||
(local.set '$it compiled_value_code)
|
||||
(block '$exit_block
|
||||
(block '$error_block
|
||||
(_loop '$l
|
||||
@@ -6011,6 +6156,39 @@
|
||||
)
|
||||
)
|
||||
|
||||
(_if '$is_run
|
||||
(i64.eq (i64.const run_val) (local.get '$monad_name))
|
||||
(then
|
||||
;; len != 2
|
||||
(br_if '$error_block (i32.ne (extract_size_code (local.get '$it)) (i32.const 2)))
|
||||
;; second entry isn't a comb -> out
|
||||
(br_if '$error_block (is_not_type_code comb_tag (i64.load 8 (local.get '$ptr))))
|
||||
(local.set '$tmp (generate_dup (i64.load 8 (local.get '$ptr))))
|
||||
(generate_drop (local.get '$it))
|
||||
(generate_drop (global.get '$debug_func_to_call))
|
||||
(generate_drop (global.get '$debug_params_to_call))
|
||||
(generate_drop (global.get '$debug_env_to_call))
|
||||
(global.set '$debug_func_to_call (generate_dup (local.get '$tmp)))
|
||||
(global.set '$debug_params_to_call (i64.const nil_val))
|
||||
(global.set '$debug_env_to_call (i64.const root_marked_env_val))
|
||||
(local.set '$it (call_indirect
|
||||
;;type
|
||||
k_vau
|
||||
;;table
|
||||
0
|
||||
;;params
|
||||
(i64.const nil_val)
|
||||
;;top_env
|
||||
(i64.const root_marked_env_val)
|
||||
;; static env
|
||||
(extract_func_env_code (local.get '$tmp))
|
||||
;;func_idx
|
||||
(extract_func_idx_code (local.get '$tmp))
|
||||
))
|
||||
(br '$l)
|
||||
)
|
||||
)
|
||||
|
||||
; second entry isn't an int -> out
|
||||
(br_if '$error_block (is_not_type_code int_tag (i64.load 8 (local.get '$ptr))))
|
||||
|
||||
@@ -6218,6 +6396,34 @@
|
||||
(mk_int_code_i32s (global.get '$num_mallocs))
|
||||
(mk_int_code_i32s (global.get '$num_sbrks))
|
||||
|
||||
(mk_int_code_i32s (global.get '$num_compiled_dzero))
|
||||
(mk_int_code_i32s (global.get '$num_compiled_done))
|
||||
(mk_int_code_i32s (global.get '$num_interp_dzero))
|
||||
(mk_int_code_i32s (global.get '$num_interp_done))
|
||||
(mk_int_code_i32s (global.get '$num_all_evals))
|
||||
(mk_int_code_i32s (global.get '$num_evals))
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
|
||||
(call '$print )
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print )
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print )
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print )
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print )
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print )
|
||||
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
(call '$print )
|
||||
(call '$print (i64.const newline_msg_val))
|
||||
@@ -6686,15 +6892,22 @@
|
||||
|
||||
) void)))
|
||||
|
||||
(run-compiler (lambda (dont_compile dont_lazy_env dont_y_comb dont_prim_inline dont_closure_inline f)
|
||||
(run-compiler (lambda (dont_partial_eval dont_lazy_env dont_y_comb dont_prim_inline dont_closure_inline f)
|
||||
(dlet (
|
||||
(_ (true_print "reading in!"))
|
||||
(read_in (read-string (slurp f)))
|
||||
;(_ (true_print "read in, now evaluating"))
|
||||
(evaled (if dont_compile (array (array 0 empty_dict) nil (mark read_in))
|
||||
(partial_eval read_in)))
|
||||
|
||||
; This is basicaly (compile <comb0 () ('eval <marked_body> root_env)>)
|
||||
; this does mean that without partial eval this is an extra and unnecessary lookup of 'eval in the root env but w/e, it's a single load
|
||||
; empty partial_eval_ctx empty partial_eval_error value to compile
|
||||
(body_value (marked_array true false nil (array (marked_symbol nil 'eval) (marked_array true false nil (array quote_internal (mark read_in)) true) root_marked_env) true))
|
||||
(constructed_body (idx (try_unval body_value (lambda (_) nil)) 1))
|
||||
(constructed_func (marked_comb 0 (+ env_id_start 1) 'outer root_marked_env false (array) constructed_body))
|
||||
(constructed_value (marked_array true false nil (array (marked_symbol nil 'run) constructed_func) true))
|
||||
(to_compile (array (array (+ env_id_start 1) empty_dict) nil constructed_value))
|
||||
;(_ (true_print "done partialy evaling, now compiling"))
|
||||
(bytes (compile evaled dont_compile dont_lazy_env dont_y_comb dont_prim_inline dont_closure_inline))
|
||||
(_ (true_print "going"))
|
||||
(bytes (compile to_compile dont_partial_eval dont_lazy_env dont_y_comb dont_prim_inline dont_closure_inline))
|
||||
;(_ (true_print "compiled, writng out"))
|
||||
(_ (write_file "./csc_out.wasm" bytes))
|
||||
;(_ (true_print "written out"))
|
||||
@@ -6712,7 +6925,7 @@
|
||||
(cond ((= "test" com) (test-most))
|
||||
((= "single" com) (single-test))
|
||||
(true (run-compiler
|
||||
(and (>= (len args) 2) (= "no_compile" (idx args 1)))
|
||||
(and (>= (len args) 2) (= "no_partial_eval" (idx args 1)))
|
||||
(and (>= (len args) 2) (= "no_lazy_env" (idx args 1)))
|
||||
(and (>= (len args) 2) (= "no_y_comb" (idx args 1)))
|
||||
(and (>= (len args) 2) (= "no_prim_inline" (idx args 1)))
|
||||
|
||||
163
website/LICENSE
Normal file
163
website/LICENSE
Normal file
@@ -0,0 +1,163 @@
|
||||
###########################
|
||||
For Recursive (the font):
|
||||
###########################
|
||||
|
||||
Copyright 2020 The Recursive Project Authors (https://github.com/arrowtype/recursive)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
|
||||
|
||||
|
||||
|
||||
###########################
|
||||
For CodeJar:
|
||||
###########################
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Anton Medvedev
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
|
||||
|
||||
###########################
|
||||
For highlight.js:
|
||||
###########################
|
||||
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2006, Ivan Sagalaev.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
BIN
website/Recursive.woff2
Normal file
BIN
website/Recursive.woff2
Normal file
Binary file not shown.
466
website/codejar.js
Normal file
466
website/codejar.js
Normal file
@@ -0,0 +1,466 @@
|
||||
const globalWindow = window;
|
||||
export function CodeJar(editor, highlight, opt = {}) {
|
||||
const options = Object.assign({ tab: '\t', indentOn: /[({\[]$/, moveToNewLine: /^[)}\]]/, spellcheck: false, catchTab: true, preserveIdent: true, addClosing: true, history: true, window: globalWindow }, opt);
|
||||
const window = options.window;
|
||||
const document = window.document;
|
||||
let listeners = [];
|
||||
let history = [];
|
||||
let at = -1;
|
||||
let focus = false;
|
||||
let callback;
|
||||
let prev; // code content prior keydown event
|
||||
editor.setAttribute('contenteditable', 'plaintext-only');
|
||||
editor.setAttribute('spellcheck', options.spellcheck ? 'true' : 'false');
|
||||
editor.style.outline = 'none';
|
||||
editor.style.overflowWrap = 'break-word';
|
||||
editor.style.overflowY = 'auto';
|
||||
editor.style.whiteSpace = 'pre-wrap';
|
||||
let isLegacy = false; // true if plaintext-only is not supported
|
||||
highlight(editor);
|
||||
if (editor.contentEditable !== 'plaintext-only')
|
||||
isLegacy = true;
|
||||
if (isLegacy)
|
||||
editor.setAttribute('contenteditable', 'true');
|
||||
const debounceHighlight = debounce(() => {
|
||||
const pos = save();
|
||||
highlight(editor, pos);
|
||||
restore(pos);
|
||||
}, 30);
|
||||
let recording = false;
|
||||
const shouldRecord = (event) => {
|
||||
return !isUndo(event) && !isRedo(event)
|
||||
&& event.key !== 'Meta'
|
||||
&& event.key !== 'Control'
|
||||
&& event.key !== 'Alt'
|
||||
&& !event.key.startsWith('Arrow');
|
||||
};
|
||||
const debounceRecordHistory = debounce((event) => {
|
||||
if (shouldRecord(event)) {
|
||||
recordHistory();
|
||||
recording = false;
|
||||
}
|
||||
}, 300);
|
||||
const on = (type, fn) => {
|
||||
listeners.push([type, fn]);
|
||||
editor.addEventListener(type, fn);
|
||||
};
|
||||
on('keydown', event => {
|
||||
if (event.defaultPrevented)
|
||||
return;
|
||||
prev = toString();
|
||||
if (options.preserveIdent)
|
||||
handleNewLine(event);
|
||||
else
|
||||
legacyNewLineFix(event);
|
||||
if (options.catchTab)
|
||||
handleTabCharacters(event);
|
||||
if (options.addClosing)
|
||||
handleSelfClosingCharacters(event);
|
||||
if (options.history) {
|
||||
handleUndoRedo(event);
|
||||
if (shouldRecord(event) && !recording) {
|
||||
recordHistory();
|
||||
recording = true;
|
||||
}
|
||||
}
|
||||
if (isLegacy && !isCopy(event))
|
||||
restore(save());
|
||||
});
|
||||
on('keyup', event => {
|
||||
if (event.defaultPrevented)
|
||||
return;
|
||||
if (event.isComposing)
|
||||
return;
|
||||
if (prev !== toString())
|
||||
debounceHighlight();
|
||||
debounceRecordHistory(event);
|
||||
if (callback)
|
||||
callback(toString());
|
||||
});
|
||||
on('focus', _event => {
|
||||
focus = true;
|
||||
});
|
||||
on('blur', _event => {
|
||||
focus = false;
|
||||
});
|
||||
on('paste', event => {
|
||||
recordHistory();
|
||||
handlePaste(event);
|
||||
recordHistory();
|
||||
if (callback)
|
||||
callback(toString());
|
||||
});
|
||||
function save() {
|
||||
const s = getSelection();
|
||||
const pos = { start: 0, end: 0, dir: undefined };
|
||||
let { anchorNode, anchorOffset, focusNode, focusOffset } = s;
|
||||
if (!anchorNode || !focusNode)
|
||||
throw 'error1';
|
||||
// If the anchor and focus are the editor element, return either a full
|
||||
// highlight or a start/end cursor position depending on the selection
|
||||
if (anchorNode === editor && focusNode === editor) {
|
||||
pos.start = (anchorOffset > 0 && editor.textContent) ? editor.textContent.length : 0;
|
||||
pos.end = (focusOffset > 0 && editor.textContent) ? editor.textContent.length : 0;
|
||||
pos.dir = (focusOffset >= anchorOffset) ? '->' : '<-';
|
||||
return pos;
|
||||
}
|
||||
// Selection anchor and focus are expected to be text nodes,
|
||||
// so normalize them.
|
||||
if (anchorNode.nodeType === Node.ELEMENT_NODE) {
|
||||
const node = document.createTextNode('');
|
||||
anchorNode.insertBefore(node, anchorNode.childNodes[anchorOffset]);
|
||||
anchorNode = node;
|
||||
anchorOffset = 0;
|
||||
}
|
||||
if (focusNode.nodeType === Node.ELEMENT_NODE) {
|
||||
const node = document.createTextNode('');
|
||||
focusNode.insertBefore(node, focusNode.childNodes[focusOffset]);
|
||||
focusNode = node;
|
||||
focusOffset = 0;
|
||||
}
|
||||
visit(editor, el => {
|
||||
if (el === anchorNode && el === focusNode) {
|
||||
pos.start += anchorOffset;
|
||||
pos.end += focusOffset;
|
||||
pos.dir = anchorOffset <= focusOffset ? '->' : '<-';
|
||||
return 'stop';
|
||||
}
|
||||
if (el === anchorNode) {
|
||||
pos.start += anchorOffset;
|
||||
if (!pos.dir) {
|
||||
pos.dir = '->';
|
||||
}
|
||||
else {
|
||||
return 'stop';
|
||||
}
|
||||
}
|
||||
else if (el === focusNode) {
|
||||
pos.end += focusOffset;
|
||||
if (!pos.dir) {
|
||||
pos.dir = '<-';
|
||||
}
|
||||
else {
|
||||
return 'stop';
|
||||
}
|
||||
}
|
||||
if (el.nodeType === Node.TEXT_NODE) {
|
||||
if (pos.dir != '->')
|
||||
pos.start += el.nodeValue.length;
|
||||
if (pos.dir != '<-')
|
||||
pos.end += el.nodeValue.length;
|
||||
}
|
||||
});
|
||||
// collapse empty text nodes
|
||||
editor.normalize();
|
||||
return pos;
|
||||
}
|
||||
function restore(pos) {
|
||||
const s = getSelection();
|
||||
let startNode, startOffset = 0;
|
||||
let endNode, endOffset = 0;
|
||||
if (!pos.dir)
|
||||
pos.dir = '->';
|
||||
if (pos.start < 0)
|
||||
pos.start = 0;
|
||||
if (pos.end < 0)
|
||||
pos.end = 0;
|
||||
// Flip start and end if the direction reversed
|
||||
if (pos.dir == '<-') {
|
||||
const { start, end } = pos;
|
||||
pos.start = end;
|
||||
pos.end = start;
|
||||
}
|
||||
let current = 0;
|
||||
visit(editor, el => {
|
||||
if (el.nodeType !== Node.TEXT_NODE)
|
||||
return;
|
||||
const len = (el.nodeValue || '').length;
|
||||
if (current + len > pos.start) {
|
||||
if (!startNode) {
|
||||
startNode = el;
|
||||
startOffset = pos.start - current;
|
||||
}
|
||||
if (current + len > pos.end) {
|
||||
endNode = el;
|
||||
endOffset = pos.end - current;
|
||||
return 'stop';
|
||||
}
|
||||
}
|
||||
current += len;
|
||||
});
|
||||
if (!startNode)
|
||||
startNode = editor, startOffset = editor.childNodes.length;
|
||||
if (!endNode)
|
||||
endNode = editor, endOffset = editor.childNodes.length;
|
||||
// Flip back the selection
|
||||
if (pos.dir == '<-') {
|
||||
[startNode, startOffset, endNode, endOffset] = [endNode, endOffset, startNode, startOffset];
|
||||
}
|
||||
s.setBaseAndExtent(startNode, startOffset, endNode, endOffset);
|
||||
}
|
||||
function beforeCursor() {
|
||||
const s = getSelection();
|
||||
const r0 = s.getRangeAt(0);
|
||||
const r = document.createRange();
|
||||
r.selectNodeContents(editor);
|
||||
r.setEnd(r0.startContainer, r0.startOffset);
|
||||
return r.toString();
|
||||
}
|
||||
function afterCursor() {
|
||||
const s = getSelection();
|
||||
const r0 = s.getRangeAt(0);
|
||||
const r = document.createRange();
|
||||
r.selectNodeContents(editor);
|
||||
r.setStart(r0.endContainer, r0.endOffset);
|
||||
return r.toString();
|
||||
}
|
||||
function handleNewLine(event) {
|
||||
if (event.key === 'Enter') {
|
||||
const before = beforeCursor();
|
||||
const after = afterCursor();
|
||||
let [padding] = findPadding(before);
|
||||
let newLinePadding = padding;
|
||||
// If last symbol is "{" ident new line
|
||||
if (options.indentOn.test(before)) {
|
||||
newLinePadding += options.tab;
|
||||
}
|
||||
// Preserve padding
|
||||
if (newLinePadding.length > 0) {
|
||||
preventDefault(event);
|
||||
event.stopPropagation();
|
||||
insert('\n' + newLinePadding);
|
||||
}
|
||||
else {
|
||||
legacyNewLineFix(event);
|
||||
}
|
||||
// Place adjacent "}" on next line
|
||||
if (newLinePadding !== padding && options.moveToNewLine.test(after)) {
|
||||
const pos = save();
|
||||
insert('\n' + padding);
|
||||
restore(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
function legacyNewLineFix(event) {
|
||||
// Firefox does not support plaintext-only mode
|
||||
// and puts <div><br></div> on Enter. Let's help.
|
||||
if (isLegacy && event.key === 'Enter') {
|
||||
preventDefault(event);
|
||||
event.stopPropagation();
|
||||
if (afterCursor() == '') {
|
||||
insert('\n ');
|
||||
const pos = save();
|
||||
pos.start = --pos.end;
|
||||
restore(pos);
|
||||
}
|
||||
else {
|
||||
insert('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
function handleSelfClosingCharacters(event) {
|
||||
const open = `([{'"`;
|
||||
const close = `)]}'"`;
|
||||
const codeAfter = afterCursor();
|
||||
const codeBefore = beforeCursor();
|
||||
const escapeCharacter = codeBefore.substr(codeBefore.length - 1) === '\\';
|
||||
const charAfter = codeAfter.substr(0, 1);
|
||||
if (close.includes(event.key) && !escapeCharacter && charAfter === event.key) {
|
||||
// We already have closing char next to cursor.
|
||||
// Move one char to right.
|
||||
const pos = save();
|
||||
preventDefault(event);
|
||||
pos.start = ++pos.end;
|
||||
restore(pos);
|
||||
}
|
||||
else if (open.includes(event.key)
|
||||
&& !escapeCharacter
|
||||
&& (`"'`.includes(event.key) || ['', ' ', '\n'].includes(charAfter))) {
|
||||
preventDefault(event);
|
||||
const pos = save();
|
||||
const wrapText = pos.start == pos.end ? '' : getSelection().toString();
|
||||
const text = event.key + wrapText + close[open.indexOf(event.key)];
|
||||
insert(text);
|
||||
pos.start++;
|
||||
pos.end++;
|
||||
restore(pos);
|
||||
}
|
||||
}
|
||||
function handleTabCharacters(event) {
|
||||
if (event.key === 'Tab') {
|
||||
preventDefault(event);
|
||||
if (event.shiftKey) {
|
||||
const before = beforeCursor();
|
||||
let [padding, start,] = findPadding(before);
|
||||
if (padding.length > 0) {
|
||||
const pos = save();
|
||||
// Remove full length tab or just remaining padding
|
||||
const len = Math.min(options.tab.length, padding.length);
|
||||
restore({ start, end: start + len });
|
||||
document.execCommand('delete');
|
||||
pos.start -= len;
|
||||
pos.end -= len;
|
||||
restore(pos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
insert(options.tab);
|
||||
}
|
||||
}
|
||||
}
|
||||
function handleUndoRedo(event) {
|
||||
if (isUndo(event)) {
|
||||
preventDefault(event);
|
||||
at--;
|
||||
const record = history[at];
|
||||
if (record) {
|
||||
editor.innerHTML = record.html;
|
||||
restore(record.pos);
|
||||
}
|
||||
if (at < 0)
|
||||
at = 0;
|
||||
}
|
||||
if (isRedo(event)) {
|
||||
preventDefault(event);
|
||||
at++;
|
||||
const record = history[at];
|
||||
if (record) {
|
||||
editor.innerHTML = record.html;
|
||||
restore(record.pos);
|
||||
}
|
||||
if (at >= history.length)
|
||||
at--;
|
||||
}
|
||||
}
|
||||
function recordHistory() {
|
||||
if (!focus)
|
||||
return;
|
||||
const html = editor.innerHTML;
|
||||
const pos = save();
|
||||
const lastRecord = history[at];
|
||||
if (lastRecord) {
|
||||
if (lastRecord.html === html
|
||||
&& lastRecord.pos.start === pos.start
|
||||
&& lastRecord.pos.end === pos.end)
|
||||
return;
|
||||
}
|
||||
at++;
|
||||
history[at] = { html, pos };
|
||||
history.splice(at + 1);
|
||||
const maxHistory = 300;
|
||||
if (at > maxHistory) {
|
||||
at = maxHistory;
|
||||
history.splice(0, 1);
|
||||
}
|
||||
}
|
||||
function handlePaste(event) {
|
||||
preventDefault(event);
|
||||
const text = (event.originalEvent || event)
|
||||
.clipboardData
|
||||
.getData('text/plain')
|
||||
.replace(/\r/g, '');
|
||||
const pos = save();
|
||||
insert(text);
|
||||
highlight(editor);
|
||||
restore({
|
||||
start: Math.min(pos.start, pos.end) + text.length,
|
||||
end: Math.min(pos.start, pos.end) + text.length,
|
||||
dir: '<-',
|
||||
});
|
||||
}
|
||||
function visit(editor, visitor) {
|
||||
const queue = [];
|
||||
if (editor.firstChild)
|
||||
queue.push(editor.firstChild);
|
||||
let el = queue.pop();
|
||||
while (el) {
|
||||
if (visitor(el) === 'stop')
|
||||
break;
|
||||
if (el.nextSibling)
|
||||
queue.push(el.nextSibling);
|
||||
if (el.firstChild)
|
||||
queue.push(el.firstChild);
|
||||
el = queue.pop();
|
||||
}
|
||||
}
|
||||
function isCtrl(event) {
|
||||
return event.metaKey || event.ctrlKey;
|
||||
}
|
||||
function isUndo(event) {
|
||||
return isCtrl(event) && !event.shiftKey && getKeyCode(event) === 'Z';
|
||||
}
|
||||
function isRedo(event) {
|
||||
return isCtrl(event) && event.shiftKey && getKeyCode(event) === 'Z';
|
||||
}
|
||||
function isCopy(event) {
|
||||
return isCtrl(event) && getKeyCode(event) === 'C';
|
||||
}
|
||||
function getKeyCode(event) {
|
||||
let key = event.key || event.keyCode || event.which;
|
||||
if (!key)
|
||||
return undefined;
|
||||
return (typeof key === 'string' ? key : String.fromCharCode(key)).toUpperCase();
|
||||
}
|
||||
function insert(text) {
|
||||
text = text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
document.execCommand('insertHTML', false, text);
|
||||
}
|
||||
function debounce(cb, wait) {
|
||||
let timeout = 0;
|
||||
return (...args) => {
|
||||
clearTimeout(timeout);
|
||||
timeout = window.setTimeout(() => cb(...args), wait);
|
||||
};
|
||||
}
|
||||
function findPadding(text) {
|
||||
// Find beginning of previous line.
|
||||
let i = text.length - 1;
|
||||
while (i >= 0 && text[i] !== '\n')
|
||||
i--;
|
||||
i++;
|
||||
// Find padding of the line.
|
||||
let j = i;
|
||||
while (j < text.length && /[ \t]/.test(text[j]))
|
||||
j++;
|
||||
return [text.substring(i, j) || '', i, j];
|
||||
}
|
||||
function toString() {
|
||||
return editor.textContent || '';
|
||||
}
|
||||
function preventDefault(event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
function getSelection() {
|
||||
var _a;
|
||||
if (((_a = editor.parentNode) === null || _a === void 0 ? void 0 : _a.nodeType) == Node.DOCUMENT_FRAGMENT_NODE) {
|
||||
return editor.parentNode.getSelection();
|
||||
}
|
||||
return window.getSelection();
|
||||
}
|
||||
return {
|
||||
updateOptions(newOptions) {
|
||||
Object.assign(options, newOptions);
|
||||
},
|
||||
updateCode(code) {
|
||||
editor.textContent = code;
|
||||
highlight(editor);
|
||||
},
|
||||
onUpdate(cb) {
|
||||
callback = cb;
|
||||
},
|
||||
toString,
|
||||
save,
|
||||
restore,
|
||||
recordHistory,
|
||||
destroy() {
|
||||
for (let [type, fn] of listeners) {
|
||||
editor.removeEventListener(type, fn);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
9
website/default.min.css
vendored
Normal file
9
website/default.min.css
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/*!
|
||||
Theme: Default
|
||||
Description: Original highlight.js style
|
||||
Author: (c) Ivan Sagalaev <maniac@softwaremaniacs.org>
|
||||
Maintainer: @highlightjs/core-team
|
||||
Website: https://highlightjs.org/
|
||||
License: see project LICENSE
|
||||
Touched: 2021
|
||||
*/pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#f3f3f3;color:#444}.hljs-comment{color:#697070}.hljs-punctuation,.hljs-tag{color:#444a}.hljs-tag .hljs-attr,.hljs-tag .hljs-name{color:#444}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#ab5656}.hljs-literal{color:#695}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta .hljs-string{color:#38a}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}
|
||||
BIN
website/favicon.ico
Normal file
BIN
website/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
1202
website/highlight.min.js
vendored
Normal file
1202
website/highlight.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
171
website/index.html
Normal file
171
website/index.html
Normal file
@@ -0,0 +1,171 @@
|
||||
<!doctype html>
|
||||
<html lang="en-us">
|
||||
<meta charset="UTF-8">
|
||||
<head>
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: 'Recursive';
|
||||
font-style: oblique 0deg 15deg;
|
||||
font-weight: 300 1000;
|
||||
font-display: swap;
|
||||
src: url(./Recursive.woff2) format('woff2');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
||||
}
|
||||
:root {
|
||||
--rec-wght: 400;
|
||||
--rec-slnt: 0;
|
||||
--rec-mono: 0;
|
||||
--rec-casl: 0;
|
||||
--rec-csrv: 0;
|
||||
}
|
||||
* {
|
||||
font-variation-settings: "wght" var(--rec-wght),
|
||||
"slnt" var(--rec-slnt),
|
||||
"MONO" var(--rec-mono),
|
||||
"CASL" var(--rec-casl),
|
||||
"CRSV" var(--rec-csrv);
|
||||
}
|
||||
body {
|
||||
max-width: 45em;
|
||||
margin: 1em auto;
|
||||
padding: 0 .62em;
|
||||
font: 1.2em/1.62 'Recursive', sans-serif;
|
||||
}
|
||||
h1, h2, h3, h4 {
|
||||
line-height:1.2;
|
||||
--rec-wght: 700;
|
||||
--rec-casl: 1;
|
||||
--rec-crsv: 1;
|
||||
}
|
||||
h1 {
|
||||
line-height:0.7;
|
||||
font-size: 4em;
|
||||
--rec-wght: 900;
|
||||
--rec-slnt: -15;
|
||||
text-decoration: underline;
|
||||
text-decoration-thickness: 0.4rem;
|
||||
//border-bottom: 0.08em solid;
|
||||
//border-left: 0.1em solid;
|
||||
//display: inline-block;
|
||||
}
|
||||
h2 { font-size: 3em; }
|
||||
h3 { font-size: 1.5em; }
|
||||
h4 { font-size: 1.2em; }
|
||||
i { --rec-slnt: -14; }
|
||||
b { --rec-wght: 600; }
|
||||
.run_container { position: relative; }
|
||||
.editor {
|
||||
font-family: 'Recursive', monospace;
|
||||
font-size: 1rem;
|
||||
--rec-mono: 1;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
|
||||
height: 7em;
|
||||
letter-spacing: normal;
|
||||
tab-size: 4;
|
||||
}
|
||||
.output {
|
||||
margin-block-start: 1rem;
|
||||
font-family: 'Recursive', monospace;
|
||||
font-size: 1rem;
|
||||
--rec-mono: 1;
|
||||
tab-size: 4;
|
||||
height: 5em;
|
||||
width: 100%;
|
||||
}
|
||||
.run_button {
|
||||
font-family: 'Recursive', sans-serif;
|
||||
font-size: 1em;
|
||||
--rec-wght: 900;
|
||||
--rec-slnt: -15;
|
||||
--rec-casl: 1;
|
||||
--rec-crsv: 1;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header><h1>Kraken</h1></header>
|
||||
<i>FOSS Fexprs: <a title="Kraken on GitHub" href="https://github.com/limvot/kraken">https://github.com/limvot/kraken</a></i>
|
||||
<br>
|
||||
<h3>Demo:</h3>
|
||||
<div class="run_container">
|
||||
<div class="editor" id="hello_editor">; Of course
|
||||
(println "Hello World")
|
||||
; Just print 3
|
||||
(println "Math works:" (+ 1 2))
|
||||
</div>
|
||||
<textarea class="output" id="hello_output">Output will appear here</textarea>
|
||||
<button class="run_button" onclick="executeKraken(hello_editor_jar.toString(), 'hello_output')"><b>Run</b></button> <br>
|
||||
</div>
|
||||
<a name="concept"/>
|
||||
<h3>Concept:</h3>
|
||||
<ul>
|
||||
<li> Minimal, close to the metal Kernel/Scheme (operate on words, bytes, arrays) as AST / core language, with Kernel/Vau calculus inspiration oblivating the need for non-reader macros (<a title="Kernel/Vau calculus thesis" href="https://web.wpi.edu/Pubs/ETD/Available/etd-090110-124904/unrestricted/jshutt.pdf">Kernel/Vau calculus thesis</a>)
|
||||
<li> Full Context-free (and eventually, context sensitive) reader macros using FUN-GLL (<a title="fun-gll paper" href="https://www.sciencedirect.com/science/article/pii/S2590118420300058">FUN-GLL paper</a>) to extend language's syntax dynamically
|
||||
<li> Implement Type Systems as Macros (but using Vaus instead of macros) (<a title="type systems as macros paper 1" href="http://www.ccs.neu.edu/home/stchang/pubs/ckg-popl2017.pdf">paper, up to System Fω</a>) (<a title="type systems as macros paper 2" href="https://www.ccs.neu.edu/home/stchang/pubs/cbtb-popl2020.pdf">second paper, up to dependent types</a>)
|
||||
<li> Use above "type systems as vaus" to create richer language and embed entire other programming languages (syntax, semantics, and type system) for flawless interop/FFI (C, Go, Lua, JS, etc)
|
||||
<li> File is interpreted, and then if "main" exists it is compiled, spidering backwards to referenced functions and data (Allows interpreted code to do metaprogramming, dependency resolution, generate code, etc, which is then compiled)
|
||||
<li> Regionalized Value State Dependence Graph as backend-IR, enabling simpler implementations of powerful optimizations (<a title="RSVDG paper" href="https://arxiv.org/pdf/1912.05036.pdf">RSVDG paper</a>) so that embedded languages have good performance when compiled with little code
|
||||
</ul>
|
||||
<a name="about"/>
|
||||
<h3> About:</h3>
|
||||
<p> Currently, I am bootstrapping this new core Lisp out of my prior compiler for my programming language, Kraken. I have implemented the first version of the FUN-GLL algorithm and have working vaus and context-free reader macros.
|
||||
<p> The general flow is that the input files will be executed with the core Lisp interpreter, and if there is a "main" symbol defined the compiler emits C code for that function & all other functions & data that it references. In this way the language supports very powerful meta-programming at compile time, including adding syntax to the language, arbitrary computation, and importing other files, and then compiles into a static executable.
|
||||
<p> Below are a few examples of using the vau / live grammar modification / context-free reader macros to implement basic methods as well as embed the BF language into the core Lisp. The core Lisp implementation has been compiled to WebAssembly and should be able to run in your browser. Feel free to make edits and play around below.
|
||||
<br>
|
||||
Note that the current implementation is inefficient, and sometimes has problems running in phone web browsers.
|
||||
<a name="hello_example"/>
|
||||
<a name="vau_core"/>
|
||||
<h4>Vau/Kernel as simple core:</h4>
|
||||
By constructing our core language on a very simple Vau/Kernel base, we can keep the base truely tiny, and build up normal Lisp functions and programming language features in the language itself. This should help implement other programming languages concisely, and will hopefully make optimization easier and more broadly applicable.
|
||||
<br>
|
||||
Below is the current prelude that adds quoting, quasiquoting, syntax for arrays and quoting/quasiquoting, do, if, let, and even lambda itself!
|
||||
<a name="next_steps"/>
|
||||
<h3>Next Steps</h3>
|
||||
<ul>
|
||||
<li> Implement persistent functional data structures
|
||||
<ul>
|
||||
<li> Hash Array-Mapped Trie (HAMT) / Relaxed Radix Balance Tree (RRB-Tree)
|
||||
<li> Hash Map based on the above
|
||||
<li> Hash Set based on the above
|
||||
</ul>
|
||||
<li> Prototype Type Systems as Macros, may require macro system rewrite/upgrade
|
||||
<li> Sketch out Kraken language on top of core Lisp, includes basic Hindley-Milner type system implemented with Macros and above data structures
|
||||
<li> Re-self-host using functional approach in above Kraken language
|
||||
<li> Use Type System Macros to implement automatic transient creation on HAMT/RBB-Tree as an optimization
|
||||
<li> Implement RVSDG IR and develop best bang-for-buck optimizations using it
|
||||
</ul>
|
||||
|
||||
<link rel="stylesheet" href="./default.min.css">
|
||||
<script src="./highlight.min.js"></script>
|
||||
<script type="module">
|
||||
import {CodeJar} from './codejar.js'
|
||||
document.querySelectorAll('.editor').forEach((editor_div) => {
|
||||
window[editor_div.id + "_jar"] = CodeJar(editor_div, hljs.highlightElement)
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
var output_name = ""
|
||||
var Module = {
|
||||
noInitialRun: true,
|
||||
onRuntimeInitialized: () => {
|
||||
},
|
||||
print: txt => {
|
||||
document.getElementById(output_name).value += txt + "\n";
|
||||
},
|
||||
printErr: txt => {
|
||||
document.getElementById(output_name).value += "STDERR:[" + txt + "]\n";
|
||||
}
|
||||
};
|
||||
function executeKraken(code, new_output_name) {
|
||||
output_name = new_output_name
|
||||
document.getElementById(new_output_name).value = "running...\n";
|
||||
Module.callMain(["-C", code]);
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript" src="k_prime.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user