3 ms·
Yes a custom foreign function interface is needed. In my compiler I did the bare minimum to bootstrap the compiler. Currently you can create a definition module
by lboasso 9y ago
Yes a custom foreign function interface is needed. In my compiler I did the bare minimum to bootstrap the compiler. Currently you can create a definition module that makes the bridge between the Java and Oberon worlds.
For example the Oberon definition below:
DEFINITION MathUtil;
PROCEDURE ln(x : REAL) : REAL;
END MathUtil.
exposes the Java MathUtil.ln() static method:
public class MathUtil {
public static float ln(float x) {
return (float) java.lang.Math.log(x);
}
}
A client module can use now the Java implementation of ln:
MODULE Client;
IMPORT MathUtil;
VAR x: REAL;
BEGIN
x: = MathUtil.ln(2.0);
MathUtil.ln()
END Client;
For a complete example see https://github.com/lboasso/oberonc/tree/master/examples/fern https://github.com/lboasso/oberonc/tree/master/examples/fern
- Koshkin 9y ago> DEFINITION I am not sure, but would a MODULE only containing declarations (and no or empty body) also work, syntactically?
- lboasso 9y agoThe DEFINITION is an extension of my compiler. It sets the compiler in a different mode, accepting only declarations in the source file. You approach would work, but I prefer a new keyword showing the intent of the source file. DEFINITION is for declarations only, to allow Java-Oberon interoperability.