The ModulaTor logo 7KB

The ModulaTor

Oberon-2 and Modula-2 Technical Publication

Ubaye's First Independent Modula-2 & Oberon-2 Journal! Nr. 5, Jun-1995


About OM2-XDS

OM2-XDS Eval Kit Review

Written by Georg Bauer, Oct-1994, edited by GD/ModulaWare 28-Oct-1994

0. Setup of OM2-XDS with Watcom C/C++ Compiler

I use OM2-XDS in conjunction with Watcom-C/C++ 10.0. It works quite good. I have been able to create definition-files for several C-header-files. And that's what you have to do, to integrate C-libs into XDS: you only have to write an own definition file (you can map to most of the C-features, but there are some _minor_ problems, like with variable arguments). Then you only have to link the lib with your program and you can use it. I wrote definition files for the graphics-functions of Watcom, for example. And I adopted SDBM (a simple hashfile database) for Watcom-C and integrated it into XDS. Was just 1 hour work (actually the definiton file took only some minutes - porting the unix-source to dos was the bigger problem).

And regarding the portability: Watcom-C can generate programs for DOS32, OS/2 2.x, Win32, Win/NT and Novell/386 - and that are only the 32bit-systems (oh, I left out QNX). So I think XDS plus Watcom-C is the ideal team. I am really happy with this combination. Ok, no integrated Environment, but that's just because I hate those IDEs. But I was able to simply integrate XDS as a Syntax/semantic-checker into BOXER-editor. So you have all advantages of an IDE.

Integration of the C-Compiler works with makefiles. Those are generated by XDS itself, you only have to have a template-file. I created two template-files for XDS, that allows me to create exe-files for dos and lib-files for dos. In connection with 4DOS commandshell and some really simple batches, I have all the comfort of an IDE (plus more!).

Debugging has to be done with the native C-debugger. I had no success to debugg the Oberon-2-Code directly, yet. But I don't consider that a major drawback, because the C-code of XDS is _really_ readable. And I have full control over the code, when I debug the C-source instead of the Oberon-2 Source - big parts of the runtime-support are written in C-macros and C-calls, that are inserted into the code at compile-time. Thats index-checking for example.

To make a conclusion: XDS+Watcom-C is a little work to get them running together, but it is worth every minote. And it is not that complicated.

Georg

PS.: No, I am not related to Modulaware in any way - I am only a happy customer ;-)

[Ed. note: the interface definition modules are listed below.]

1. 16 versus 32 bit integers

Can I mix modules that use M2BASE16 and modules that don't?

I need M2BASE16 to build a .DEF-File for the graphics library of WATCOM/C, as Watcom uses short ints there, and short ints are 16-bit Integers. And without M2BASE16 I have no 16bit- Integers. The generated C-Source makes no problem, as there are different types defined for 16-bit and 32-bit integers - with M2BASE16 XDS generates INT16 types, without it generates INT32 types. But my question is, if XDS itself is able to proper mix those two modules - does XDS see a CARDINAL or INTEGER in a module with M2BASE16 as a different type than the same type in a module without M2BASE16? Because if it doesn't, there may be some runtime-errors by mixing those two types - as assigning an INT32 to an INT16 will loose some significant bits.

2. Opaque types

When I declare a record-type and a pointer to this record and then when I export this pointer-type as opaque type in the .DEF- File, XDS creates a opaque (void *) pointer in the generated .H-file, but also creates the correct pointer-type under the same name in the .C-file. So the C-compiler (most C-compilers will do the same, I think) complains about the incorrect redefinition of the type. But if I define the record- type, a Pointer-type to this record and define another type as simple identic to the pointer-typ, and THEN export this second type opaque, everything goes well.

Some source to clarify this:


  TYPE Rec=RECORD
       i:INTEGER;
    END;
    Ptr=POINTER TO Rec;
    Ptr2=Ptr;
If I export Ptr opaque, I get the redefinition error. If I export Ptr2 opaque, everything goes well.
3. Garbage collector

There was a problem with the garbage collector of Oberon-2. This is why I used Modula-2 only until now. The problem was, that I got a "trap" when calling the garbage collector. But with the new Patch of Watcom-C C/C++ 10.0a it works. Now I can start to evaluate the Oberon-2 of OM2-XDS.

4. Library source code

The unrestricted version of OM2-XDS, does it include the library source in Modula-2?

Answer (ModulaWare): Yes, but only ANSI C sources (for 16 bit and 32 bit compilers) are included. Releasing Modula-2 source would provide our competitors with too much know-how. No other product currently includes the source code of the ISO M2 lib in human readable form (not even in C). Providing C source only is our way of protecting know-how; it's kind of encryption. Hope you understand.

5. Type redefinition

Things like the redefinition of a type will make problems with many C-compilers. And the OM2-XDS developers are really good in avoiding compiler-messages. When compiling the lib of the demo-version, I only got some 8 warnings, that was all! Thats _much_ better than most C- packages, where I sometimes get more warnings than source-lines.



<*+ NOHEADER *> <*+ M2ADDTYPES *> <*+ M2EXTENSIONS *> DEFINITION MODULE [2] Direct; (* These are the Watcom C directory functions. From: Georg_Bauer@ms3.maus.westfalen.de (Georg Bauer) To: 100023.2527@compuserve.com Date: Wed, 23 Nov 94 17:18:00 +0200 *) FROM SYSTEM IMPORT ADDRESS,CARD16,INT16,INT8,BYTE; CONST NAME_MAX=12; _A_NORMAL=0; _A_RDONLY=1; _A_HIDDEN=2; _A_SYSTEM=4; _A_VOLID=8; _A_SUBDIR=16; _A_ARCH=32; <*$< GENTYPEDEF+ *> TYPE DIR=RECORD d_dta: ARRAY[0..20] OF BYTE; d_attr: INT8; d_time: CARD16; d_date: CARD16; d_size: LONGCARD; d_name: ARRAY[0..NAME_MAX] OF CHAR; d_ino: CARD16; d_first: INT8; END; <*$>*> DIRPOINTER=POINTER TO DIR; <*$< GENTYPEDEF- *> _diskfree_t=RECORD total_clusters: CARD16; avail_clusters: CARD16; sectors_per_cluster: CARD16; bytes_per_sector: CARD16; END; <*$>*> PROCEDURE chdir(path: ARRAY OF CHAR): INTEGER; PROCEDURE closedir(dir: DIR): INTEGER; PROCEDURE getcwd(buf: ARRAY OF CHAR;size: CARDINAL); PROCEDURE _getdrive(): CARDINAL; PROCEDURE _getdiskfree(drive: CARDINAL;VAR free: _diskfree_t): CARDINAL; PROCEDURE mkdir(path: ARRAY OF CHAR): INTEGER; PROCEDURE opendir(path: ARRAY OF CHAR): DIRPOINTER; PROCEDURE readdir(dp: DIR): DIRPOINTER; PROCEDURE rmdir(path: ARRAY OF CHAR): INTEGER; END Direct.
<*+ NOHEADER *> <*+ M2ADDTYPES *> <*+ M2EXTENSIONS *> DEFINITION MODULE [2] Graph; (* From: Georg_Bauer@ms3.maus.westfalen.de (Georg Bauer) To: 100023.2527@compuserve.com *) FROM SYSTEM IMPORT ADDRESS,INT16; CONST _MAXRESMODE = -3; (* Modus mit hvchster Auflvsung *) _MAXCOLORMODE = -2; (* graphics mode with most colours *) _DEFAULTMODE = -1; (* restore screen to original mode *) _TEXTBW40 = 0; (* 40 x 25 text, 16 grey *) _TEXTC40 = 1; (* 40 x 25 text, 16/8 color *) _TEXTBW80 = 2; (* 80 x 25 text, 16 grey *) _TEXTC80 = 3; (* 80 x 25 text, 16/8 color *) _MRES4COLOR = 4; (* 320 x 200, 4 color *) _MRESNOCOLOR = 5; (* 320 x 200, 4 grey *) _HRESBW = 6; (* 640 x 200, BW *) _TEXTMONO = 7; (* 80 x 25 text, BW *) _HERCMONO = 11; (* 720 x 350, BW *) _MRES16COLOR = 13; (* 320 x 200, 16 color *) _HRES16COLOR = 14; (* 640 x 200, 16 color *) _ERESNOCOLOR = 15; (* 640 x 350, BW *) _ERESCOLOR = 16; (* 640 x 350, 4 or 16 color *) _VRES2COLOR = 17; (* 640 x 480, BW *) _VRES16COLOR = 18; (* 640 x 480, 16 color *) _MRES256COLOR = 19; (* 320 x 200, 256 color *) _URES256COLOR = 256; (* 640 x 400, 256 color *) _VRES256COLOR = 257; (* 640 x 480, 256 color *) _SVRES16COLOR = 258; (* 800 x 600, 16 color *) _SVRES256COLOR= 259; (* 800 x 600, 256 color *) _XRES16COLOR = 260; (* 1024 x 768, 16 color *) _XRES256COLOR = 261; (* 1024 x 768, 256 color *) _NODISPLAY = -1; (* no display device *) _UNKNOWN = 0; (* unknown adapter/monitor type *) _MDPA = 1; (* monochrome display/printer adapter *) _CGA = 2; (* colour/graphics monitor adapter *) _HERCULES = 3; (* Hercules monochrome adapter card *) _MCGA = 4; (* PS/2 Model 30 monitor *) _EGA = 5; (* enhanced graphics adapter *) _VGA = 6; (* vector graphics array *) _SVGA = 7; (* super VGA *) _MONO = 1; (* regular monochrome *) _COLOR = 2; (* regular color *) _ENHANCED = 3; (* enhanced color *) _ANALOGMONO = 5; (* analog monochrome *) _ANALOGCOLOR = 6; (* analog color *) _GROK = 0; (* no error *) _GRERROR = -1; (* graphics error *) _GRMODENOTSUPPORTED = -2; (* video mode not supported *) _GRNOTINPROPERMODE = -3; (* function n/a in this mode *) _GRINVALIDPARAMETER = -4; (* invalid parameter(s) *) _GRINSUFFICIENTMEMORY = -5; (* out of memory *) _GRFONTFILENOTFOUND = -6; (* can't open font file *) _GRINVALIDFONTFILE = -7; (* font file has invalid format *) _GRNOOUTPUT = 1; (* nothing was done *) _GRCLIPPED = 2; (* output clipped *) _BLACK = 0000000H; _BLUE = 02a0000H; _GREEN = 0002a00H; _CYAN = 02a2a00H; _RED = 000002aH; _MAGENTA = 02a002aH; _BROWN = 000152aH; _WHITE = 02a2a2aH; _GRAY = 0151515H; _LIGHTBLUE = 03F1515H; _LIGHTGREEN = 0153f15H; _LIGHTCYAN = 03f3f15H; _LIGHTRED = 015153fH; _LIGHTMAGENTA = 03f153fH; _YELLOW = 0153f3fH; _BRIGHTWHITE = 03f3f3fH; _GOR = 0; _GAND = 1; _GPRESET = 2; _GPSET = 3; _GXOR = 4; _GCLEARSCREEN = 0; _GVIEWPORT = 1; _GWINDOW = 2; _GBORDER = 2; _GFILLINTERIOR = 3; _GCURSOROFF = 0; _GCURSORON = 1; _GWRAPOFF = 0; _GWRAPON = 1; _NORMAL = 0; _LEFT = 1; _CENTER = 2; _RIGHT = 3; _TOP = 1; _CAPT = 2; _HALF = 3; _BASE = 4; _BOTTOM = 5; _PATH_RIGHT = 0; _PATH_LEFT = 1; _PATH_UP = 2; _PATH_DOWN = 3; _GSCROLLUP = 1; _GSCROLLDOWN = -1; _MAXTEXTROWS = -1; TYPE xycoord=RECORD (* normale Grafik-Koordinaten *) xcoord: INT16; ycoord: INT16; END; wxycoord=RECORD (* Window-Coordinaten (Weltsystem) *) xcoord: LONGREAL; ycoord: LONGREAL; END; rccoord=RECORD (* Spalten/Zeilen Koordinaten *) row: INT16; col: INT16; END; videoconfig=RECORD (* Struktur fuer GetVideoConfig *) numxpixels: INT16; numypixels: INT16; numtextcols: INT16; numtextrows: INT16; numcolors: INT16; bitsperpixel: INT16; numvideopages: INT16; mode: INT16; adapter: INT16; monitor: INT16; memory: INT16; END; textsettings=RECORD (* Struktur fuer GetTextSettings *) basevectorx: INT16; basevectory: INT16; txpath: INT16; height: INT16; width: INT16; spacing: INT16; horizalign: INT16; vertalign: INT16; END; fontinfo=RECORD (* Struktur fuer GetFontInfo *) type: INT16; ascent: INT16; pixwidth: INT16; pixheight: INT16; avgwidth: INT16; filename: ARRAY[1..81] OF CHAR; facename: ARRAY[1..32] OF CHAR; END; PROCEDURE _setvideomode(mode: INT16): INT16; PROCEDURE _setvideomoderows(mode,rows: INT16): INT16; PROCEDURE _getvideoconfig(VAR vcf: videoconfig); PROCEDURE _grstatus(): INT16; PROCEDURE _setactivepage(page: INT16): INT16; PROCEDURE _getactivepage(): INT16; PROCEDURE _setvisualpage(page: INT16): INT16; PROCEDURE _getvisualpage(): INT16; PROCEDURE _setcolor(c: INT16): INT16; PROCEDURE _getcolor(): INT16; PROCEDURE _setbkcolor(c: LONGCARD): LONGCARD; PROCEDURE _getbkcolor(): LONGCARD; PROCEDURE _remappalette(entry: INT16;rgb: LONGCARD): LONGCARD; PROCEDURE _remapallpalette(rgbtab: ARRAY OF LONGCARD): INT16; PROCEDURE _selectpalette(p: INT16): INT16; PROCEDURE _lineto(x,y: INT16): INT16; PROCEDURE _lineto_w(x,y: LONGREAL): INT16; PROCEDURE _rectangle(fill,x1,y1,x2,y2: INT16): INT16; PROCEDURE _rectangle_w(fill: INT16;x1,y1,x2,y2: LONGREAL): INT16; PROCEDURE _rectangle_wxy(fill: INT16;VAR a,b: wxycoord): INT16; PROCEDURE _arc(x1,y1,x2,y2,x3,y3,x4,y4: INT16): INT16; PROCEDURE _arc_w(x1,y1,x2,y2,x3,y3,x4,y4: LONGREAL): INT16; PROCEDURE _arc_wxy(VAR p1,p2,p3,p4: wxycoord): INT16; PROCEDURE _ellipse(fill,x1,y1,x2,y2: INT16): INT16; PROCEDURE _ellipse_w(fill: INT16;x1,y1,x2,y2: LONGREAL): INT16; PROCEDURE _ellipse_wxy(fill: INT16; VAR p1,p2: wxycoord): INT16; PROCEDURE _pie(fill,x1,y1,x2,y2,x3,y3,x4,y4: INT16): INT16; PROCEDURE _pie_w(fill: INT16;x1,y1,x2,y2,x3,y3,x4,y4: LONGREAL): INT16; PROCEDURE _pie_wxy(fill: INT16;VAR p1,p2,p3,p4: wxycoord): INT16; PROCEDURE _polygon(fill,numpts: INT16;p: ARRAY OF INT16): INT16; PROCEDURE _polygon_w(fill,numpts: INT16;p: ARRAY OF LONGREAL): INT16; PROCEDURE _polygon_wxy(fill,numpts: INT16;p: ARRAY OF wxycoord): INT16; PROCEDURE _floodfill(x,y,stop_color: INT16): INT16; PROCEDURE _floodfill_w(x,y: LONGREAL;stop_color: INT16): INT16; PROCEDURE _setpixel(x,y: INT16): INT16; PROCEDURE _setpixel_w(x,y: INT16): INT16; PROCEDURE _getpixel(x,y: INT16): INT16; PROCEDURE _getpixel_w(x,y: INT16): INT16; PROCEDURE _getarcinfo(VAR start_pt,end_pt,inside_pt: xycoord); PROCEDURE _getcurrentposition(): xycoord; PROCEDURE _getcurrentposition_w(): wxycoord; PROCEDURE _getviewcoord(x,y: INT16): xycoord; PROCEDURE _getviewcoord_w(x,y: LONGREAL): xycoord; PROCEDURE _getviewcoord_wxy(VAR x,y: wxycoord): xycoord; PROCEDURE _getphyscoord(x,y: INT16): xycoord; PROCEDURE _getwindowcoord(x,y: INT16): wxycoord; PROCEDURE _moveto(x,y: INT16): xycoord; PROCEDURE _moveto_w(x,y: LONGREAL): wxycoord; PROCEDURE _setvieworg(x,y: INT16): xycoord; PROCEDURE _setfillmask(mask: ARRAY OF CHAR); PROCEDURE _getfillmask(VAR mask: ARRAY OF CHAR): ADDRESS; PROCEDURE _setlinestyle(style: INT16); PROCEDURE _getlinestyle(): INT16; PROCEDURE _setplotaction(a: INT16): INT16; PROCEDURE _getplotaction(): INT16; PROCEDURE _clearscreen(area: INT16); PROCEDURE _setviewport(x1,y1,x2,y2: INT16); PROCEDURE _setcliprgn(x1,y1,x2,y2: INT16); PROCEDURE _getcliprgn(VAR x1,y1,x2,y2: INT16); PROCEDURE _displaycursor(onoff: INT16): INT16; PROCEDURE _wrapon(onoff: INT16): INT16; PROCEDURE _setwindow(invert: INT16;x1,y1,x2,y2: LONGREAL); PROCEDURE _gettextsettings(VAR ts: textsettings): ADDRESS; PROCEDURE _gettextextent(x,y: INT16;text: ARRAY OF CHAR; VAR concat,extent: xycoord); PROCEDURE _setcharsize(h,w: INT16); PROCEDURE _setcharsize_w(h,w: LONGREAL); PROCEDURE _settextalign(horiz,vert: INT16); PROCEDURE _settextpath(path: INT16); PROCEDURE _settextorient(vecx,vecy: INT16); PROCEDURE _setcharspacing(s: INT16); PROCEDURE _setcharspacing_w(s: LONGREAL); PROCEDURE _grtext(x,y: INT16;text: ARRAY OF CHAR): INT16; PROCEDURE _grtext_w(x,y: LONGREAL;text: ARRAY OF CHAR): INT16; PROCEDURE _settextwindow(x1,y1,x2,y2: INT16); PROCEDURE _outtext(text: ARRAY OF CHAR); PROCEDURE _settextcolor(c: INT16): INT16; PROCEDURE _gettextcolor(): INT16; PROCEDURE _settextposition(x,y: INT16): rccoord; PROCEDURE _gettextposition(): rccoord; PROCEDURE _scrolltextwindow(direction: INT16); PROCEDURE _gettextwindow(VAR x1,y1,x2,y2: INT16); PROCEDURE _gettextcursor(): INT16; PROCEDURE _settextcursor(c: INT16): INT16; PROCEDURE _outmem(f: ADDRESS;amount: INT16); PROCEDURE _settextrows(n: INT16): INT16; PROCEDURE _getimage(x1,y1,x2,y2: INT16;i: ARRAY OF CHAR); PROCEDURE _getimage_w(x1,y1,x2,y2: LONGREAL;i: ARRAY OF CHAR); PROCEDURE _getimage_wxy(VAR p1,p2: wxycoord;i: ARRAY OF CHAR); PROCEDURE _putimage(x1,y1,x2,y2: INT16;i: ARRAY OF CHAR); PROCEDURE _putimage_w(x1,y1,x2,y2: LONGREAL;i: ARRAY OF CHAR); PROCEDURE _imagesize(x1,y1,x2,y2: INT16): LONGCARD; PROCEDURE _imagesize_w(x1,y1,x2,y2: LONGREAL): LONGCARD; PROCEDURE _imagesize_wxy(VAR p1,p2: wxycoord): LONGCARD; PROCEDURE _registerfonts(name: ARRAY OF CHAR): INT16; PROCEDURE _unregisterfonts(); PROCEDURE _setfont(parm: ARRAY OF CHAR): INT16; PROCEDURE _getfontinfo(VAR fi: fontinfo): INT16; PROCEDURE _outgtext(text: ARRAY OF CHAR); PROCEDURE _getgtextextent(text: ARRAY OF CHAR): INT16; PROCEDURE _setgtextvector(x,y: INT16): xycoord; PROCEDURE _getgtextvector(): xycoord; END Graph.
<*+ NOHEADER *> <*+ M2ADDTYPES *> <*+ M2EXTENSIONS *> DEFINITION MODULE [2] io; (* From: Georg_Bauer@ms3.maus.westfalen.de (Georg Bauer) To: 100023.2527@compuserve.com Date: Mon, 28 Nov 94 17:58:00 +0200 These are the Low-Level-IO-Routinen of Watcom C. Most of the functions should also be available with other C compilers, except whose procedure name start with "_". The constants arte from sys/stat.h and fcntl.h. *) FROM SYSTEM IMPORT BYTE; (* symbolic constants for the access function *) CONST R_OK=4; W_OK=2; X_OK=1; F_OK=0; ACCESS_WR=2; ACCESS_RD=4; (* symbolic constants for the lseek function *) SEEK_SET=0; SEEK_CUR=1; SEEK_END=2; (* symbolic constants for stream io *) STDIN_FILENO=0; STDOUT_FILENO=1; STDERR_FILENO=2; STDAUX_FILENO=3; STDPRN_FILENO=4; (* constants from fcntl.h *) O_RDONLY=0; O_WRONLY=1; O_RDWR=2; O_APPEND=16; O_CREAT=32; O_TRUNC=64; O_NOINHERIT=128; O_TEXT=256; O_BINARY=512; O_EXCL=1024; (* constants from sys/stat.h *) (* owner permission *) S_IRWXU=7*8*8; S_IRUSR=4*8*8; S_IWUSR=2*8*8; S_IXUSR=1*8*8; S_IREAD=4*8*8; S_IWRITE=2*8*8; S_IEXEC=1*8*8; (* group permission. same as owner's on PC and PenPoint *) S_IRWXG=7*8; S_IRGRP=4*8; S_IWGRP=2*8; S_IXGRP=1*8; (* other permission. same as owner's on PC and PenPoint *) S_IRWXO=7; S_IROTH=4; S_IWOTH=2; S_IXOTH=1; (* setuid, setgid, and sticky.?always false on PC *) S_ISUID=4*8*8*8; S_ISGID=2*8*8*8; S_ISVTX=1*8*8*8; (* functions for low-level io *) PROCEDURE access(path: ARRAY OF CHAR;mode: INTEGER): INTEGER; PROCEDURE _access(path: ARRAY OF CHAR;mode: INTEGER): INTEGER; PROCEDURE chmod(path: ARRAY OF CHAR;pmode: INTEGER): INTEGER; PROCEDURE chsize(handle: INTEGER;size: LONGINT): INTEGER; PROCEDURE close(handle: INTEGER): INTEGER; PROCEDURE creat(path: ARRAY OF CHAR;pmode: INTEGER): INTEGER; PROCEDURE dup(handle: INTEGER): INTEGER; PROCEDURE _dup(handle: INTEGER): INTEGER; PROCEDURE dup2(handle1: INTEGER;handle2: INTEGER): INTEGER; PROCEDURE eof(handle: INTEGER): INTEGER; PROCEDURE filelength(handle: INTEGER): LONGINT; PROCEDURE _hdopen(handle: INTEGER;mode: INTEGER): INTEGER; PROCEDURE isatty(handle: INTEGER): INTEGER; PROCEDURE lock(handle: INTEGER;offset: LONGINT;nbytes: LONGINT): INTEGER; PROCEDURE lseek(handle: INTEGER;offset: LONGINT;origin: INTEGER): LONGINT; PROCEDURE _lseek(handle: INTEGER;offset: LONGINT;origin: INTEGER): LONGINT; PROCEDURE open(path: ARRAY OF CHAR;oflag: INTEGER;permflag: INTEGER): INTEGER; PROCEDURE _os_handle(handle: INTEGER): INTEGER; PROCEDURE read(handle: INTEGER;VAR buf: ARRAY OF BYTE;len: CARDINAL): INTEGER; PROCEDURE setmode(handle: INTEGER;mode: INTEGER): INTEGER; PROCEDURE sopen(path: ARRAY OF CHAR;oflag: INTEGER;shflag: INTEGER;permflag: INTEGER): INTEGER; PROCEDURE tell(handle: INTEGER): LONGINT; PROCEDURE umask(permission: INTEGER): INTEGER; PROCEDURE unlink(path: ARRAY OF CHAR): INTEGER; PROCEDURE unlock(handle: INTEGER;offset: LONGINT;nbytes: LONGINT): INTEGER; PROCEDURE write(handle: INTEGER;VAR buf: ARRAY OF BYTE;len: CARDINAL): INTEGER; END io.
<*+ NOHEADER *> <*+ M2ADDTYPES *> <*+ M2EXTENSIONS *> DEFINITION MODULE [2] malloc; (* Based-Heaps are not yet supported From: Georg_Bauer@ms3.maus.westfalen.de (Georg Bauer) To: 100023.2527@compuserve.com This is the definitions for malloc.h from Watcom. It's not complete (I left out based heaps), but it is good enough for me. The most important functions was memavl - there is nothing comparable in the [iso m2] standard defs. *) FROM SYSTEM IMPORT ADDRESS,BYTE,INT32,CARD32,int,size_t; CONST _HEAPOK = 0; _HEAPEMPTY = 1; _HEAPBADBEGIN = 2; _HEAPBADNODE = 3; _HEAPEND = 4; _HEAPBADPTR = 5; _USEDENTRY = 0; _FREEENTRY = 1; TYPE _HEAPINFO=RECORD _pentry: ADDRESS; _size: size_t; _useflag: int; END; PROCEDURE alloca(size: size_t): ADDRESS; PROCEDURE __doalloca(size: size_t): ADDRESS; PROCEDURE stackavail(): CARD32; PROCEDURE _heapenable(enabled: int): int; PROCEDURE _heapchk(): int; PROCEDURE _heapset(fill: CARD32): int; PROCEDURE _heapwalk(VAR h: _HEAPINFO): int; PROCEDURE _heapgrow(); PROCEDURE _heapmin(): int; PROCEDURE _heapshrink(): int; PROCEDURE _msize(ptr: ADDRESS): size_t; PROCEDURE _memavl(): size_t; PROCEDURE _memmax(): size_t; PROCEDURE calloc(n: size_t;size: size_t): ADDRESS; PROCEDURE free(ptr: ADDRESS); PROCEDURE malloc(size: size_t): ADDRESS; END malloc.

6. How to use exceptions in Oberon-2 - An Example

(* Oberon-2 *) MODULE exc; (* Ned 01-04-95 02:14pm *)
 
(*
received from Alex, 04-Jan-1995
Guenter Dotzel, ModulaWare
 
  This is an Oberon-2 module for OM2-XDS which shows how to use
  RTS procedures (from module xmRTS) to organize the exception body.
 
  The following text contains 4 samples of using exceptions in Oberon.
  Correspoding procedures in ISO Modula are provided in comments.
 
  Important notes:
     1) The call of "setjmp" must be written directly in
        IF statement. It is not possible to define some procedure
        that calls setjmp and call it in IF.
     2) The call of X2C_REMOVE shall be done at the end
        of procedure.
     3) There are three variants of ending the exceptional
        body:
          3.1. with call of X2C_XON which means that the exception
               will be re-raised in the surrounding context
          3.2. with call of X2C_XRETRY, which corresponds
               to M2 RETRY statement.
          3.3. no ending, which corresponds to RETURN statement
               at the end of exceptional body in M2. In this
               case the exception will not be re-raised.
     4) All RTS procedures used are implemented in the module
        EXCEPTIONS.
 
If you will have any trouble with more complicated examples,
you can write a procedure in M2, translate it to C to find out
how it can be written.
*)
 
IMPORT xmRTS, setjmp, SYSTEM;
 
VAR res: INTEGER;
 
(*
PROCEDURE proc1;
BEGIN
  res:=0; (* procedure body *)
EXCEPT
  res:=1; (* exception body *)
END proc1;
*)
 
PROCEDURE proc1;
  VAR trap: xmRTS.X2C_XHandler_STR;
BEGIN
  xmRTS.X2C_XInitHandler(SYSTEM.VAL(xmRTS.X2C_XHandler,SYSTEM.ADR(trap)));
  IF setjmp.setjmp(trap.buf) < 2 THEN
    res:=0; (*procedure body*)
    xmRTS.X2C_XOFF();
  ELSE
    res:=1; (*exception body*)
    xmRTS.X2C_XON();
  END;
  xmRTS.X2C_XREMOVE();
END proc1;
 
(*
PROCEDURE proc2;
BEGIN
  res:=0; (* procedure body *)
EXCEPT
  res:=1; (* exception body *)
  RETURN
END proc2;
*)
PROCEDURE proc2;
  VAR trap: xmRTS.X2C_XHandler_STR;
BEGIN
  xmRTS.X2C_XInitHandler(SYSTEM.VAL(xmRTS.X2C_XHandler,SYSTEM.ADR(trap)));
  IF setjmp.setjmp(trap.buf) < 2 THEN
    res:=0; (*procedure body*)
    xmRTS.X2C_XOFF();
  ELSE
    res:=1; (*exception body*)
  END;
  xmRTS.X2C_XREMOVE();
END proc2;
 
(*
PROCEDURE proc3;
BEGIN
  res:=0; (* procedure body *)
EXCEPT
  res:=1; (* exception body *)
  RETRY
END proc3;
*)
PROCEDURE proc3;
  VAR trap: xmRTS.X2C_XHandler_STR;
BEGIN
  xmRTS.X2C_XInitHandler(SYSTEM.VAL(xmRTS.X2C_XHandler,SYSTEM.ADR(trap)));
  IF setjmp.setjmp(trap.buf) < 2 THEN
    res:=0; (*procedure body*)
    xmRTS.X2C_XOFF();
  ELSE
    res:=1; (*exception body*)
    xmRTS.X2C_XRETRY();
  END;
  xmRTS.X2C_XREMOVE();
END proc3;
 
(*
PROCEDURE func(i: INTEGER): INTEGER;
BEGIN
  RETURN i DIV i;
EXCEPT
  RETURN -1
END func;
*)
PROCEDURE func(i: INTEGER): INTEGER;
  VAR trap: xmRTS.X2C_XHandler_STR;
    result: INTEGER;
BEGIN
  xmRTS.X2C_XInitHandler(SYSTEM.VAL(xmRTS.X2C_XHandler,SYSTEM.ADR(trap)));
  IF setjmp.setjmp(trap.buf) < 2 THEN
    result:=i DIV i;
    xmRTS.X2C_XOFF();
  ELSE
    result:=-1;
  END;
  xmRTS.X2C_XREMOVE();
  RETURN result
END func;
 
BEGIN
  proc1;
  proc2;
  proc3;
  res:=func(0);
END exc.
From: Georg_Bauer@ms3.maus.westfalen.de (Georg Bauer)

Hi,

> I'm sending you an Oberon-2 module which shows how to use RTS procedures (from module xmRTS) to organize exception body.

I don't have a module xmRTS. Only oberonRTS or X2C. The latter uses the same function-prefix in the C-Source, but does not have XInitHandler. Is there a new version in work, so they have different modules?

But the source does look interesting, maybe I can fill in the missing part.

Ok. The examples do look simple enough ;-) - but I do not have XInitHandler. But I do have XTry - that accepts a X2C_XHandler_STR Variable and returns a boolean. Is this identical to X2C_XInitHandler? When I look at the call to XInitHandler, I see that there is a XHandler_STR whose address is converted to a XHandler. And in X2C.H I see that XTry is defined as a macro that calls XInitHandler and setjmp and compares the setjmp with 2. Riddle solved?

The first example would look like this, right?


MODULE t;

IMPORT X2C;

PROCEDURE TestExc;
VAR h:X2C.X2C_XHandler_STR;
BEGIN
   IF X2C.X2C_XTry(h) THEN
      (* Procedure Body *)
      X2C.XOFF();
   ELSE
      (* Exceptional Body *)
      X2C.XON();
   END;
   X2C.XREMOVE();
END TestExc;

END t.
Looks simple enough - although I would prefer a TRY-RECOVER-syntax for exceptions. But Oberon-2 does not have one. Wirth should have put it into Oberon-2. I think exception-handling is important enough to be defined in the language. And the language constructs involved are really quite simple, so a language wouldn't be overloaded by this feature.

Georg

7. Run-time type information and persistent object support

Written by NED@iisnw.iis.nsk.su

All necessary meta-language facilities are implemented in the module oberonRTS of OM2-XDS.

But there is currently no special library, that supports persistent objects. I am going to write (or to port from Mithril) several libraries, including persistent object, but not in this version.

Below is the sketch of such library.



TYPE Obj = POINTER TO ObjDesc; ObjDesc = RECORD PROCEDURE (o: Obj) Load(f: File); (* load object attributes *) PROCEDURE (o: Obj) Store(f: File); (* store object attributes *) END; PROCEDURE Store(o: Obj; f: File); VAR t: oberonRTS.Type; m: oberonRTS.Module; BEGIN ASSERT(o#NIL); t:=oberonRTS.TypeOf(o); m:=oberonRTS.ModuleOf(t); oberonRTS.NameOfModule(t,name); WriteString(f,name); Write(f,0X); oberonRTS.NameOfType(t,name); WriteString(f,name); Write(f,0X); o.Store(f); END Store; PROCEDURE Load(VAR o: Obj; f: File); VAR t: oberonRTS.Type; m: oberonRTS.Module; BEGIN ReadString(f,name); m:=oberonRTS.Search(name); IF m = NIL THEN error .... ELSE ReadString(f,name); t:=oberonRTS.ThisType(m,name); IF t = NIL THEN error .... ELSE o:=oberonRTS.NewObj(t); o.Load(f); END; END; END Load;

IMPRESSUM: The ModulaTor is an unrefereed journal. Technical papers are to be taken as working papers and personal rather than organizational statements. Items are printed at the discretion of the Editor based upon his judgement on the interest and relevancy to the readership. Letters, announcements, and other items of professional interest are selected on the same basis. Office of publication. The Editor of The ModulaTor is Günter Dotzel; he can be reached at mailto:[email deleted due to spam]

Home | Site_index | Legal | OpenVMS_compiler | Alpha_Oberon_System | ModulaTor | Bibliography | Oberon[-2]_links | Modula-2_links |

Amazon.com [3KB] [Any browser]

Books Music Video Enter keywords...


Amazon.com logo

Webdesign by www.otolo.com/webworx, 16-Dec-1998