[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Pnet-developers] Array access in the java compiler ?
From: |
Rhys Weatherley |
Subject: |
Re: [Pnet-developers] Array access in the java compiler ? |
Date: |
Fri, 28 Mar 2003 06:56:33 +1000 |
User-agent: |
KMail/1.4.3 |
On Friday 28 March 2003 02:18 am, Gopal V wrote:
> Other than generating
>
> int [][]a=new int[10][];
> for(int i=0;i<a.length;i++)
> {
> a[i]=new int[10];
> }
>
> I can't find any decent way to have the constructor.
That's pretty much what you have to do. Either that or use a helper method to
do the work for you. e.g.
Array CreateJavaMultiArray(Type type, params int[] dims);
This would use "Array.CreateInstance" within a recursive create loop to build
up the array and return it.
> Similarly array accesses seem to degenerate into recursive ldelems when
> I do it this way.
>
> //a[0][0]=42;
>
> ldloc.1
> ldc.i4.0
> ldelem
> ldc.i4.0
> ldc.i4.s 42
> stelem.i4
That's how javac compiles it too.
> So do I need to fix up ILNode_JavaArrayAccess and ILNode_JavaNewExpression
> ?. (I hate that !)
You should be able to avoid "JavaArrayAccess". The existing array access code
will evaluate "a[0]" with ILNode_GenValue, and then call ILNode_Prepare for
the next dimension. It should just happen automatically.
You will probably need JavaNewExpression for multi-dimensional arrays though
(single-dimensional should be OK).
Every front-end language will have a few language-specific node types (e.g.
ILNode_CBitField in cscc/c/c_defs.tc). This is to be expected.
Cheers,
Rhys.