[Coco] A bug in Basic09/RunB
Willard Goosey
goosey at virgo.sdc.org
Tue Dec 8 01:59:34 EST 2009
On Mon, Dec 07, 2009 at 09:09:37PM -0800, Wayne Campbell wrote:
> Willard,
>
> I understand. In most languages I have looked at this is true. I am merely
> testing the limits of what appeared to be a possibility, given that I can
> pass a 32-byte array to a 32-character string, or vice-versa, and it works
> just fine.
The difference between BASIC-09 strings and arrays always seemed like
an artificial one to me. Especially since BASIC-09 strings can't vary
in size like MS BASIC strings
>No type checking. I thought, if this is true, then I should be
> able to pass 3 parameters, the sum of whose lengths equal the size of the
> expected variable. I guess the former is relegated to individual
> parameters, and not the list as a whole.
>
Look, I don't know anything about the insides of the ICODE interpeter,
but if the module interface there is the same as the binary module
interface then there is no way that'll work.
For a binary module, there is no such thing as pass by value. It's all
pass by reference. The closest you get is what compiler theory calls
"Pass by value-result". This is really pass-by-reference, but with
checks to make sure you don't clobber the constant table. (BTW this
hack was introduced in FORTRAN II).
Given the strongly stack-oriented behavior of the ICODE engine, I'm
pretty sure it works the same way.
So look at your stack: (16-bit numbers)
you call RUN foo(a,b,c)
stack looks like:
size of c
address of c
size of b
address of b
size of a
address of a
num of args
return address
you call RUN foo(array)
stack looks like:
size of array
address of array
num of args
return address
Whichever one foo() expects, it's going to do bad things when it gets
the other.
The lack of type checking goes both ways. The code doesn't catch it
when you send a module the wrong arguments, and therefore can't do
anything to turn them into sensible arguments.
It's not all bad, though. This interface may not be particularly
type-safe but it easly lends itself to subroutine modules in assembly
and C. It makes it especially easy to write varaidic modules in
assembly (such as GFX and GFX2).
Willard
--
Willard Goosey goosey at sdc.org
Socorro, New Mexico, USA
I search my heart and find Cimmeria, land of Darkness and the Night.
-- R.E. Howard
More information about the Coco
mailing list