clvm-tools-rs


Nameclvm-tools-rs JSON
Version 0.1.42 PyPI version JSON
download
home_pagehttps://prozacchiwawa.github.io/clvm_tools_rs/
Summarytools for working with chialisp language; compiler, repl, python and wasm bindings
upload_time2024-05-01 19:39:00
maintainerNone
docs_urlNone
authorArt Yerkes <art.yerkes@gmail.com>
requires_pythonNone
licenseApache-2.0
keywords chia chialisp clvm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            clvm_tools_rs
=

Theory of operation of the modern compiler: ./HOW_CHIALISP_IS_COMPILED.md
-
This repo can be installed via cargo

    cargo install clvm_tools_rs

or via pip

    pip install clvm_tools_rs@git+https://github.com/Chia-Network/clvm_tools_rs.git@e17412032aa7d3b8b1d1f931893fb5802eee626a

Note: `pip` installs a subset of the tools installed by `cargo`, including `brun`, `run`, `opc` and `opd`.


The most current version of the language is in the nightly branch:

    [nightly](https://github.com/Chia-Network/clvm_tools_rs/tree/nightly)

To install from a specific branch:

    cargo install --no-default-features --git 'https://github.com/Chia-Network/clvm_tools_rs' --branch nightly
    
To install a git checkout into your current python environment (must be in some kind of venv or conda environment):

    git clone https://github.com/Chia-Network/clvm_tools_rs
    cd clvm_tools_rs
    maturin develop

Install from PYPI:

    pip install -i https://pypi.chia.net/nightlies/ clvm_tools_rs
    
Most people still compile chialisp via python.  One way to set up compilation
in that way is like this:

    import json
    from clvm_tools_rs import compile_clvm

    def compile_module_with_symbols(include_paths,source):
        path_obj = Path(source)
        file_path = path_obj.parent
        file_stem = path_obj.stem
        target_file = file_path / (file_stem + ".clvm.hex")
        sym_file = file_path / (file_stem + ".sym")
        compile_result = compile_clvm(source, str(target_file.absolute()), include_paths, True)
        symbols = compile_result['symbols']
        if len(symbols) != 0:
            with open(str(sym_file.absolute()),'w') as symfile:
                symfile.write(json.dumps(symbols))

The command line tools provided:

    - run -- Compiles CLVM code from chialisp

    Most commonly, you'll compile chialisp like this:

      ./target/debug/run -O -i include_dir chialisp.clsp
    
    'run' outputs the code resulting from compiling the program, or an error.
    
    - repl -- Accepts chialisp forms and expressions and produces results
              interactively.
              
    Run like:
    
      ./target/debug/repl
      
    Example session:
    
    >>> (defmacro assert items
       (if (r items)
           (list if (f items) (c assert (r items)) (q . (x)))
         (f items)
         )
       )
    (q)
    >>> (assert 1 1 "hello")
    (q . hello)
    >>> (assert 1 0 "bye")
    failed: CompileErr(Srcloc { file: "*macros*", line: 2, col: 26, until: Some(Until { line: 2, col: 82 }) }, "clvm raise in (8) (())")
    >>> 

    - cldb -- Stepwise run chialisp programs with program readable yaml output.
    
      ./target/debug/cldb '(mod (X) (x X))' '(4)'
      ---
      - Arguments: (() (4))
        Operator: "4"
        Operator-Location: "*command*(1):11"
        Result-Location: "*command*(1):11"
        Row: "0"
        Value: (() 4)
      - Env: "4"
        Env-Args: ()
        Operator: "2"
        Operator-Location: "*command*(1):11"
        Result-Location: "*command*(1):13"
        Row: "1"
        Value: "4"
      - Arguments: (4)
        Failure: clvm raise in (8 5) (() 4)
        Failure-Location: "*command*(1):11"
        Operator: "8"
        Operator-Location: "*command*(1):13"

    - brun -- Runs a "binary" program.  Instead of serving as a chialisp
      compiler, instead runs clvm programs.
    
    As 'brun' from the python code:
    
    $ ./target/debug/run '(mod (X) (defun fact (N X) (if (> 2 X) N (fact (* X N) (- X 1)))) (fact 1 X))'
    (a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))
    $ ./target/debug/brun '(a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))' '(5)'
    120
    
    - opc -- crush clvm s-expression form to hex.
    
    As 'opc' from the python code.
    
    opc '(a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))'
    ff02ffff01ff02ff02ffff04ff02ffff04ffff0101ffff04ff05ff8080808080ffff04ffff01ff02ffff03ffff15ffff0102ff0b80ffff0105ffff01ff02ff02ffff04ff02ffff04ffff12ff0bff0580ffff04ffff11ff0bffff010180ff808080808080ff0180ff018080
    
    - opd -- disassemble hex to s-expression form.
    
    As 'opd' from the python code.
    
    opd 'ff02ffff01ff02ff02ffff04ff02ffff04ffff0101ffff04ff05ff8080808080ffff04ffff01ff02ffff03ffff15ffff0102ff0b80ffff0105ffff01ff02ff02ffff04ff02ffff04ffff12ff0bff0580ffff04ffff11ff0bffff010180ff808080808080ff0180ff018080'
    (a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))

History
=

This is a second-hand port of chia's [clvm tools](https://github.com/Chia-Network/clvm_tools/) to rust via the work of
ChiaMineJP porting to typescript.  This would have been a lot harder to
get to where it is without prior work mapping out the types of various
semi-dynamic things (thanks, ChiaMineJP).

Some reasons for doing this are:

 - Chia switched the clvm implementation to rust: [clvm_rs](https://github.com/Chia-Network/clvm_rs), and this code may both pick up speed and track clvm better being in the same language.
 
 - I wrote a new compiler with a simpler, less intricate structure that should be easier to improve and verify in the future in ocaml: [ochialisp](https://github.com/prozacchiwawa/ochialisp).

 - Also it's faster even in this unoptimized form.

All acceptance tests i've brought over so far work, and more are being added.
As of now, I'm not aware of anything that shouldn't be authentic when running
these command line tools from clvm_tools in their equivalents in this repository

 - opc
 
 - opd
 
 - run
 
 - brun

 - repl
 
argparse was ported to javascript and I believe I have faithfully reproduced it
as it is used in cmds, so command line parsing should work similarly in all three
versions.

The directory structure is expected to be:

    src/classic  <-- any ported code with heritage pointing back to
                     the original chia repo.
                    
    src/compiler <-- a newer compiler (ochialisp) with a simpler
                     structure.  Select new style compilation by
                     including a `(include *standard-cl-21*)`
                     form in your toplevel `mod` form.

Mac M1
===

Use ```cargo build --no-default-features``` due to differences in how mac m1 and
other platforms handle python extensions.

Use with chia-blockchain
===

    # Activate your venv, then
    $ maturin develop --release



            

Raw data

            {
    "_id": null,
    "home_page": "https://prozacchiwawa.github.io/clvm_tools_rs/",
    "name": "clvm-tools-rs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "chia, chialisp, clvm",
    "author": "Art Yerkes <art.yerkes@gmail.com>",
    "author_email": "Art Yerkes <art.yerkes@gmail.com>",
    "download_url": null,
    "platform": null,
    "description": "clvm_tools_rs\n=\n\nTheory of operation of the modern compiler: ./HOW_CHIALISP_IS_COMPILED.md\n-\nThis repo can be installed via cargo\n\n    cargo install clvm_tools_rs\n\nor via pip\n\n    pip install clvm_tools_rs@git+https://github.com/Chia-Network/clvm_tools_rs.git@e17412032aa7d3b8b1d1f931893fb5802eee626a\n\nNote: `pip` installs a subset of the tools installed by `cargo`, including `brun`, `run`, `opc` and `opd`.\n\n\nThe most current version of the language is in the nightly branch:\n\n    [nightly](https://github.com/Chia-Network/clvm_tools_rs/tree/nightly)\n\nTo install from a specific branch:\n\n    cargo install --no-default-features --git 'https://github.com/Chia-Network/clvm_tools_rs' --branch nightly\n    \nTo install a git checkout into your current python environment (must be in some kind of venv or conda environment):\n\n    git clone https://github.com/Chia-Network/clvm_tools_rs\n    cd clvm_tools_rs\n    maturin develop\n\nInstall from PYPI:\n\n    pip install -i https://pypi.chia.net/nightlies/ clvm_tools_rs\n    \nMost people still compile chialisp via python.  One way to set up compilation\nin that way is like this:\n\n    import json\n    from clvm_tools_rs import compile_clvm\n\n    def compile_module_with_symbols(include_paths,source):\n        path_obj = Path(source)\n        file_path = path_obj.parent\n        file_stem = path_obj.stem\n        target_file = file_path / (file_stem + \".clvm.hex\")\n        sym_file = file_path / (file_stem + \".sym\")\n        compile_result = compile_clvm(source, str(target_file.absolute()), include_paths, True)\n        symbols = compile_result['symbols']\n        if len(symbols) != 0:\n            with open(str(sym_file.absolute()),'w') as symfile:\n                symfile.write(json.dumps(symbols))\n\nThe command line tools provided:\n\n    - run -- Compiles CLVM code from chialisp\n\n    Most commonly, you'll compile chialisp like this:\n\n      ./target/debug/run -O -i include_dir chialisp.clsp\n    \n    'run' outputs the code resulting from compiling the program, or an error.\n    \n    - repl -- Accepts chialisp forms and expressions and produces results\n              interactively.\n              \n    Run like:\n    \n      ./target/debug/repl\n      \n    Example session:\n    \n    >>> (defmacro assert items\n       (if (r items)\n           (list if (f items) (c assert (r items)) (q . (x)))\n         (f items)\n         )\n       )\n    (q)\n    >>> (assert 1 1 \"hello\")\n    (q . hello)\n    >>> (assert 1 0 \"bye\")\n    failed: CompileErr(Srcloc { file: \"*macros*\", line: 2, col: 26, until: Some(Until { line: 2, col: 82 }) }, \"clvm raise in (8) (())\")\n    >>> \n\n    - cldb -- Stepwise run chialisp programs with program readable yaml output.\n    \n      ./target/debug/cldb '(mod (X) (x X))' '(4)'\n      ---\n      - Arguments: (() (4))\n        Operator: \"4\"\n        Operator-Location: \"*command*(1):11\"\n        Result-Location: \"*command*(1):11\"\n        Row: \"0\"\n        Value: (() 4)\n      - Env: \"4\"\n        Env-Args: ()\n        Operator: \"2\"\n        Operator-Location: \"*command*(1):11\"\n        Result-Location: \"*command*(1):13\"\n        Row: \"1\"\n        Value: \"4\"\n      - Arguments: (4)\n        Failure: clvm raise in (8 5) (() 4)\n        Failure-Location: \"*command*(1):11\"\n        Operator: \"8\"\n        Operator-Location: \"*command*(1):13\"\n\n    - brun -- Runs a \"binary\" program.  Instead of serving as a chialisp\n      compiler, instead runs clvm programs.\n    \n    As 'brun' from the python code:\n    \n    $ ./target/debug/run '(mod (X) (defun fact (N X) (if (> 2 X) N (fact (* X N) (- X 1)))) (fact 1 X))'\n    (a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))\n    $ ./target/debug/brun '(a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))' '(5)'\n    120\n    \n    - opc -- crush clvm s-expression form to hex.\n    \n    As 'opc' from the python code.\n    \n    opc '(a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))'\n    ff02ffff01ff02ff02ffff04ff02ffff04ffff0101ffff04ff05ff8080808080ffff04ffff01ff02ffff03ffff15ffff0102ff0b80ffff0105ffff01ff02ff02ffff04ff02ffff04ffff12ff0bff0580ffff04ffff11ff0bffff010180ff808080808080ff0180ff018080\n    \n    - opd -- disassemble hex to s-expression form.\n    \n    As 'opd' from the python code.\n    \n    opd 'ff02ffff01ff02ff02ffff04ff02ffff04ffff0101ffff04ff05ff8080808080ffff04ffff01ff02ffff03ffff15ffff0102ff0b80ffff0105ffff01ff02ff02ffff04ff02ffff04ffff12ff0bff0580ffff04ffff11ff0bffff010180ff808080808080ff0180ff018080'\n    (a (q 2 2 (c 2 (c (q . 1) (c 5 ())))) (c (q 2 (i (> (q . 2) 11) (q . 5) (q 2 2 (c 2 (c (* 11 5) (c (- 11 (q . 1)) ()))))) 1) 1))\n\nHistory\n=\n\nThis is a second-hand port of chia's [clvm tools](https://github.com/Chia-Network/clvm_tools/) to rust via the work of\nChiaMineJP porting to typescript.  This would have been a lot harder to\nget to where it is without prior work mapping out the types of various\nsemi-dynamic things (thanks, ChiaMineJP).\n\nSome reasons for doing this are:\n\n - Chia switched the clvm implementation to rust: [clvm_rs](https://github.com/Chia-Network/clvm_rs), and this code may both pick up speed and track clvm better being in the same language.\n \n - I wrote a new compiler with a simpler, less intricate structure that should be easier to improve and verify in the future in ocaml: [ochialisp](https://github.com/prozacchiwawa/ochialisp).\n\n - Also it's faster even in this unoptimized form.\n\nAll acceptance tests i've brought over so far work, and more are being added.\nAs of now, I'm not aware of anything that shouldn't be authentic when running\nthese command line tools from clvm_tools in their equivalents in this repository\n\n - opc\n \n - opd\n \n - run\n \n - brun\n\n - repl\n \nargparse was ported to javascript and I believe I have faithfully reproduced it\nas it is used in cmds, so command line parsing should work similarly in all three\nversions.\n\nThe directory structure is expected to be:\n\n    src/classic  <-- any ported code with heritage pointing back to\n                     the original chia repo.\n                    \n    src/compiler <-- a newer compiler (ochialisp) with a simpler\n                     structure.  Select new style compilation by\n                     including a `(include *standard-cl-21*)`\n                     form in your toplevel `mod` form.\n\nMac M1\n===\n\nUse ```cargo build --no-default-features``` due to differences in how mac m1 and\nother platforms handle python extensions.\n\nUse with chia-blockchain\n===\n\n    # Activate your venv, then\n    $ maturin develop --release\n\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "tools for working with chialisp language; compiler, repl, python and wasm bindings",
    "version": "0.1.42",
    "project_urls": {
        "Homepage": "https://prozacchiwawa.github.io/clvm_tools_rs/",
        "Source Code": "https://github.com/Chia-Network/clvm_tools_rs"
    },
    "split_keywords": [
        "chia",
        " chialisp",
        " clvm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9823c4b372231b7cdf1f9b4d7aae956d4db85775256911313955b746617ec61",
                "md5": "4f7c7f9ede5d113e1c992da7b5e3b1c5",
                "sha256": "07e868ecfdcd5ae263af7e6ebd97bd8cd6211dd71c0060d9ce6917b0e9ce0e81"
            },
            "downloads": -1,
            "filename": "clvm_tools_rs-0.1.42-cp38-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "4f7c7f9ede5d113e1c992da7b5e3b1c5",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 1219079,
            "upload_time": "2024-05-01T19:39:00",
            "upload_time_iso_8601": "2024-05-01T19:39:00.641476Z",
            "url": "https://files.pythonhosted.org/packages/c9/82/3c4b372231b7cdf1f9b4d7aae956d4db85775256911313955b746617ec61/clvm_tools_rs-0.1.42-cp38-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61cd1f6de89f91e720f83a29bdf511dbf8f22cdb89dad76b4823c3070055c1a2",
                "md5": "021ed1aee6072317df11bfd60d35d401",
                "sha256": "3abfa4f4bc7c5f90bcbd17e03ec88ebd6d9d7b1cc8cdd59d1f2d546d2b798516"
            },
            "downloads": -1,
            "filename": "clvm_tools_rs-0.1.42-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "021ed1aee6072317df11bfd60d35d401",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 1477876,
            "upload_time": "2024-05-01T19:39:09",
            "upload_time_iso_8601": "2024-05-01T19:39:09.615769Z",
            "url": "https://files.pythonhosted.org/packages/61/cd/1f6de89f91e720f83a29bdf511dbf8f22cdb89dad76b4823c3070055c1a2/clvm_tools_rs-0.1.42-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-01 19:39:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Chia-Network",
    "github_project": "clvm_tools_rs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "clvm-tools-rs"
}
        
Elapsed time: 0.25850s