Skip to content

Commit

Permalink
Merge pull request #32 from Chia-Mine/v1.0.9
Browse files Browse the repository at this point in the history
V1.0.9
  • Loading branch information
ChiaMineJP authored Dec 2, 2021
2 parents a74dccc + 0817da9 commit 8a27f56
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.0.9]
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

## [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)

Expand Down Expand Up @@ -239,6 +245,7 @@ At this version, I've managed to improve test complete time to `79s` -> `2s` by
Initial (beta) release.

<!--[Unreleased]: https://github.com/Chia-Mine/clvm-js/compare/v0.0.1...v0.0.2-->
[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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clvm",
"version": "1.0.8",
"version": "1.0.9",
"author": "ChiaMineJP <[email protected]>",
"description": "Javascript implementation of chia lisp",
"license": "MIT",
Expand Down
22 changes: 7 additions & 15 deletions src/as_javascript.ts
Original file line number Diff line number Diff line change
@@ -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<Bytes|SExp|SExp[]|Tuple<SExp, SExp>>;
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions tests/as_javascript_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([_]));
Expand Down

0 comments on commit 8a27f56

Please sign in to comment.