Oxygen Basic

Programming => Bugs & Feature Requests => Topic started by: Brian Alvarez on May 22, 2019, 03:58:59 PM

Title: Error passing quad and int to function
Post by: Brian Alvarez on May 22, 2019, 03:58:59 PM
 Hello Charles, I found something weird, please take a look at this:

Code: [Select]
FUNCTION SFUNC1(byval long v1) as quad
    if (v1 = 3434222111) then
        print "SUCCESS" chr(13, 10)
    ELSE
        print "FAILURE" chr(13, 10)
    end if
end function

 FUNCTION SFUNC2(byval quad v1) as quad
    if (v1 = 3434222111) then
        print "SUCCESS" chr(13, 10)
    ELSE
        print "FAILURE" chr(13, 10)
    end if
end function

SFUNC1(3434222111)
SFUNC2(3434222111)

This is supposed to return:

Code: [Select]
FAILURE
SUCCESS

but returns:

Code: [Select]
SUCCESS
FAILURE

Am i wrong?
Title: Re: Error passing quad and int to function
Post by: Brian Alvarez on May 22, 2019, 04:23:26 PM
In these, it should be all SUCCESS, but in SFUNC4 not explicitly stating BYVAL makes it fail and in SFUNC5, passing a second parameter makes it fail...

Code: [Select]
FUNCTION SFUNC4(byval quad v1) as quad
    if (v1 = 3434234233) then
        print "SUCCESS" chr(13, 10)
    ELSE
        print "FAILURE" chr(13, 10)
    end if
end function

FUNCTION SFUNC5(byval quad v1, v2) as quad
    if (v1 = 3434234233) then
        print "SUCCESS" chr(13, 10)
    ELSE
        print "FAILURE" chr(13, 10)
    end if
end function

SFUNC4(3434234233)
SFUNC4(byval 3434234233)
SFUNC5(byval 3434234233, 2)
Title: Re: Error passing quad and int to function
Post by: Charles Pegge on May 22, 2019, 07:43:50 PM
Hi Brian,

The limit for integer literals is currently 32 bits.

o2 may eventually adopt MSVCRT to handle all numeric inputs:

Code: [Select]
'http://www.cplusplus.com/reference/cstdio/scanf/
'http://www.cplusplus.com/reference/cstdio/sscanf/
uses corewin
quad q
char c[256]
c="3434234233"
sscanf(strptr(c), "%dll", @q)
print c chr(13,10) q
Title: Re: Error passing quad and int to function
Post by: Brian Alvarez on May 22, 2019, 08:31:33 PM
 Charles, does this mean passing integers as a quad parameter? is there any other limitation regarding this?
Because as far as i know, 3434234233 does not overflow a 32 bit value.... i looked at my code and it already
handles big integers nicely, but taking "big" a number exceeding 4294967295.

 Also taking in account that it works with 1 parameter but fails with two, tells me there may be something else
in this... specially because this works:

Code: [Select]
quad v = 0
SFUNC5(v+3434234233)

While this:

Code: [Select]
FUNCTION SFUNC5(quad v1, v2) as quad
    if (v1 = 3434234233) then
        print "SUCCESS" chr(13, 10)
    ELSE
        print "FAILURE" chr(13, 10)
    end if
end function

quad v = 0
SFUNC5(v+3434234233, v)

Complains about this:

Code: [Select]
ERROR: parameters mismatch for procedure sfunc5
params given : #long@_

OPTIONS:
sfunc5(quad,quad) returns quad

And this fixes all:

Code: [Select]
SFUNC5(quad (3434234233), quad 2+2)
 Another question: Is there a chance to support BYCOPY with big numbers so that Oxygen creates a temporary
quad variable to pass it as a non-literal number? currently this appears to have no effect... so, i will temporarily
use quad as some sort of bycopy.
Title: Re: Error passing quad and int to function
Post by: Brian Alvarez on May 22, 2019, 09:03:10 PM
The hack worked. Now MOD, AND and other operators work fine with quads, floats and big literal numbers.
Title: Re: Error passing quad and int to function
Post by: Charles Pegge on May 22, 2019, 09:42:09 PM
Your example works correctly on my new o2:

Code: [Select]
FUNCTION SFUNC5(quad v1, v2) as quad
    if (v1 = 3434234233) then
        print "SUCCESS" chr(13, 10)
    ELSE
        print "FAILURE" chr(13, 10)
    end if
end function

quad v = 0
SFUNC5(v+3434234233, v)

bycopy is supported, but unnecessary for numeric primitives passed directly.


PS:

I've been able to extend number literals into the quad range directly, so this will go into the o2 update. :)