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

range definitions
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

1

Range Definitions

type ConstExp 5 integer range [1..5] one_five ;

DoMakeRange

int 2 ConstExp 1

slide-2
SLIDE 2

2

Range Definitions

type ConstExp 5 integer range [1..5] one_five ;

DoMakeRange

int 2 ConstExp 1 range 2 lo=1 hi = 5 bo =4 base = newType C1 ... ... int 1 int 5

slide-3
SLIDE 3

3

Range Definitions

type integer range [1..5] one_five ;

DoMakeRange

int 2 range 2 lo=1 hi = 5 bo = 4 base = newType

slide-4
SLIDE 4

4

Array Definitions

type mark integer array [one_five] [one_three] *a, b ;

DoMakeArray

int 2 Assumes we have previously defined integer range [1..5] one_five; integer range [1..3] one_three; type type range 1 3... range 1 5...

slide-5
SLIDE 5

5

Array Definitions

in DoMakeArray

int 2

finalType

integer array [one_five] [one_three] *a, b ; type mark type type range 1 3... range 1 5...

slide-6
SLIDE 6

6

Array Definitions

in DoMakeArray

int 2

finalType currentType

array 6 subs= comp= integer array [one_five] [one_three] *a, b ; range 1 3... type mark type type

slide-7
SLIDE 7

7

Array Definitions

in DoMakeArray

integer array [one_five] [one_three] *a, b ; At end of loop

  • n first pass

int 2

finalType currentType

array 6 subs= comp= range 1 3... type mark type type

slide-8
SLIDE 8

8

Array Definitions

in DoMakeArray

array 30 subs= comp= integer array [one_five] [one_three] *a, b ;

finalType

int 2

finalType currentType

array 6 subs= comp= range 1 3... range 1 5... type mark type type

slide-9
SLIDE 9

9

Array Definitions

in DoMakeArray

integer array [one_five] [one_three] *a, b ; End of 2nd pass array 30 subs= comp=

finalType

int 2

finalType currentType

array 6 subs= comp= range 1 3... range 1 5... type mark type type

slide-10
SLIDE 10

10

Array Definitions

in DoMakeArray

integer array [one_five] [one_three] *a, b ; array 30 subs= comp=

finalType

int 2

finalType currentType

array 6 subs= comp= range 1 3... range 1 5... type mark type type

slide-11
SLIDE 11

11

Array Definitions

DoDeclVars exactly as before

integer array [one_five] [one_three] *a, b ; array 30 subs= comp= int 2 array 6 subs= comp= type range 1 3... range 1 5...

slide-12
SLIDE 12

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.

slide-13
SLIDE 13

13

Subscript reduction

x := a[ 3 ] • [ m] ; expr “x” expr int 3

Subscript

expr “a” (1,4,false) array 30 subs= comp= array 6 subs= comp= range 1 3... range 1 5... int 2

slide-14
SLIDE 14

14

Subscript reduction

expr “x” expr “a” (1,4,false) expr int 3

in Subscript

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

slide-15
SLIDE 15

15

Subscript reduction

expr “x” expr var (0,1,true) this represents a[3] x := a[ 3 ] • [ m] ;

in Subscript

LD R0, #3 TRNG R0, +..(R14) IC R0, #1 IM R0, #6 LDA R1, +4(R15) IA R1, R0 array 30 subs= comp= array 6 subs= comp= range 1 3... range 1 5... int 2

slide-16
SLIDE 16

16

Subscript reduction

x := a[ 3 ] [ m ] • ; expr “x” expr var (0,1,true)

Subscript(second call)

expr “m” (1,6,false) LD R0, #3 TRNG R0, +..(R14) IS R0, #1 IM R0, #6 LDA R1, +4(R15) IA R1, R0 array 30 subs= comp= array 6 subs= comp= range 1 3... range 1 5... int 2

slide-17
SLIDE 17

17

Subscript reduction

expr “x” expr var (0,1,true)

in Subscript(second call)

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

slide-18
SLIDE 18

18

Subscript reduction

expr “x” expr var (0,1,true)

Assign: exactly as before

LD R0, #3 TRNG R0, +..(R14) IS R0, #1 IM R0, #6 LD R1, +4(R15) IA R1, R0 LD R0, +6(R15) TRNG R0, +..R14) IS R0, #1 IM R0, #2 IA R1, R0 This represents a[ 3] [ m ] x := a[ 3 ] [ m ] ;• array 30 subs= comp= array 6 subs= comp= range 1 3... range 1 5... int 2

slide-19
SLIDE 19

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.

slide-20
SLIDE 20

20

Range Checking

HALT C1 INT 1 INT 3 Bounds offset for this array would be +0(R14)

back in DoMakeRange

integer range [1..3] one_three ; type ConstExp 3 int 2 ConstExp 1 range 2 lo=1 hi = 3 bo =0 base = newType Assuming no constants had yet been allocated in C1 block

slide-21
SLIDE 21

21

Range Checking

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