You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2013/06/14 05:47:41 UTC

[lucy-commits] [3/5] git commit: refs/heads/LUCY-256-thunk-hack1 - Generate thunks.

Generate thunks.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/687b754f
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/687b754f
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/687b754f

Branch: refs/heads/LUCY-256-thunk-hack1
Commit: 687b754fe835dda01b7c48fb8a0cd60d678e5cfb
Parents: e130baf
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Jun 7 18:14:35 2013 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Thu Jun 13 20:36:06 2013 -0700

----------------------------------------------------------------------
 clownfish/compiler/src/CFCBindCore.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/687b754f/clownfish/compiler/src/CFCBindCore.c
----------------------------------------------------------------------
diff --git a/clownfish/compiler/src/CFCBindCore.c b/clownfish/compiler/src/CFCBindCore.c
index fff63ef..a145a7a 100644
--- a/clownfish/compiler/src/CFCBindCore.c
+++ b/clownfish/compiler/src/CFCBindCore.c
@@ -353,6 +353,30 @@ S_write_parcel_h(CFCBindCore *self, CFCParcel *parcel) {
     FREEMEM(file_content);
 }
 
+static char*
+S_gen_cfish_thunks() {
+    int offset = 56; // offsetof(cfish_VTable, methods)
+    int max_methods = 256;
+    char *thunks = CFCUtil_strdup("");
+    static const char pattern[] =
+        "CFISH_VISIBLE void\n"
+        "cfish_thunk%d(const void *vself) {\n"
+        "   char *vtable_address = (char*)((cfish_Dummy*)vself)->vtable;\n"
+        "   cfish_method_t method = *((cfish_method_t*)(vtable_address + %d));\n"
+        "   method(vself);\n"
+        "}\n"
+        "\n";
+    char buf[sizeof(pattern) + 32];
+
+    for (int i = 0; i < max_methods; i++) {
+        sprintf(buf, pattern, offset, offset);
+        thunks = CFCUtil_cat(thunks, buf, NULL);
+        offset += 8; // sizeof(void*)
+    }
+
+    return thunks;
+}
+
 static void
 S_write_parcel_c(CFCBindCore *self, CFCParcel *parcel) {
     S_write_aliases_txt(self, parcel); // hack
@@ -367,6 +391,11 @@ S_write_parcel_c(CFCBindCore *self, CFCParcel *parcel) {
     char *vt_specs = CFCUtil_strdup(
         "static cfish_VTableSpec vtable_specs[] = {\n");
     int num_specs = 0;
+    if (strcmp(prefix, "cfish_") == 0) {
+        char *thunks = S_gen_cfish_thunks();
+        c_data = CFCUtil_cat(c_data, thunks, NULL);
+        FREEMEM(thunks);
+    }
     CFCClass **ordered  = CFCHierarchy_ordered_classes(hierarchy);
     for (int i = 0; ordered[i] != NULL; i++) {
         CFCClass *klass = ordered[i];