Skip to content

Commit

Permalink
Merge pull request #7 from Chia-Mine/v0.1.6
Browse files Browse the repository at this point in the history
V0.1.6
  • Loading branch information
ChiaMineJP authored Jul 12, 2021
2 parents 8c2f5ff + c3f1c90 commit d63ad17
Show file tree
Hide file tree
Showing 255 changed files with 1,225 additions and 187 deletions.
10 changes: 9 additions & 1 deletion dist/CHANGELOG.md → .dist/npm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Changelog

## [0.1.6]
### Added
- Added license information to README.md
- Added tests and fixed bugs found

## [0.1.5]
### Changed
- Updated to clvm version to 0.0.15
- Updated to clvm version to 0.1.5

## [0.1.4]
### Changed
Expand All @@ -19,6 +24,9 @@
## [0.1.0] - 2021-06-29
Initial release.

[0.1.6]: https://github.com/Chia-Mine/clvm_tools-js/compare/v0.1.5...v0.1.6
[0.1.5]: https://github.com/Chia-Mine/clvm_tools-js/compare/v0.1.4...v0.1.5
[0.1.4]: https://github.com/Chia-Mine/clvm_tools-js/compare/v0.1.2...v0.1.4
[0.1.2]: https://github.com/Chia-Mine/clvm_tools-js/compare/v0.1.0...v0.1.2
[0.1.1]: https://github.com/Chia-Mine/clvm_tools-js/compare/v0.1.0...v0.1.1
[0.1.0]: https://github.com/Chia-Mine/clvm_tools-js/releases/tag/v0.1.0
File renamed without changes.
6 changes: 3 additions & 3 deletions dist/README.md → .dist/npm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ clvm_tools.brun(["brun", "(+ 1 (q . 3))", "2"]);
```


## Original clvm_tools written in python

https://github.com/Chia-Network/clvm_tools
## clvm_tools license
`clvm_tools-js` is based on [clvm_tools](https://github.com/Chia-Network/clvm_tools) with the
[Apache license 2.0](https://github.com/Chia-Network/clvm_tools/blob/main/LICENSE)
File renamed without changes.
4 changes: 2 additions & 2 deletions dist/bin/cli.js → .dist/npm/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("../");
const index_1 = require("../index");
const cmds_1 = require("../clvm_tools/cmds");
const COMMANDS = {
read_ir: cmds_1.read_ir,
Expand All @@ -36,7 +36,7 @@ function main() {
return;
}
// Async load BLS modules
yield __1.initialize();
yield index_1.initialize();
COMMANDS[command](argv);
});
}
File renamed without changes.
File renamed without changes.
12 changes: 9 additions & 3 deletions dist/clvm_tools/NodePath.js → .dist/npm/clvm_tools/NodePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class NodePath {
constructor(index = 1) {
this.as_path = this.as_short_path;
if (index < 0) {
const blob = clvm_1.int_to_bytes(index);
index = clvm_1.int_from_bytes(clvm_1.h(blob.length % 2 ? `0${blob}` : `00${blob}`));
const byte_count = ((-index).toString(2).length + 7) >>> 3;
let hex = (index >>> 0).toString(16);
hex = hex.substring(hex.length - byte_count * 2);
index = parseInt(hex, 16);
}
this._index = index;
}
Expand All @@ -71,7 +73,11 @@ class NodePath {
}
as_short_path() {
const index = this._index;
return clvm_1.int_to_bytes(index);
let hexStr = (index >>> 0).toString(16);
if (index >= 0) {
hexStr = hexStr.length % 2 ? `0${hexStr}` : hexStr;
}
return clvm_1.h(hexStr);
}
add(other_node) {
const composedPath = compose_paths(this.index, other_node.index);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions dist/clvm_tools/clvmc.js → .dist/npm/clvm_tools/clvmc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.find_files = exports.compile_clvm = exports.compile_clvm_text = void 0;
const distutils_1 = require("../__platform__/distutils");
const io_1 = require("../__platform__/io");
const distutils_1 = require("../platform/distutils");
const io_1 = require("../platform/io");
const reader = require("../ir/reader");
const binutils = require("../clvm_tools/binutils");
const binutils = require("./binutils");
const stage_2 = require("../stages/stage_2");
const clvm_1 = require("clvm");
function compile_clvm_text(text, search_paths) {
Expand Down
5 changes: 2 additions & 3 deletions dist/clvm_tools/cmds.d.ts → .dist/npm/clvm_tools/cmds.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { SExp, str, Tuple, Bytes, int } from "clvm";
import { Stream } from "clvm/dist/__type_compatibility__";
import * as stage_0 from "../stages/stage_0";
import * as stage_1 from "../stages/stage_1";
import * as stage_2 from "../stages/stage_2";
import * as stage_2 from "../stages/stage_2/index";
import { TRunProgram } from "../stages/stage_0";
export declare function path_or_code(arg: string): any;
export declare function stream_to_bin(write_f: (f: Stream) => void): Bytes;
export declare type TConversion = (text: str) => Tuple<SExp, str>;
export declare function call_tool(tool_name: str, desc: str, conversion: TConversion, input_args: str[]): void;
export declare function opc(args: string[]): void;
export declare function opd(args: string[]): void;
export declare function stage_import(stage: str): typeof stage_2 | typeof stage_0 | typeof stage_1;
export declare function stage_import(stage: str): typeof stage_2 | typeof stage_0;
export declare function as_bin(streamer_f: (s: Stream) => unknown): Bytes;
export declare function run(args: str[]): -1 | undefined;
export declare function brun(args: str[]): -1 | undefined;
Expand Down
15 changes: 8 additions & 7 deletions dist/clvm_tools/cmds.js → .dist/npm/clvm_tools/cmds.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const reader = require("../ir/reader");
const binutils = require("./binutils");
const debug_1 = require("./debug");
const sha256tree_1 = require("./sha256tree");
const io_1 = require("../__platform__/io");
const io_1 = require("../platform/io");
const __type_compatibility__1 = require("clvm/dist/__type_compatibility__");
const argparse = require("../__platform__/argparse");
const argparse = require("../platform/argparse");
const stage_0 = require("../stages/stage_0");
const stage_1 = require("../stages/stage_1");
const stage_2 = require("../stages/stage_2");
const performance_1 = require("../__platform__/performance");
const print_1 = require("../__platform__/print");
const stage_2 = require("../stages/stage_2/index");
const performance_1 = require("../platform/performance");
const print_1 = require("../platform/print");
function path_or_code(arg) {
try {
if (!io_1.fs_exists(arg) || !io_1.fs_isFile(arg)) {
Expand Down Expand Up @@ -59,7 +59,7 @@ function opc(args) {
return clvm_1.t(sexp, sexp.as_bin().hex());
}
catch (ex) {
console.error(`${ex instanceof Error ? ex.message : JSON.stringify(ex)}`);
print_1.print(`${ex instanceof Error ? ex.message : JSON.stringify(ex)}`);
return clvm_1.t(clvm_1.None, clvm_1.None);
}
}
Expand Down Expand Up @@ -120,6 +120,7 @@ function calculate_cost_offset(run_program, run_script) {
exports.calculate_cost_offset = calculate_cost_offset;
function launch_tool(args, tool_name, default_stage = 0) {
const parser = new argparse.ArgumentParser({
prog: ["clvm_tools", tool_name].join(" "),
description: "Execute a clvm script.",
});
parser.add_argument(["--strict"], { action: "store_true",
Expand Down Expand Up @@ -226,7 +227,7 @@ function launch_tool(args, tool_name, default_stage = 0) {
input_sexp = clvm_1.sexp_from_stream(new __type_compatibility__1.Stream(input_serialized), clvm_1.to_sexp_f);
}
time_parse_input = performance_1.now();
const run_program_result = run_program(run_script, input_sexp, undefined, max_cost, pre_eval_f, parsedArgs["strict"]);
const run_program_result = run_program(run_script, input_sexp, { max_cost, pre_eval_f, strict: parsedArgs["strict"] });
cost = run_program_result[0];
result = run_program_result[1];
time_done = performance_1.now();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions dist/clvm_tools/debug.js → .dist/npm/clvm_tools/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ exports.make_trace_pre_eval = exports.trace_to_table = exports.trace_to_text = e
const clvm_1 = require("clvm");
const sha256tree_1 = require("./sha256tree");
const binutils_1 = require("./binutils");
const io_1 = require("../__platform__/io");
const print_1 = require("../__platform__/print");
const io_1 = require("../platform/io");
const print_1 = require("../platform/print");
exports.PRELUDE = `<html>
<head>
<link rel="stylesheet"
Expand Down Expand Up @@ -88,6 +88,7 @@ function text_trace(disassemble_f, form, symbol, env, result) {
symbol = `${disassemble_f(form)} [${disassemble_f(env)}]`;
}
print_1.print(`${symbol} => ${result}`);
print_1.print("");
}
exports.text_trace = text_trace;
function table_trace(disassemble_f, form, symbol, env, result) {
Expand Down Expand Up @@ -139,7 +140,7 @@ function make_trace_pre_eval(log_entries, symbol_table = clvm_1.None) {
return function pre_eval_f(sexp, args) {
const [_sexp, _args] = [sexp, args].map(_ => clvm_1.SExp.to(_));
if (symbol_table) {
const h = sha256tree_1.sha256tree(sexp).hex();
const h = sha256tree_1.sha256tree(_sexp).hex();
if (!(h in symbol_table)) {
return clvm_1.None;
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function unify_bindings(bindings, new_key, new_value) {
*/
const new_key_str = new_key.decode();
if (new_key_str in bindings) {
if (bindings[new_key_str] !== new_value) {
if (!bindings[new_key_str].equal_to(new_value)) {
return clvm_1.None;
}
return bindings;
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dist/index.d.ts → .dist/npm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from "./clvm_tools/debug";
export * from "./clvm_tools/NodePath";
export * from "./clvm_tools/pattern_match";
export * from "./clvm_tools/sha256tree";
import { TPrinter } from "./__platform__/print";
import { TPrinter } from "./platform/print";
/**
* Change print function. Default is `console.log`.
* If you want to print messages to file, variable or something, you need to change printer function by this function.
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js → .dist/npm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ __exportStar(require("./clvm_tools/debug"), exports);
__exportStar(require("./clvm_tools/NodePath"), exports);
__exportStar(require("./clvm_tools/pattern_match"), exports);
__exportStar(require("./clvm_tools/sha256tree"), exports);
const print_1 = require("./__platform__/print");
const print_1 = require("./platform/print");
const clvm_1 = require("clvm");
/**
* Change print function. Default is `console.log`.
* If you want to print messages to file, variable or something, you need to change printer function by this function.
* @param {(...msg: string[]) => void} printer
*/
function setPrintFunction(printer) {
print_1.setPrinter(printer);
print_1.setStdout(printer);
}
exports.setPrintFunction = setPrintFunction;
/**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 7 additions & 2 deletions dist/ir/reader.js → .dist/npm/ir/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports.read_ir = exports.token_stream = exports.tokenize_sexp = exports.tokeniz
const clvm_1 = require("clvm");
const Type_1 = require("./Type");
const utils_1 = require("./utils");
const for_of_1 = require("../__platform__/for_of");
const for_of_1 = require("../platform/for_of");
function consume_whitespace(s, offset) {
// This also deals with comments
// eslint-disable-next-line no-constant-condition
Expand Down Expand Up @@ -78,6 +78,10 @@ function tokenize_cons(token, offset, stream) {
exports.tokenize_cons = tokenize_cons;
function tokenize_int(token, offset) {
try {
// Don't recognize hex string to int
if (token.slice(0, 2).toUpperCase() === "0X") {
return clvm_1.None;
}
const nToken = +token;
if (isNaN(nToken) || !isFinite(nToken)) {
return clvm_1.None;
Expand All @@ -91,7 +95,7 @@ function tokenize_int(token, offset) {
}
exports.tokenize_int = tokenize_int;
function tokenize_hex(token, offset) {
if (token.slice(0, 2).toLowerCase() === "0x") {
if (token.slice(0, 2).toUpperCase() === "0X") {
try {
token = token.substring(2);
if (token.length % 2 === 1) {
Expand Down Expand Up @@ -192,6 +196,7 @@ function read_ir(s, to_sexp = clvm_1.to_sexp_f) {
const isExecutedOnce = for_of_1.for_of(stream, (value) => {
const [token, offset] = value;
retVal = to_sexp(tokenize_sexp(token, offset, stream));
return "stop";
});
if (!isExecutedOnce) {
throw new SyntaxError("unexpected end of stream");
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion dist/ir/writer.js → .dist/npm/ir/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function* iter_ir_format(ir_sexp) {
if (type === Type_1.Type.CODE.i) {
const bio = new clvm_1.Stream();
clvm_1.sexp_to_stream(utils_1.ir_val(ir_sexp), bio);
const code = bio.getValue().as_word().toString();
const code = bio.getValue().hex();
yield `CODE[${code}]`;
return;
}
Expand Down
8 changes: 4 additions & 4 deletions dist/package.json → .dist/npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clvm_tools",
"version": "0.1.5",
"version": "0.1.6",
"author": "Admin ChiaMineJP <admin@chiamine.jp>",
"description": "Javascript implementation of clvm_tools",
"license": "MIT",
Expand All @@ -15,8 +15,7 @@
"clvm_tools": "./bin/cli.js"
},
"scripts": {
"build": "node pre_build.js && tsc --project tsconfig.json --declarationDir ./build --outDir ./build",
"build:prod": "node pre_build.js --prod && tsc --project tsconfig.json --declarationDir ./dist --outDir ./dist --sourcemap false",
"build": "node pre_build.js && tsc --sourcemap false",
"test": "jest"
},
"keywords": [
Expand All @@ -30,7 +29,7 @@
"node": ">=12.13.0"
},
"dependencies": {
"clvm": "^0.0.15"
"clvm": "^0.0.18"
},
"devDependencies": {
"@types/jest": "^26.0.23",
Expand All @@ -42,6 +41,7 @@
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsdoc": "^30.4.1",
"jest": "^27.0.6",
"shlex": "^2.1.0",
"tmp": "^0.2.1",
"ts-jest": "^27.0.3",
"typescript": "^4.2.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ export declare class ArgumentParser {
add_argument(argName: string[], options?: Partial<TArgOption>): void;
parse_args(args: string[]): Record<string, unknown>;
compileHelpMessages(): string;
/**
* Separate short form argument which doesn't have space character between name and value.
* For example, turn:
* "-x1" => ["-x", "1"]
* "-x 1" => ["-x", "1"]
* "-xxxxx" => ["-x", "xxxx"]
* @param args - arguments passed
*/
normalizeArgs(args: string[]): string[];
}
Loading

0 comments on commit d63ad17

Please sign in to comment.