00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "comma/runtime/crt_types.h"
00010 #include "comma/runtime/crt_itable.h"
00011
00012 #include <stdarg.h>
00013 #include <stdbool.h>
00014 #include <stdlib.h>
00015 #include <string.h>
00016
00017 static bool lookup_instance(domain_info_t info,
00018 domain_instance_t *args, domain_instance_t *instance)
00019 {
00020 if (!info->instance_table)
00021 info->instance_table = alloc_itable();
00022
00023 return itable_lookup(info->instance_table, info, args, instance);
00024 }
00025
00026
00027
00028
00029 domain_instance_t _comma_get_domain(domain_info_t info, ...)
00030 {
00031 domain_instance_t instance;
00032 unsigned i;
00033 domain_instance_t *args;
00034
00035 if (info->arity) {
00036 args = malloc(sizeof(domain_instance_t)*info->arity);
00037 for (i = 0; i < info->arity; ++i) {
00038 va_list ap;
00039 va_start(ap, info);
00040 args[i] = va_arg(ap, domain_instance_t);
00041 }
00042 }
00043 else
00044 args = 0;
00045
00046
00047
00048
00049
00050
00051
00052
00053 if (lookup_instance(info, args, &instance))
00054 return instance;
00055
00056 instance->info = info;
00057 instance->params = args;
00058
00059
00060
00061
00062 if (info->ctor != 0)
00063 info->ctor(instance);
00064
00065 return instance;
00066 }
00067
00068
00069
00070
00071
00072 domain_instance_t alloc_domain_instance(domain_info_t info)
00073 {
00074 return malloc(sizeof(struct domain_instance));
00075 }