Re: Array initialization

David Hakim <dhakim-Gkm/TONP9n1Wk0Htik3J/[email protected]> Mon, 27 Jan 2003 11:40:18 -0500
Newsgroups gmane.comp.lang.moto.devel
Message-ID <[email protected]>
On Monday, January 27, 2003, at 12:11  PM, Stefano Corsi wrote:

> Alle 15:58, lunedì 27 gennaio 2003, David Hakim ha scritto:
>
>> If pippo is declared as 'int[][][] pippo' you should be able to do the
>> following print fine without the cast.
>
> It's true!!!!!!!! This works:
>
> int[][][] pippo = <int[][][]>[
>       [1,2],
>       [2,4],
>       [
>          [8,9],
>          [10,11]
>       ]
>    ];
>
> print pippo[2][1][1];
>
> I didn't noticed it. Isn't it beautiful when things take their place
> automagically?
>
> And now... any hint on the compiled version?

I see lots and lots and lots of commas :) Probably one giant compound 
expression that both allocates the arrays and sub arrays and then sets 
the individual elements.

The interpreter code looks very nice btw!
-Dave

> Assign values to array is
> puzzling me. In the interpreted version I did:
>
> MotoVal *val;
> MotoVar *rvar;
>
> ...loop...
>
> val = opstack_pop(env);
>
> rvar = moto_createVar(
> 	env,NULL,
> 	r->refval.subtype->name,
> 	r->refval.dim - dimarr[0],
> 	'\1',
> 	NULL
> );
> rvar->address = &ua->aa.data[i];
>
> moto_setVarVal(env, rvar, val);
>
> moto_freeVal(env, val);
> moto_freeVar(env, rvar);
>
> ...end loop...
>
> Stefano
>
>
>