klvm-tools-rs


Nameklvm-tools-rs JSON
Version 0.1.44 PyPI version JSON
download
home_pagehttps://prozacchiwawa.github.io/klvm_tools_rs/
Summarytools for working with chiklisp language; compiler, repl, python and wasm bindings
upload_time2024-07-27 12:59:25
maintainerNone
docs_urlNone
authorArt Yerkes <art.yerkes@gmail.com>
requires_pythonNone
licenseApache-2.0
keywords chik chiklisp klvm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            klvm_tools_rs
=

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

    cargo install klvm_tools_rs

or via pip

    pip install klvm_tools_rs@git+https://github.com/Chik-Network/klvm_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/Chik-Network/klvm_tools_rs/tree/nightly)

To install from a specific branch:

    cargo install --no-default-features --git 'https://github.com/Chik-Network/klvm_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/Chik-Network/klvm_tools_rs
    cd klvm_tools_rs
    maturin develop

Install from PYPI:

    pip install -i https://pypi.chiknetwork.com/nightlies/ klvm_tools_rs
    
Most people still compile chiklisp via python.  One way to set up compilation
in that way is like this:

    import json
    from klvm_tools_rs import compile_klvm

    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 + ".klvm.hex")
        sym_file = file_path / (file_stem + ".sym")
        compile_result = compile_klvm(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 KLVM code from chiklisp

    Most commonly, you'll compile chiklisp like this:

      ./target/debug/run -O -i include_dir chiklisp.clsp
    
    'run' outputs the code resulting from compiling the program, or an error.
    
    - repl -- Accepts chiklisp 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 }) }, "klvm raise in (8) (())")
    >>> 

    - cldb -- Stepwise run chiklisp 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: klvm 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 chiklisp
      compiler, instead runs klvm 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 klvm 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 chik's [klvm tools](https://github.com/Chik-Network/klvm_tools/) to rust via the work of
ChikMineJP 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, ChikMineJP).

Some reasons for doing this are:

 - Chik switched the klvm implementation to rust: [klvm_rs](https://github.com/Chik-Network/klvm_rs), and this code may both pick up speed and track klvm 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: [ochiklisp](https://github.com/prozacchiwawa/ochiklisp).

 - 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 klvm_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 chik repo.
                    
    src/compiler <-- a newer compiler (ochiklisp) 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 chik-blockchain
===

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



            

Raw data

            {
    "_id": null,
    "home_page": "https://prozacchiwawa.github.io/klvm_tools_rs/",
    "name": "klvm-tools-rs",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "chik, chiklisp, klvm",
    "author": "Art Yerkes <art.yerkes@gmail.com>",
    "author_email": "Art Yerkes <art.yerkes@gmail.com>",
    "download_url": null,
    "platform": null,
    "description": "klvm_tools_rs\n=\n\nTheory of operation of the modern compiler: ./HOW_CHIKLISP_IS_COMPILED.md\n-\nThis repo can be installed via cargo\n\n    cargo install klvm_tools_rs\n\nor via pip\n\n    pip install klvm_tools_rs@git+https://github.com/Chik-Network/klvm_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/Chik-Network/klvm_tools_rs/tree/nightly)\n\nTo install from a specific branch:\n\n    cargo install --no-default-features --git 'https://github.com/Chik-Network/klvm_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/Chik-Network/klvm_tools_rs\n    cd klvm_tools_rs\n    maturin develop\n\nInstall from PYPI:\n\n    pip install -i https://pypi.chiknetwork.com/nightlies/ klvm_tools_rs\n    \nMost people still compile chiklisp via python.  One way to set up compilation\nin that way is like this:\n\n    import json\n    from klvm_tools_rs import compile_klvm\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 + \".klvm.hex\")\n        sym_file = file_path / (file_stem + \".sym\")\n        compile_result = compile_klvm(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 KLVM code from chiklisp\n\n    Most commonly, you'll compile chiklisp like this:\n\n      ./target/debug/run -O -i include_dir chiklisp.clsp\n    \n    'run' outputs the code resulting from compiling the program, or an error.\n    \n    - repl -- Accepts chiklisp 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 }) }, \"klvm raise in (8) (())\")\n    >>> \n\n    - cldb -- Stepwise run chiklisp 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: klvm 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 chiklisp\n      compiler, instead runs klvm 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 klvm 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 chik's [klvm tools](https://github.com/Chik-Network/klvm_tools/) to rust via the work of\nChikMineJP 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, ChikMineJP).\n\nSome reasons for doing this are:\n\n - Chik switched the klvm implementation to rust: [klvm_rs](https://github.com/Chik-Network/klvm_rs), and this code may both pick up speed and track klvm 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: [ochiklisp](https://github.com/prozacchiwawa/ochiklisp).\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 klvm_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 chik repo.\n                    \n    src/compiler <-- a newer compiler (ochiklisp) 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 chik-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 chiklisp language; compiler, repl, python and wasm bindings",
    "version": "0.1.44",
    "project_urls": {
        "Homepage": "https://prozacchiwawa.github.io/klvm_tools_rs/",
        "Source Code": "https://github.com/Chik-Network/klvm_tools_rs"
    },
    "split_keywords": [
        "chik",
        " chiklisp",
        " klvm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "84d85d89feba5132cba474355a1196c84cf80dcbe1466acaaba90ba173c5291d",
                "md5": "74e7f00929891ad23b09f80ab1618a09",
                "sha256": "433d56b6208585632391b99d967c6335f101281589d2ae2bef682d3999dfe7ea"
            },
            "downloads": -1,
            "filename": "klvm_tools_rs-0.1.44-cp38-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "74e7f00929891ad23b09f80ab1618a09",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 1230757,
            "upload_time": "2024-07-27T12:59:25",
            "upload_time_iso_8601": "2024-07-27T12:59:25.263847Z",
            "url": "https://files.pythonhosted.org/packages/84/d8/5d89feba5132cba474355a1196c84cf80dcbe1466acaaba90ba173c5291d/klvm_tools_rs-0.1.44-cp38-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-27 12:59:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Chik-Network",
    "github_project": "klvm_tools_rs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "klvm-tools-rs"
}
        
Elapsed time: 0.26247s