From c34dfc85b14f51c34f96e2209533f6c10dd55e6f Mon Sep 17 00:00:00 2001 From: ChiaMineJP Date: Wed, 1 Dec 2021 09:21:29 +0900 Subject: [PATCH 1/5] Problem with `.as_javascript` with tuples inside tuples and not ending with `0` --- src/as_javascript.ts | 22 +++++++--------------- tests/as_javascript_test.ts | 4 ++++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/as_javascript.ts b/src/as_javascript.ts index b75fa76..a9afd00 100644 --- a/src/as_javascript.ts +++ b/src/as_javascript.ts @@ -1,5 +1,5 @@ import {CastableType, SExp} from "./SExp"; -import {Bytes, Tuple, t} from "./__type_compatibility__"; +import {Bytes, Tuple, t, isList, isBytes} from "./__type_compatibility__"; export type TOpStack = Array<(op_stack: TOpStack, val_stack: TValStack) => unknown>; export type TValStack = Array>; @@ -18,32 +18,24 @@ export function as_javascript(sexp: SExp){ function _make_tuple(op_stack: TOpStack, val_stack: TValStack){ const left = val_stack.pop() as SExp; const right = val_stack.pop() as SExp; - if(right.equal_to(Bytes.NULL)){ + if(isBytes(right) && right.equal_to(Bytes.NULL)){ val_stack.push([left]); } + else if(isList(right)){ + const v = [left].concat(right); + val_stack.push(v); + } else{ val_stack.push(t(left, right)); } } - function _extend_list(op_stack: TOpStack, val_stack: TValStack){ - let left = [val_stack.pop()]; - const right = val_stack.pop(); - left = left.concat(right); - val_stack.push(left as SExp[]); - } - function _as_javascript(op_stack: TOpStack, val_stack: TValStack){ const v = val_stack.pop() as SExp; const pair = v.as_pair(); if(pair){ const [left, right] = pair; - if(right.listp()){ - op_stack.push(_extend_list); - } - else{ - op_stack.push(_make_tuple); - } + op_stack.push(_make_tuple); op_stack.push(_as_javascript); op_stack.push(_roll); op_stack.push(_as_javascript); diff --git a/tests/as_javascript_test.ts b/tests/as_javascript_test.ts index 735d03d..a529b80 100644 --- a/tests/as_javascript_test.ts +++ b/tests/as_javascript_test.ts @@ -42,6 +42,10 @@ test("test_null", () => { check_as_javascript(b("")); }); +test("test_embedded_tuples", () => { + check_as_javascript(t(b("10"), t(t(b("200"), b("300")), b("400")))); +}); + test("test_single_bytes", () => { for(let _=0;_<256;_++){ check_as_javascript(Bytes.from([_])); From ca9e2a8c5056e588ed8d03267150f504e163f9e3 Mon Sep 17 00:00:00 2001 From: ChiaMineJP Date: Thu, 2 Dec 2021 02:30:24 +0900 Subject: [PATCH 2/5] Updated CHANGELOG --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49d502e..c9e2c8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [1.0.9] +This version is compatible with [`389efa3fbe65c77600da63c78d29c0866d292754`](https://github.com/Chia-Network/clvm/tree/2722c78ddb92f067c5025196f397e4d2955f9053) of [clvm](https://github.com/Chia-Network/clvm) + +### Fixed +- Fixed an issue of `as_javascript` with tuples inside tuples and ending with 0 + ## [1.0.8] This version is compatible with [`2722c78ddb92f067c5025196f397e4d2955f9053`](https://github.com/Chia-Network/clvm/tree/2722c78ddb92f067c5025196f397e4d2955f9053) of [clvm](https://github.com/Chia-Network/clvm) @@ -239,6 +245,7 @@ At this version, I've managed to improve test complete time to `79s` -> `2s` by Initial (beta) release. +[1.0.9]: https://github.com/Chia-Mine/clvm-js/compare/v1.0.8...v1.0.9 [1.0.8]: https://github.com/Chia-Mine/clvm-js/compare/v1.0.7...v1.0.8 [1.0.7]: https://github.com/Chia-Mine/clvm-js/compare/v1.0.6...v1.0.7 [1.0.6]: https://github.com/Chia-Mine/clvm-js/compare/v1.0.5...v1.0.6 From 25ba565836f8f2c214b3186c5d4c5a4026fddd0a Mon Sep 17 00:00:00 2001 From: ChiaMineJP Date: Fri, 3 Dec 2021 04:34:43 +0900 Subject: [PATCH 3/5] Updated README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0188064..5e0fd73 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ If you find something not compatible with Python's clvm, please report it to Git ## Compatibility This code is compatible with: -- [`2722c78ddb92f067c5025196f397e4d2955f9053`](https://github.com/Chia-Network/clvm/tree/2722c78ddb92f067c5025196f397e4d2955f9053) of [clvm](https://github.com/Chia-Network/clvm) - - [Diff to the latest clvm](https://github.com/Chia-Network/clvm/compare/2722c78ddb92f067c5025196f397e4d2955f9053...main) +- [`389efa3fbe65c77600da63c78d29c0866d292754`](https://github.com/Chia-Network/clvm/tree/389efa3fbe65c77600da63c78d29c0866d292754) of [clvm](https://github.com/Chia-Network/clvm) + - [Diff to the latest clvm](https://github.com/Chia-Network/clvm/compare/389efa3fbe65c77600da63c78d29c0866d292754...main) - [`f9db7faa370c4743e48be8a9823232e4d906c4d0`](https://github.com/Chia-Network/bls-signatures/tree/f9db7faa370c4743e48be8a9823232e4d906c4d0) of [bls-signatures](https://github.com/Chia-Network/bls-signatures) - [Diff to the latest bls-signatures](https://github.com/Chia-Network/bls-signatures/compare/f9db7faa370c4743e48be8a9823232e4d906c4d0...main) From eb651f7ffb8051640502cc335566f82c1cd07a92 Mon Sep 17 00:00:00 2001 From: ChiaMineJP Date: Fri, 3 Dec 2021 04:36:19 +0900 Subject: [PATCH 4/5] Set version to 1.0.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba75d23..365fe5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clvm", - "version": "1.0.8", + "version": "1.0.9", "author": "ChiaMineJP ", "description": "Javascript implementation of chia lisp", "license": "MIT", From 0817da9c5bbc81c198d0a34875416c8f3335c701 Mon Sep 17 00:00:00 2001 From: ChiaMineJP Date: Fri, 3 Dec 2021 04:37:41 +0900 Subject: [PATCH 5/5] Updated CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9e2c8c..76c4482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## [1.0.9] -This version is compatible with [`389efa3fbe65c77600da63c78d29c0866d292754`](https://github.com/Chia-Network/clvm/tree/2722c78ddb92f067c5025196f397e4d2955f9053) of [clvm](https://github.com/Chia-Network/clvm) +This version is compatible with [`389efa3fbe65c77600da63c78d29c0866d292754`](https://github.com/Chia-Network/clvm/tree/389efa3fbe65c77600da63c78d29c0866d292754) of [clvm](https://github.com/Chia-Network/clvm) ### Fixed - Fixed an issue of `as_javascript` with tuples inside tuples and ending with 0