Spivoxity / obc-3

Oxford Oberon-2 compiler
38 stars 7 forks source link

LSL missing in Oberon-2 mode #5

Closed Spivoxity closed 5 years ago

Spivoxity commented 5 years ago

Seems the LSL did not make it into the system, when compiling https://bitbucket.org/inkytonik/oberon0 I get a

/usr/local/lib/obc/obc1 -g -pl -O -I /usr/local/lib/obc RISC.m >RISC.k
"RISC.m", line 42: 'LSL' has not been declared
>       |  LSH, LSHI: R[a] := LSL(R[b], c)
>                             ^^^
Spivoxity commented 5 years ago

I'm afraid I was in a pedantic mood when I finalised the built in functions. In Oberon-2 mode, ASH is provided, and in Oberon07 mode, it is replaced by LSL, LSR, ASR and ROR. Perhaps I should relax this in a future release and make all these available in both modes. In the meantime, three possible workarounds (none of which result in a single inlined instruction at runtime).

  1. Replace LSL(x, y) with ASH(x, y) and ASR(x, y) with ASH(x, -y). [No equivalent for LSR or ROR].

  2. Write a C primitive for each shift operator and link it in.

  3. If you want LSR to be available in Oberon-2 code, write a module Shift and compile it in Oberon07 mode, then call Shift.Lsr from Oberon-2.

    MODULE Shift;
    PROCEDURE Lsr(x, y: INTEGER): INTEGER; RETURN LSR(x, y) END Lsr; 
    END Shift.

    (yes, that is valid Oberon07 syntax).

Spivoxity commented 5 years ago

Christian Kleinert writes: Had to check the language reports for Oberon-2 and Oberon07 to remember that LSL is not part of the Oberon-2 language, or is it? So if to enable it in Oberon-2 mode, maybe better via -x option (Enable language extensions) to stay as close to the language report as possible in standard mode? Prefer the separate Module though :-)

Spivoxity commented 5 years ago

Actually, note that LSR is not listed in the latest Oberon07 report.

Spivoxity commented 5 years ago

Not really a bug. But in the next release I will save fuss by providing all 5 functions in both modes.