[Scilab-Dev] Accessing the stack
ycollet at freesurf.fr
ycollet at freesurf.fr
Fri Jan 9 11:11:13 CET 2009
Thanks a lot.
I will try all these functions and, If I find some time, I will add some
examples on the wiki page.
YC
On Fri, 09 Jan 2009 11:08:53 +0100, Antoine ELIAS
<antoine.elias at scilab.org> wrote:
> Hi Yann,
> I think you are fluent in stack language :D
>
> So I wrote some functions to "abstract" the complexity of the stack
> structures but these functions aren't available in the git master branch
> (only in YaSp branch).
> I don't have enough time for the moment to make all tests to validate
> them but I hope you can find information for your stack problem ...
>
> modules/core/includes/stack3.h:
>
http://gitweb.scilab.org/?p=scilab;a=blob;f=scilab/modules/core/includes/stack3.h;h=315fbeb8cd85bd0f83e84b90637e8e359ac4eaaf;hb=refs/heads/YaSp
>
> ( line 134 to the EOF ) and
> modules/core/src/c/stack3.c :
>
http://gitweb.scilab.org/?p=scilab;a=blob;f=scilab/modules/core/src/c/stack3.c;h=ee1dcab2a5ec276e21fd34d5a8169a54df608d71;hb=refs/heads/YaSp
>
> ( line 1272 to EOF )
>
> In your case:
>
> *istk(iadr(1)) = 1; // For a vector of double
> I think iadr(1) must be replaced by iadr(*Lstk(VariablePosition))
>
> with Lstk macro, you get the "Scilab address" of the variable in the
> stack via vstk.lstk array and after translate this "Scilab address" to a
> real pointer ( int* ) with iadr ( easy ! )
>
> Sample :
> int iAddr = iadr(*Lstk(Top - Rhs + YourNewVarPosition));
> int* piAddr = istk(iAddr);
>
> piAddr[0] = 1; //sci_matrix
> piAddr[1] = 2; //Rows
> piAddr[2] = 3; //Cols
> piAddr[3] = 0; //Real
>
> double *pdblRealData = (double*)(_piAddr + 4);
>
> for(i = 0 ; i < 6 ; i++)
> {
> pdblRealData[i] = 1.0;
> }
>
> I hope you can resolve your problem, don't hesitate to ask me, here or
> directly, if you have any questions about the stack.
>
>
> ELIAS Antoine
> antoine.elias at scilab.org
>
> ycollet at freesurf.fr a écrit :
>> Hello,
>>
>> I have some questions related to how to access the stack.
>> I would like to create a function which takes a mlist as parameters and
>> returns a pointers to one element of the list. Something like:
>>
>> GetRhsVar(1, "m", &m_list, &n_list, &l_list);
>> GetListVar(1, &m_list, &n_list, &l_list, 2, "d", &m_param_2, &n_param_2,
>> &l_param_2);
>>
>> And now, I am able to access to the element 2 of the mlist like a normal
>> scilab variable.
>> I needed such a function to be able to access / create mlist in mlist.
>>
>> So my questions are related to the functions used to access the stack.
>>
>> iadr(pos): returns a "scilab pointer" to an int variable stored at
>> position
>> pos on the stack ?
>> sard(pos): returns a "scilab pointer" to a double variable stored at
>> position pos on the stack ?
>> card(pos): returns a "scilab pointer" to a char variable stored at
>> position
>> pos on the stack ?
>>
>> Lstk(pos): returns a generic "scilab pointer" to a variable stored at
>> position pos on the stack ?
>>
>> What are the use of the vstk, com and iop stack structure ?
>>
>> The document "scilab internal" is a little bit hard to understand / read
>> for such questions.
>>
>> Now, let's try to create manually a vector of doubles:
>>
>> From the wiki:
>>
>> Type 32 bits 1 integer from Scilab Internal Datatypes
>> Lines 32 bits 1 integer, number of lines in the matrix, for
>> a
>> single number, Scilab store it like a matrix [1,1]
>> Columns 32 bits 1 integer, number of columns in the matrix,
>> for
>> a single number, Scilab store it like a matrix [1,1]
>> Complex 32 bits 1 integer, 0 for real number, 1 for complex
>> number
>> Real part n * 64 bits Each real part is store in a double
>> Imaginary part n * 64 bits Each imaginary part is store in a double
>>
>> // My var is at position 1
>>
>> *istk(iadr(1)) = 1; // For a vector of double
>> *istk(iadr(1)+1) = 2;
>> *istk(iadr(1)+2) = 3; // So we have a 2x3 matrix
>> *istk(iadr(1)+3) = 0: // and it's a real matrix
>> for(i=0;i<6;i++) *istk(iadr(1)+4+2*i+0) = 1.0;
>>
>> Am I accessing the double vector structure correctly ?
>>
>> YC
>>
>>
>
More information about the dev
mailing list