HighTechTalks DotNet Forums  

IL coding question

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss IL coding question in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Antonio Linares
 
Posts: n/a

Default IL coding question - 06-30-2003 , 06:00 AM






I am curretly porting an open source language www.harbour-project.org to
..NET.

I have the following IL coding question, hopefully someone may provide me
some guidance:

I have some objects ("object" type) placed at the stack. Then I need to
create an ArrayList and pop those objects from the stack and add them to the
array. i.e.:

ldc.i4.s 123
box [mscorlib]System.Int32
ldc.i4.s 456
box [mscorlib]System.Int32
call object ObjArrayGen( int32 ) // I do know how many objects are
placed at the stack

The question is how could I pop those objects from the stack and add them to
a new created ArrayList from inside ObjArrayGen() ? I can't create a
object[] in advance (I already considered such way).

thanks!

Please remove REMOVE_THIS from my address to answer me directly.

Antonio



Reply With Quote
  #2  
Old   
Antonio Linares
 
Posts: n/a

Default Re: IL coding question - 06-30-2003 , 07:03 AM






Mattias,

Quote:
You can't access the caller's part of the stack from inside
ObjArrayGen. You have to pass in those objects as parameters.
Ok, I see.

And what about if I don't call a method ObjArrayGen() ? I mean, could I
place some IL instructions there to get what I need ? I am thinking about
something like this:

ldc.i4.s 123
box [mscorlib]System.Int32
ldc.i4.s 456
box [mscorlib]System.Int32

create object[ number of stack params ] // pseudo code
fill such object[] from the stack // pseudo code

call object ObjArrayGen( object[] )

thanks,

Antonio




Reply With Quote
  #3  
Old   
Antonio Linares
 
Posts: n/a

Default Re: IL coding question - 06-30-2003 , 08:07 AM



Mattias,

I am reviewing some docs abot the varargs way of working. You are right,
that could be the way :-)

thanks!

Antonio



Reply With Quote
  #4  
Old   
Gabriele G. Ponti
 
Posts: n/a

Default Re: IL coding question - 06-30-2003 , 08:25 AM



Antonio,

One of the constructors of the ArrayList class accepts an ICollection as
parameter. Stack is a class that implements the ICollection interface. So
what I am suggesting here is to use a temporary class to push your objects,
and then create the ArrayList from the stack.

..locals init ([0] class [mscorlib]System.Collections.Stack stack,
[1] class [mscorlib]System.Collections.ArrayList arraylist)
newobj instance void [mscorlib]System.Collections.Stack::.ctor()
stloc.0
ldloc.0
ldc.i4.s 123
box [mscorlib]System.Int32
callvirt instance void
[mscorlib]System.Collections.Stack::Push(object)
ldloc.0
ldc.i4 456
box [mscorlib]System.Int32
callvirt instance void
[mscorlib]System.Collections.Stack::Push(object)
ldloc.0
newobj instance void
[mscorlib]System.Collections.ArrayList::.ctor(class [mscorlib]
System.Collections.ICollection)
stloc.1

Maybe having a temporary variable is not the most elegant solution, but it
is something that VB.NET and C# compilers often do.

Gabriele

"Antonio Linares" <alinaresREMOVE_THIS (AT) fivetechsoft (DOT) com> wrote

Quote:
I am curretly porting an open source language www.harbour-project.org to
.NET.

I have the following IL coding question, hopefully someone may provide me
some guidance:

I have some objects ("object" type) placed at the stack. Then I need to
create an ArrayList and pop those objects from the stack and add them to
the
array. i.e.:

ldc.i4.s 123
box [mscorlib]System.Int32
ldc.i4.s 456
box [mscorlib]System.Int32
call object ObjArrayGen( int32 ) // I do know how many objects
are
placed at the stack

The question is how could I pop those objects from the stack and add them
to
a new created ArrayList from inside ObjArrayGen() ? I can't create a
object[] in advance (I already considered such way).

thanks!

Please remove REMOVE_THIS from my address to answer me directly.

Antonio





Reply With Quote
  #5  
Old   
Antonio Linares
 
Posts: n/a

Default Re: IL coding question - 06-30-2003 , 10:05 AM



Gabriele,

Thanks for your suggestion, but I got it working using Mattias advice,

regards,

Antonio



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.