CosmosOS / Cosmos

Cosmos is an operating system "construction kit". Build your own OS using managed languages such as C#, VB.NET, and more!
https://www.goCosmos.org
BSD 3-Clause "New" or "Revised" License
2.85k stars 536 forks source link

'yasm' failed to build when using C# matrix array. #2943

Closed CodeCs1 closed 2 months ago

CodeCs1 commented 3 months ago

Why i'm open this issue ?

Because i want to know why Cosmos doesn't support matrix array.

What happened ?

int[,] numbers = { {1, 4, 2}, {3, 6, 8} };
Console.WriteLine(numbers[0, 2]);

When I start to build the project with those code, 'yasm' failed to build.

Error Message:

  bin/cosmos/Debug/net6.0/TerminalOS_L.asm:56212: error: undefined symbol `SystemVoidA0A0SystemInt32arrayctorA0SystemInt32A0SystemInt32' (first use)
  bin/cosmos/Debug/net6.0/TerminalOS_L.asm:56212: error:  (Each undefined symbol is reported only once.)
  bin/cosmos/Debug/net6.0/TerminalOS_L.asm:56260: error: undefined symbol `A0SystemInt32A0A0SystemInt32arrayGetA0SystemInt32A0SystemInt32' (first use)

Cosmos Version

Latest version (dev)

Operating System (in case)

Linux x86_64

So, it there any alternative way to use matrix in Cosmos C#?

--- Sorry for my bad English =| ---

pleasenoban commented 3 months ago

you could use jagged arrays instead because multidimensional arrays arent plugged yet

CodeCs1 commented 3 months ago

This is what i get: Screenshot_20240205_184645

I use this example code:

    int[][] jagged_arr = new int[4][]; 
    jagged_arr[0] = new int[] {1, 2, 3, 4}; 
    jagged_arr[1] = new int[] {11, 34, 67}; 
    jagged_arr[2] = new int[] {89, 23}; 
    jagged_arr[3] = new int[] {0, 45, 78, 53, 99}; 

Somehow using jagged arrays caused exception.

zarlo commented 3 months ago

you might be able to use Multidimensional Indexers (dont know if this is supported in cosmos) to make a wrapper around a d1 array to expose it as 2d

public class MultidimensionalArrary<T> { 
    T[] data; 

    int _sizeLevel1;
    int _sizeLevel2;

    public MultidimensionalArrary<T>(int sizeLevel1, int sizeLevel2)
    {
        data = new T[sizeLevel1 * sizeLevel2]
        _sizeLevel1 = sizeLevel1;
        _sizeLevel2 = sizeLevel2;
    }

    public T this[int index1, int index2] 
    {
        get
        {                
            return data[(index1 * _sizeLevel1) * index2];      
        } 
        set
        { 
            data[(index1 * _sizeLevel1) * index2] = value;               
        } 
    }

} 

note i have not tested this

pleasenoban commented 3 months ago

This is what i get: Screenshot_20240205_184645

I use this example code:

    int[][] jagged_arr = new int[4][]; 
    jagged_arr[0] = new int[] {1, 2, 3, 4}; 
    jagged_arr[1] = new int[] {11, 34, 67}; 
    jagged_arr[2] = new int[] {89, 23}; 
    jagged_arr[3] = new int[] {0, 45, 78, 53, 99}; 

Somehow using jagged arrays caused exception.

jagged arrays are supposed to work in cosmos. are you sure the problem isnt in other regions of your code?

COR-ET commented 2 months ago

@CodeCs1 You can use Lists, its way better, here is an example :

List<Point> snake;

        private class Point
        {
            public int X { get; set; }
            public int Y { get; set; }

            public Point(int x, int y)
            {
                X = x;
                Y = y;
            }
        }
quajak commented 2 months ago

Issue is already being tracked here https://github.com/CosmosOS/IL2CPU/issues/11