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

Improvement on Pascal sets - Part one

Compiler version: 08.2017

The improvement on Pascal sets took longer as expected. In fact I tried far too many changes in one sprint, and so the new version did not run at all. I had to fall back to the previous version and restart work from there, and I had to restructure first some parts of the internal set representation ... and some of the goals have to be moved to a later completion date.

The new version has the following extensions:

- Pascal sets now may have up to 2000 elements (previous 256)
- the internal origin of the set type is still zero
- that is: sets have to be in the range 0 .. 1999
- they may be of char type, integer subrange type, or scalar (aka enum)
- all integer subrange set types are compatible
- no negative integers in sets
- some errors removed and some performance enhancements
- characters and integers inside of set constants may be written in hex and binary notation
(example: 0x0a for integers, x'0a' and B'1111_0000' for characters)
- the PCINT debugger has been improved (type ? for online help)

Further improvements will be done in the next releases (preparations have been done already):

- min and max value of set types not limited to 0 .. 1999
- the origin may be in the range -16.000.000 to +16.000.000 (for integer subranges);
negative integers in sets are possible
- warning on portability issues with hex and binary constants in sets
- run time errors, when assigning out-of-range constants to sets (or sets of other subrange types)
- simpler P-Code instructions for sets
- new release of the P-Code documentation with the reworked set instructions (and other changed P-Code instructions)

The new version of the compiler uses the new feature already; for example: at the end the compiler shows a listing of all error messages issued (by error message type).
Because the maximum error message code is 999 (was 401 before), is it now possible to build a "set of errcode", where errcode is a subrange "1 .. maxerrnr".

The following example shows, how a boolean expression involving IN and a char based set constant is implemented. First you see the (portable) P-Code, and then the resulting machine instructions from the Mainframe variant (generated by the P-Code to 370 translator PASCAL2.PAS).

if CH in [ '+' , '-' , '*' , '/' ] then WRITELN ( 'arithm. operator' ) ;

The generated P-Code looks like this (only the IF part is shown, not the WRITELN) - including some comments on the right side:

LOD C,1,912 load the char CH ORD convert to integer LCA S,C32'+*-/' load the set SLD 32,968 copy to workarea INN check, if int is in set FJP L13 jump, if false

The copy to workarea could be omitted in future releases, room for improvement.

The P-Code translator builds the following 370-code from this (you may notice that no code is produced for the SLD instruction, which copies the set):

-------------------- LOC 246 -------------------------------- 0714: LOD C,1,912 0714: ORD @@ 0714: SR 2,2 @@ 0716: IC 2,912(13) load ch into reg 2 071A: LCA S,C32'+*-/' 071A: SLD 32,968 071A: INN @@ 071A: AH 2,=H'-72' subtract 72 @@ 071E: L 3,=X'020008C0' bit string (part of set) @@ 0722: LA 0,32 @@ 0726: CLR 2,0 look if ch - 72 > 32 @@ 0728: BC 11,*+10 if so, jump false @@ 072C: SLL 3,0(2) shift bit in set left @@ 0730: LTR 3,3 test leftmost bit 0732: FJP L13 @@ 0732: BC 11,L13 jump false, if off

Of course, this only works, because the characters in the set constant are within a codepage range of size 32. If the set range is larger, there are other implementations. But anyway: the original implementors of PASCAL2 did a great job, and I tried not to compromise this, although the maximum size of sets has been extended.

The new version will be available in the next few days from the New Stanford Pascal compiler website.

Back to Compiler main page