User:Klange/Kuroko
Kuroko is a bytecode-compiled interpreted programming language. It is an independent implementation of a dialect of Python with the addition of declaration statements and C-style block scoping.
History
Kuroko was originally developed in late 2020 / early 2021 as an extension language for the Bim code editor.
Use in Hobby OSes
Kuroko is most notably found in ToaruOS, where it is used as part of the build system, provided as a userspace interpreter, powers a handful of utilities, and is integrated with the Bim text editor.
Kuroko can be built with a very small libc footprint, which makes it suitable as an early port for a new OS. It can also be built to run directly under EFI to run "bare-metal", or compiled to WebAssembly to be hosted in a sandboxed environment.
Language Features
As an implementation of Python, Kuroko has many useful features such as lists, dicts (key-value maps), comprehensions (expressions generating lists and dicts), closures (functions inheriting an environment), lambdas, module imports, "big ints", and mechanisms for asynchronous programming.
Kuroko is garbage collected, with a simple scan-and-sweep collector that does not need to be adapted to new architectures. Kuroko's VM is a straightforward bytecode interpreter with no JIT, and should also be portable to new architectures without additional code changes.
Kuroko's compiler is fast enough that code can be distributed in source form with no need for a bytecode cache. The interpreter also has low cold start costs.
Kuroko can be embedded in host applications as an extension language (both through static linking and as a shared library), and can be extended with C modules to provide wrappers to third-party libraries such as OS-specific windowing interfaces. On platforms without runtime shared library loading, extension modules can be statically built into the interpreter.
Why would I want Kuroko instead of CPython?
If you're looking to run existing Python code, you probably don't want Kuroko. Porting Python code to Kuroko may be possible in the case of code that does not use third-party modules or esoteric metaprogramming tricks, but Kuroko is not intended for this and porting can be a considerable effort of adding variable declarations and tweaking expressions and control flow.
If you are looking to write new code or get an interactive REPL started up early in a new OS, Kuroko may be a viable choice: It is significantly smaller than CPython, while more functional and less reduced than something like MicroPython. It can be built for more restricted environments than CPython, including ones without threading - something that has become a requirement in Python 3.7 and newer.
Can I write an OS in Kuroko?
Probably not without more effort than it is worth. Kuroko is a bytecode-interpreted language, and any interaction with hardware would require additional C code. While Kuroko can be built as an EFI application, extending this to a full OS would be a considerable challenge.