[comp.sys.mips] Mips Pascal 2.0 problem

haroldt@yunexus.yorku.ca (Harold Tomlinson) (06/02/90)

Hello:

  This seems like the right place to post this... 

We have resently run into a couple of problems with our Mips machine.
I Scientist here at York University complained that the compiler was not
working.

  The following is a file that we plan to send to Mips (we are awaiting 
a return call, they are at some show right now).  Perhaps someone here
has experienced this and could help.

-------------------cut here---------------------
Apparent problem with MIPS pascal 2.0 (from RISC/os4.00 & cmplrs2.0)

  Some time ago a user reported to us that he could not use Pascal.  Using 
a program as simple as:

	program test;
	begin
		writeln("hello ");
	end.

and a compile command as simple as:

	pc -o test test.p

we got an error message saying that it could not locate the library:
	libxmalloc.a

I called Duncan Pool who suggested that I t:ry 

	pc -V

which gave me the following (much deleted):

		pc  (pc)
	        Mips Computer Systems 2.0
	/usr/lib/cmplrs/pc/cpp:
	        MIPS cmplrs 2.0 (from RISC/os 4.00)
	/usr/lib/cmplrs/pc/upas:
	        MIPS pascal 2.0 (from RISC/os4.00 & cmplrs2.0)
	/usr/lib/cmplrs/pc/ujoin:
	        MIPS cmplrs 2.0 (from RISC/os 4.00)
	/usr/lib/cmplrs/pc/uld:
	        MIPS cmplrs 2.0 (from RISC/os 4.00)
			.
			.
			.
	/bsd43/usr/lib/cmplrs/pc/libexc.a:
	**** can't open /bsd43/usr/lib/cmplrs/pc/libxmalloc.a (26) ****
			.
			.
			.
	
There was, however, a libxmalloc_BSD.a2.0 in the directory where this
'file' pointed (symlinked).  I added another symlink for now to
point from libxmalloc.a to libxmalloc_BSD.a2.0.  This has cleared up
the bulk of the problems we had (ie. stuff will now compile 
<*** was this a safe and/or smart move??? ***> ), but there is still 
one that bothers us.

The program that has shown the problem is called show (for other 
reasons) and runs well on another machine.  This program compiles
and links perfectly (it appears) but... it won't run.

The process is as follows:

	pc -o showback showback.p dfback.p

	showback n.dat hds

		.
		.
		.
	READING:
	    1 mu = cos(theta)                          200
	    2 linear combination of Pl(mu)             200
	begin plot_hds.p: send any character to start or continue
	
	
	^[^L
	Bus error (core dumped)
	
	
Having done much work to trace the problem by removing all 
unnecessary code and inserting many writeln statements, I have 
located the source of the bus error.

In the code there is a procedure call followed by a writeln.
The writeln was never reached.  The last line of the procedure
that was called was also a writeln followed by 'end;'.  This
writeln was reached.  Locically then, we have something like
this:

	do stuff;
	writeln();
	end;              <---------- crash here.
	writeln();

The code that follows is my condenced version.  It compiles and links
fine with all of the following commands, but will only run with the last.

	pc -o show show.p
	pc -O1 -o show show.p
	pc -O2 -o show show.p
	pc -O3 -o show show.p
	
As you can see, only the highest level of optimization has allowed this
program to function properly... The rest result in core dumps pointing 
to (in order as above):

	Child died at pc 0x400b03 of signal : Bus error
	reading symbolic information ...
	[using memory image in core]
	(dbx) where
	>  0 plot_hds(0x74202020, 0x20202020, 0x20000350, 0x0, 0x400200) ["show.p":123, 0x400aff]
	   1 main(0x0, 0x0, 0x0, 0x0, 0x0) ["show.p":152, 0x400e84]
	
	Child died at pc 0x400b03 of signal : Bus error
	reading symbolic information ...
	[using memory image in core]
	(dbx) where
	>  0 plot_hds(0x74202020, 0x20202020, 0x20000350, 0x0, 0x400200) ["show.p":123, 0x400aff]
	   1 main(0x0, 0x0, 0x0, 0x0, 0x0) ["show.p":152, 0x400e84]
	
	
	Child died at pc 0x400a03 of signal : Bus error
	reading symbolic information ...
	[using memory image in core]
	(dbx) where
	>  0 plot_hds(0x74202020, 0x20202020, 0x20000350, 0x0, 0x400200) ["show.p":122, 0x4009ff]
	   1 main(0x0, 0x0, 0x0, 0x0, 0x0) ["show.p":152, 0x400de4]
	
	
	
(pc -O3... resulting in working code.)

code follows:
Note: remove comments around 'writeln's to get debugging printouts.

 -----------------------------start of code---------------------------------
  type data_vec  = array[1..201] of real;
       title_40  = array[1..40] of char;
       data_rec  = record
                   title:title_40; dsno:integer;
                   vector:data_vec end;
      data_file  = file of data_rec;
      data_mat   = array[1..5,1..201] of real; 
        (* matrix having data_vecs as rows *)
      rec_array  = array[1..5] of data_rec;
      title_array= array[1..5] of title_40;
      filename   = array[1..13] of char;
      alfa       = array[1..10] of char;

  var indat,indat2,outdat,outdat2: data_file;
      infname,infname2,outfname,outfname2: filename;
      strng10   :alfa; (* holds date or time *)


program show(input,output,indat); (* Fri May 18 11:33:05 EDT 1990 *)

  var dim              :integer;
      rvec             :rec_array;

procedure get_data_recs 
    (var indat:data_file; var rvec:rec_array; var recno:integer);
    var r     :integer;
        rec   :data_rec;
    begin
       reset(indat); r:=0;
       writeln('READING:');                   
       while not eof(indat) do begin
         read(indat,rec); r:=r+1;
         writeln('  ',r:3,' ',rec.title,rec.dsno:4);
         rvec[r]:=rec;
         end; (* while not eof *)
       recno:=r;
       end; (* get_data_recs *)


procedure min_max(n: integer; vec: data_vec; var vmin, vmax: real; 
       var imin,imax: integer);
    var
	ip: integer;
    begin
	vmin := vec[1];
	vmax := vec[1];
	imin := 1;
	imax := 1; (* initialize *)
	for ip := 2 to n do begin (* IP loop to find max *)
	    if vec[ip] < vmin then begin
		vmin := vec[ip];
		imin := ip
	    end;
	    if vec[ip] > vmax then begin
		vmax := vec[ip];
		imax := ip
	    end
	end (* IP loop to find max *)
    end; (* proc min_max *)

procedure plot_hds(infname :filename);

  type coordinate = (yh,yl,xh,xl);
       pointch    = array[coordinate] of char;

  var reccnt,recno,i,xi,yi  :integer;
      coord                 :coordinate;
      yxch                  :pointch;
      yxchstr               :array[1..4] of char;
      ch                    :char;
      xrec,yrec             :data_rec;
      xvec,yvec             :data_vec;

  procedure scale(var vec:data_vec; dim:integer; scalefac:real);
    var imin,imax            :integer;
        vmin,vmax            :real;
    begin
(**	writeln( " now in scale ... " );**)
    min_max(dim,vec,vmin,vmax,imin,imax);
(**	writeln( " max is ", vmax, " position ", imax );**)
      for i:=1 to dim do vec[i]:=scalefac*(vec[i]-vmin)/(vmax-vmin);
      end; (* proc scale *)

  procedure yxchar(yi,xi:integer; var yxch:pointch);
    begin
      yxch[yh]:=chr(32+trunc(yi/32)); yxch[yl]:=chr(96+(yi mod 32));
      yxch[xh]:=chr(32+trunc(xi/32)); yxch[xl]:=chr(64+(xi mod 32));
    end; (* proc yxchar *)

  procedure place(x,y:real);
    var i,xi,yi  :integer;
    begin
(**	writeln("place yi ", yi, " and xi ",xi);**)
      yi:=round(y); xi:=round(x);
      yxchar(yi,xi,yxch); 
(**	writeln("called yxchar resulting in ", yxch[yh], yxch[xh] );**)
      i:=1; for coord:=yh to xl do begin
(**	writeln(" looping with coord = ", coord );**)
        yxchstr[i]:=yxch[coord]; 
	i:=i+1 end;
       write(yxchstr);
(**	writeln(" wrote the control string ");**)
    end; (* proc place *)

  begin (* main block, proc plot_hds *)
    reset(indat,infname);
    get_data_recs(indat,rvec,recno); xrec:=rvec[1]; 
    xvec:=xrec.vector; dim:=xrec.dsno;
    writeln('begin plot_hds.p: send any character to start or continue');
    readln(ch); if ch<>'d' then begin (* plot *)
    writeln(chr(27),chr(12)); (* clear graphics display *)
    write(chr(155),chr(29));  (* enter graphics vectormode *)
    scale(xvec,dim,1000); 
    for reccnt:=2 to recno do 
      begin
(**	writeln( "reccnt = ", reccnt);**)
(**	writeln( "rvec[ ] = ", rvec[reccnt].title );**)
      yrec:=rvec[reccnt]; 
	yvec:=yrec.vector; 
	scale(yvec,dim,700);
(**	writeln(" after scale dim is ", dim );**)
      write(chr(155),chr(29)); (* enter graphics vectormode *)
      for i:=1 to dim do begin
(**	 writeln(" going to place ");**)
	 place(xvec[i],yvec[i]); 
(**	 writeln(" in place ", dim );**)
	 end;
      write(chr(155),chr(28)); (* enter graphics point mode *)
(**	writeln(" looped for two to two");**)
      end; 
    write(chr(155),chr(28)); (* enter graphics point mode *)
(**	writeln("another place comming ");**)
    place(10.0,10.0);
(**	writeln( "another place ");**)
    write(chr(155),chr(31)); (* enter alpha mode *)
    (* writeln(xrec.title); write(yrec.title); *)
    read(ch); writeln
    end; (* if ch<>d *) 
    writeln(chr(27),'"0g'); (* return to text mode *)
    while ch='d' do begin (* diagnostics *)
      write('enter yi, xi '); readln(yi,xi);
      yxchar(yi,xi,yxch); writeln('yi, xi, yxchar  ',yi:5,xi:5,'  ',yxchstr);
      readln(ch)   
      end; (* diagnostics *)
    writeln('end execution of plot_hds, data from ',infname);
  end; (* proc plot_hds *)

  begin (* main block pgm show *)
    if argc<>0 then writeln(" this is for testing, running with params ... n.dat hds ... ");
 	  infname := 'n.dat';
    	  reset(indat,infname); 
          plot_hds(infname);
    end. (* pgm shodat *)

----------------------------------end of code-----------------------------------

Thank you...

	... harold.t.
--
==========================================================================
Disclaimer:  What you think my opinion is may not even be my opinion.
             It is in fact only what my opinion is in your opinion.
==========================================================================
    |\/~\/~\/|         Harold Tomlinson
    |        |         
    |        |         Academic Computing Services
    |        |         York University
     \__  __/          4700 Keele St., North York (Toronto)
       '||`            Ontario, Canada.  M3J 1P3
        ||
==========================================================================
Backup:  The duplicate copy of crucial data that no one bothered to make.
==========================================================================