COMPUTER ONE PASCAL COMPILER
In the first Pascal demonstrations and workshops we used a compiler called “QL Pascal” from Metacomco. This system provides a screen editor, a compiler, and a linker, each as a separate file. It takes two microdrive cartridges and an EPROM to run the system.
Later Cliff Watson provided a copy of “Computer One” Pascal for the QL. When I checked this out I found it was a joy to use. The editor, compiler, and linker are all on one mdv and any access to other files is transparent to the user. The user accesses all the features from a main menu, followed by submenus. The editor does not have all of the features of Metacomco’s editor, but it is quite adequate. Futhermore, the compiler has a super feature, when it finds an error in the source code it writes this to an “ERR” file. Then when the editor brings the source code file back for editing the bad line is written from the ERR file and set-off by “x”‘s. Not only is the number of the error reported but a descriptive phrase is shown. No more checking the compile-time error list in the manual’s appendix! Also on the mdv are two sample programs, and no EPROM is required! I tried the compiler on some of the exercise programs that we have been working on. It worked on many of them, and with small changes it worked on all of them. Therefore, we used this system in our last workshops (We can also operate it through the network if desired.)
Come and see, the sample program has some colored graphics- you can do that with Pascal too. OK, what’s the rub? For one thing the object code (executeable program) from the compiler runs slower than the QL Pascal, and certain advanced Pascal features are not implemented. Still, for learning the language it is easier to use.
MORE QL SPEED!
In the September N/L, I described some programs in two version of Pascal, Forth, and SUPERBASIC. They allowed us to determine relative speeds obtained by the software. Each program determined all the primes less than the max. down to a limit as input by the user. Each then prints the primes to the screen, and when finished, prints the run-time. The results for a calculation of primes from 29000 to 32767 were:
Language Run-time,seconds Forth79(Quanta lib.) 23 QL Pascal (Metacomco) 27 Computer One Pascal 67 SUPERBASIC (intepreter) 245
I plan to compile the BASIC program, but I need to get a compiler, or someone else to do that for me. Maybe, we could compare “The Liberator” with”Turbo-Charge”. The source code for these programs are shown in listings 1 through 4.
LISTING 1
First Block:
( A comparison program)
2VARIABLE P-BEGIN
: ATEST ( n1,n2 .. n1,tf tests for
even div. by n2 ) OVER SWAP
MOD 0= ;
: FACTORS ( n .. ff/n returns
num if prime ) 192 3 DO I
ATEST IF DROP 0 LEAVE THEN
2+LOOP ;
: PRIMES ( n,32767 .. prints
primes ) 32767 DO I
FACTORS ?DUP IF . THEN -2
+LOOP;
: SET-TIME TIME P-BEGIN 2! ;
: DISPLAY-TIME CR CR
."Runtime = " TIME P-BEGIN 2· D-
D. ." seconds " ;
: INFO-PRIMES ." This is a short
program in FORTH (from QUANTA
lib.) " CR ." This program will find
prime numbers less than 32767. " CR
CR ;
: INITIATE ( .. n, inputs the
bottom limit ) ." Stop
calculation at what value less than
32767? " CR ." Enter lower limit, a
space, and START (caps), and
'ENTER'. " ; -->
Second block:
( A comparison program )
2VARIABLE P-BEGIN
: ATEST ( n1,n2 .. n1,tf tests
for even div. by n2 ) OVER
SWAP MOD 0= ;
: FACTORS ( n .. ff/n returns
num if prime ) 192 3 DO I
ATEST IF DROP 0 LEAVE THEN 2
+LOOP ;
: PRIMES ( n,32767 .. prints
primes ) 32767 DO I
FACTORS ?DUP IF . THEN -2
+LOOP ;
: SET-TIME TIME P-BEGIN 2! ;
: DISPLAY-TIME CR CR ."
Runtime = " TIME P-BEGIN 2· D-
D. ." seconds " ;
: INFO-PRIMES ." This is a short
program in FORTH (from QUANTA
lib.) " CR ." This program will find
prime numbers less than 32767. "
CR CR ;
: INITIATE ( .. n, inputs the
bottom limit ) ." Stop
calculation at what value less than
32767? " CR ." Enter lower limit, a
space, and START (caps), and
'ENTER'. " ; -->
LISTING 2
PROGRAM
primes(INPUT,OUTPUT);
CONST
max=32767;
testfactor=191;
VAR
start,stop,minval,index,j,pos:
INTEGER;
trial:BOOLEAN;
FUNCTION
time : INTEGER;EXTERNAL 34;
BEGIN
pos:=maxDIV 100;
WRITELN ('This is a short
Metacomco Pascal program.');
WRITELN;
REPEAT
BEGIN
WRITE('Stop calculation at what
value less than ',max,'? ');
READLN(minval);
IF minval >= max THEN
WRITELN('Invalid!');
END;
UNTIL minval <max;
WRITELN('Primes <',max:6,'& >
',minval:6);
WRITELN;
start:= time;
FOR index:=max DOWNTO minval
DO
BEGIN
j:=3;
WHILE j < testfactor DO
BEGIN
IF ((index MOD j) = 0)
OR (NOT ODD(index)) THEN
j:= testfactor + 2
ELSE j:=j + 2;
END; {of
WHILE/DO} IF index
< (pos*100) THEN
BEGIN
WRITELN;
pos:= pos -1;
END; {of IF/THEN}
IF j = testfactor THEN
WRITE(index:6);
END; {ofFOR/DO }stop:=time;
WRITELN;
WRITELN;
WRITE('Runtime = ',(stop - start):7);
WRITELN(' seconds, by
Metacomco Pascal');
END.
Listing 3
PROGRAM primes;
CONST
max=32767;
testfactor=191;
VAR
start,stop,minval,index,j,pos:
INTEGER;
trial:BOOLEAN;
BEGIN
pos:=max DIV 100;
WRITELN('This is a short Computer
One Pascal program [#2].');
WRITELN;
REPEAT
BEGIN
WRITE('Stop calculation at what
value less than ',max,'? ');
READLN(minval);
IF minval >= max THEN
WRITELN('Invalid!');
END;
UNTIL minval <max;
WRITELN('Primes < ',max:6,'&>
',minval:6);
WRITELN;
start:=READCLOCK;
OR index:=max DOWNTO minval
DO
BEGIN
j:=3;
WHILE j < testfactor DO
BEGIN
IF ((index MOD j) = 0) OR
(NOT ODD(index)) THEN
j:= testfactor + 2 ELSE j:=j
+ 2;
END; {of WHILE/DO}
IF index < (pos*100) THEN
BEGIN
WRITELN;
pos:= pos -1;
END; {of IF/THEN}
IF j = testfactor THEN
WRITE(index:6);
END; {of FOR/DO}
stop:=READCLOCK;
WRITELN;
WRITELN;
WRITE('Runtime = ',(stop -start):7);
WRITELN(' seconds, by Computer
One Pascal');
END.
Listing 4
100 REMark A superbasic program for comparison to other languages.
110 WINDOW 496,200,0,0:CLS
120 PRINT "This is a 26-line program in QL-SUPERBASIC"\
130 PRINT "This program will find the prime numbers less than 32767."
140 INPUT "Stop calculation at what value less than 32767? Please enter."\v
150 pos = 32767 DIV 100
160 IF v>32767 OR v<0 THEN PRINT "Invalid!":PAUSE 250 :CLS: GO TO 130
170 CLS: PRINT "Primes < 32767 & > ";v \ \
180LET start= DATE
190 FOR i = 32767 TO v STEP -2
200 FOR j=3 TO 191 STEP 2:IF NOT i MOD j THEN GO TO 240
210 IF (i < pos*100) THEN PRINT \:pos=pos-1
220 PRINT i;' ';
230 END FOR j
240 END FOR i
250 time=DATE-start: PRINT \\"Runtime = ";time;" seconds,in SUPERBASIC"
260 STOP
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.