C++, Python, JavaScript, and Swift code streams flowing through a processor to analytics dashboardColorful code streams converge through a central processing system into an analytics dashboard.

Many languages. One native application.

An introduction to polyglot compilation, shared libraries and code that works together.

What if choosing a programming language did not mean choosing a separate island of tools, libraries and application code?

MPC V90, the version chosen for MPC’s first beta, brings several languages into one native compiler. A JavaScript module can call a BASIC function. A MimerCode interface can use application logic written in another language. And those languages can reach shared services, including a 3D scene, through their own syntax.

The interesting part is what happens between the languages.

What is a polyglot compiler?

Polyglot means “many languages.” A polyglot compiler understands more than one programming language and translates supported programs into executable code. When it also supports interoperability, modules written in different languages can become parts of the same application.

Think of a team whose members speak different languages but agree on how to exchange information. Each person keeps their language. The shared agreement makes collaboration possible.

MPC has frontends for MimerCode, Object Pascal, C, Python, JavaScript, BASIC, Fortran, Java and C#, plus a CLI/IL input path. Each frontend understands its language’s syntax and rules. The compilation paths converge on a shared, structured Pascal representation, which MPC compiles to native machine code.

Flowchart showing multiple programming languages feeding into language frontends, a shared compilation path, and native applications with matching libraries.

The V90 packages target Windows x64 and Linux x64. Within MPC’s supported language profiles, execution does not require Node.js, CPython, a JVM or the CLR. The application uses MPC’s matching native libraries. These are defined language profiles, so existing framework and package compatibility still depends on the documented support.

A real call between two languages

Start with a small BASIC module, shared_math.bas:

Function Add(ByVal left As Long, ByVal right As Long) As Long
Return left + right
End Function

Now call it from JavaScript in main.js:

import * as math from './shared_math.bas';
console.log(math.Add(19, 23));

The output is 42. The JavaScript import names the BASIC source file, and the call uses ordinary JavaScript member syntax. MPC connects the exported function and its declared parameter and result types. This example needs no web service, JSON message or separate BASIC process.

This is the smallest useful picture of interoperability: code in one language asks code in another language to do some work, passes values, and receives a result.

What crosses the boundary?

A function name is only the beginning. The compiler also needs to know what each argument means, how the result is represented, and whether an argument is a value or a reference to something the callee may change.

For simple numbers and text, that can feel almost invisible. For arrays, objects, callbacks and resources, the contract matters more. Who keeps a value alive? Can the called function modify it? How does an error reach the caller?

MPC’s interoperability machinery carries information about parameter types, reference parameters, result types and error contracts. Its shared library and channel bindings adapt those contracts to the calling language. This lets ordinary calls stay readable while giving the compiler the information needed to connect them correctly.

One library, familiar imports

Interoperability also means being able to use the same facilities without rewriting them in every language. V90 makes MimerCode standard-library modules available through imports in the other MIMER languages.

Here is JavaScript using the shared string and JSON functions:

import { IntToHex } from 'mimer/stdlib/strings';
import { json_parse, json_stringify } from 'mimer/stdlib/data';
console.log(IntToHex(255, 4));
const plan = json_parse('{"visits":3}');
console.log(json_stringify(plan));

Output:

00FF
{"visits":3}

The corresponding string function is available in Python through from mimer.stdlib import strings, in C through <mimer/stdlib/strings.h>, and in Pascal through uses MimerStdLib.Strings;. These bindings call the same library function that MimerCode uses.

Simple values use the language’s own types. Structured values follow its documented binding: JavaScript and Python use their own values, while C exposes a mimer_value * with explicit release. Functions tied to a MimerCode view, such as report rendering, stay in that view context.

Channels bring the application to life

A channel is MPC’s way to work with a resource or service: open it, call its operations, handle its events, and close it. The shared channel system includes facilities for files, HTTP, GIS and Scene3D.

Here is a complete JavaScript example that creates a headless 3D scene, adds a cube, counts it, and cleans up:

import { Scene3dChannel } from 'mimer/channels/scene3d';
const scene = new Scene3dChannel('scene3d://?ticker=html');
const cube = scene.addCube();
console.log(scene.nodeCount());
scene.removeNode(cube);
scene.close();

It prints 1. This example exercises the scene API without opening a visible viewport. The important capability is direct access to Scene3D from JavaScript through its channel class.

Events travel in the other direction too. The supplied JavaScript Scene3D example registers an onFrame function and pumps events until the handler runs. A channel can therefore invoke application code as well as receive calls from it. Resource access remains governed by the application’s security policy.

Putting it together: one application, several languages

The included Harbour example shows the idea at application scale. A shared MimerCode view provides the interface, while language-specific modules supply scheduling rules and data. In the JavaScript variant, a small MimerCode library connects the view’s named functions to JavaScript logic.

Diagram showing MimerCode view and JavaScript rules connected by function calls, results, shared libraries, and channels.


The Harbour pattern: a shared view calls language-specific logic. Libraries and channels provide common services.

The application combines scheduling, visit planning, a workload chart, a map, a 3D site view, local HTTP endpoints and a PDF report. Each part has a role: the view presents information, the rules calculate it, and shared facilities handle the services around them.

That is where a polyglot compiler becomes practical. You can keep a calculation in Fortran, express rules in JavaScript, or build a view in MimerCode, provided the modules expose supported interfaces. A language choice can belong to one part of the application rather than dictate every part of it.

A small place to begin

Put the BASIC and JavaScript files above in the same directory. With the Windows V90 package extracted and a terminal open in that directory, compile them using the package’s compiler and library:

C:\MPC-V90\mpc.exe -r main.js -u C:\MPC-V90\lib\runtime.mca -o hello.exe
.\hello.exe

Replace C:\MPC-V90 with your extraction directory. Then change the BASIC function, rebuild, and see the JavaScript caller use the new result.

From there, try a shared library import or a channel. The central idea stays the same: write each module in a supported language, give it a clear interface, and let MPC connect the parts into a native application.

Examples checked with the packaged MPC V90 compiler on Windows x64. Illustrations are schematic.

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.