3 ms·
It seems it would be hard to make Oberon the language to play well with "foreign" environments, such as the Java VM and the library. How does one implement inte
by Koshkin 9y ago
It seems it would be hard to make Oberon the language to play well with "foreign" environments, such as the Java VM and the library. How does one implement interfaces, for example?
- lboasso 9y agoYes 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.