#scripting #scripting-language #koto #language

koto_bytecode

The bytecode compiler used by the Koto programming language

14 releases (breaking)

0.12.0 Oct 18, 2023
0.11.0 Jul 14, 2022
0.10.0 Dec 2, 2021
0.9.1 Nov 1, 2021
0.5.0 Dec 17, 2020

#186 in Programming languages

Download history 23/week @ 2023-11-26 8/week @ 2023-12-03 9/week @ 2023-12-10 46/week @ 2023-12-17 19/week @ 2023-12-24 44/week @ 2023-12-31 18/week @ 2024-01-07 20/week @ 2024-01-14 6/week @ 2024-01-21 16/week @ 2024-02-04 23/week @ 2024-02-11 22/week @ 2024-02-18 43/week @ 2024-02-25 26/week @ 2024-03-03 32/week @ 2024-03-10

130 downloads per month
Used in 11 crates (2 directly)

MIT license

400KB
9K SLoC

Koto


Docs Crates.io CI Discord

Koto is an embeddable scripting language developed in Rust. Prioritizing speed and ease of use, its goal is to be an ideal option for adding scripting support to Rust applications.

During its early development there was a focus on interactive systems, such as rapid iteration during game development, but Koto is versatile enough to be useful in a wide range of applications.

Current State

...I think we're getting somewhere?

The language is close to feature complete from my perspective, but it hasn't been used in enough real-world projects for me to suggest that anyone else should use it for anything serious. In particular, you can expect breaking changes to the language, although these are now becoming less frequent.

That said, your feedback is invaluable to Koto's development. If you decide to try it out, please let me know how you get on.

Getting Started

See the Getting Started section of the language guide.

Reference documentation for Koto's core library can be found here.

You're also welcome to reach out in Discussions, or on Discord.

A Quick Tour

## Strings
name = 'Koto'
print 'Hello, $name!'
# -> Hello, Koto!

## Functions
square = |n| n * n
print '8 squared is ${square 8}'
# -> 8 squared is 64

add_squares = |a, b| (square a) + (square b)
assert_eq (add_squares 2, 4), 20

## Iterators, Ranges, and Lists
fizz_buzz = 
  (1..100)
    .keep |n| (10..=15).contains n
    .each |n|
      match n % 3, n % 5
        0, 0 then 'Fizz Buzz'
        0, _ then 'Fizz'
        _, 0 then 'Buzz'
        else n
    .to_list()
print fizz_buzz
# -> ['Buzz', 11, 'Fizz', 13, 14, 'Fizz Buzz']

## Maps and tuples

### Maps can be defined with curly braces
fruits = {peaches: 42, pears: 99}

### Maps can also be defined using indented `key: value` pairs
more_fruits = 
  apples: 123
  plums: 99

fruits.extend more_fruits
print fruits.keys().to_tuple(),
# -> ('peaches', 'pears', 'apples', 'plums')

fruit, amount = fruits.max |(_, amount)| amount
print 'The highest amount of fruit is: $amount $fruit'
# -> The highest amount of fruit is: 123 apples

Learning the Language

The language guide and core library reference give an overview of Koto's features.

Rendered versions of the docs are available on the Koto website.

There are also some code examples that are a good starting point for getting to know the language.

Installation

The most recent release of the Koto CLI can be installed with Cargo:

cargo install koto_cli

To build and install the latest version of the CLI from source:

cargo install --path core/cli

Language Goals

  • A clean, minimal syntax designed for coding in creative contexts.
  • Fast compilation.
    • The lexer, parser, and compiler are all written with speed in mind, enabling as-fast-as-possible iteration when working on an idea.
  • Fast and predictable runtime performance.
    • Memory allocations are reference counted.
    • Currently there's no tracing garbage collector (and no plan to add one) so memory leaks are possible if cyclic references are created.
  • Lightweight integration into host applications.
    • One of the primary use cases for Koto is for it to be embedded as a library in other applications, so it should be a good citizen and not introduce too much overhead.

Editor Support

MSRV

Koto is still under active development, and is tested against the latest stable release of Rust.


lib.rs:

Contains Koto's compiler and its bytecode operations

Dependencies

~0.6–1.1MB
~25K SLoC