Page 1 of 1

Compiler register limits.

PostPosted: Fri Oct 21, 2016 9:15 pm
by Robert
The compiler complains that this code is too complicted, but I think it is relatively simple, and that the compiler should be able to handle it.

If you change the TYPE to POINTER TO REAL (also 64-bits) there is no problem.
Code: Select all
MODULE  PrivTest;

TYPE
  Vector*  =  POINTER  TO  ARRAY  OF  LONGINT;

PROCEDURE  Rotate* (vec : Vector; s : INTEGER) : Vector;
  VAR
    n, k  :  INTEGER;
    w     :  Vector;
  BEGIN
    IF  vec  #  NIL  THEN
      n  :=  LEN (vec); k  :=  n;
      NEW (w, n);
      WHILE  k  >  0  DO  DEC (k); w [(k + s) MOD n]  :=  vec [k]  END
    END;
    RETURN  w
  END  Rotate;

END  PrivTest.

Re: Compiler register limits.

PostPosted: Sat Oct 22, 2016 6:54 am
by Josef Templ
This is probably because a LONGINT on a 32-bit CPU needs 2 Registers instead of 1.

Re: Compiler register limits.

PostPosted: Sat Oct 22, 2016 8:36 am
by Robert
An adequate work-around here is to replace the first line, which won't compile, with the second, which does.

But it still seems like a surprisingly severe restriction.

Code: Select all
      WHILE  k  >  0  DO  DEC (k); w [(k + s) MOD n]  :=  vec [k]  END
      WHILE  k  >  0  DO  DEC (k); w [k]  :=  vec [(k - s) MOD n]  END