- sqlite3_stmt *statement;
-
- _sqlcall(sqlite3_prepare(Bridge_,
- "select "
- "\"bridge\".\"mode\", "
- "\"bridge\".\"value\" "
- "from \"bridge\" "
- "where"
- " \"bridge\".\"name\" = ?"
- " limit 1"
- , -1, &statement, NULL));
-
- _sqlcall(sqlite3_bind_text(statement, 1, name.data, name.size, SQLITE_STATIC));
-
- int mode;
- const char *value;
-
- if (_sqlcall(sqlite3_step(statement)) == SQLITE_DONE) {
- mode = -1;
- value = NULL;
- } else {
- mode = sqlite3_column_int(statement, 0);
- value = sqlite3_column_pooled(pool, statement, 1);
+ size_t length(name.size);
+ char keyed[length + 2];
+ memcpy(keyed + 1, name.data, length + 1);
+
+ static const char *modes = "0124";
+ for (size_t i(0); i != 4; ++i) {
+ char mode(modes[i]);
+ keyed[0] = mode;
+
+ if (CYBridgeEntry *entry = CYBridgeHash(keyed, length + 1))
+ switch (mode) {
+ case '0':
+ return JSEvaluateScript(CYGetJSContext(context), CYJSString(entry->value_), NULL, NULL, 0, NULL);
+
+ case '1':
+ if (void (*symbol)() = reinterpret_cast<void (*)()>(CYCastSymbol(name.data)))
+ return CYMakeFunctor(context, symbol, entry->value_, &entry->cache_);
+ else return NULL;
+
+ case '2':
+ if (void *symbol = CYCastSymbol(name.data)) {
+ // XXX: this is horrendously inefficient
+ sig::Signature signature;
+ sig::Parse(pool, &signature, entry->value_, &Structor_);
+ ffi_cif cif;
+ sig::sig_ffi_cif(pool, &sig::ObjectiveC, &signature, &cif);
+ return CYFromFFI(context, signature.elements[0].type, cif.rtype, symbol);
+ } else return NULL;
+
+ // XXX: implement case 3
+ case '4':
+ return CYMakeType(context, entry->value_);
+ }