[Oberon] Negative integer literals in Oberon
Joerg
joerg.straube at iaeth.ch
Sat May 2 13:59:00 CEST 2020
Dave
Let’s assume we are on a 64bit CPU and we have two integer types: INTEGER (32bit) and LONGINT (64bit)
In my point of view, you would need two value cast operators H and L to cover those cases.
But in additiion to the H and L thingy, the compiler might make a difference between
SHORT(long) and
SYSTEM.VAL(INTEGER, long)
SHORT could generate a runtime error.
SYSTEM.VAL most probably not as it is low level and most compilers implement this just as
long MOD 100000000L
br
Jörg
> Am 01.05.2020 um 18:46 schrieb dave at brownsmeet.com:
>
> Hi Oleg,
>
> Re 1 - Personally I really dislike '90909090H - 100000000H' because it is more confusing to read than the alternatives.
>
> Instead of SYSTEM.VAL(INTEGER, 90909090H) you may prefer SHORT(90909090H). It's a bit more concise, avoids the dependency on SYSTEM, and works whatever the 32 bit integer type is called (i.e. INTEGER or LONGINT).
>
> (If you are adding support for LONGINT then you will almost certainly be adding support for SHORT() and LONG()).
>
> ---
>
> Re 2 - Yes, this fixes 32 bit hex literals. But it doesn't fix 16 or 8 bit hex literals. I think these should be considered too. It's also difficult to explain the use of the H vs L suffix - the description in the component pascal documentation is correct but very confusing.
>
> ---
>
> Re 3 - Yes, in this case (assuming you have added support for 64 bit integers) all arithmetic is 64 bit, and assignments to smaller int variables are simply clipped at the time they are stored. You don't need SHORT() or LONG().
>
> If you do this I'd like to see a compilation option to do range checking at run time on every store to < 64 bits.
>
> ---
>
> Re 4 - Oberon already has casting under another name (type guard) for extended types - with the type name in brackets following the variable name. Maybe keep the syntax similar.
>
>
> -- Dave.
>
>
>> On 2020-05-01 11:26, Oleg N. Cher wrote:
>> Dear Dave,
>> After all, the question: is the literal 90909090H considered 64-bit
>> unsigned or 32-bit signed? We have four solutions:
>> 1. Consider it as a 64-bit literal, by context. And if we need to
>> declare it as a 32-bit literal, we'll write it like this:
>> myint := 90909090H - 100000000H;
>> If we don't like writing code this way, we'll write it differently:
>> myint := SYSTEM.VAL(INTEGER, 90909090H);
>> , quite in the spirit of the Oberon paradigm. So, Artur, this is what
>> I suggest you do in your compiler.
>> 2. Consider it as a 32-bit literal. And for 64-bit use the postfix
>> modifier like 0FFFFFFFFL, as in Component Pascal. Ofront+ also
>> implements this option (in -C mode).
>> 3. Pretend that we have all integer literals of the same size. In this
>> case, all the hexadecimal digits allowed as a bitfield value of the
>> literal. This way is implemented in most Oberon-07 compilers, which is
>> justified by the lack of integer arithmetic of different bits in them.
>> (BYTE is a non-arithmeric type in Oberon-07, and its size does not
>> used in operations, always casted to INTEGER).
>> 4. Explicitly specifying the constant type, as there was in Turbo Pascal:
>> CONST MyConst = INTEGER(90909090H);
>> As in Active Oberon, Delphi and Turbo Pascal. But then it is necessary
>> to allow the same (note, non-system) casting in expressions - and
>> rushed.
>> I would suggest two ways. The non-system way:
>> CONST MyConst = 90909090H - 100000000H;
>> This will be our payment for the fact that there are no unsigned types
>> in Oberon. This is a simplification that I think is very useful, but
>> has a cost. So now we have all integer constants as signed numbers.
>> And the system way. Ofront+ supports:
>> myint := SYSTEM.VAL(INTEGER, 90909090H);
>> And in constants too:
>> CONST MyConst = SYSTEM.VAL(INTEGER, 90909090H);
>> The disadvantage here is the compatibility problem, because old
>> sources may contain literals that rely on the size of 32 bits. But
>> this is mitigated by the fact that Ofront+ supports 5 Oberon dialects,
>> and we can choose any of it at our discretion.
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
More information about the Oberon
mailing list