Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup Node 12
uses: actions/setup-node@v1
- name: Setup Node 16
uses: actions/setup-node@v3
with:
node-version: '12.x'
node-version: 16

- name: Get yarn version
run: echo "yarn_version=$(yarn -v)" >> $GITHUB_ENV
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [0.9.6]
### Changed
- Updated `clvm` to v2.0.0
- Replaced `clvm_rs` with `clvm_wasm`
- Renamed `--experiment-backend` flag to `--backend`
- Now `--backend python` must be `--backend js`
### Added
- Added tests for `div` operator

## [0.9.5]
### Changed
- Updated `clvm` to v1.0.9
Expand Down Expand Up @@ -68,6 +77,7 @@ This version was deleted/unpublished because I published useless uncompiled modu
## [0.1.0] - 2021-06-29
Initial release.

[0.9.6]: https://github.com/Chia-Mine/clvm_tools-js/compare/v0.9.5...v0.9.6
[0.9.5]: https://github.com/Chia-Mine/clvm_tools-js/compare/v0.9.4...v0.9.5
[0.9.4]: https://github.com/Chia-Mine/clvm_tools-js/compare/v0.9.3...v0.9.4
[0.9.3]: https://github.com/Chia-Mine/clvm_tools-js/compare/v0.9.2...v0.9.3
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ See details [here](https://github.com/Chia-Network/clvm_rs/issues/108).

## Compatibility
This code is compatible with:
- [`c23032ee0aa667358564fd876ad78168a61bf595`](https://github.com/Chia-Network/clvm_tools/tree/c23032ee0aa667358564fd876ad78168a61bf595) of [clvm_tools](https://github.com/Chia-Network/clvm_tools)
- [Diff to the latest clvm_tools](https://github.com/Chia-Network/clvm_tools/compare/c23032ee0aa667358564fd876ad78168a61bf595...main)
- [`a6ff35de34308021bdf74dcfae1192838acb378a`](https://github.com/Chia-Network/clvm_rs/tree/a6ff35de34308021bdf74dcfae1192838acb378a) of [clvm_rs@0.1.15](https://github.com/Chia-Network/clvm_rs)
- [Diff to the latest clvm_rs](https://github.com/Chia-Network/clvm_rs/compare/a6ff35de34308021bdf74dcfae1192838acb378a...main)
- [`dca2c8e56917055fd86c93cb408e6e99730f558b`](https://github.com/Chia-Network/clvm_tools/tree/dca2c8e56917055fd86c93cb408e6e99730f558b) of [clvm_tools](https://github.com/Chia-Network/clvm_tools)
- [Diff to the latest clvm_tools](https://github.com/Chia-Network/clvm_tools/compare/dca2c8e56917055fd86c93cb408e6e99730f558b...main)
- [`611a7b8e13d086fb2e674b5501acbfacd9aad687`](https://github.com/Chia-Network/clvm_rs/tree/611a7b8e13d086fb2e674b5501acbfacd9aad687) of [clvm_rs@0.1.15](https://github.com/Chia-Network/clvm_rs)
- [Diff to the latest clvm_rs](https://github.com/Chia-Network/clvm_rs/compare/611a7b8e13d086fb2e674b5501acbfacd9aad687...main)

## Examples
### Command line
Expand All @@ -66,7 +66,7 @@ $ npx clvm_tools brun "(+ 1 (q . 3))" "2"
const clvm_tools = require("clvm_tools");

// You can skip async-initialization below until `op_pubkey_for_exp` or `op_point_add` is called
// or dispatch run/brun command with "--experiment-backend rust" option
// or dispatch run/brun command with "--backend rust" option
await clvm_tools.initialize();

clvm_tools.go("run", "(mod ARGUMENT (+ ARGUMENT 3))");
Expand All @@ -75,7 +75,7 @@ clvm_tools.go("brun", "(+ 1 (q . 3))", "2");
// 5

// use clvm_rs for backend
clvm_tools.go("brun", "(+ 1 (q . 3))", "2", "--time", "--experiment-backend", "rust");
clvm_tools.go("brun", "(+ 1 (q . 3))", "2", "--time", "--backend", "rust");
// assemble_from_ir: 0.00034061598777768154
// to_sexp_f: 0.0005161969661706678
// run_program: 0.0003017840385446391
Expand Down Expand Up @@ -133,7 +133,7 @@ clvm_tools.setPrintFunction(printFn);
Some parts of `clvm_tools`/`clvm` depend on WebAssembly.
For example:
- `op_point_add` and `op_pubkey_for_exp` relies on wasm build of [bls-signatures](https://github.com/Chia-Mine/bls-signatures/tree/npm).
- option `--experiment-backend clvm_rs` for `run` and `brun` commands relies on wasm build of [clvm_rs](https://github.com/Chia-Network/clvm_rs)
- option `--backend rust` for `run` and `brun` commands relies on wasm build of [clvm_rs](https://github.com/Chia-Network/clvm_rs)

#### .wasm file installation
In order for those wasm files to be loaded correctly, you need to make sure that the wasm files are stored in the same folder as the main js file, which `clvm_tools` is bundled into.
Expand Down
30 changes: 23 additions & 7 deletions clvm_tools/cmds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ export function launch_tool(args: string[], tool_name: "run"|"brun", default_sta
help: "Output result as data, not as a program"},
);
parser.add_argument(
["--experiment-backend"], {type: "str",
help: "force use of 'rust' or 'python' backend"},
["--backend"], {type: "str", help: "force use of 'rust' or 'js' backend"},
);
parser.add_argument(
["-i", "--include"],
Expand Down Expand Up @@ -288,11 +287,28 @@ export function launch_tool(args: string[], tool_name: "run"|"brun", default_sta
try{
const arg_max_cost = parsedArgs["max_cost"] as number;
const max_cost = Math.max(0, (arg_max_cost !== 0 ? arg_max_cost - cost_offset : 0));
const use_rust = (
tool_name !== "run"
&& !pre_eval_f
&& parsedArgs["experiment_backend"] === "rust"
);

let use_rust = false;
if(parsedArgs["backend"] === "rust"){
use_rust = true;
}
else if(parsedArgs["backend"] === "js"){
use_rust = false;
}
/* // If you uncomment the lines below, the default runtime will be clvm_wasm
else{
const is_stage0 = !(
typeof (parsedArgs["stage"] as typeof stage_2).run_program_for_search_paths === "function"
|| typeof (parsedArgs["stage"] as typeof stage_1).make_invocation === "function"
)

use_rust = (
tool_name !== "run"
&& !pre_eval_f
&& is_stage0
);
}
// */

if(use_rust){
if(input_serialized === None){
Expand Down
2 changes: 1 addition & 1 deletion costs/run-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function run_benchmark_file(fn, existing_results){

const command = [
"node",
`"${commandPath}"`, "brun", "-c", "--quiet", "--time", `--experiment-backend ${useRust ? "rust" : "js"}`,
`"${commandPath}"`, "brun", "-c", "--quiet", "--time", `--backend ${useRust ? "rust" : "js"}`,
`"${toOSPath(fn)}"`, `"${toOSPath(envPath)}"`
].join(" ");
for(let i=0;i<number_of_iterations;i++){
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"typescript"
],
"engines": {
"node": ">=12.22.0"
"node": ">=14.14.0"
},
"dependencies": {
"clvm": "^1.0.9",
"clvm_rs": "^0.1.15"
"clvm": "^2.0.0",
"clvm_wasm": "^0.1.21"
},
"devDependencies": {
"@types/jest": "^26.0.23",
Expand All @@ -53,8 +53,8 @@
"ts-jest": "^27.0.3",
"ts-loader": "^9.2.3",
"typescript": "^4.2.4",
"webpack": "^5.39.1",
"webpack-cli": "^4.7.2"
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"browserslist": [
"edge >= 79",
Expand Down
6 changes: 3 additions & 3 deletions platform/clvm_rs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export function run_clvm(program: Uint8Array, args: Uint8Array) {
const defaultClvmRsWasmPath = (() => {
if(typeof document !== "undefined" && document.currentScript){
const scriptDir = (document.currentScript as HTMLScriptElement).src.replace(/\/[^/]+$/, "");
return scriptDir + "/clvm_rs_bg.wasm";
return scriptDir + "/clvm_wasm_bg.wasm";
}
else{
return "./clvm_rs_bg.wasm";
return "./clvm_wasm_bg.wasm";
}
})();

Expand All @@ -69,7 +69,7 @@ export type TInitOption = {
export async function initialize(option?: TInitOption){
if (typeof window === "undefined") {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require.resolve("clvm_rs/clvm_rs_bg.wasm");
const path = require.resolve("clvm_wasm/clvm_wasm_bg.wasm");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const bytes = require("fs").readFileSync(path);

Expand Down
10 changes: 5 additions & 5 deletions pre_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ if(!fs.existsSync(distDir)){
// clean and create output dir
const npmDir = path.join(__dirname, ".dist", "npm");
if(fs.existsSync(npmDir)){
fs.rmdirSync(npmDir, {recursive: true});
fs.rmSync(npmDir, {recursive: true});
}
fs.mkdirSync(npmDir);

// Copy wasm file
const browserDir = path.join(npmDir, "browser");
if(fs.existsSync(browserDir)){
fs.rmdirSync(browserDir, {recursive: true});
fs.rmSync(browserDir, {recursive: true});
}
fs.mkdirSync(browserDir);
const blsWasmSrcPath = path.join(__dirname, "node_modules", "clvm", "browser", "blsjs.wasm");
Expand All @@ -29,10 +29,10 @@ if(!fs.existsSync(blsWasmSrcPath)){
}
fs.copyFileSync(blsWasmSrcPath, blsWasmDestPath);

const clvmrsWasmSrcPath = require.resolve("clvm_rs/clvm_rs_bg.wasm");
const clvmrsWasmDestPath = path.join(browserDir, "clvm_rs_bg.wasm");
const clvmrsWasmSrcPath = require.resolve("clvm_wasm/clvm_wasm_bg.wasm");
const clvmrsWasmDestPath = path.join(browserDir, "clvm_wasm_bg.wasm");
if(!fs.existsSync(clvmrsWasmSrcPath)){
console.error("clvm_rs_bg.wasm not found at:");
console.error("clvm_wasm_bg.wasm not found at:");
console.error(clvmrsWasmSrcPath);
console.error("Probably you haven't execute npm install yet");
return;
Expand Down
3 changes: 3 additions & 0 deletions tests/brun/div-6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
brun -c '(/ (q . 3) (q . 10))'
cost = 1046
()
3 changes: 3 additions & 0 deletions tests/brun/div-7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
brun -c '(/ (q . -3) (q . 10))'
cost = 1046
()
3 changes: 3 additions & 0 deletions tests/brun/div-8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
brun -c '(/ (q . 3) (q . -10))'
cost = 1046
()
3 changes: 3 additions & 0 deletions tests/brun/div-9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
brun -c '(/ (q . -3) (q . -10))'
cost = 1046
()
2 changes: 1 addition & 1 deletion tests/brun/trace-1.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
brun --experiment-backend javascript -c -v '(+ (q . 10) (f 1))' '(51)'
brun --backend js -c -v '(+ (q . 10) (f 1))' '(51)'
cost = 860
61

Expand Down
2 changes: 1 addition & 1 deletion tests/brun/trace-2.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
brun --experiment-backend javascript -c -v '(x)'
brun --backend js -c -v '(x)'
FAIL: clvm raise ()

(a 2 3) [((x))] => (didn't finish)
Expand Down
2 changes: 1 addition & 1 deletion tests/cmds_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function invoke_tool(cmd_line: string){

const args = shlex.split(cmd_line);
if(use_rust && args[0] === "brun"){
args.push("--experiment-backend", "rust");
args.push("--backend", "rust");
}
const v = console_scripts[args[0] as "run"|"brun"|"opc"|"opd"|"read_ir"](args);

Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
"crypto": false,
},
alias: {
"clvm_rs": false,
"clvm_wasm": false,
},
},
target: ["es5"],
Expand All @@ -46,5 +46,6 @@ module.exports = {
library: ["clvm_tools"],
libraryTarget: "umd",
globalObject: "this",
hashFunction: "xxhash64"
},
};
Loading