bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

StaticArray as return or param #552

Closed GWRon closed 3 years ago

GWRon commented 3 years ago
SuperStrict
Framework Brl.StandardIO
Import Brl.Retro

Struct STest
    Field StaticArray ints:Int[10]

    Method GetInts:Int[]()
        Return ints
    End Method
End Struct

Local s:STest = New STest
s.ints[0] = 10

Print s.GetInts().length 'prints 0

How to return the static array? How do I need to format it to define a function param to be of "StaticArray int[]" ?

HurryStarfish commented 3 years ago

StaticArray as a parameter doesn't seem to be working right either. This does not compile:

Struct STest
    Field StaticArray a:Byte[8]
End Struct

Function Get:STest(StaticArray x:Byte[8])
    Local s:STest = New STest
    s.a = x
End Function

But this does:

Struct STest
    Field a:Byte[8]
End Struct
Function Get:STest(StaticArray x:Byte[8])
    Local s:STest = New STest
    s.a = x
End Function
HurryStarfish commented 3 years ago

On a related note, the StaticArray syntax is quite weird. When declaring an identifier, despite being part of the type, the keyword StaticArray keyword goes in front of the identifier. This makes it unlike anything else in BlitzMax and splits the type in two halves. So what would be the syntax for writing a StaticArray type without declaring an identifier (for example: function return type, generic type parameter)? Personally, I'd have preferred syntax like Field a:Byte[Const 8] for it - which wouldn't have this problem (and not have required a new keyword either).

GWRon commented 3 years ago

Thanks