range definitions
play

Range Definitions integer range [1..5] one_five ; ConstExp 5 - PowerPoint PPT Presentation

Range Definitions integer range [1..5] one_five ; ConstExp 5 int 2 ConstExp 1 type 1 DoMakeRange Range Definitions integer range [1..5] one_five ; newType range 2 lo=1 hi = 5 bo =4 base = ConstExp 5 C1 ... int 2


  1. Range Definitions integer range [1..5] one_five ; ConstExp 5 int 2 ConstExp 1 type 1 DoMakeRange

  2. Range Definitions integer range [1..5] one_five ; newType range 2 lo=1 hi = 5 bo =4 base = ConstExp 5 C1 ... int 2 ConstExp 1 ... int 1 int 5 type 2 DoMakeRange

  3. Range Definitions integer range [1..5] one_five ; newType range 2 lo=1 hi = 5 bo = 4 base = int 2 type 3 DoMakeRange

  4. Array Definitions integer array [one_five] [one_three] *a, b ; Assumes we have previously defined integer range [1..5] one_five; integer range [1..3] one_three; range 1 3... type range 1 type 5... mark int 2 type 4 DoMakeArray

  5. Array Definitions integer array [one_five] [one_three] *a, b ; finalType range 1 3... type range 1 type 5... mark int 2 type 5 in DoMakeArray

  6. Array Definitions integer array [one_five] [one_three] *a, b ; currentType finalType type range array 6 1 subs= type 3... comp= mark int 2 type 6 in DoMakeArray

  7. Array Definitions integer array [one_five] [one_three] *a, b ; currentType At end of loop on first pass finalType type range array 6 1 subs= type 3... comp= mark int 2 type 7 in DoMakeArray

  8. Array Definitions integer array [one_five] [one_three] *a, b ; currentType array 30 range finalType finalType subs= 1 5... comp= type range array 6 1 subs= type 3... comp= mark int 2 type 8 in DoMakeArray

  9. Array Definitions integer array [one_five] [one_three] *a, b ; End of 2nd pass currentType array 30 range finalType finalType subs= 1 5... comp= type range array 6 1 subs= type 3... comp= mark int 2 type 9 in DoMakeArray

  10. Array Definitions integer array [one_five] [one_three] *a, b ; currentType array 30 range finalType finalType subs= 1 5... comp= type range array 6 1 subs= type 3... comp= mark int 2 type 10 in DoMakeArray

  11. Array Definitions integer array [one_five] [one_three] *a, b ; array 30 range subs= 1 5... comp= range array 6 1 subs= 3... comp= int 2 type 11 DoDeclVars exactly as before

  12. Array Definitions Notes: Type pointers represent linked lists (if we have records then trees actually) We may need to “walk” the list to process an array type. The “head” pointer represents the type as a whole. 12

  13. Subscript reduction x := a[ 3 ] • [ m] ; array 30 range subs= 1 5... comp= range array 6 1 subs= 3... comp= expr int 3 expr “a” (1,4,false) int 2 expr “x” Subscript 13

  14. Subscript reduction x := a[ 3 ] • [ m] ; LD R0, #3 array 30 TRNG R0, +..(R14) range subs= IS R0, #1 1 IM R0, #6 5... comp= LDA R1, +4(R15) IA R1, R0 range array 6 1 subs= 3... comp= expr int 3 expr “a” (1,4,false) int 2 expr “x” in Subscript 14

  15. Subscript reduction x := a[ 3 ] • [ m] ; LD R0, #3 array 30 TRNG R0, +..(R14) range subs= IC R0, #1 1 IM R0, #6 5... comp= LDA R1, +4(R15) IA R1, R0 range array 6 1 subs= 3... this represents comp= a[3] expr var (0,1,true) int 2 expr “x” in Subscript 15

  16. Subscript reduction x := a[ 3 ] [ m ] • ; LD R0, #3 array 30 TRNG R0, +..(R14) range subs= IS R0, #1 1 IM R0, #6 5... comp= LDA R1, +4(R15) IA R1, R0 range array 6 1 subs= 3... comp= expr “m” (1,6,false) expr var (0,1,true) int 2 expr “x” Subscript(second call) 16

  17. Subscript reduction x := a[ 3 ] [ m ] • ; LD R0, #3 TRNG R0, +..(R14) array 30 range IS R0, #1 subs= 1 IM R0, #6 5... LDA R1, +4(R15) comp= IA R1, R0 LD R0, +6(R15) TRNG R0, +..R14) range array 6 IS R0 #1 1 subs= IM R0, #2 3... IA R1, R0 comp= expr “m” (1,6,false) expr var (0,1,true) int 2 expr “x” in Subscript(second call) 17

  18. Subscript reduction x := a[ 3 ] [ m ] ;• LD R0, #3 TRNG R0, +..(R14) array 30 range IS R0, #1 subs= 1 IM R0, #6 5... LD R1, +4(R15) comp= IA R1, R0 LD R0, +6(R15) TRNG R0, +..R14) range array 6 IS R0, #1 1 subs= IM R0, #2 3... IA R1, R0 comp= This represents a[ 3] [ m ] expr var (0,1,true) int 2 expr “x” Assign: exactly as before 18

  19. Subscript reduction Notes: ReduceSubscript handles only one subscript. It is called multiple times if there are many. It needs to check its two entries for legality--top = integer type, next has array type. 19

  20. Range Checking integer range [1..3] one_three ; Bounds offset for this array would be +0(R14) newType Assuming no constants had yet been allocated in C1 block range 2 lo=1 hi = 3 bo =0 base = HALT ConstExp 3 C1 INT 1 int 2 ConstExp 1 INT 3 type back in DoMakeRange 20

  21. Range Checking integer range [1..5] one_five ; Bounds offset for this array would be +4(R14) newType range 2 lo=1 hi = 5 bo =4 base = HALT ConstExp 5 C1 INT 1 int 2 INT 3 ConstExp 1 INT 1 INT 5 type In actuality, you enter two constants into the 21 constant table, lobound and highbound

Recommend


More recommend