//----------------------------------------------------------------- // Example of array constructors - with low array index not 1 //----------------------------------------------------------------- // // The following pattern it generated by various array constructor techniques. // For the purpose of this test, so as to thoroughly test the indexing in the // contructors, only the items in the middle (not the edges) of the matrix // is set up by most of the constructor statements. // // The 7's are do to the initially of the original Integer_item declaration. // The "1, 6, 6, 6, 1" rows are due to the initially of the X_array // // columes 1 to 5 // -------------- // ( 1, 6, 6, 6, 1 ), // row 1 // ( 7, 1, 2, 2, 7 ), // row 2 // ( 7, 2, 2, 3, 7 ), // row 3 // ( 7, 3, 4, 5, 7 ), // row 4 // ( 7, 4, 5, 5, 7 ), // row 5 // ( 1, 6, 6, 6, 1 ) ) // row 6 // // The size of the Integer_item, and packing of the array can be editted // for more interesting tests. //_Author: J. Duffy / F. Holloway //------------------------------------------------------------------------- main module LOWCONST use TEXTIO declare // v---- edit this for interesting test (4 to 32 is legal) Integer_item is 5 bit integer initially 7 XRANGE is -3..1 YRANGE is -3..2 // v---- use packed for very demanding test X_array is packed array [XRANGE] of Integer_item X is X_array initially X_array ( [-3]:1, [-2..0]:6, [1]:1) YX is array [YRANGE] of X CGRID = // row column2 column 3 column 4 // --- ----------- ---------- ----------- YX ( [-2] : X ( [-2] : 1, [-1..0] : 2 ), [-1] : X ( [-2..-1]: 2, [0] : 3), [0] : X ( [-2] : 3, [-1] : 4, [0] : 5), [1] : X ( [-2] : 4, [-1..0] : 5 )) GRID : YX GRID_s : static YX GRID_c : YX GRID_cs : static YX GRID_t : YX GRID_ts : static YX enddeclare procedure out_grid ( G: in ref YX ) if G <> GRID_ts do // assume the static table construct is correct out_line (TTY, "ERROR in grid comparison") for YIndex in YRANGE do for XIndex in XRANGE do out_integer (TTY, G [ YIndex, XIndex], " ") endfor out_record (TTY) endfor otherwise out_line (TTY, "PASSED") endif endprocedure declare //------------------------------------------------------------------- // Dynamic grid initialized from inline constructor GRID_i : YX initially // row column2 column 3 column 4 // --- ----------- ---------- ----------- YX ( [-2] : X ( [-2] : 1, [-1..0] : 2 ), [-1] : X ( [-2..-1]: 2, [0] : 3), [0] : X ( [-2] : 3, [-1] : 4, [0] : 5), [1] : X ( [-2] : 4, [-1..0] : 5 )) //------------------------------------------------------------------- // Static grid initialized from inline constructor GRID_is : static YX initially // row column2 column 3 column 4 // --- ----------- ---------- ----------- YX ( [-2] : X ( [-2] : 1, [-1..0] : 2 ), [-1] : X ( [-2..-1]: 2, [0] : 3), [0] : X ( [-2] : 3, [-1] : 4, [0] : 5), [1] : X ( [-2] : 4, [-1..0] : 5 )) //------------------------------------------------------------------- // Dynamic grid initialized from constant constructor GRID_ic : YX initially CGRID //------------------------------------------------------------------- // Static grid initialized from constant constructor GRID_ics: static YX initially CGRID enddeclare //---------------------------------------------------------- // Dynamic grid assigned from inline constructor GRID := // row column2 column 3 column 4 // --- ----------- ---------- ----------- YX ( [-2] : X ( [-2] : 1, [-1..0] : 2 ), [-1] : X ( [-2..-1]: 2, [0] : 3), [0] : X ( [-2] : 3, [-1] : 4, [0] : 5), [1] : X ( [-2] : 4, [-1..0] : 5 )) //---------------------------------------------------------- // Static grid assigned from inline constructor GRID_s := // row column2 column 3 column 4 // --- ----------- ---------- ----------- YX ( [-2] : X ( [-2] : 1, [-1..0] : 2 ), [-1] : X ( [-2..-1]: 2, [0] : 3), [0] : X ( [-2] : 3, [-1] : 4, [0] : 5), [1] : X ( [-2] : 4, [-1..0] : 5 )) //---------------------------------------------------------- // Dynamic grid assigned from constant constructor GRID_c := CGRID //---------------------------------------------------------- // Static grid assigned from constant constructor GRID_cs := CGRID //---------------------------------------------------------- // Dynamic grid assigned from inline table constructor GRID_t := table // columes 1 to 5 // -------------- YX (table X ( 1, 6, 6, 6, 1 ), // row 1 table X ( 7, 1, 2, 2, 7 ), // row 2 table X ( 7, 2, 2, 3, 7 ), // row 3 table X ( 7, 3, 4, 5, 7 ), // row 4 table X ( 7, 4, 5, 5, 7 ), // row 5 table X ( 1, 6, 6, 6, 1 ) ) // row 6 //---------------------------------------------------------- // Static grid assigned from inline table constructor GRID_ts := table // columes 1 to 5 // -------------- YX (table X ( 1, 6, 6, 6, 1 ), // row 1 table X ( 7, 1, 2, 2, 7 ), // row 2 table X ( 7, 2, 2, 3, 7 ), // row 3 table X ( 7, 3, 4, 5, 7 ), // row 4 table X ( 7, 4, 5, 5, 7 ), // row 5 table X ( 1, 6, 6, 6, 1 ) ) // row 6 //---------------------------------------------------- tty_line ("test pattern is:") for YIndex in YRANGE do for XIndex in XRANGE do out_integer (TTY, GRID_ts [ YIndex, XIndex], " ") endfor out_record (TTY) endfor tty_line ("dynamic grid assigned from inline constructor") out_grid( GRID ) tty_line ("static grid assigned from inline constructor") out_grid( GRID_s ) tty_line ("dynamic grid assigned from constant constructor") out_grid( GRID_c ) tty_line ("static grid assigned from constant constructor") out_grid( GRID_cs ) //---------------------------------------------------- tty_line ("dynamic grid initialized from inline constructor") out_grid( GRID_i ) tty_line ("static grid initialized from inline constructor") out_grid( GRID_is ) tty_line ("dynamic grid initialized from constant constructor") out_grid( GRID_ic ) tty_line ("static grid initialized from constant constructor") out_grid( GRID_ics ) //---------------------------------------------------- tty_line ("dynamic grid assigned from inline table constructor") out_grid( GRID_t ) tty_line ("static grid assigned from inline table constructor") out_grid( GRID_ts ) endmodule