z505 / ofront

Automatically exported from code.google.com/p/ofront
0 stars 0 forks source link

Allow using SYSTEM.ADR("A") #5

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Dear Josef, dear all,
take a look at this code.

MODULE TestAdrChar;
IMPORT SYSTEM;

VAR adr: LONGINT;

BEGIN
  adr := SYSTEM.ADR("AA");
END TestAdrChar.

It's compiled and works. I prefer to a result of SYSTEM.ADR will be compatible 
with SYSTEM.PTR, but this issue not about it.

If you change "AA" to "A", Ofront shows error "illegal use of object". It's 
natural - "A" is a CHAR, but it may be a string too.

In context of being "A" as an argument of SYSTEM.ADR, I would propose to equate 
a char to string here.

I use Ofront for system programming. And it's annoying me sometimes, that 
strings used with SYSTE.ADR must have LEN only > 1.

I propose this fix:

https://github.com/Oleg-N-Cher/Ofront/commit/7cbdd1cc4299494a9dabe78eb31fb19daa3
1c267

Thanks.

Original issue reported on code.google.com by al...@bk.ru on 17 May 2015 at 3:11

GoogleCodeExporter commented 8 years ago
To prevent wrong processing of non-constant CHAR value, as:

MODULE TestAdrChar;
IMPORT SYSTEM;

VAR adr: LONGINT; ch: CHAR;

BEGIN
  adr := SYSTEM.ADR(ch);
END TestAdrChar.

one additional condition is required into my code. Was:

IF f = Char THEN CharToString(z); f := String END;

Now:

IF (z^.class = Nconst) & (f = Char) THEN CharToString(z); f := String END;

https://github.com/Oleg-N-Cher/Ofront/commit/d907fa0f5e0b7d26805d6a340fd883161b7
f0be3

Original comment by al...@bk.ru on 17 May 2015 at 7:33

GoogleCodeExporter commented 8 years ago
And extra condition to make sure that a character code of SYSTEM.ADR("x") 
argument is in range {0X, 20X..7FX}:

IF (z^.class = Nconst) & (f = Char) THEN
    CASE CHR(z^.conval^.intval) OF 0X, 20X..7FX: CharToString(z); f := String ELSE err(127) END;
END;

https://github.com/Oleg-N-Cher/Ofront/commit/a5e7d06a6eb713ce9a893c8d3f673f81cf6
55c13

It's required for preventing to declare the one-character string with a 
non-printable character. Note: SYSTEM.ADR(0X) translates to (LONGINT)"" - I see 
sense to get the address of an empty string in such way.

Original comment by al...@bk.ru on 17 May 2015 at 8:53