/* * CONTEXT.H * * (c)Copyright 1993-2014, Matthew Dillon, All Rights Reserved. See the * COPYRIGHT file at the base of the distribution. * * Interpreter and Code Generator context and storage structures. Note that * a number of important run-time structures also exist in librune/type.h. */ struct SemGroup; struct Thread; /* * RunContext - store physical data * * The Context structure is used to represent the physical storage for * a procedure, a procedure's arguments during a call, global * storage declarations in a class, and global storage declarations * in a module. * * In regards to storing arguments for a procedure-call it should * be noted that the context is typically synthesized on the fly * using data already instantiated via the compound expression * representing the procedure's arguments. A second context is * created by the procedure itself to deal with local variables and * such, with ct_ArgsCtx initialized to point at the synthesized * argument context. * * ct_ArgsType is the type of the procedure's arguments. In a * var-args call it may not match the ty_ProcType.et_ArgsType. * * For a procedure call, storage for ct_RetData is supplied by the * caller for non-lvalue returns, and supplied by the callee for * lvalue returns. */ typedef struct RunContext { char *ct_Data; /* proc/args/class/module data */ runesize_t ct_Bytes; /* size of context */ int ct_BreakCount; /* break/continue handling */ char *ct_ObjData; /* proc/args/class/module data */ RefStor *ct_ObjRS; char *ct_TmpData; /* temporary space for global init */ runesize_t ct_TmpBytes; /* size of global temporary space */ runesize_t ct_TmpOffset; /* track temporary storage use */ int ct_Flags; /* CTF flags */ struct RunContext *ct_CallCtx; /* parent context (backtrace) */ struct RunContext *ct_Parent; /* parent context (backtrace) */ rundata_t *ct_RetData; Type *ct_RetType; /* return type for initialization */ Type *ct_ArgsType; /* possibly var-extended */ struct RunContext *ct_ArgsCtx; /* related arguments if a procedure */ void *ct_ThreadData; /* (in argument context) */ int ct_SchedPreempt; int ct_ICount; /* execution counter for thread sw */ int ct_NestLevel; /* (nested proc) 0 = top level */ int ct_NestSize; /* (nested proc) 1 = normal procedure */ RefStor ct_CtxRefStor; /* references into this context */ rundata_t *ct_DCopyData; /* direct-copy data target */ Type *ct_TypeSideEF; /* type side-effect TY_DYNAMIC type */ Declaration *ct_DeclSideEF; /* decl side-effect */ } RunContext; #define CTF_RESOLVING 0x0001 /* resolve-time context */ #define CTF_GLOBALINIT 0x0002 /* global initialization context */ typedef struct RunSaveObjCtx { char *objData; /* proc/args/class/module data */ RefStor *objRS; } RunSaveObjCtx; typedef struct RunThreadCall { RunContext *tc_ArgsCtx; Stmt *tc_Stmt; tdlist_t tc_List; struct Thread *tc_CallingThread; } RunThreadCall; /* * Main contex-tracking structure during code generation. * * XXX ct_ArgsType must be passed in for var-args */ typedef struct GenContext { int ct_Op; gendata_t *ct_Data; /* proc/args/class/module data */ runesize_t ct_Bytes; /* size of context */ gendata_t *ct_ObjData; /* proc/args/class/module data */ gendata_t *ct_TmpData; /* temporary space for global init */ gendata_t *ct_BEStackData;/* extra space for backend args */ runesize_t ct_TmpBytes; /* size of global temporary space */ runesize_t ct_TmpOffset; /* track temporary storage use */ runesize_t ct_TmpAlignMask;/* track temporary storage use */ int ct_Flags; /* CTF flags */ struct GenContext *ct_CallCtx; /* parent context (backtrace) */ struct GenContext *ct_Parent; /* parent context (backtrace) */ struct SemGroup *ct_SubGroup; /* statement block-level group */ gendata_t *ct_RetData; gendata_t *ct_ArgData; Type *ct_RetType; /* return type for initialization */ Type *ct_ArgsType; /* possibly var-extended XXX */ void *ct_ThreadData; /* (in argument context) */ int ct_SchedPreempt; int ct_NestLevel; /* (nested proc) 0 = top level */ int ct_NestSize; /* (nested proc) 1 = normal procedure */ int ct_LabelActive; gendata_t *ct_DCopyData; /* direct-copy data target */ gendata_t *ct_TypeSideEF; /* type side-effect TY_DYNAMIC type */ Declaration *ct_DeclSideEF; /* decl side-effect */ genlabel_t *ct_BreakLabel; /* label action */ genlabel_t *ct_ContinueLabel; /* label action (also continue if) */ genlabel_t *ct_ElseLabel; /* label action for continue else */ } GenContext; /* NOTE! CTF_* flags for RunContext also apply */ #define CTF_LOOP 0x00010000 /* Prevent semantic exit on continue */ #define CTF_INLINED 0x00020000 /* In Inlined context */ #define GENCT_GLOBAL 1 /* global context */ #define GENCT_PROC 2 /* procedure context */ #define GENCT_SEMANTIC 3 /* sub-semantic context in procedure */ #define GENCT_INLINE 4 /* inline procedure context */ typedef struct GenSaveObjCtx { gendata_t *objData; } GenSaveObjCtx;