19. Interop

Overview

Fantom was founded upon the principle of writing code portable to heterogeneous runtime environments. Today we target three runtimes:

  • Java: use of the Java VM as primary server runtime; interoperability with Java code
  • JavaScript: target browsers and NodeJS; interoperability with JavaScript and TypeScript
  • .NET: legacy, unsupported target for .NET CLR; interoperability with C#

Options

The following options provide different interop pathways:

  • Natives: allows Fantom types/slots to be implemented in native Java or JavaScript
  • JavaFFI: allows Fantom code to call Java APIs directly
  • Java: transpile Fantom to Java source code via
  • JavaScript: transpile Fantom to JavaScript source code
  • JarDist: package Fantom into a Java jar

Also see Fanc.

Java

Fantom targets Java as its primary runtime, especially for server side applications. The Java runtime fully supports multi-threading via Concurrency and Actors. Out of the box, Fantom is designed to run via the Java VM. You can also use JarDist and Fanc to package Fantom pods into a library for use by Java code.

JavaScript

Fantom is designed to cross-compile into JavaScript with TypeScript binding. Primarily this is used to write portable code that can execute in browser front ends. Most of the sys APIs can also be used in NodeJS including the file and zip APIs. Note however that the concurrency APIs that assume multi-threading are not available in JS environments.

C# and .NET

The original Fantom framework targeted Java and .NET/C#. However .NET is not currently supported. Most of the original Fantom APIs are fully working in .NET and the infrastructure is in the place. So with some effort .NET could be brought up to production quality with some effort.