Frequently Used TypeDef Structures and Variables
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 same-name tagPL_YYSTYPE. This formation parallels nicely with APL's workspace State Indicator )SI intrinsic Interpreter design feature which is used for APL-programmer debugging purposes.
- For ⎕ System Function and Primary APL Function calls, the above typedef is the normal or the expected - returned value-group, the returned value-set structure. Further, since NARS by its very nature handles nested arrays, the above structure similarly manages nested data arrays well. In case it is not obvious to anyone reading this web page or examining NARS source code - NARS represents a highly evolved, data-fluid, APL Interpreter with a full, rich symbol-set programming environment.
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;
tkToken Commonly Used Structures
C Source Code Sample Short List of tkToken Structure Groupings Found in files <qf_*.c and pf_*.c> Functions with FileName plus Line # Cross References and Frequencies (per C:\NARS2000\trunk qf_*.c/pf_*.c files) as of Mon 8/17/15:
FileName | Line # | Structure/Value | Overall Found Freq | Overall Found % Tot |
---|---|---|---|---|
qf_ec.c | 237 | tkToken | 820 | 100.0% |
qf_a.c | 67 | tkToken.tkCharIndex | 134 | 16.3% |
pf_cstile.c | 182 | tkToken.tkData.tkBoolean | 13 | 1.6% |
qf_tc.c | 162 | tkToken.tkData.tkChar | 5 | 0.6% |
qf_dl.c | 179 | tkToken.tkData.tkFloat | 9 | 1.1% |
qf_a.c | 66 | tkToken.tkData.tkGlbData | 135 | 16.5% |
qf_dr.c | 98 | tkToken.tkData.tkInteger | 25 | 3.0% |
qf_dr.c | 309 | tkToken.tkData.tkLongest | 18 | 2.2% |
qf_ec.c | 275 | tkToken.tkData.tkSym | 3 | 0.4% |
qf_ec.c | 268 | tkToken.tkData.tkVoid | 1 | 0.1% |
qf_a.c | 64 | tkToken.tkFlags.ImmType | 145 | 17.7% |
qf_a.c | 65 | tkToken.tkFlags.NoDisplay | 140 | 17.1% |
qf_a.c | 63 | tkToken.tkFlags.TknType | 148 | 18.0% |
pf_index.c | 774 | tkToken.tkSynObj | 1 | 0.1% |
One analogy to NARS tkToken structure groupings can be found in Particle Physics where Quarks, Leptons, Gluons and Gravitons comprise a particle class known as Fermions; particle and C code subtypes or subclasses also exist. NARS tkToken structure groupings, just as is true for Fermions, allows for a wide range of C coded functionality groupings. tkToken is a convenient way of grouping several pieces of related information together with flexibility for handling potentially broadly different datatypes, shapes and even functionality. A nested matrix of mixed elements can be handled, as well accommodation for workspace state indicator stack value-sets - all within tkToken structures.
tkToken Structures More Detailed Sample Uses Table
C Source Code Sample Uses Unique (duplicates removed) List of tkToken Structure = Values Found in files <qf_*.c and pf_*.c> Functions with FileName plus Line # Cross References (per C:\NARS2000\trunk qf_*.c/pf_*.c files), sorted by source filename, as of Mon 8/17/15:
FileName | Line # | Ref. Variable Name -> Structure Group = Value |
---|---|---|
qf_a.c | 63 | lpYYRes->tkToken.tkFlags.TknType = TKT_VARARRAY; |
qf_a.c | 66 | lpYYRes->tkToken.tkData.tkGlbData = MakePtrTypeGlb (hGlbQuadA); |
qf_a.c | 67 | lpYYRes->tkToken.tkCharIndex = lptkFunc->tkCharIndex; |
qf_at.c | 406 | lpYYRes->tkToken.tkData.tkGlbData = MakePtrTypeGlb (hGlbRes); |
qf_av.c | 66 | lpYYRes->tkToken.tkData.tkGlbData = MakePtrTypeGlb (hGlbQuadAV); |
qf_d.c | 66 | lpYYRes->tkToken.tkData.tkGlbData = MakePtrTypeGlb (hGlbQuadD); |
qf_dl.c | 176 | lpYYRes->tkToken.tkFlags.TknType = TKT_VARIMMED; |
qf_dl.c | 177 | lpYYRes->tkToken.tkFlags.ImmType = IMMTYPE_FLOAT; |
qf_dl.c | 179 | lpYYRes->tkToken.tkData.tkFloat = aplFloatRht; |
qf_dr.c | 96 | lpYYRes->tkToken.tkFlags.ImmType = IMMTYPE_INT; |
qf_dr.c | 110 | lpYYRes->tkToken.tkData.tkInteger = DR_BOOL; |
qf_dr.c | 115 | lpYYRes->tkToken.tkData.tkInteger = DR_INT64; |
qf_dr.c | 120 | lpYYRes->tkToken.tkData.tkInteger = DR_FLOAT; |
qf_dr.c | 125 | lpYYRes->tkToken.tkData.tkInteger = DR_CHAR16; |
qf_dr.c | 130 | lpYYRes->tkToken.tkData.tkInteger = DR_APA; |
qf_dr.c | 135 | lpYYRes->tkToken.tkData.tkInteger = DR_HETERO; |
qf_dr.c | 140 | lpYYRes->tkToken.tkData.tkInteger = DR_NESTED; |
qf_dr.c | 145 | lpYYRes->tkToken.tkData.tkInteger = DR_RAT; |
qf_dr.c | 150 | lpYYRes->tkToken.tkData.tkInteger = DR_VFP; |
qf_dr.c | 307 | lpYYRes->tkToken.tkFlags.ImmType = immTypeRes; |
qf_dr.c | 309 | lpYYRes->tkToken.tkData.tkLongest = aplLongestRes; |
qf_em.c | 70 | lpYYRes->tkToken.tkData.tkGlbData = hGlbRes; |
qf_fx.c | 353 | lpYYRes->tkToken.tkData.tkInteger = GetQuadIO () + SF_Fcns.uErrLine; |
qf_mf.c | 493 | lpYYRes->tkToken.tkData.tkInteger = aplIntegerRes; |
qf_mf.c | 506 | lpYYRes->tkToken.tkData.tkFloat = aplFloatRes; |
qf_mf.c | 806 | lpYYRes->tkToken.tkFlags.NoDisplay = TRUE; |
qf_nfns.c | 275 | lpYYRes->tkToken.tkData.tkInteger = aplFileOff; |
qf_nfns.c | 592 | lpYYRes->tkToken.tkFlags.NoDisplay = (aplLongestRht NE 0); |
qf_nfns.c | 593 | lpYYRes->tkToken.tkData.tkInteger = TieNum; |
qf_nfns.c | 1083 | lpYYRes->tkToken.tkData.tkGlbData = hGlbRht; |
qf_nfns.c | 1091 | lpYYRes->tkToken.tkData.tkInteger = aplLongestRht; |
qf_nfns.c | 3298 | lpYYRes->tkToken.tkData.tkInteger = aplFileSize; |
qf_t.c | 75 | lpYYRes->tkToken.tkData.tkFloat = aplFloatSec; |
qf_tc.c | 160 | lpYYRes->tkToken.tkFlags.ImmType = IMMTYPE_CHAR; |
qf_tc.c | 162 | lpYYRes->tkToken.tkData.tkChar = wc; |
qf_ucs.c | 206 | lpYYRes->tkToken.tkData.tkLongest = aplLongestRht; |
qf_wa.c | 70 | lpYYRes->tkToken.tkData.tkInteger = msex.ullAvailPhys + msex.ullAvailPageFile; |
pf_bar.c | 323 | lpYYRes->tkToken.tkData.tkGlbData = MakePtrTypeGlb (*lphGlbRes); |
pf_cslope.c | 255 | lpYYRes->tkToken.tkData.tkGlbData = MakePtrTypeGlb (hGlbLft); |
pf_cslope.c | 259 | lpYYRes2 = PrimFnDydCircleSlope_EM_YY (&lpYYRes->tkToken, |
pf_cslope.c | 416 | lpYYRes->tkToken.tkFlags.ImmType = lptkRhtArg->tkData.tkSym->stFlags.ImmType; |
pf_cslope.c | 418 | lpYYRes->tkToken.tkData.tkLongest = lptkRhtArg->tkData.tkSym->stData.stLongest; |
pf_cslope.c | 425 | lpYYRes->tkToken = *lptkRhtArg; |
pf_cstile.c | 178 | lpYYRes->tkToken = tkZero; |
pf_cstile.c | 252 | lpYYRes->tkToken.tkFlags.ImmType = IMMTYPE_BOOL; |
pf_cstile.c | 374 | lpYYRes->tkToken = *CopyToken_EM (lptkRhtArg, FALSE); |
pf_darrow.c | 372 | lpYYRes->tkToken.tkFlags.ImmType = TranslateArrayTypeToImmType (aplTypeRht); |
pf_domino.c | 220 | lpYYRes->tkToken.tkData.tkBoolean = 1; |
pf_domino.c | 481 | lpYYRes->tkToken.tkFlags.TknType = |
pf_domino.c | 526 | lpYYRes->tkToken.tkData.tkGlbData = |
pf_dshoe.c | 161 | lpYYRes->tkToken.tkData.tkGlbData = MakePtrTypeGlb (hGlbZilde); |
pf_dshoe.c | 480 | hGlbGup = lpYYRes->tkToken.tkData.tkGlbData; |
pf_dtack.c | 219 | lpYYRes->tkToken.tkData.tkBoolean = FALSE; |
pf_dtack.c | 224 | lpYYRes->tkToken.tkData.tkInteger = 0; |
pf_dtack.c | 229 | lpYYRes->tkToken.tkData.tkFloat = 0; |
pf_dtack.c | 234 | lpYYRes->tkToken.tkData.tkChar = L' '; |
pf_dtack.c | 248 | lpYYRes->tkToken.tkFlags.ImmType = lptkRhtArg->tkFlags.ImmType; |
pf_dtack.c | 309 | lpYYRes->tkToken.tkData.tkGlbData = hSymGlbRes; |
pf_dtackjot.c | 375 | lpYYRes->tkToken.tkData.tkChar = aplCharRht; |
pf_epsilon.c | 2398 | hGlbGupLft = lpYYRes->tkToken.tkData.tkGlbData; |
pf_epsilon.c | 2429 | hGlbGupRht = lpYYRes->tkToken.tkData.tkGlbData; |
pf_epsilon.c | 3731 | bCmp = lpYYTmp->tkToken.tkData.tkBoolean; |
pf_epsund.c | 279 | lpYYRes->tkToken.tkData.tkBoolean = // Filled in below |
pf_epsund.c | 288 | lpMemRes = &lpYYRes->tkToken.tkData.tkBoolean; |
pf_equalund.c | 532 | lpYYRes->tkToken.tkData.tkBoolean = (APLBOOL) ((BIT0 & aplIntegerRes) NE bNotEqual); |
pf_index.c | 117 | lpYYRes->tkToken.tkFlags.ImmType = TranslateArrayTypeToImmType (aplTypeNam); |
pf_index.c | 119 | lpYYRes->tkToken.tkData.tkLongest = aplLongestNam; |
pf_index.c | 120 | lpYYRes->tkToken.tkCharIndex = lptkLstArg->tkCharIndex; |
pf_index.c | 127 | lpYYRes->tkToken.tkData.tkGlbData = CopySymGlbDirAsGlb (hGlbNam); |
pf_index.c | 591 | *((LPAPLBOOL) lpMemRes) |= lpYYItm->tkToken.tkData.tkBoolean << uBitIndex; |
pf_index.c | 604 | *((LPAPLINT) lpMemRes)++ = lpYYItm->tkToken.tkData.tkInteger; |
pf_index.c | 610 | *((LPAPLFLOAT) lpMemRes)++ = lpYYItm->tkToken.tkData.tkFloat; |
pf_index.c | 616 | *((LPAPLCHAR) lpMemRes)++ = lpYYItm->tkToken.tkData.tkChar; |
pf_index.c | 639 | lpSymTmp = MyGlobalLock (lpYYItm->tkToken.tkData.tkGlbData); |
pf_index.c | 645 | MyGlobalUnlock (lpYYItm->tkToken.tkData.tkGlbData); lpSymTmp = NULL; |
pf_index.c | 648 | DbgGlobalFree (lpYYItm->tkToken.tkData.tkGlbData); lpYYItm->tkToken.tkData.tkGlbData = NULL; |
pf_index.c | 774 | lpYYRes->tkToken.tkSynObj = soA; |
pf_index.c | 878 | lpYYRes->tkToken.tkFlags.ImmType = immTypeNam; |
pf_index.c | 2016 | lpYYRes->tkToken.tkFlags.TknType = TKT_LSTIMMED; |
pf_index.c | 2019 | lpYYRes->tkToken.tkFlags.TknType = TKT_LSTARRAY; |
pf_index.c | 2514 | lpMemRes[0] = lpYYItm->tkToken.tkData.tkGlbData; |
pf_index.c | 2546 | hGlbSubRht = lpYYSub->tkToken.tkData.tkGlbData; |
pf_index.c | 2913 | lpYYRes2 = PrimFnDydRho_EM_YY (&lpYYRes1->tkToken, |
pf_index.c | 2924 | hGlbRes = lpYYRes2->tkToken.tkData.tkGlbData; |
pf_index.c | 3593 | hGlbSubLst2 = lpYYItm->tkToken.tkData.tkGlbData; |
pf_index.c | 4536 | lpYYRes2 = ExecFuncStr_EM_YY (&lpYYRes1->tkToken, |
pf_lshoe.c | 212 | lpYYRes->tkToken.tkFlags.ImmType = ImmType; |
pf_lshoe.c | 214 | lpYYRes->tkToken.tkData.tkLongest = aplLongest; |
pf_lshoe.c | 316 | lpYYRes->tkToken.tkData.tkGlbData = CopySymGlbDirAsGlb (hGlbRht); |
pf_rshoe.c | 263 | lpYYRes->tkToken.tkFlags.ImmType = immType; |
pf_rshoe.c | 1769 | lpYYRes2->tkToken.tkFlags.TknType = TKT_VARARRAY; |
pf_rshoe.c | 1772 | lpYYRes2->tkToken.tkData.tkGlbData = MakePtrTypeGlb (hGlbLft); |
pf_rshoe.c | 1773 | lpYYRes2->tkToken.tkCharIndex = lptkFunc->tkCharIndex; |
pf_rshoe.c | 1776 | lpYYRes3 = PrimFnDydCircleSlope_EM_YY (&lpYYRes2->tkToken, |
pf_rshoe.c | 1996 | lpYYRes->tkToken.tkFlags.ImmType = immTypeRht; |
pf_rshoe.c | 2396 | lpYYRes->tkToken.tkData.tkGlbData = CopySymGlbNumDir_PTB (hGlbRes, aplTypeRht, lptkFunc); |
pf_rshoe.c | 3014 | lpYYRes->tkToken.tkFlags.ImmType = immTypeSubRht; |
pf_rshoe.c | 3016 | lpYYRes->tkToken.tkData.tkLongest = aplLongestSubRht; |
pf_rshoe.c | 3034 | lpYYRes->tkToken.tkData.tkGlbData = CopySymGlbNumDir_PTB (hGlbRht, aplTypeRht, lptkFunc); |
pf_rtack.c | 188 | lpYYRes->tkToken.tkData.tkGlbData = CopySymGlbDirAsGlb (hGlbArg); |
pf_rtack.c | 194 | lpYYRes->tkToken.tkFlags.ImmType = TranslateArrayTypeToImmType (aplType); |
pf_squad.c | 228 | lpMemRht = &lpYYRht->tkToken.tkData.tkInteger; |
pf_squad.c | 232 | hGlbRht = lpYYRht->tkToken.tkData.tkGlbData; |
pf_squad.c | 278 | *lpMemRes++ = lpYYRes->tkToken.tkData.tkGlbData; |
pf_uarrow.c | 232 | lpYYRes->tkToken.tkData.tkGlbData = CopySymGlbNumDir_PTB (lpSymGlb, aplTypeRht, lptkFunc); |
pf_utackjot.c | 379 | lpYYRes->tkToken.tkFlags.NoDisplay |= (exitType EQ EXITTYPE_NODISPLAY); |