rvjansen / simula67

0 stars 0 forks source link

Specification exception when OutInt second argument is 0 (zero) #1

Open rvjansen opened 5 months ago

rvjansen commented 5 months ago

Given the following program:

 BEGIN                                     
    INTEGER PROCEDURE fib1(n); INTEGER n;  
    BEGIN                                  
       fib1 := IF n = 1 THEN 0             
          ELSE IF n = 2 THEN 1             
          ELSE fib1(n-1) + fib1(n-2)       
    END;                                   

    INTEGER PROCEDURE fib2(n); INTEGER n;  
    BEGIN                                  
       INTEGER ARRAY F(1:n);               
       INTEGER i;                          

       F(1) := 0;                          
       IF n > 1 THEN F(2) := 1;            

       FOR i := 3 STEP 1 UNTIL n DO        
          F(i) := F(i-1) + F(i-2);         

       fib2 := F(n);                       
    END;                                   

   OutInt(fib1(12), 0); OutImage;          
   OutInt(fib2(12), 0); OutImage;          

The outcome is:

ZYQ994   SIMULA 67 RUN TIME SYSTEM : VERSION 12.00, DATE OF RELEASE  9 AUG 1985                                  
ZYQ994   SIMULA PROGRAM COMPILED ON  5 APR 2024 AT 21:28:35.41, START OF EXECUTION ON  5 APR 2024 AT 21:28:35.41 
ZYQ994   PROCESSING OPTIONS : DUMP=1,HIARCHY=0,LINECNT=60,SIZE=761856,TRACE=0,SYMBDUMP=1,TIME=10.00 SEC.         
ZYQ077****SPECIFICATION    at line 00000 in *SYSTEM* ************************************************************

ZYQ994   END OF SIMULA PROGRAM EXECUTION AT 21:28:35.68   EXECUTION TIME 0.00 SEC.   RETURN CODE IS #00000008    
ZYQ994   00000 STORECOLLAPSES, DATA STORAGE USED : 8792 BYTES                                                    

When we specify something else than 0 as the second argument to OutInt, the program works ok.

rvjansen commented 5 months ago

Simula standard: 10.5.8 (Svensk Standard SS 63 61 14 Programspråk Simula)

procedure outint(i,w); integer i,w;
if w = 0 then FIELD(...).putint(i) else if w < 0
then begin text f;
f :- FIELD(-w);
f := notext; f.sub(1,...).putint(i) end
! see below;
else FIELD(w).putint(i);
procedure outfix(r,n,w); long real r; integer n,w;
... ; ! as body of outint, with "putfix" substituted for "putint";
procedure outreal(r,n,w); long real r; integer n,w;
... ; ! as body of outint, with "putreal" substituted for "putint";
procedure outfrac(i,n,w); integer i,n,w;
... ; ! as body of outint, with "putfrac" substituted for "putint";
The procedures "outint", "outfix", "outreal" and "outfrac" are defined in terms of the corresponding editing procedures of "image". They provide facilities for "item-oriented" output. Each item is edited into a "field" (subtext of "image") normally starting at the current accessible character. POS is advanced correspondingly. If the remainder of "image" is too short to contain the item, "outimage" is called implicitly prior to the editing operation. The field is space-filled before the editing operation.
A run-time error occurs if a field cannot be contained within the full length of "image".
Parameter "w" determines both the length of this field and the adjustment of the item within it, as follows.
w>0 The field length is w, the item is right-adjusted.
w<0 The field length is abs(w), the item is left-adjusted.
w=0 The field length is the exact number of characters needed to contain the item (i.e. no leading or trailing spaces).