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

Porting Stanford Pascal to Windows, OS/2 and Linux - portable branch tables

Please refer to the "other issues" section, too:

Porting Stanford Pascal to Windows, OS/2 and Linux - other issues

I decided to build the correct solution for the branch table problem now. That is, I removed the two constants for the lowest and highest value. And I marked the XJP instruction with a flag (N); this N stands for "new format of branch table".

The new XJP instruction needs only two labels, not four. But when working on the P-Code translator, I discovered that the translator still needs the min and max value fields and uses the label names for the machine code, although they aren't used in the P-Code any more. So I decided to reserve the names in the first pass, but not to use them; the names are left unused and can be used by the second pass.

Here is an example; the P-Code for a character based case statement looked like this before:


case T of 'A' : WRITE ( ' SONNTAG,' ) ; 'B' : WRITE ( ' MONTAG,' ) ; 'D' : WRITE ( ' MITTWOCH,' ) ; 'F' : WRITE ( ' FREITAG,' ) ; 'G' : WRITE ( ' SAMSTAG,' ) ; end (* case *) ; /***************************************************/ /* generated P-Code */ /***************************************************/ XJP L3 ... L3 DEF C,'A' L4 DEF C,'G' L5 LAB DEF C,'A' UJP L8 DEF C,'B' UJP L9 DEF C,'D' UJP L11 DEF C,'F' UJP L13 DEF C,'G' UJP L14 L6 LAB

and it looks now like this:


case T of 'A' : WRITE ( ' SONNTAG,' ) ; 'B' : WRITE ( ' MONTAG,' ) ; 'D' : WRITE ( ' MITTWOCH,' ) ; 'F' : WRITE ( ' FREITAG,' ) ; 'G' : WRITE ( ' SAMSTAG,' ) ; end (* case *) ; /***************************************************/ /* generated P-Code */ /***************************************************/ XJP N,L5 ... L5 LAB DEF C,'A' UJP L8 DEF C,'B' UJP L9 DEF C,'D' UJP L11 DEF C,'F' UJP L13 DEF C,'G' UJP L14 L6 LAB

The labels L3 and L4 are not used any more, but they are reserved and may be used by the P-Code generator to store (internally) the min and max values, which are derived from the DEF constants of the branch table (which need not be sorted by the char set sequence - in the char case).

There is an interesting difference between integer based branch tables and character based branch tables:

The difference between highest and lowest value is limited by the compiler constant CIXMAX; at the moment, CIXMAX = 400. This is equivalent to the largest possible branch table (equals 800 Bytes in the CSECT), and its by far large enough for the whole char type.

Some possible improvements for the future (if this should be a problem):

In the end, the implementation of the case statement turned out to be pretty interesting; this is something that was already observed very early by C.A.R. Hoare, IIRC.

Back to Compiler main page