Skip to content

nimpylib/npython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

634 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPython

CI (C/JS Test) CD (play build) docs

Python programming VM implemented in Nim.

Online playground demo Read API Docs
(by compiling Nim to Javascript) Wiki about History

Purpose

  • Fun and practice. Learn both Python and Nim.
  • Serve as a altertive small version of CPython (as of 0.1.1, less than 2MB on release build mode)
  • Used as plugin for those using WASM

How to use

Easiest installation

nimble install npython

Then you can use as if using python, e.g.

npython --version
npython -c "print('hello, NPython')"

Manually Install (e.g. JS backend)

Or you may wanna build for js backend or something else:

prepare
git clone https://github.com/nimpylib/npython.git
cd npython

NPython support C backend and multiply JS backends:

after build passing -h flag to npython and you will see help message

For a binary executable (C backend)
nimble build
bin/npython
For a WASM executable (wasi-sdk backend)
nimble buildWasm
wasmtime --invoke NimMain bin/npython.wasm
For JS backend
  • NodeJS: nimble buildJs -d:nodejs
  • Deno: nimble buildJs -d:deno
  • Browser, prompt&alert-based repl: nimble buildJs -d:jsAlert
  • single page website: nimble buildKarax (requires nimble install karax). This is how online playground runs

Status

Capable of:

  • flow control with if else, while, for, ...
  • function (closure) defination and call. Decorators.
  • builtin print, dir, len, range, tuple, list, dict, exceptions, etc.
  • import such as import foo.
  • raise exceptions, basic try ... except XXXError ... , with detailed traceback message. Assert statement.
  • interactive mode and file mode
  • ...

Check out ./tests to see more examples.

Todo

About

Python interpreter written in Nim (C or Js backend)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors