[Oberon] Oberon compiler futures

Jan Verhoeven jan at verhoeven272.nl
Sun Dec 23 19:17:11 CET 2012


On Sunday 23 December 2012 07:57:53 Srinivas Nayak wrote:
> Dear All,
>
> Is it not possible to call C APIs from Oberon?

In Modula-2 we would call this a FOREIGN MODULE. Something similar is 
also possible in Oberon (I assume).

This is what I once made for the mocka compiler:

-------------------------- Vga.def

FOREIGN MODULE Vga;

TYPE	EGAcolour  = (black, blue, green, cyan, red,    pink,  brown,
		       white, GREY, BLUE, GREEN, CYAN, RED, MAGENTA,
		       YELLOW, WHITE);

PROCEDURE Initialize () : BOOLEAN;
PROCEDURE MaxWidth () : CARDINAL;
PROCEDURE MaxHeight () : CARDINAL;
PROCEDURE Clear;
PROCEDURE SetColour (colour : CARDINAL);
PROCEDURE SetEGAcolour (colour : CARDINAL);
PROCEDURE SetRGB (red, green, blue : CARDINAL);
PROCEDURE DrawLine (x0, y0, dx, dy : CARDINAL);
PROCEDURE Plot (x, y : CARDINAL);
PROCEDURE ThisColour (x, y : CARDINAL) : CARDINAL;
PROCEDURE SetMode (newmode : CARDINAL);
PROCEDURE GetMode () : CARDINAL;
PROCEDURE GetKey (VAR ch : CHAR);
END Vga.

------------------- Vga.c

#include <vga.h>

int   Initialize (void)
{
   if ( vga_init () == 0 )
     return 1;
   else
     return 0;
}

void  SetMode (int newmode) { vga_setmode (newmode); }
int   GetMode (void) { return vga_getcurrentmode (); }
int   MaxWidth (void) { return vga_getxdim (); }
int   MaxHeight (void) { return vga_getydim (); }
void  Clear (void) {vga_clear ();}
void  SetColour (int colour) { vga_setcolor (colour); }
void  SetEGAcolour (int colour)

Etcetera

------------------------

You would now call a function like Vga.SetMode as if it was a true 
Modula-2 function. Which it is, just that the lower source was not in 
Modula-2

-- 
Met vriendelijke groeten,

Jan Verhoeven
http://www.verhoeven272.nl



More information about the Oberon mailing list