Frequently Used TypeDef Structures and Variables: Difference between revisions
m (→TOKEN: expanded) |
m (→LPPL_YYSTYPE: nested struct tagPL_YYSTYPE) |
||
Line 37: | Line 37: | ||
} PL_YYSTYPE, *LPPL_YYSTYPE; // Data type of yacc stack; most frequently used is LPPL_YYSTYPE, long pointer to the above structure. | } PL_YYSTYPE, *LPPL_YYSTYPE; // Data type of yacc stack; most frequently used is LPPL_YYSTYPE, long pointer to the above structure. | ||
</pre> | </pre> | ||
In the above code snippet note the '''nested struct''' formation. '''Inner struct tagPL_YYSTYPE resides within code confines''' of outer struct tagPL_YYSTYPE. This formation complies with APL's workspace '''[[System_Command_SI|State Indicator )SI]]''' intrinsic Interpreter design feature. | |||
'''LPPL_YYSTYPE''' is customarily '''variable-type''', as per the following:<br> | '''LPPL_YYSTYPE''' is customarily used as a '''variable-type''', as per the following:<br> | ||
LPPL_YYSTYPE lpYYRes = NULL, // initialize, lpYYRes will be Ptr to result of a ⎕ quad System Function or Primary APL Function call | 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:<br> | and '''macro YYAlloc''' (def. file <macros.h>) call instantiated, then with specific values inserted:<br> |
Revision as of 21:34, 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.
In the above code snippet note the nested struct formation. Inner struct tagPL_YYSTYPE resides within code confines of outer struct tagPL_YYSTYPE. This formation complies with APL's workspace State Indicator )SI intrinsic Interpreter design feature.
LPPL_YYSTYPE is customarily used as a 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 shown at left are beginning byte # in structure) 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 above, ref. TOKEN use just below:
TOKEN tkToken; // (var name = tkToken, extensively used in System and APL Function calls)
Linked or indirect referencing through typed variable-name example: (to fill in a result token):
// Sample token type choices: TKT_VARNAMED, TKT_VARIMMED, TKT_LSTIMMED, TKT_LSTARRAY, TKT_LSTMULT, TKT_VARARRAY(primary), TKT_STRAND and TKT_STRING. // Full list of token types found in file <tokens.h>. TKT_VARARRAY used just below: lpYYRes->tkToken.tkFlags.TknType = TKT_VARARRAY;