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 * Forward declaration of the instance table used to manage the construction of 00017 * domain instances (defined in crt_itable.h). 00018 */ 00019 struct itable; 00020 typedef struct itable *itable_t; 00021 00022 /* 00023 * Forward declarations for the basic types defined herein. 00024 */ 00025 struct domain_instance; 00026 typedef struct domain_instance *domain_instance_t; 00027 00028 struct domain_info; 00029 typedef struct domain_info *domain_info_t; 00030 00031 00032 /* 00033 * The type of pointers to domain constructors. 00034 */ 00035 typedef void (*domain_ctor_t)(domain_instance_t); 00036 00037 /* 00038 * For each domain definition the compiler emits a domain_info_t structure which 00039 * is associated with a global symbol pointing to the object. The main use of 00040 * such a structure is to provide the information necessary to construct 00041 * instances of the domain in question. 00042 */ 00043 struct domain_info { 00044 00045 /* 00046 * The number of arguments which this domain accepts. 00047 */ 00048 uint32_t arity; 00049 00050 /* 00051 * The name of this domain, as seen in the source code definition. 00052 */ 00053 const char *name; 00054 00055 /* 00056 * The constructor used to initialize instances of this domain. If this 00057 * field is null, the domain does not require initialization. 00058 */ 00059 domain_ctor_t ctor; 00060 00061 /* 00062 * An itable mapping arrays of domain views (parameters) to specific 00063 * instances. This is initially a null pointer when emitted by the 00064 * compiler. 00065 */ 00066 itable_t instance_table; 00067 }; 00068 00069 /* 00070 * An actual instance of a domain, generated by calls to make_domain. This is 00071 * the runtime representation of a domain. 00072 */ 00073 struct domain_instance { 00074 /* 00075 * Compiler generated information about this domain. 00076 */ 00077 domain_info_t info; 00078 00079 /* 00080 * Next pointer to support open chaining of hashed instances. 00081 */ 00082 domain_instance_t next; 00083 00084 /* 00085 * The actual parameters supplied to this domain. 00086 */ 00087 domain_instance_t *params; 00088 00089 /* 00090 * The domains required by this instance. 00091 */ 00092 domain_instance_t *requirements; 00093 }; 00094 00095 domain_instance_t alloc_domain_instance(domain_info_t info); 00096 00097 /* 00098 * Get a domain instance. 00099 */ 00100 domain_instance_t _comma_get_domain(domain_info_t info, ...); 00101 00102 #endif