Author Topic: Curious things with brackets...  (Read 2160 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Guest
Curious things with brackets...
« 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?

JRS

  • Guest
Re: Curious things with brackets...
« Reply #1 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 .

Brian Alvarez

  • Guest
Re: Curious things with brackets...
« Reply #2 on: June 02, 2019, 07:10:52 PM »

Yes, it fails. Which doesnt make much sense...

JRS

  • Guest
Re: Curious things with brackets...
« Reply #3 on: June 02, 2019, 08:14:02 PM »
Looks like you discovered a core BASIC missing feature.  8)

Brian Alvarez

  • Guest
Re: Curious things with brackets...
« Reply #4 on: June 02, 2019, 08:17:06 PM »
Is this a bug?

 Nah... more likely an inconsistency. Lets see what Charles says. :)

JRS

  • Guest
Re: Curious things with brackets...
« Reply #5 on: June 02, 2019, 08:26:20 PM »

I figured it out.

Solution
« Last Edit: June 02, 2019, 08:56:10 PM by John »

Charles Pegge

  • Guest
Re: Curious things with brackets...
« Reply #6 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

Mike Lobanovsky

  • Guest
Re: Curious things with brackets...
« Reply #7 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.

Charles Pegge

  • Guest
Re: Curious things with brackets...
« Reply #8 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..

Brian Alvarez

  • Guest
Re: Curious things with brackets...
« Reply #9 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.
« Last Edit: June 03, 2019, 03:10:40 PM by Brian Alvarez »

Charles Pegge

  • Guest
Re: Curious things with brackets...
« Reply #10 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.

Brian Alvarez

  • Guest
Re: Curious things with brackets...
« Reply #11 on: June 04, 2019, 03:10:22 PM »
Will it do the same?

Charles Pegge

  • Guest
Re: Curious things with brackets...
« Reply #12 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.



Brian Alvarez

  • Guest
Re: Curious things with brackets...
« Reply #13 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