Skip to content
Hacker-lotPublic

About

Use Python, Rust, C++, Java, and Go together in one program. Conflate handles the data exchange between language blocks.

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

Conflate logo

Conflate

Use the language that fits each part of the job.

Tests

Conflate is an experimental polyglot language that puts Python, C++, Rust, Java, and Go in one .confl file. Each block keeps the syntax and libraries of its language. You choose what crosses a block boundary, and Conflate prepares the entry points and value bridges.

That makes it possible to use the language that fits each part of a small tool: Python for quick data handling and its large ecosystem, Rust for memory-safe parsing and checked arithmetic, C++ for existing native code, and Java for the libraries your project already uses. Go and optional PHP or JavaScript backends fit the same model. Conflate handles the data exchange so you can work on each part without writing a separate wrapper for it.

Python, C++, Rust, Java and Go exchanging a typed value

The polyglot tour runs all five built-in languages and is a compact way to see the syntax. For a more practical first example, start with the Python and Rust orders example.

Languages and extension paths

Languages Integration
Python, C++, Rust, Java, Go Built-in value sharing and cross-language function workers
JavaScript / Node.js Recognized registration with value and function sharing
PHP Optional command-manifest JSON bridge, with value sharing; no cross-language function workers
Other runtimes Command manifests; value sharing requires a bridge for that runtime

The concept is extensible polyglot programming. Different integrations have different capabilities; adding a compiler path alone does not supply a bridge.

Explicit boundaries

@python(out: seed: int)
seed = 40
local_note = "This stays inside the block"

@cpp(in: seed: int; out: answer: int)
int answer = seed.as<int>() + 2;

@python(in: answer: int)
print(answer)  # 42

in names are required inputs; out names are the values a block publishes. Conflate checks their types at runtime and reports boundary failures at the source marker. A missing clause means an empty list. Bare @python and @cpp markers retain the earlier implicit sharing behavior.

Read the language specification, or run typed-pipeline.confl:

python -m pip install -e .
conflate --doctor
conflate --run-source examples/typed-pipeline.confl

Prepare a local build

conflate --build examples/typed-pipeline.confl -o build/typed-pipeline
conflate --run-build build/typed-pipeline

The build directory contains a source snapshot, manifest, and prepared native artifacts. Building does not execute your program. These are local builds for the current environment, not standalone or cross-platform distribution bundles. Python and Conflate remain required, alongside the native runtimes in use.

A quick example

The Python and Rust orders example shows the division of labor Conflate is meant for. Python supplies order rows as strings and formats a configurable report. Rust parses quantities and cents, uses checked arithmetic, and rejects malformed, negative, or overflowing rows. That keeps the input handling flexible while putting the arithmetic and failure cases in a small, memory-safe Rust block.

conflate --run-source examples/rust-python-orders.confl

The example notes show the sample output and explain the validation choices.

Install from source

You need Python 3.11 or newer and a C++20 compiler named g++ or clang++. Programs using other blocks also need their normal tools: rustc, javac plus java, or go. Put the commands on your PATH.

git clone https://github.com/Hacker-lot/conflate.git
cd conflate
python -m pip install -e .

Then try the included example:

cd examples
conflate -c helloWorld.confl
conflate -r helloWorld.exe

What works today

  • Python, C++, Rust, Java, and Go blocks execute from top to bottom.
  • Strings, numbers, booleans, lists, dictionaries, and None cross the boundary.
  • Simple native variables can return to later language blocks.
  • Functions stay callable across blocks. Native workers keep function state until the program exits, and can call back into Python.
  • Register another compiler or enable JavaScript by pointing Conflate at Node.js.
  • Conflate generates entry points, state plumbing, and build commands.
  • Compiled blocks are cached and reused when only input values change.

What does not

  • The generated executable is a launcher, not a standalone binary. It still needs Python, Conflate, and a C++ compiler on the machine where it runs.
  • Native variable discovery is based on straightforward declarations, not full language parsers.
  • Automatic integration needs known language conventions. Other tools can run through a command manifest; full value and function sharing needs a bridge.

Conflate is version 0.4.0, and the format may change.

Call a function across languages

@python
def square(n):
    return n * n

@cpp
std::cout << square(12); // 144

C++ functions, Java methods, Go functions, Rust functions, and registered JavaScript functions can return values to Python too. See examples/functions.confl for a counter that keeps its state while the program switches languages. Calls use JSON messages, so a call across languages costs more than a local function call.

Add a language

conflate --add-language javascript node
conflate --add-language mycpp "C:\Tools\LLVM\bin\clang++.exe"
conflate --list-languages

Now @javascript and @mycpp work in .confl files. No Conflate source edits are needed. Python, g++/clang++, rustc, javac, go, and Node.js are recognized. For an unfamiliar compiler, a command manifest defines how to build and run its source. A compiler executable alone cannot describe an arbitrary language's values or function signatures.

More detail

Read DOCUMENTATION.md for the execution model, supported types, CLI reference, examples, and current limits.

Examples worth trying

Bug reports and small, focused pull requests are welcome. Start with CONTRIBUTING.md.

License

Conflate is released under the MIT License.

About

Use Python, Rust, C++, Java, and Go together in one program. Conflate handles the data exchange between language blocks.

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages