All Projects → liwt31 → NPython

liwt31 / NPython

Licence: other
(Subset of) Python programming language implemented in Nim

Programming Languages

nim
578 projects
python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to NPython

vonuvoli-scheme
vonuvoli Scheme -- an R7RS interpreter written in Rust focused on systems programming and scripting (i.e. processes, file-system, etc.) with performance and safety in mind
Stars: ✭ 81 (+376.47%)
Mutual labels:  interpreter
clover2
Clover2 can be used as shell. The completion is powerfull like IDE. Also clover2 is a Ruby-like compiler language with static type like Java. This is high performnace. Please see the wiki for details
Stars: ✭ 100 (+488.24%)
Mutual labels:  interpreter
RSqueak
A Squeak/Smalltalk VM written in RPython.
Stars: ✭ 78 (+358.82%)
Mutual labels:  interpreter
mlang
My toy programming languages
Stars: ✭ 36 (+111.76%)
Mutual labels:  interpreter
whilelang
A small programming language created with ANTLR and Scala
Stars: ✭ 29 (+70.59%)
Mutual labels:  interpreter
Garam-Interpreter
"훈민정음은 디자인이다" 가람은 튜링 완전 프로그래밍 언어입니다.
Stars: ✭ 23 (+35.29%)
Mutual labels:  interpreter
fcal
Extensive math expression evaluator library for JavaScript and Node.js
Stars: ✭ 86 (+405.88%)
Mutual labels:  interpreter
MUA-Interpreter
MUA is a functional language for teaching use in Principles of Programming Languages course.
Stars: ✭ 16 (-5.88%)
Mutual labels:  interpreter
minima
A fast, byte-code interpreted language
Stars: ✭ 43 (+152.94%)
Mutual labels:  interpreter
xin
Xin (신/心) is a flexible functional programming language with a tiny core, inspired by Lisp and CSP
Stars: ✭ 20 (+17.65%)
Mutual labels:  interpreter
consize
Consize is a concatenative programming language
Stars: ✭ 27 (+58.82%)
Mutual labels:  interpreter
xstate
State machines and statecharts for the modern web.
Stars: ✭ 21,286 (+125111.76%)
Mutual labels:  interpreter
tiny-lang
tiny-lang — A different programming language. Supports a bunch of spoken languages.
Stars: ✭ 26 (+52.94%)
Mutual labels:  interpreter
klisp
A Lisp written in about 200 lines of Ink, featuring an interactive literate programming notebook
Stars: ✭ 28 (+64.71%)
Mutual labels:  interpreter
pawn-3.2-plus
Pawn scripting language with runtime fixes and improvements
Stars: ✭ 14 (-17.65%)
Mutual labels:  interpreter
color-math
Expressions to manipulate colors.
Stars: ✭ 18 (+5.88%)
Mutual labels:  interpreter
kpspemu
PSP Emulator written in Kotlin for JVM, JS and Native. Can work as PWA.
Stars: ✭ 57 (+235.29%)
Mutual labels:  interpreter
ol
Otus Lisp (Ol in short) is a purely* functional dialect of Lisp.
Stars: ✭ 157 (+823.53%)
Mutual labels:  interpreter
foth
Tutorial-style FORTH implementation written in golang
Stars: ✭ 50 (+194.12%)
Mutual labels:  interpreter
bfloader
🧠 Brainfuck IDE and interpreter in 512 bytes. (boot sector)
Stars: ✭ 41 (+141.18%)
Mutual labels:  interpreter

NPython

(Subset of) Python programming language implemented in Nim, from the compiler to the VM.

Online interactive demo by compiling Nim to Javascript.

Purpose

Fun and practice. Learn both Python and Nim.

Status

Capable of:

  • flow control with if else, while and for
  • basic function (closure) defination and call. Decorators.
  • builtin print, dir, len, range, tuple, list, dict, exceptions and bunch of other simple helper functions
  • list comprehension (no set or dict yet).
  • basic import such as import foo. No alias, no from, etc
  • raise exceptions, basic try ... except XXXError ... , with detailed traceback message. Assert statement.
  • primitive class defination. No inheritance, no metatype, etc
  • interactive mode and file mode

Check out ./tests to see more examples.

How to use

git clone https://github.com/liwt31/NPython.git
cd NPython
nimble c ./Python/python
./Python/python

Todo

  • more features on user defined class
  • builtin compat dict
  • yield stmt
  • better bigint lib

Performance

Nim is claimed to be as fast as C, and indeed it is. According to some primitive micro benchmarks (spin.py and f_spin.py in tests/benchmark/), although NPython is currently 5x-10x slower than CPython 3.7, it is at least in some cases faster than CPython < 2.4. This is already a huge achievement considering the numerous optimizations out there in the CPython codebase and NPython is focused on quick prototyping and lefts many rooms for optimization. For comparison, RustPython0.0.1 is 100x slower than CPython3.7 and uses 10x more memory.

Currently, the performance bottlenecks are object allocation, seq accessing (compared with CPython direct memory accessing). The object allocation and seq accessing issue are basically impossible to solve unless we do GC on our own just like CPython.

Drawbacks

NPython aims for both C and JavaScript targets, so it's hard (if not impossible) to perform low-level address based optimization. NPython currently relies on Nim GC. Frankly speaking it's not satisfactory.

  • The GC uses thread-local heap, makes threading nearly impossible (for Python).
  • The GC can hardly be shared between different dynamic libs, which means NPython can not import extensions written in Nim.

If memory is managed manually, hopefully these drawbacks can be overcomed. Of course that's a huge sacrifice.

License

Not sure. I think it should follow CPython license, but other Python implementations like RustPython use licenses like MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].