Frequently Used TypeDef Structures and Variables: Difference between revisions

From NARS2000
Jump to navigationJump to search
m (→‎LPPL_YYSTYPE: expanded)
m (added typedef TOKEN)
Line 7: Line 7:
===LPPL_YYSTYPE===
===LPPL_YYSTYPE===


The full definition for typedef '''LPPL_YYTYPE''' is found in file <'''pl_parse.h'''>. '''Partial''', extracted, compiler-directives-excluded/simplified definition:
Full definition for typedef '''LPPL_YYTYPE''': found in file <'''pl_parse.h'''>. '''Partial''', extracted, compiler-directives-excluded/simplified definition:
<pre>
<pre>
typedef struct tagPL_YYSTYPE        // YYSTYPE for ParseLine
typedef struct tagPL_YYSTYPE        // YYSTYPE for ParseLine
Line 46: Line 46:
     lpYYRes->tkToken.tkData.tkGlbData  = MakePtrTypeGlb (hGlbRes);
     lpYYRes->tkToken.tkData.tkGlbData  = MakePtrTypeGlb (hGlbRes);
     lpYYRes->tkToken.tkCharIndex      = lptkFunc->tkCharIndex;
     lpYYRes->tkToken.tkCharIndex      = lptkFunc->tkCharIndex;
===TOKEN===
Full definition for typedef '''TOKEN''': found in file <'''tokens.h'''>:
<pre>
typedef struct tagTOKEN
{
    TKFLAGS          tkFlags;      // 00:  The flags part (numbers at left are beginning byte #)
    SO_ENUM          tkSynObj;      // 04:  The Syntax Object for this token
    TOKEN_DATA      tkData;        // 08:  The data part (16 bytes=18 Hex - 08 Hex = 10 Hex)
    int              tkCharIndex;  // 18:  Index into the input line of this token
                                    // 1C:  Length (1C Hex = 16+12 decimal # = byte #28)
} TOKEN, *LPTOKEN;
</pre>
<u>Primary sample usage</u>: Above typedef TOKEN is the first type-var found in typedef LPPL_YYSTYPE, ref:
<pre>
    TOKEN tkToken; // (var name = tkToken, extensively used in System and APL Function calls)
</pre>
<u>Linked or through variable-name example usage</u>: (to fill in a result token):
<pre>
    lpYYRes->tkToken.tkFlags.TknType  = TKT_VARARRAY;
</pre>


==Variable Types==
==Variable Types==

Revision as of 19:55, 6 August 2015

NARS C Source Code Frequently Used TypeDef Structures and Variables:

NARS has multiple frequently used TypeDefs, Structures, Type-Variables and Variables. Familiarity with these structures, including variables employed, is essential toward gaining increased understanding of how NARS C source code works, including insight into C program flow.

TypeDefs

LPPL_YYSTYPE

Full definition for typedef LPPL_YYTYPE: found in file <pl_parse.h>. Partial, extracted, compiler-directives-excluded/simplified definition:

typedef struct tagPL_YYSTYPE        // YYSTYPE for ParseLine
{
    // N.B.:  The first item in this struct *MUST* be the TOKEN
    //   because when we pass it as an argument to an LPPRIMFNS
    //   we might need it to be an LPPL_YYSTYPE (for a function strand)
    //   or an LPTOKEN (single function).
    TOKEN   tkToken;                // 00:  Token info (28 bytes)
    UINT    TknCount;               // 1C:  Count of adjacent tokens including this one
    UINT    YYInuse:1,              // 20:  00000001:  This entry is in use
            YYIndirect:1,           //      00000002:  Arg is indirect
            YYPerm:1,               //      00000004:  Item is permanent, don't free
            YYStranding:1,          //      00000008:  Item is in the process of being stranded
            :28;                    //      FFFFFFF0:  Available bits

    struct tagPL_YYSTYPE
           *lpYYFcnBase,            // 24:  Ptr to base function/operator
                                    //      Not valid outside the enclosing
                                    //        invocation of ParseLine
           *lpYYStrandBase,         // 28:  Ptr to this token's strand base
           *lpplYYArgCurry,         // 2C:  Ptr to left argument curry
           *lpplYYIdxCurry,         // 30:  Ptr to axis curry
           *lpplYYFcnCurry,         // 34:  ...         function ...
           *lpplYYOpRCurry;         // 38:  ...    right operand ...
    LPTOKEN lptkLftBrace,           // 3C:  Ptr to the AFO's left brace token
            lptkRhtBrace;           // 40:  ...              right ...
                                    // 44:  Length
} PL_YYSTYPE, *LPPL_YYSTYPE;        // Data type of yacc stack; most frequently used is LPPL_YYSTYPE, long pointer to the above structure.

LPPL_YYSTYPE is customarily variable-type, as per the following:

   LPPL_YYSTYPE lpYYRes = NULL,    // initialize, lpYYRes will be Ptr to result of a ⎕ quad System Function or Primary APL Function call

and macro YYAlloc (def. file <macros.h>) call instantiated, then with specific values inserted:

   lpYYRes = YYAlloc ();           // Allocate free memory, fill LPPL_YYSTYPE memory structure with default setup/values, e.g. <qf_ec.c>
   // Fill in the result token
   lpYYRes->tkToken.tkFlags.TknType   = TKT_VARARRAY;
   lpYYRes->tkToken.tkData.tkGlbData  = MakePtrTypeGlb (hGlbRes);
   lpYYRes->tkToken.tkCharIndex       = lptkFunc->tkCharIndex;

TOKEN

Full definition for typedef TOKEN: found in file <tokens.h>:

typedef struct tagTOKEN
{
    TKFLAGS          tkFlags;       // 00:  The flags part (numbers at left are beginning byte #)
    SO_ENUM          tkSynObj;      // 04:  The Syntax Object for this token
    TOKEN_DATA       tkData;        // 08:  The data part (16 bytes=18 Hex - 08 Hex = 10 Hex)
    int              tkCharIndex;   // 18:  Index into the input line of this token
                                    // 1C:  Length (1C Hex = 16+12 decimal # = byte #28)
} TOKEN, *LPTOKEN;

Primary sample usage: Above typedef TOKEN is the first type-var found in typedef LPPL_YYSTYPE, ref:

    TOKEN tkToken; // (var name = tkToken, extensively used in System and APL Function calls)

Linked or through variable-name example usage: (to fill in a result token):

    lpYYRes->tkToken.tkFlags.TknType   = TKT_VARARRAY;

Variable Types

Variables