Oppolzer - Informatik / Stanford Pascal Compiler


Home       Lebenslauf       Schwerpunkte       Kenntnisse       Seminare       Kunden       Projekte       Produkte       Blog       Stanford Pascal       Kontakt

The Stanford Pascal Compiler / Evolution Steps

Back to Compiler main page

New standard type ANYFILE - VOIDPTR renamed to ANYPTR

Compiler version: 05.2017

I am planning to rewrite parts of the Pascal runtime in Pascal and, as told before, I am working all the time doing extensions to the Pascal runtime, for example working with PDS members on MVS.

What makes things difficult:

the Pascal language defined files as typed files; the files differ by the types of their element. So for example it is not possible to write a function that works for a file of type TEXT (FILE OF CHAR) as well as for a file of type FILE OF INTEGER, even if the function doesn't do anything with respect to the content of the file - e.g. if the function does only ASSIGN file names or member names to the file.

The only solution to this problem until now was: the function had to be implemented by the compiler itself, and the compiler could be tolerant for all types of files.

But I wanted to be able to write such functions as ASSIGN in Pascal, in a library seperate from the compiler.

My solution is:

I added a new standard type ANYFILE to the compiler, much the same way as I added last year a new type VOIDPTR. The type ANYFILE is compatible to every other file type. But, because you cannot assign files using the assignment statement, the only thing you can do: you can call a procedure or function and pass a "normal" file argument to an ANYFILE var parameter. Inside the function, the (somehow) restricted actions on the ANYFILE variable may be executed - for example ASSIGN, or FILEFCB, which gives you access to the file's FCB.

This extension will be present in the next release of the Stanford Pascal compiler; and then the ASSIGN and ASSIGNMEM Procedures, which were limited to TEXT files until now, will be possible for all sorts of files.

BTW: ANYPTR is the new name for VOIDPTR; VOIDPTR will be kept for compatibility reasons. For both ANYPTR and ANYFILE, access to the elements (dereferencing) via the arrow operator is not allowed; this is now flagged by the compiler with two new error messages

187: DEREF NOT ALLOWED WITH ANYPTR TYPE;
188: ACCESS TO FILE BUFFER NOT ALLOWED WITH ANYFILE TYPE.

Here is a short example of a function using the new ANYFILE type:


procedure ASSIGNMEM ( var X : ANYFILE ; MEMBNAME : CHARPTR ; LEN : INTEGER ) ; var FCB : VOIDPTR ; CPT : -> CHAR ; begin (* ASSIGNMEM *) if PLATF = PLATF_UNKNOWN then CHECK_PLATFORM ; if PLATF = PLATF_INTEL then begin end (* then *) else begin FCB := FILEFCB ( X ) ; CPT := PTRADD ( FCB , 40 ) ; MEMSET ( CPT , ' ' , 8 ) ; if MEMBNAME <> NIL then if LEN > 8 then MEMCPY ( CPT , MEMBNAME , 8 ) else MEMCPY ( CPT , MEMBNAME , LEN ) end (* else *) end (* ASSIGNMEM *) ;

this way, ASSIGNMEM is usable for every type of file.

Back to Compiler main page