Skip to content
A source-to-source transpiler to convert Clojure to multiple target languages (Rust, C++, Java, ...)
Clojure
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples/a [cli] Adds a command line interface for compiling Mar 26, 2020
src/kalai
test/kalai
.gitignore
README.md
project.clj

README.md

Kalai Transpiler

Kalai transpiler is a source-to-source transpiler to convert Clojure to multiple target languages (Rust, C++, Java, ...).

The goal of Kalai is to allow useful algorithms to be encoded once and then automatically be made available natively to other target programming languages.

Rationale

See why Clojure is good for writing transpilers.

Usage

Supported forms

The forms that are currently supported are listed in interface.clj.

Example

If you have code written in your.namespace, then you can emit code as follows, assuming there is a file your/namespace.clj relative to where the program is run:

lein run -i your -o someoutdir -l rust

In this example, an output file will be written to someoutdir/your/namespace.rs.

Example demo 1 has input code at test/kalai/demo/demo01.clj and emitter tests at test/kalai/demo/demo01.clj.

Example demo 2 has input code at test/kalai/demo/demo02.clj and emitter tests at test/kalai/demo/demo02.clj and logic tests at test/kalai/demo/demo02_logic_test.clj.

Implemented target languages

  • Rust
  • C++
  • Java
  • Clojure (Kalai is source compatible with Clojure)

See also kalai.emit.langs/TARGET-LANGS

Development

Extending or adding languages

Clojure supports namespaced keywords to enable the dynamic dispatch fallback hierarchies for multimethods. The namespaced keywords for the target languages follow the Clojure derivation tree:

  • ::l/curlybrace ("curly brace" languages)
    • ::l/rust (Rust)
    • ::l/cpp (C++)
    • ::l/java (Java)

To extend or add implementations, add multimethod definitions in kalai.emit.impl/mylang.clj.

Contributing

Issues and Pull requests welcome!

License

Copyright © 2020 The Kalai Authors.

This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: Unicode License (https://www.unicode.org/license.html).

You can’t perform that action at this time.