# Last modified on Mon May 8 15:35:36 PDT 1995 by heydon # # This program tests the built-in INT() predicate. # Global variables # # Strings to print in integer/non-integer cases V0 "\tInteger\n" V1 "\tNot integer\n" # # Starting offset and offset delta V3 0.25 V4 0.125 # # Starting value and divisor V5 64.0 V6 4.0 # # Ending value V7 1.0 # # Final test value V8 0.0 # PROC TestVal(x); (* Code slot 1 *) # (* Test the value "x" with the "IS_INT" instruction. Print the # global value 0 if it is an integer, global value 1 if not. *) C1 # # Print(Unparse(x)) .INCSP b1 .PUSHL s-1 .CALLEXT c2 .DECSP b1 .CALLEXT c0 .DECSP b1 # # IF INT(x) -> Print("\tInteger\n") | Print("\tNot integer\n") FI .PUSHL s-1 .IS-INT .DECSP b1 .FJUMP s8 .PUSHG c0 .JUMP s5 .PUSHG c1 .CALLEXT c0 .DECSP b1 .RET # PROC TestAround(x) IS (* Code slot 2 *) # VAR curr, last IN # curr := x - V3; # last := x + V3; # DO curr <= last -> # TestVal(curr); # curr := curr + V4 # OD # END # (* Test floating point values around the (integer) "x". *) C2 # # VAR curr, last IN .PUSHM3NIL b2 # # curr := x - V3; .PUSHL s-1 .PUSHG c3 .SUBTRACT s3 .JUMP s3 .ERROR b4 .RET .POPL s1 # # last := x + V3; .PUSHL s-1 .PUSHG c3 .ADD s3 .JUMP s3 .ERROR b4 .RET .POPL s2 # # DO curr <= last -> .PUSHL s1 .PUSHL s2 .AT-MOST .FJUMP s33 # # TestVal(curr); .PUSHL s1 .CALL c1 .DECSP b1 # # curr := curr + V4 .PUSHL s1 .PUSHG c4 .ADD s3 .JUMP s3 .ERROR b4 .RET .POPL s1 # # OD .JUMP s-43 # # END .RET # PROC Main() IS (* Code slot 3 *) # VAR curr IN # curr := V5; # DO V7 <= curr -> # TestAround(curr); # TestAround(-curr); # curr := curr / V6 # OD; # TestAround(V8) # END C3 # # VAR curr IN .PUSHM3NIL b1 # curr := V5; .PUSHG c5 .POPL s1 # # DO V7 <= curr -> .PUSHG c7 .PUSHL s1 .AT-MOST .FJUMP s52 # # TestAround(curr); .PUSHL s1 .CALL c2 .DECSP b1 # # TestAround(-curr); .PUSHL s1 .NEGATE s3 .JUMP s3 .ERROR b4 .RET .CALL c2 .DECSP b1 # # curr := curr / V6 .PUSHL s1 .PUSHG c6 .DIVIDE s3 .JUMP s3 .ERROR b4 .RET .POPL s1 # # OD .JUMP s-64 # # TestAround(V8) .PUSHG c8 .CALL c2 .DECSP b1 # # END .RET END