When I started to code the LE inspired storage allocation routines, I soon discovered that some more compiler features are needed to make this task more fun. In fact, I borrowed some features from the C language and added them to Stanford Pascal in a sensible way (I hope), so that the overall spirit of the language will not be compromised.
The features added in this sprint include
new function ADDR to get the address of any variable; the result of this function is a pointer without type, similar to the NIL pointer, which is compatible with every other pointer type
new function PTRADD to add an integer expression to a pointer (of any type) - this adds addresses in contrast to C, where element sizes are added
new function PTRDIFF, that subtracts two pointers (of any type), giving an integer result
new function SIZEOF, which works much the same as the C function of the same name; as with C, you can specify a variable as argument or a type identifier
new function PTR2INT, which converts a pointer to an integer value; this is not really needed, but it was good for testing the other functions - in fact there were some problems due to some optimizations that lead to wrong results in the first shot; I had to implement two new P-Code instructions ADA and SBA to overcome these problems (ADA = add integer to address, SBA = subtract addresses)
Here is an example program that shows the new features:
|
Note: the type SHOWPTR shows how you could do pointer arithmetic before my extensions (it is indeed done this way in SNAPSHOT and other system related routines). I used it to test the results.
The A+ switch tells the P-Code translator to output ASSEMBLER code in addition to the binary 370 code to file ASMOUT, which proved to be very useful when doing these changes and implementing the new P-Code instructions.
When adding the new functions, I also improved the compiler (PASCAL1), so that future additions of new library functions are still easier (improved table layout of the internal compiler tables).