Oxygen Basic

Information => Development => Topic started by: Brian Alvarez on June 02, 2019, 04:24:49 PM

Title: Curious things with brackets...
Post by: Brian Alvarez on June 02, 2019, 04:24:49 PM
This compiles and runs fine:

Code: [Select]
   BYTE grr
   grr = 325

As expected, this overflows to 69.

However, this fails:

Code: [Select]
   BYTE grr
   grr = (325)

It complains about this:

Code: [Select]
ERR: mov  al,325!!  Value out of range 325
LINE: 366
FILE: "main source

I would expect the byte to overflow to 69... why not?
Title: Re: Curious things with brackets...
Post by: JRS on June 02, 2019, 06:15:40 PM
I wonder If this would fail?

grr = (325+0)

() means expression included to me. Looks like an expressionless constant .
Title: Re: Curious things with brackets...
Post by: Brian Alvarez on June 02, 2019, 07:10:52 PM

Yes, it fails. Which doesnt make much sense...
Title: Re: Curious things with brackets...
Post by: JRS on June 02, 2019, 08:14:02 PM
Looks like you discovered a core BASIC missing feature.  8)
Title: Re: Curious things with brackets...
Post by: Brian Alvarez on June 02, 2019, 08:17:06 PM
Is this a bug?

 Nah... more likely an inconsistency. Lets see what Charles says. :)
Title: Re: Curious things with brackets...
Post by: JRS on June 02, 2019, 08:26:20 PM

I figured it out.

Solution (https://t.co/AbZpKQfZZx)
Title: Re: Curious things with brackets...
Post by: Charles Pegge on June 03, 2019, 02:21:12 AM
I can fix this problem by setting the minimum accumulator width to 32 bits instead of relying on the bit-width of the destination.

Thanks for pointing it out!

Note:
The error will still be generated if you try this in assembler:

mov al,325
Title: Re: Curious things with brackets...
Post by: Mike Lobanovsky on June 03, 2019, 04:13:23 AM
Gentlemen,

Silent overflows have been the source of countless headaches in the industry for decades. I think they should be intercepted and error-flagged wherever possible.
Title: Re: Curious things with brackets...
Post by: Charles Pegge on June 03, 2019, 07:41:39 AM
Hi Mike,

I think most unintended overflows are likely to be dynamic, and have to be trapped explicitly.

Beware the bank account when your savings exceed 2 billion..
Title: Re: Curious things with brackets...
Post by: Brian Alvarez on June 03, 2019, 10:03:50 AM
I think most unintended overflows are likely to be dynamic, and have to be trapped explicitly.

Exactly.

Added:
 But i also agree with Mike. Maybe i could add ACCOUNTING modules. Which would raise exceptions with dynamic overflows. Or even better....
allow TRY / CATCH to trap any dynamic overflows.
Title: Re: Curious things with brackets...
Post by: Charles Pegge on June 04, 2019, 05:59:25 AM
Quote
I can fix this problem by setting the minimum accumulator width to 32 bits instead of relying on the bit-width of the destination.

Unfortunately, my fix interferes with byte operations in o2 self-compilation so I won't be able to apply it.

But we could have types with built-in limit checks. This can be implemented with the new operator overloading system. It's worth pursuing.
Title: Re: Curious things with brackets...
Post by: Brian Alvarez on June 04, 2019, 03:10:22 PM
Will it do the same?
Title: Re: Curious things with brackets...
Post by: Charles Pegge on June 05, 2019, 12:23:10 AM
Brian,

I'll keep the core behaviour as it is. The programmer can use a bit-mask if appropriate. (For instance working with unresolved equates)

byte a=0xff and 325


My other comment is just an idea. I understand ADA supports types with limits, and also specified values.


Title: Re: Curious things with brackets...
Post by: Brian Alvarez on June 05, 2019, 10:02:54 PM

 I fixed it, and it now gives correct results.

Code: [Select]
byte b

b += 325
b = 325
incr b by 325
b = 255
b++
b = 255
incr b