//--------------------------------------------------------------- // RANGE CHECKING EXAMPLE //-------------------------------------------------------------- // Set the compiler directives "subrange_check" and "subscript_check" // at the top of the module to specify either or both // types of run time range checking code be generated when // the "X_Range_Error" is armed. // // The compiler directives "subrange_check" and "subscript_check" // are defaulted to false when compiler is envoked. // // The "subscript_check" may be the most useful for programs // where space is limited because array subscript violations // are probably the most usual cause of crashing codes. // "Subrange_check" generates a LOT of code. // %set subrange_check = false %set subscript_check = true main module testarm use TEXTIO declare I : static 16 bit integer range 1..4 initially 1 A : static array [1..4] of 16 bit integer enddeclare guard I *= +2 A [i] := 2 procedure JOIE () ARM X_RANGE_ERROR // Range checking code only generated // in scopes where it is armed. // And, it applies over the entire // scope so it doesnt matter where // in the scope the statement is. I := I + 1 A [i] := 2 // It is illegal to both arm and // disarm within the same scope. endprocedure procedure SAM () DISARM X_RANGE_ERROR I := I + 2 procedure PETE () ARM X_RANGE_ERROR A [i] := 2 // THIS STATEMENT CAUSE X_RANGE ERROR I := 2 endprocedure A [i] := 1 PETE () endprocedure JOIE () SAM () catch case X_RANGE_ERROR: out_line (TTY, "Caught you you bugger") endguard endmodule