kuroko/README.md

82 lines
4.9 KiB
Markdown
Raw Normal View History

2021-03-20 10:07:36 +03:00
# <img src="https://kuroko-lang.github.io/logo.png" align="bottom" height="24"> Kuroko
2020-12-26 10:59:43 +03:00
**Kuroko** is a dynamic, bytecode-compiled programming language and a [dialect](#python-compatibility) 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](https://kuroko-lang.github.io/docs/embedding.html) and limited libc footprint. Kuroko has been successfully built for a wide range of targets, including Linux, [ToaruOS](https://github.com/klange/toaruos), WebAssembly, macOS (including M1 ARM devices), and Windows (with mingw64).
2020-12-28 10:08:06 +03:00
2021-03-20 10:07:36 +03:00
## Build Kuroko
2020-12-26 10:59:43 +03:00
2021-03-20 10:07:36 +03:00
On most platforms, `make` is sufficient to build in the standard configuration which will produce a dynamically-linked REPL binary (`kuroko`) and a shared library containing the compiler and bytecode interpreter (`libkuroko.so`).
2021-03-20 10:07:36 +03:00
Addition build configurations are available with the following options:
2021-03-20 10:07:36 +03:00
- `KRK_ENABLE_STATIC=1`: Build a single static binary. This will also disable support for C extension modules.
- `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_ENABLE_BUNDLE=1`: Embed C extension modules (which are normally built as shared objects) into the REPL binary. Generally used with `KRK_ENABLE_STATIC`.
- `KRK_NO_DOCUMENTATION=1`: Do not include documentation strings for builtins. Can reduce the library size by around 100KB depending on other configuration options.
2021-03-20 10:07:36 +03:00
### Windows
2021-03-20 10:07:36 +03:00
To build for Windows, it is recommended that a Unix-like host environment be used with the MingW64 toolchain:
2021-03-20 10:07:36 +03:00
```sh
CC=x86_64-w64-mingw32-gcc make
```
2021-01-07 16:45:52 +03:00
2021-03-20 10:07:36 +03:00
### WASM
2021-01-08 06:12:44 +03:00
2021-03-20 10:07:36 +03:00
WASM builds can be built from [kuroko-lang/kuroko-wasm-repl](https://github.com/kuroko-lang/kuroko-wasm-repl).
2021-01-08 06:12:44 +03:00
2021-03-20 10:07:36 +03:00
Kuroko can be built with the Asyncify option and as a worker.
2021-01-07 16:45:52 +03:00
2021-03-20 10:07:36 +03:00
## Extend and Embed Kuroko
2021-01-07 16:45:52 +03:00
2021-03-20 10:07:36 +03:00
Kuroko is easy to embed in a host application or extend with C modules. Please see [the documentation on our website](https://kuroko-lang.github.io/docs/embedding.html) for further information.
2021-01-08 06:12:44 +03:00
2021-03-20 10:07:36 +03:00
## Learn Kuroko
2021-01-08 06:12:44 +03:00
2021-03-20 10:07:36 +03:00
If you already know Python, adapting to Kuroko is a breeze.
2021-01-08 06:12:44 +03:00
2021-03-20 10:07:36 +03:00
If you want to get started, [try the interactive tutorial](https://kuroko-lang.github.io/?r=y&c=tutorial()).
2021-01-07 16:45:52 +03:00
2021-03-20 10:07:36 +03:00
## Supported Functionality
2021-01-07 16:45:52 +03:00
2021-03-20 10:07:36 +03:00
Kuroko supports a wide range of functionality and syntax expected from a Python implementation, and this list is by no means exhaustive:
2021-03-20 10:07:36 +03:00
- 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.
2021-03-20 10:07:36 +03:00
## Python Compatibility
2021-03-20 10:07:36 +03:00
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:
2021-01-16 12:30:53 +03:00
2021-03-20 10:07:36 +03:00
### Async/Await
2021-01-16 12:30:53 +03:00
2021-03-20 10:07:36 +03:00
Kuroko does not support the `async`/`await` keywords and related `asyncio` module. They are planned for a future release.
2021-01-19 06:38:52 +03:00
2021-03-20 10:07:36 +03:00
### Iterables
2021-01-19 06:38:52 +03:00
2021-03-20 10:07:36 +03:00
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).
2021-01-19 06:38:52 +03:00
2021-03-20 10:07:36 +03:00
### Inheritance
2021-01-19 06:38:52 +03:00
2021-03-20 10:07:36 +03:00
Kuroko provides only _single inheritance_. When porting from Python, mix-in classes and other uses of multiple inheritance may need to be redesigned.
2021-03-20 10:07:36 +03:00
### Global/Nonlocal
2021-03-20 10:07:36 +03:00
The scoping system in Kuroko makes the `global` and `nonlocal` keywords unnecessary and they are not supported.
2020-12-31 06:26:17 +03:00
2021-03-20 10:07:36 +03:00
### Walrus Operator
2021-03-20 10:07:36 +03:00
Kuroko has generalized assignment expressions, so skip the walrus and assign whatever you like (some additional parenthesis wrapping may be necessary to disambiguate assignments).