Dialect of Python with explicit variable declaration and block scoping, with a lightweight and easy-to-embed bytecode compiler and interpreter.
Go to file
2022-07-03 19:38:04 +09:00
.github (meta) upgrade github codeql workflow 2022-06-02 20:11:34 +09:00
bench (bench) python fasttimer should check for exceptions 2022-06-04 15:34:47 +09:00
docs Scan new src/modules/ directory for Doxygen stuff 2021-04-28 21:26:44 +09:00
modules Add more keywords to the stdlib highlighter 2022-06-03 13:45:12 +09:00
src Exceptions with no argument should not set it to 'None' 2022-07-03 19:38:04 +09:00
test Exceptions with no argument should not set it to 'None' 2022-07-03 19:38:04 +09:00
tools Support more special methods in doc generation 2022-06-29 13:53:31 +09:00
.gitattributes Concede defeat the language identification battle; we're _A_ Python? 2021-03-05 11:39:10 +09:00
.gitignore Ignore .lo files 2021-04-09 21:45:27 +09:00
LICENSE Update copyright years, it's been 2022 for a while now 2022-05-26 20:46:06 +09:00
Makefile Add versions, local Kuroko to benchmark 2022-05-05 08:23:40 +09:00
README.md Invert debugging-related build flags 2021-04-12 12:05:35 +09:00
SECURITY.md Just post an issue report, please. 2021-10-20 09:46:04 +09:00

Kuroko

Kuroko is a dynamic, bytecode-compiled programming language and a dialect of Python. The syntax features indentation-driven blocks, familiar keywords, and explicit variable declaration with block scoping. The runtime interpreter includes a tracing garbage collector, multithreading support without a global lock, and support for single-step debugging and bytecode disassembly. The full interpreter and compiler can be built on Unix-like platforms to a shared library of around 500K and is easy to embed and extend with a clean C API and limited libc footprint. Kuroko has been successfully built for a wide range of targets, including Linux, ToaruOS, WebAssembly, macOS (including M1 ARM devices), and Windows (with mingw64).

Build Kuroko

On most platforms, make is sufficient to build in the standard configuration which will produce both REPL binary (kuroko) with the compiler and interpreter included, as well as both a static (libkuroko.a) and shared library version (libkuroko.so) that can be used for embedding.

Additional build configurations are available with the following options:

  • KRK_DISABLE_RLINE=1: Do not build with support for the rich syntax-highlighted line editor.
  • KRK_DISABLE_DEBUG=1: Do not build support for disassembly. Not recommended, as it does not offer any visible improvement in performance.
  • KRK_DISABLE_DOCS=1: Do not include documentation strings for builtins. Can reduce the library size by around 100KB depending on other configuration options.

Windows

To build for Windows, it is recommended that a Unix-like host environment be used with the MingW64 toolchain:

CC=x86_64-w64-mingw32-gcc make

WASM

WASM builds can be built from kuroko-lang/kuroko-wasm-repl.

Kuroko can be built with the Asyncify option and as a worker.

Fully Static

Normally, the main interpreter binary statically links with the VM library, but is otherwise built as a dynamic executable and links to shared libraries for libc, pthreads, and so on. To build a fully static binary, adding -static to CFLAGS and building only the kuroko target should suffice.

Whether a static build supports importing C extension modules depends on the specifics of your target platform.

Extend and Embed Kuroko

Kuroko is easy to embed in a host application or extend with C modules. Please see the documentation on our website for further information.

Learn Kuroko

If you already know Python, adapting to Kuroko is a breeze.

If you want to get started, try the interactive tutorial.

Supported Functionality

Kuroko supports a wide range of functionality and syntax expected from a Python implementation, and this list is by no means exhaustive:

  • Iteration loops with for
  • list, dict and set comprehensions with chained for expressions and if conditions.
  • Generator expressions and generator functions with yield and yield from.
  • Context managers and with.
  • Exceptions and try/except/finally.
  • Complex assignment targets.
  • Classes with inheritance, general attributes, methods (including static and class methods)
  • Decorators, both for classes and functions.
  • Type hints and other uses of function annotations.
  • Unicode strings.
  • Debugger hooks and instruction stepping.
  • Multithreading.
  • C extension modules.

Python Compatibility

Kuroko aims for wide compatibility with Python 3.x and supports most syntax features and a growing collection of standard library functions. The most notable difference between Kuroko and standard Python is explicit variable declaration and the use of the let keyword. Many Python snippets can be ported to Kuroko with only the addition of declaration statements. Some syntax features remain unimplemented, however:

async for, async with, asyncio module

Kuroko does not support the async for/async with constructs, and does not have a asyncio module. They are planned for a future release.

Iterables

Kuroko iterables do not use the __next__() method, but rather are called normally. This allows iteration objects to be implemented as simple functions. If you are porting code which has a different use of __call__() than __next__() it will likely be necessary to change the implementation. Kuroko also doesn't have a StopIteration exception; iterators return themselves to signal they are exhausted (if you need an iterator to return itself, consider boxing it in a tuple).

Inheritance

Kuroko provides only single inheritance. When porting from Python, mix-in classes and other uses of multiple inheritance may need to be redesigned.

Global/Nonlocal

The scoping system in Kuroko makes the global and nonlocal keywords unnecessary and they are not supported.

Walrus Operator

Kuroko has generalized assignment expressions, so skip the walrus and assign whatever you like (some additional parenthesis wrapping may be necessary to disambiguate assignments).