00001 /*===-- runtime/crt_types.h -----------------------------------------------=== 00002 * 00003 * This file is distributed under the MIT license. See LICENSE.txt for details. 00004 * 00005 * Copyright (C) 2009, Stephen Wilson 00006 * 00007 *===----------------------------------------------------------------------===*/ 00008 00009 #ifndef COMMA_RUNTIME_CRT_TYPES_HDR_GUARD 00010 #define COMMA_RUNTIME_CRT_TYPES_HDR_GUARD 00011 00012 #include <stddef.h> 00013 #include <inttypes.h> 00014 00015 /* 00016 * The type of pointers to functions which a domain exports. 00017 */ 00018 typedef void (*export_fn_t)(); 00019 00020 /* 00021 * Forward declaration of the instance table used to manage the construction of 00022 * domain instances (defined in crt_itable.h). 00023 */ 00024 struct itable; 00025 typedef struct itable *itable_t; 00026 00027 /* 00028 * Forward declarations for the basic types defined herein. 00029 */ 00030 struct domain_view; 00031 typedef struct domain_view *domain_view_t; 00032 00033 struct domain_instance; 00034 typedef struct domain_instance *domain_instance_t; 00035 00036 struct domain_info; 00037 typedef struct domain_info *domain_info_t; 00038 00039 00040 /* 00041 * The type of pointers to domain constructors. 00042 */ 00043 typedef void (*domain_ctor_t)(domain_instance_t); 00044 00045 /* 00046 * For each domain definition the compiler emits a domain_info_t structure which 00047 * is associated with a global symbol pointing to the object. The main use of 00048 * such a structure is to provide the information necessary to construct 00049 * instances of the domain in question. 00050 */ 00051 struct domain_info { 00052 00053 /* 00054 * The number of arguments which this domain accepts. 00055 */ 00056 uint32_t arity; 00057 00058 /* 00059 * The number of super signatures this domain implements. 00060 */ 00061 uint32_t num_signatures; 00062 00063 /* 00064 * The name of this domain, as seen in the source code definition. 00065 */ 00066 const char *name; 00067 00068 /* 00069 * The constructor used to initialize instances of this domain. If this 00070 * field is null, the domain does not require initialization. 00071 */ 00072 domain_ctor_t ctor; 00073 00074 /* 00075 * An itable mapping arrays of domain views (parameters) to specific 00076 * instances. This is initially a null pointer when emitted by the 00077 * compiler. 00078 */ 00079 itable_t instance_table; 00080 00081 /* 00082 * An array with num_signatures entries giving offsets into the exports 00083 * vector corresponding to each super signature of this domain. 00084 */ 00085 uint64_t *sig_offsets; 00086 00087 /* 00088 * An array of exported functions, ordered so that each index 00089 * corresponds to the declaration order of the functions as given by a 00090 * depth-first preorder traversal of the signature hierarchy (duplicates 00091 * are not ignored here). 00092 */ 00093 export_fn_t *exports; 00094 }; 00095 00096 /* 00097 * Represents a domain constrained to a particular signature. These views 00098 * provide that portion of the implementing domains exports vector which 00099 * supplies the functions available thru a particular signature. 00100 */ 00101 struct domain_view { 00102 /* 00103 * The particular domain instance implementing this view. 00104 */ 00105 domain_instance_t instance; 00106 00107 /* 00108 * The signature index as understood by the implementing domain (its 00109 * DFPO index in the domains signature graph). 00110 */ 00111 ptrdiff_t index; 00112 }; 00113 00114 /* 00115 * An actual instance of a domain, generated by calls to make_domain. This is 00116 * the runtime representation of a domain. 00117 */ 00118 struct domain_instance { 00119 /* 00120 * Compiler generated information about this domain. 00121 */ 00122 domain_info_t info; 00123 00124 /* 00125 * Next pointer to support open chaining of hashed instances. 00126 */ 00127 domain_instance_t next; 00128 00129 /* 00130 * Actual parameters supplied to this domain, viewed thru the signature 00131 * constraint of the parameter. 00132 */ 00133 domain_view_t *params; 00134 00135 /* 00136 * A view of this instance for each super signature, in DFPO of the 00137 * signature graph. 00138 */ 00139 struct domain_view *views; 00140 00141 /* 00142 * The domains required by this instance. 00143 */ 00144 domain_instance_t *requirements; 00145 }; 00146 00147 domain_instance_t alloc_domain_instance(domain_info_t info); 00148 00149 /* 00150 * Get a domain instance. 00151 */ 00152 domain_instance_t _comma_get_domain(domain_info_t info, ...); 00153 00154 #endif