Skip to content

Files

Latest commit

f2e0839 · Apr 4, 2025

History

History

docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Dec 4, 2024
Apr 12, 2024
Jun 23, 2021
Mar 16, 2023
Sep 11, 2023
Nov 10, 2023
Nov 8, 2024
Nov 9, 2023
Nov 7, 2023
Feb 13, 2023
Jan 25, 2024
Feb 9, 2022
Nov 10, 2023
Oct 23, 2023
Oct 11, 2021
Jul 29, 2024
Jul 29, 2024
Oct 30, 2024
Jul 25, 2024
Oct 11, 2021
Nov 10, 2023
Feb 20, 2025
Apr 18, 2022
Apr 4, 2025
Nov 19, 2024
Nov 23, 2021
Jun 23, 2021
Feb 9, 2022
Jan 10, 2024
Jul 12, 2023
Jun 23, 2021
Aug 11, 2023
Nov 8, 2024
Sep 30, 2021
Sep 30, 2021
layout toc_group link_title permalink
docs
truffle
Truffle Language Implementation Framework
/graalvm-as-a-platform/language-implementation-framework/

Truffle Language Implementation Framework

The Truffle language implementation framework (Truffle) is an open source library for building tools and programming languages implementations as interpreters for self-modifying Abstract Syntax Trees. Together with the open source Graal compiler, Truffle represents a significant step forward in programming language implementation technology in the current era of dynamic languages.

The Truffle artifacts are uploaded to Maven Central - Sonatype{:target="_blank"}. You can use them from your pom.xml file as:

<properties>
    <graalvm.version>24.2.0</graalvm.version> <!-- or any later version -->
</properties>
<dependency>
    <groupId>org.graalvm.truffle</groupId>
    <artifactId>truffle-api</artifactId>
    <version>${graalvm.version}</version> <!-- or any later version -->
</dependency>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.14.0</version>
            <configuration>
                <source>21</source>
                <target>21</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.graalvm.truffle</groupId>
                        <artifactId>truffle-dsl-processor</artifactId>
                        <version>${graalvm.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

Implement Your Language

The Truffle framework allows you to run programming languages efficiently on GraalVM. It simplifies language implementation by automatically deriving high-performance code from interpreters.

Getting Started

We provide extensive Truffle API documentation. Start by looking at the TruffleLanguage class, which you should subclass to start developing a language. Truffle comes with the Graal Compiler and several language implementations as part of GraalVM.

A good way to start implementing your language with Truffle is to fork the SimpleLanguage project and start hacking. SimpleLanguage is a relatively small language implementation, well-documented, and designed to demonstrate most of the Truffle features. You could also try by looking at code in one of the existing open source languages implementations and experiments.

Advanced Topics

Implementing a language using Truffle offers a way to interoperate with other "Truffle" languages. To estimate if your language is a valid polyglot citizen, read about using the Polyglot API-based Test Compatibility Kit. Somewhat related topics worth exploring are Truffle Libraries, as well as how to use them to implement a language interoperability. Languages implemented with Truffle can also be embedded in Java host applications using the Polyglot API.

To better understand how to improve the performance of your language, see the documentation on Profiling Truffle Interpreters and Optimizing Truffle Interpreters. Also, to better understand how to use Truffle's automated monomorphization feature (for example, splitting), look at the related documentation.

Implement Your Tool

With the Truffle framework, you can develop language-agnostic tools such as debuggers, profilers, and other instrumentations. Start with looking at the TruffleInstrument class, which -- similar to TruffleLanguage -- one should subclass to start developing a tool.

If you want to implement your own "Truffle" tool, a good way to start is to fork the SimpleTool project -- like the SimpleLanguage project described above -- and start hacking. SimpleTool is a well-documented, minimalistic code-coverage tool designed to be a starting point for understanding the tool development process using Truffle.

Since tools, developed with Truffle, instrument the language using the same AST-node-based approach, most of the techniques available to language developers, in terms of improving performance, are available to the tool developers as well. This is why it is recommended that you understand how Truffle works from a language developer's perspective to get the maximum out of your tool.

Compatibility

The Truffle API is evolved in a backwards-compatible manner from one version to the next. When an API is deprecated, then it will stay deprecated for at least two GraalVM releases before it will be removed.

As a best practice it is recommended to upgrade Truffle only one version at a time. This way you can increment the version and fix deprecation warnings before continuing to the next version. The deprecated Javadoc tags on the deprecated APIs are designed to be a guide on how to upgrade.

The latest additions and changes can be seen in the changelog.

Modifying Truffle

To understand how to modify Truffle, check this file. If you would like to contribute to Truffle, consult the contribution documentation.