ack
ack copied to clipboard
Using ACK to bootstrap Pascal-P5
Pascal-P5 is a Pascal compiler confirmed to ISO 7185, updated form Pascal-P4.
As I found that Pascal compiler in ACK followed ISO 7185 quite closely, it would be interesting if ACK can be used to bootstrap Pascal-P5.
Currently, following error occurred when compiling pcom.pas
and pint.pas
. It seems that one serious problem is that ACK do not support using subrange as base type of SET, see (pcom.p:L265 and pint.p:L286).
% ack -o pcom pcom.p
"pcom.p", line 265: illegal integer base type of set
"pcom.p", line 276: (warning) old-fashioned syntax ':' missing
"pcom.p", line 535: (warning) old-fashioned syntax ':' missing
"pcom.p", line 539: (warning) old-fashioned syntax ':' missing
"pcom.p", line 788: (warning) "lp" used before set
"pcom.p", line 908: (warning) "m" unused in "strltnvf"
"pcom.p", line 1362: (warning) "i" used before set
"pcom.p", line 3122: "IN": right operand must be a set
"pcom.p", line 3631: (warning) "llev" unused in "pageprocedure"
"pcom.p", line 4413: "+": illegal operand type(s)
"pcom.p", line 4439: "+": illegal operand type(s)
"pcom.p", line 4460: "<>": illegal operand type(s)
% ack -o pint pint.p
"pint.p", line 286: illegal integer base type of set
"pint.p", line 494: (warning) old-fashioned syntax ':' missing
"pint.p", line 513: (warning) old-fashioned syntax ':' missing
"pint.p", line 531: (warning) old-fashioned syntax ':' missing
"pint.p", line 549: (warning) old-fashioned syntax ':' missing
"pint.p", line 587: (warning) old-fashioned syntax ':' missing
"pint.p", line 605: (warning) old-fashioned syntax ':' missing
"pint.p", line 657: (warning) old-fashioned syntax ':' missing
"pint.p", line 675: (warning) old-fashioned syntax ':' missing
"pint.p", line 769: (warning) "ads" unused in "lstins"
"pint.p", line 1385: "+": illegal operand type(s)
"pint.p", line 2599: "=": illegal operand type(s)
"pint.p", line 2607: "<>": illegal operand type(s)
"pint.p", line 2614: ">=": illegal operand type(s)
"pint.p", line 2632: "<=": illegal operand type(s)
"pint.p", line 2676: "IN": right operand must be a set
"pint.p", line 2678: "IN": right operand must be a set
"pint.p", line 2748: "-": illegal operand type(s)
"pint.p", line 2749: "*": illegal operand type(s)
"pint.p", line 2750: "+": illegal operand type(s)
"pint.p", line 2751: "IN": right operand must be a set
"pint.p", line 2894: (warning) "c" unused in "pcode"
"pint.p", line 2894: (warning) "ad3" unused in "pcode"
"pint.p", line 2894: (warning) "option" unused in "pcode"
It seems that ACK support subrange as base type of SET, only this range is out of the default setting, which can be changed with -i
option for em_pc
. This message "illegal integer base type of set" is a bit misleading.
pcom
and pint
can be compiled successfully with following command:
ack -Rpc-i512 -o pcom pcom.p
ack -Rpc-i512 -o pint pint.p
But report error when compiling following simple program:
PROGRAM Hello (output);
BEGIN
WriteLn('Hello World!');
END.
Output:
% ./pcom hello.p
P5 Pascal compiler vs. 1.3.x
Pascal-P5 complies with the requirements of level 0 of ISO/IEC 7185.
./pcom: range bound error
It seems that char
in ACK's Pascal is 0-127, after I change ordmaxchar
in pcom.p
from 255
to 127
, the previous example compiles and runs correctly.
I think the character range is set by type.c#L97, can not figure out why 7 bits characters is used instead of 8 bits.
Re -i: beats me, I don't even know what a set subrange is! At the very least the error ought to be improved.
The implementation uses an EM feature where sets are first-class values on the stack, so a 512-bit set is going to involve pushing and popping 64 bytes at a time. However, it looks like the default value is 32 bits (a word size), which is clearly far too small.
Re char size: probably to avoid problems with signed chars. I don't know what code the Pascal compiler makes; if it uses the signed comparison instructions then values >127 will behave funny. This should be checked.
For the set size, according to code in P5, I have checked that 256-bit is enough to compile it.
The char > 127 is used by pcom.pas
, which is used for lexical parsing.
I kind of think that 8-bit characters support is needed, or ACK Pascal will unable to UTF-8 text, e.g.:
PROGRAM Hello (output);
BEGIN
WriteLn ('测试');
END.
ACK will refused to compile:
% ack hello.p
"hello.p", line 4: fatal error -- non-ascii '\346' read
Okay, so, looking at the code I was misunderstanding what was going on --- that number isn't the size of the type, it's the number of items a set of that type can have.
I've changed the value, and added a test, and (which took much longer) added proper set support to both the PowerPC backends so that the test passes...
The error with UTF-8 text was simply because the compiler was checking for and disallowing characters above 127; I've taken the check out, and UTF-8 should work fine now.
(I'll look at the -i issue later.)
When trying to compile previous UTF-8 example, following error occurred:
"hello.p", line 4: newline in string
"hello.p", line 9: newline in string
"hello.p", line 9: , missing before string
"hello.p", line 11: ) missing before end
There should not be a reason for Pascal-p5 not to run with a 128 bit sets (0-127). You would want to alter the equations:
setsize sethigh ordmaxchar
In both pcom.pas and pint.pas. Selecting 256 bit sets in ACK works as well.
The printing characters are only in 0 to 127. The reason for 256 bit sets is to support ISO 8859 character sets, which use the entire 8 bit byte to form a character.