C:/Users/Dennis/src/lang/russell.orig/src/stree/streedefs.h

Go to the documentation of this file.
00001 /*
00002  * Syntax Tree Structure Definitions
00003  *
00004  * This file is a collection of macro invocations
00005  *
00006  * The calling environment must contain definitions for
00007  *
00008  * TOP          called at the beginning
00009  * START        called to start each structure declaration
00010  * INT, UNSIGNED, REFCNT, NODEKIND, NODESTAR, VLINENO, STTINDX,
00011  *      LISTPTR, BACKREF,CNSTAR(= pointer to Cons Node),STRPTR,
00012  *      BITVECTOR, NBPTR, HNODESTAR (identical to NODESTAR except hidden,
00013  *      i.e. not passed to mknode ), SIG, and HSIG.
00014  *      (The latter two are used for pointers from expression
00015  *      nodes to signature nodes.)
00016  *              called to define individual fields
00017  * FINISH       called to finish each structure
00018  * BOTTOM       called to finish everything
00019  */
00020 
00021 /* 
00022  *      Note that certain fields are not really part of the syntax tree,
00023  * but rather comprise the symbol table.  In particular each identifier
00024  * structure contains a field which eventually points to the last
00025  * declaration in the innermost enclosing scope of that identifier.
00026  * All constructs which can define a new identifier contain fields
00027  * used for chaining all definitions of a given identifier together.
00028  * If several of these constructs can occur in a given scope, i.e.
00029  * in the case of declarations and parameters, another field is
00030  * included to point back to some structure which uniquely identifies
00031  * that scope, so that illegal multiple declarations can subsequently
00032  * be detected.
00033  *  Identifier nodes contain an additional field identifying the
00034  * surrounding use list.  Use lists themselves are chained together
00035  * like identifier declarations.  Thus the list of types from which
00036  * selections can be inferred is easily identifiable.
00037  *  Also the first field of any structure which can possibly represent
00038  * a denotation is one for the signature of that denotation.  In general
00039  * this field is hidden and not used until the signature deduction phase.
00040  *  Any node which can declare an identifier (outside a signature)
00041  * contains displacement and level fields in the third and fourth positions
00042  * following the prefix.  The level number refers to function nesting
00043  * depth before the storage allocation pass of the code generator, and
00044  * is then changed to be activation record nesting depth.  (The two may
00045  * differ, since blocks occasionally require activation records.)
00046  *  Any signature field must be followed by a corresponding sig_done field.
00047  */
00048 
00049 
00050 #define PREFIX \
00051   /* REFCNT(refcount) - we now garbage collect */ \
00052   NODEKIND(kind) \
00053   VLINENO(vlineno) \
00054   INT(pre_num) \
00055   INT(post_num) 
00056 
00057 @ifndef STREEDEFS
00058 @  define SZSTANDARDPREFIX 4
00059 /* used to be 5, before we dropped refcount */
00060 @endif
00061 
00062 /*
00063  * Notes:
00064  *  
00065  */
00066 
00067 TOP
00068 
00069 START(LISTHEADER,ListHeader)
00070   PREFIX
00071   CNSTAR(lh_first)
00072   CNSTAR(lh_last)
00073 FINISH
00074 
00075 START(DECLARATION,Declaration)
00076   PREFIX
00077   NODESTAR(decl_id)
00078   NODESTAR(decl_denotation)
00079   INT(displacement)
00080   INT(level)
00081   SIG(decl_signature)
00082   INT(decl_sig_done)
00083   INT(decl_sig_transp)        /* This declaration is transparent to */
00084                               /* signature checking.                */
00085   BACKREF(decl_innermost_id)  /* decl of an innermost let-declared identifier*/
00086                               /* declared by r.h.s.  Used only for signature */
00087                               /* transparent declarations.  References       */
00088                               /* to signature transparent ids are counted    */
00089                               /* as refs to the right side of their          */
00090                               /* declarations for export rule checks.        */
00091                               
00092   BACKREF(decl_previous_definition)
00093   BACKREF(decl_scope)
00094 
00095   INT(decl_can_be_refd)       /* Smallest pre-order number of declaration  */
00096                               /* in this block which may require the value */
00097                               /* of the declared identifier.               */
00098                               /* Used to detect possible forward refs.     */
00099   INT(decl_special)           /* This is a variable which was unusually    */
00100                               /* allocated.                                */
00101 @ ifndef STREEDEFS
00102 @   define VAR_ON_STACK 7     /* Variable was directly stack allocated */
00103 @       define SIMPLE_VAR_ON_STACK 1
00104 @       define PTR_VAR_ON_STACK 2
00105 @       define INIT_VAR_ON_STACK 4
00106 @   define ARRAY_CONTIG 8     /* Array is contiguously allocated.      */
00107 @   define ID_IMPORTED  16    /* Imported into nested scope            */
00108 @   define VAR_NONTR_REF 32   /* Variable is referenced other than as  */
00109                               /* argument to V or :=                   */
00110                 /* With the -R option, the -G code generator keeps     */
00111                 /* identifier bindings or variables in v. registers:   */
00112 @   define ID_IN_REG    64      /* displacement is v. register number  */
00113 @   define SIMPLE_VAR_IN_REG   128
00114 @   define PTR_VAR_IN_REG      256
00115 @   define INIT_VAR_IN_REG     512
00116 @   define VAR_IN_REG          896
00117                /* r.h.s always evaluates to integer constant decl_const_val: */
00118 @   define DECL_CONST         1024
00119 @   define NOT_DECL_CONST     2048
00120 @ endif
00121   INT(decl_sel_index)           /* index for with list components       */
00122   INT(decl_needed)              /* The rhs really needs to be evald     */
00123   INT(decl_const_val)
00124 FINISH
00125 
00126 START(PARAMETER,Parameter)
00127   PREFIX
00128   NODESTAR(par_id)
00129   NODESTAR(par_signature)
00130   INT(displacement)
00131   INT(level)
00132   BACKREF(par_previous_definition)
00133   BACKREF(par_scope)
00134   BACKREF(par_only_def)         /* The only argument passed as this  */
00135                                 /* parameter.  NIL indicates no call */
00136                                 /* found so far. MULTIPLE_DEFS       */
00137                                 /* indicates that different arguments*/
00138                                 /* are passe, or we don't know the   */
00139                                 /* identity of the argument.         */
00140                                 /* MULTIPLE_TP_DEFS indicates that   */
00141                                 /* different arguments are passed,   */
00142                                 /* but they are all types with       */
00143                                 /* standard := and V operations.     */
00144 @ define MULTIPLE_DEFS ((NODE *) 1)
00145 @ define MULTIPLE_TP_DEFS ((NODE *) 2)
00146 @ define is_real_def(x) (((unsigned) (x)) > 2)
00147 FINISH
00148 
00149 START(RECORDELEMENT,RElement)
00150                         /* also used for unions */
00151   PREFIX
00152   NODESTAR(re_id)
00153   NODESTAR(re_denotation)
00154   INT(re_New_index)
00155   INT(re_ValueOf_index)
00156   INT(re_assign_index)
00157 FINISH
00158 
00159 START(VARSIGNATURE,VarSignature)
00160   PREFIX
00161   HSIG(signature)
00162   INT(sig_done)
00163   NODESTAR(var_denotation)
00164 FINISH
00165 
00166 START(VALSIGNATURE,ValSignature)
00167   PREFIX
00168   HSIG(signature)
00169   INT(sig_done)
00170   NODESTAR(val_denotation)
00171 FINISH
00172 
00173 START(FUNCSIGNATURE,FSignature)
00174   PREFIX
00175   HSIG(signature)
00176   INT(sig_done)
00177   BACKREF(fsig_construction)   /* Corresponding function construction */
00178                                /* (if known) - used for optimization  */
00179   INT(fsig_special)            /* Look at ststructs for definitions   */
00180   INT(fsig_slink_known)        /* ep can be found by tracing static   */
00181                                /* chain from environment in which     */
00182                                /* expression occurs.                  */
00183   STRPTR(fsig_inline_code)
00184   LISTPTR(fsig_param_list)
00185   NODESTAR(fsig_result_sig)
00186 FINISH
00187 
00188 START(TYPESIGNATURE,TSignature)
00189   PREFIX
00190   HSIG(signature)
00191   INT(sig_done)
00192   INT(ts_simple_type)   /* Representation can't point (indirectly) to   */
00193                         /* activation records.  (Used for optimization) */
00194   NODESTAR(ts_local_type_id)
00195   LISTPTR(ts_clist)
00196   BACKREF(ts_previous_definition)
00197   STRPTR(ts_const_code)            /* inline code for quoted single char  */
00198   STRPTR(ts_string_code)           /* inline code for string as a whole   */
00199   STRPTR(ts_element_code)          /* inline code for each string element */
00200   INT(ts_string_max)               /* maximum length for above string     */
00201                                    /* expansion.  -1 ==> default          */
00202   STRPTR(ts_meta_concat)           /* inline code to concatenate string   */
00203                                    /* sections of long string.            */
00204 FINISH
00205 
00206 START(TSCOMPONENT,TSComponent)
00207   PREFIX
00208   NODESTAR(tsc_id)
00209   NODESTAR(tsc_signature)
00210 FINISH
00211 
00212 START(DEFCHARSIGS,DefCharSigs)
00213 /* Gives list of quoted characters with */
00214 /* default signatures. Also used as a   */
00215 /* type signature component.                    */
00216 /* Assumes ASCII, 32 bits per word              */
00217   PREFIX
00218   BITVECTOR(dcs_0)
00219   BITVECTOR(dcs_1)
00220   BITVECTOR(dcs_2)
00221   BITVECTOR(dcs_3)
00222 @ ifndef STREEDEFS
00223 @   define NVECTORS 4
00224 @ endif
00225   HLISTPTR(dcs_exceptions)        /* List of DCSEXCEPTION nodes         */
00226                                   /* for constants with non-nil special */
00227                                   /* or in-line code values.            */
00228 FINISH
00229 
00230 START(SIGNATURESIG, SignatureSig)
00231                                 /* The signature of a signature */
00232   PREFIX
00233   HSIG(signature)
00234   INT(sig_done)
00235 FINISH
00236 
00237 START(BLOCKDENOTATION,BlDenotation)
00238   PREFIX
00239   HSIG(signature)
00240   INT(sig_done)
00241   /* Activation record info, used only if INSIDE_LOOP and CONTAINS_CLOSURE */
00242   /* are both set, and the declaration list is not empty.                  */
00243     INT(ar_size)
00244     BACKREF(ar_static_link)
00245     INT(ar_static_level)
00246   LISTPTR(bld_declaration_list)
00247   LISTPTR(bld_den_seq)
00248   INT(bld_precedence)
00249   INT(bld_flags)
00250 @   define INSIDE_LOOP       1   /* There is a sourrounding loop with no */
00251                                  /* intervening blocks or function       */
00252                                  /* abstractions.                        */
00253                                  /* Also set if there is a possibility   */
00254                                  /* that the block may be reexecuted     */
00255                                  /* without leaving the surrounding      */
00256                                  /* function due to Call/cc calls.       */
00257 @   define CONTAINS_CLOSURE  2   /* A closure value is built inside the  */
00258                                  /* block.                               */
00259 @   define CALLCC_CALL       4   /* There may be an embedded Call/cc     */
00260                                  /* call.                                */
00261 @   define REQUIRES_AR       8   /* We need an a.r. if this is inside a  */
00262                                  /* loop, and it either the block builds */
00263                                  /* a closure, or there is a Call/cc     */
00264                                  /* call embedded in the block.          */
00265                                  /* These imply that it is not safe to   */
00266                                  /* promote bindings to surrounding      */
00267                                  /* function activation record.          */
00268 @   define NO_SURR_LOOP     16   /* It is known that there is no         */
00269                                  /* explicit loop between this block     */
00270                                  /* and the surrounding function         */
00271                                  /* construction.  Implies not           */
00272                                  /* INSIDE_LOOP, but can be computed     */
00273                                  /* much earlier.                        */
00274 FINISH                                                                     
00275 
00276 
00277 START(USELIST,UseList)
00278   PREFIX
00279   HSIG(signature)
00280   INT(sig_done)     /* signature checking done flag */
00281   LISTPTR(usl_type_list)
00282   LISTPTR(usl_den_seq)
00283   BACKREF(usl_previous_list)
00284   INT(usl_precedence)
00285 FINISH
00286 
00287 START(APPLICATION,Application)
00288   PREFIX
00289   HSIG(signature)
00290   INT(sig_done)
00291   NODESTAR(ap_operator)
00292   LISTPTR(ap_args)
00293   BACKREF(ap_void_decl)         /* enclosing var Void parameter */
00294 FINISH
00295 
00296 START(ENUMERATION,Enumeration)
00297   PREFIX
00298   HSIG(signature)
00299   INT(sig_done)
00300   LISTPTR(enum_id_list)
00301 FINISH
00302 
00303 START(EXTENSION,Extension)
00304   PREFIX
00305   HSIG(signature)
00306   INT(sig_done)
00307   NODESTAR(ext_denotation)
00308   INT(In_index)                 /* Position of In operation in type sign. */
00309   INT(Out_index)
00310 FINISH
00311 
00312 START(PRODCONSTRUCTION,Product)
00313   PREFIX
00314   HSIG(signature)
00315   INT(sig_done)
00316   NODESTAR(prod_local_type_id)
00317   LISTPTR(prod_components)      /* a list of parameter nodes */
00318   BACKREF(prod_previous_definition)
00319 FINISH
00320 
00321 START(RECORDCONSTRUCTION,Record)
00322   PREFIX
00323   HSIG(signature)
00324   INT(sig_done)
00325   LISTPTR(rec_component_list)
00326   BACKREF(rec_previous_definition)
00327 FINISH
00328 
00329 START(UNIONCONSTRUCTION,Union)
00330   PREFIX
00331   HSIG(signature)
00332   INT(sig_done)
00333   NODESTAR(prod_local_type_id)
00334   LISTPTR(prod_components)       /* list of parameter nodes */
00335   BACKREF(prod_previous_definition)
00336 FINISH
00337 
00338 START(WITHLIST,WithList)
00339   PREFIX
00340   NODESTAR(wl_local_type_id)
00341   LISTPTR(wl_component_list)
00342   BACKREF(wl_previous_definition)
00343 FINISH
00344 
00345 START(MODPRIMARY,MPrimary)
00346   PREFIX
00347   HSIG(signature)
00348   INT(sig_done)
00349   INT(displacement)
00350   INT(level)
00351   NODESTAR(mp_primary)
00352   NODESTAR(mp_type_modifier)    /* NIL if this represents a coercion */
00353   STRPTR(mp_delete_v)           /* bit vector specifying components  */
00354                                 /* to be deleted.                    */
00355   INT(mp_orig_length)           /* number of type components before  */
00356                                 /* deletions.                        */
00357   INT(mp_needed)                /* Need to actually construct value  */
00358   INT(mp_no_surr_loop)
00359 FINISH
00360 
00361 START(EXPORTLIST,Elist)
00362   PREFIX
00363   NODESTAR(el_local_type_id)
00364   LISTPTR(el_export_element_list)
00365   BACKREF(el_previous_definition)
00366 FINISH
00367 
00368 START(HIDELIST,Hlist)
00369   PREFIX
00370   NODESTAR(el_local_type_id)
00371   LISTPTR(el_export_element_list)
00372   BACKREF(el_previous_definition)
00373 FINISH
00374 
00375 START(EXPORTELEMENT,EElement)
00376   PREFIX
00377   NODESTAR(ee_id)
00378   NODESTAR(ee_signature)
00379   NODESTAR(ee_export_list)
00380 FINISH
00381 
00382 START(ALLCONSTANTS,ConstsKeyWord)
00383   PREFIX
00384 FINISH
00385 
00386 START(WORDELSE,ElseKeyWord)
00387   PREFIX
00388   HSIG(signature)
00389   INT(sig_done)
00390 FINISH
00391 
00392 START(WORDCAND,CandKeyWord)
00393   PREFIX
00394 FINISH
00395 
00396 START(WORDCOR,CorKeyWord)
00397   PREFIX
00398 FINISH
00399 
00400 START(GUARDEDLIST,GList)
00401   PREFIX
00402   HSIG(signature)
00403   INT(sig_done)
00404   LISTPTR(gl_list)
00405 FINISH
00406 
00407 START(LOOPDENOTATION,LDenotation)
00408   PREFIX
00409   HSIG(signature)
00410   INT(sig_done)
00411   LISTPTR(gl_list)
00412 FINISH
00413 
00414 START(GUARDEDELEMENT,GElement)
00415   PREFIX
00416   NODESTAR(ge_guard)
00417   NODESTAR(ge_element)
00418 FINISH
00419 
00420 START(OPRID,OpId)
00421   PREFIX
00422   HSIG(signature)
00423   INT(sig_done)
00424   HNODESTAR(sel_type)         /* optional type denotation from which    */
00425                               /* identifier is to be selected.          */
00426   STTINDX(id_str_table_index) /* -1 ==> imm. surrounding local type id  */
00427                               /* Note that the local type id is in fact */
00428                               /* always defined by a TYPESIGNATURE node */
00429                               /* since this convention is used only for */
00430                               /* id's with a default signature.         */
00431   BACKREF(id_use_list)
00432   BACKREF(id_last_definition) /* innermost definition of identifier     */
00433   INT(id_def_found)           /* TRUE ==> last_definition points to     */
00434                               /* actual definition rather than last     */
00435                               /* overloading of the identifier and the  */
00436                               /* sel_type field has its final value.    */
00437   INT(sel_index)
00438   BACKREF(id_appl)            /* An application of the identifier       */
00439   INT(id_forward_ref)         /* Need to check for erroneous forward ref */
00440 FINISH
00441 
00442 START(LETTERID,LetterId)
00443   PREFIX
00444   HSIG(signature)
00445   INT(sig_done)
00446   HNODESTAR(sel_type)
00447   STTINDX(id_str_table_index)
00448   BACKREF(id_use_list)
00449   BACKREF(id_last_definition)
00450   INT(id_def_found)
00451   INT(sel_index)
00452   HNODESTAR(id_appl)          /* An application of the identifier         */
00453                               /* Useful for overload resolution           */
00454   INT(id_forward_ref)       /* Need to check for erroneous forward ref */
00455 FINISH
00456 
00457 START(QSTR,QStr)
00458   /* quoted string */
00459   PREFIX
00460   HSIG(signature)
00461   INT(sig_done)
00462   HNODESTAR(sel_type)
00463   STRPTR(str_string)
00464   BACKREF(str_use_list)
00465   HNODESTAR(str_expansion)   
00466 FINISH
00467 
00468 START(UQSTR,UQStr)
00469   /* unquoted string */
00470   PREFIX
00471   HSIG(signature)
00472   INT(sig_done)
00473   HNODESTAR(sel_type)
00474   STRPTR(str_string)
00475   BACKREF(str_use_list)
00476   HNODESTAR(str_expansion)
00477 FINISH
00478 
00479 START(FUNCCONSTR,FConstruction)
00480   PREFIX
00481   NODESTAR(signature)   /* completed by signature deduction pass if */
00482                         /* necessary.  */
00483   INT(sig_done)
00484 
00485   /* Activation record info */
00486     INT(ar_size)
00487     BACKREF(ar_static_link)
00488     INT(ar_static_level)
00489 
00490   NODESTAR(fc_body)
00491   INT(fc_complexity)    /* used to hold the following bits of dataflow */
00492                         /* information:                                */
00493 @ ifndef STREEDEFS
00494 @   define COMPLICATED  0 /* No special properties */
00495 @   define NO_SL        1 /* Static link not needed,       */
00496                           /* no "complicated" constructs,  */
00497                           /* no accesses through AR.       */
00498 @   define NO_PUT       2 /* No calls to an output routine */
00499 @   define NO_CALLCC    4 /* Environment can't be saved by   */
00500                           /* call/cc call.  This implies     */
00501                           /* that it's safe to allocate      */
00502                           /* variables directly on the stack */
00503 @   define NO_CONSTR    8 /* There are no nested fn constrs.  */
00504                           /* that could conceivably be        */
00505                           /* exported.                        */
00506                           /* Thus it is safe to copy id       */
00507                           /* bindings into the closure itself */
00508 @   define NEED_CL     16 /* Closure must be explicitly represented */
00509 @   define CP_GLOBALS  32 /* Nonlocal bindings WILL BE copied to */
00510                           /* closure. Requires that NO_CONSTR    */
00511                           /* holds, that there aren't too many   */
00512                           /* non-locals, that the closure needs  */
00513                           /* to be explicitly built, that        */
00514                           /* none of the non-locals constitute   */
00515                           /* forward references, and that there  */
00516                           /* are no calls to the procedure that  */
00517                           /* could otherwise bypass evaluation   */
00518                           /* of the operator.                    */
00519 @   define NO_AR_REFS  64 /* All nested fn constructions that require  */
00520                           /* a closure copy identifier bindings into   */
00521                           /* the closure itself.  Thus it is           */
00522                           /* automatically safe to allocate            */
00523                           /* activation record on the stack.           */
00524 @   define DIR_REC    128 /* Known to call itself directly and */
00525                           /* tail-recursively.                 */   
00526 @   define DIR_CALL   256 /* There is a direct call to this  */
00527                           /* procedure that does not require */
00528                           /* an explicit closure.            */
00529 @   define SL_ACC     512 /* Procedure may indirect through   */
00530                           /* static link.  Thus it better be  */
00531                           /* there.  (Accesses through AR are */
00532                           /* possible even if SL_ACC is false)*/
00533 @   define NESTED_AR_BLOCK 1024
00534                           /* Procedure contains a nested block that */
00535                           /* requires its own activation record.    */
00536 @ endif
00537   HSTRPTR(fc_code_label)
00538 
00539   LBACKREF(fc_free_vars)        /* List of occurrences of distinct   */
00540                                 /* non-local identifiers inside the  */
00541                                 /* function.  Meaningful only in the */
00542                                 /* presence of CP_GLOBALS.  Ordering */
00543                                 /* in list determines ordering in    */
00544                                 /* closure.                          */
00545                                 /* References to identifiers that    */
00546                                 /* are global to the entire program  */
00547                                 /* are excluded.                     */
00548 
00549   INT(fc_body_needed)           /* need to generate code for body */
00550 FINISH
00551 
00552 START(FREEVARNODE,FreeVarNode)
00553                                 /* A list of these is pointed to        */
00554   PREFIX                        /* by each funcconstructor (i.e.        */
00555                                 /* lambda abstraction)                  */
00556   BACKREF(fv_last_definition)   /* Pointer to declaration               */
00557   INT(fv_surr_class)            /* Local/Global in surrounding scope    */
00558   INT(fv_surr_index)            /* Variable Index in surrounding scope  */
00559   INT(fv_index)                 /* Free Variable Index (in closure)     */
00560 FINISH
00561 
00562 START(EXTERNDEF,ExternDef)
00563                                 /* used as body of externally defined  */
00564                                 /* functions.                          */
00565   PREFIX
00566   STRPTR(ext_name)
00567 FINISH
00568 
00569 START(REXTERNDEF,RExternDef)
00570                                  /* used as body of separately compiled  */
00571                                  /* Russell functions.                   */
00572   PREFIX
00573   SIG(signature)
00574   INT(sig_done)
00575   STRPTR(r_ext_name)
00576 FINISH
00577 
00578 START(DCSEXCEPTION, DCSException)
00579                                    /* Single character type component with */
00580                                    /* in-line code or special field.       */
00581   PREFIX
00582   INT(dcse_char)
00583   HSTRPTR(dcse_inline)
00584   INT(dcse_special)              /* Same conventions as fsig_special  */
00585   BACKREF(dcse_construction)     /* Must be BACKREF so that subst etc.*/
00586                                  /* don't try to follow it.           */
00587 FINISH
00588 
00589 BOTTOM
00590 
00591 @define STREEDEFS

Generated on Fri Jan 25 10:39:48 2008 for russell by  doxygen 1.5.4