RustPython 是一个用Rust写的Python解释器(Interpreter),目前热度GitHub 上有 6.7k 的Star,并118个人查看。
 
 
RustPython需要很稳定版本(2020年5月24日的1.43.0),那么如何检查Rust版本:rustc --version,如果想要更新, rustup update stable小伙伴。
 
 
 
 
要在本地构建RustPython,并且执行以下操作哦:
 
  $ git clone https://github.com/RustPython/RustPython $ cd RustPython   # if you're on windows: $ powershell scripts\symlinks-to-hardlinks.ps1   # --release is needed (at least on windows) to prevent stack overflow $ cargo run --release demo.py Hello, RustPython! 
 
 
还可以使用交互式的外壳。
 
  $ cargo run --release Welcome to rustpython >>>>> 2+2 4 
 
 
除此之外,还可以进行下命令安装和运行RustPython:
 
 
  $ cargo install rustpython $ rustpython Welcome to the magnificent Rust Python interpreter >>>>> 
 
或者也可以经过conda包管理器:
 
  $ conda install rustpython -c conda-forge $ rustpython 
 
 
除了在本地进行运行以外的话,还可以让RustPython编译为独立WebAssembly WASI模块,这样就能够运用在任何地方。
 
 
  $ wapm安装rustpython$ wapm运行rustpython>>>>> 2 + 24 
 
 
构建WebAssembly WASI文件:
 
  cargo build --release --target wasm32-wasi --features="freeze-stdlib" 
 
 
 注意:使用将该freeze-stdlib标准库包含在二进制文件中。
 
 
 
RustPython有一个非常试验性的JIT编译器,可将python函数编译为本地代码。
 
 
默认情况下,不启用JIT编译器,而JIT编译器是通过jitcargo功能启用的。
 
  $ cargo run --features jit 
 
这需要安装autoconf,automake,libtool和clang。
 
 
编译函数,请__jit__()对其进行调用。
 
  def  foo():     a  =  5     返回 10  +  a富。__jit__()   #这会将foo编译为本机代码,随后的调用将执行该本机代码assert  foo()==  15 
 
 
以上介绍里面部分示列哦,需要的小伙伴可以进Github相关了解更多信息哦,在这里附上项目链接:https://github.com/RustPython/RustPython