Author: nickg
Date: Mon Jan 16 08:28:44 2006
New Revision: 11215

Modified:
   branches/nci/NCI_NOTES.txt
   branches/nci/include/parrot/nci.h
   branches/nci/src/inter_cb.c
   branches/nci/src/nci_ffcall.c
   branches/nci/src/nci_libffi.c
   branches/nci/tools/build/nci_builtin_c.pl
Log:
NCI #12. Update Notes and add a vtable entry for creating callbacks.


Modified: branches/nci/NCI_NOTES.txt
==============================================================================
--- branches/nci/NCI_NOTES.txt  (original)
+++ branches/nci/NCI_NOTES.txt  Mon Jan 16 08:28:44 2006
@@ -52,3 +52,16 @@ Implement an NCI abstraction which will 
    nci_free
 
 
+
+Current 'Builtin' Callbacks:
+
+The 'new_callback ' opcode is used to create a callback, and actually
+returns a C pointer wrapped in an unmanaged struct. Behind the op
+parrot calls Parrot_make_cb in inter_cb.c. The returned pointer is
+actually a pointer to either Parrot_callback_C or Parrot_callback_D,
+which expect two arguments [Note: this logic is flawed in my opinion]
+
+When the callback code is called at some point later, the types of the
+arguments are verified. One of the arguments must be a PMC which has
+various attributes hanging off it. The arguments for the real callback
+are prepared, and is called using Parrot_runops_from_args.

Modified: branches/nci/include/parrot/nci.h
==============================================================================
--- branches/nci/include/parrot/nci.h   (original)
+++ branches/nci/include/parrot/nci.h   Mon Jan 16 08:28:44 2006
@@ -21,6 +21,11 @@ typedef void (*nci_new_method_t)(Interp*
 typedef void (*nci_clone_method_t)(Interp* interpreter,  PMC* pmc1, PMC* pmc2);
 typedef void (*nci_invoke_method_t)(Interp* interpreter, PMC* pmc);
 typedef void (*nci_free_method_t)(Interp* interpreter, PMC *pmc);
+typedef void (*nci_new_callback_method_t)(Interp* interpreter,
+                                          PMC* pmc,
+                                          PMC* sub,
+                                          STRING *cb_signature,
+                                          PMC* user_data);
 
 
 struct nci_vtable {
@@ -33,6 +38,8 @@ struct nci_vtable {
     nci_invoke_method_t nci_invoke;
     /* Cleans up the NCI data structures */
     nci_free_method_t   nci_free;
+    /* Turn an unmanagedstruct into a callback */
+    nci_new_callback_method_t nci_new_callback;
 
 };
 

Modified: branches/nci/src/inter_cb.c
==============================================================================
--- branches/nci/src/inter_cb.c (original)
+++ branches/nci/src/inter_cb.c Mon Jan 16 08:28:44 2006
@@ -42,7 +42,7 @@ Create a callback function according to 
 
 PMC*
 Parrot_make_cb(Parrot_Interp interpreter, PMC* sub, PMC* user_data,
-        STRING *cb_signature)
+               STRING *cb_signature)
 {
     PMC* interp_pmc, *cb, *cb_sig;
     int type = '?';     /* avoid -Ox warning */

Modified: branches/nci/src/nci_ffcall.c
==============================================================================
--- branches/nci/src/nci_ffcall.c       (original)
+++ branches/nci/src/nci_ffcall.c       Mon Jan 16 08:28:44 2006
@@ -390,8 +390,8 @@ static void nci_ffcall_invoke (Interp *i
 /* TODO: Synchronous/Assynchronous */
 
 
-static void Parrot_callback_trampoline (void *data,
-                                        va_alist alist)
+static void nci_ffcall_callback_trampoline (void *data,
+                                            va_alist alist)
 {
     PMC *    passed_interp;
     PMC *    signature;
@@ -633,10 +633,11 @@ static void Parrot_callback_trampoline (
 }
 
 
-#if 0
-PMC*
-Parrot_make_cb (Parrot_Interp interpreter, PMC* sub,
-                PMC* user_data, STRING *cb_signature)
+static void nci_ffcall_new_callback (Interp* interpreter,
+                                     PMC* pmc,
+                                     PMC* sub,
+                                     STRING *cb_signature,
+                                     PMC* user_data)
 {
 
     PMC* interp_pmc, *cb, *cb_sig;
@@ -660,21 +661,15 @@ Parrot_make_cb (Parrot_Interp interprete
 
     dod_register_pmc(interpreter, user_data);
 
-    cb = pmc_new(interpreter, enum_class_UnManagedStruct);
-
-    dod_register_pmc(interpreter, cb);
-
-    callback = alloc_callback (Parrot_callback_trampoline,
+    callback = alloc_callback (nci_ffcall_callback_trampoline,
                                user_data);
 
-    PMC_data(cb) = callback;
-
-    return cb;
+    PMC_data(pmc) = callback;
 }
 
 
 
-
+#if 0
 void
 Parrot_run_callback(Parrot_Interp interpreter,
                     PMC* user_data, void* external_data)
@@ -689,7 +684,8 @@ struct nci_vtable nci_ffcall_vtable =
     nci_ffcall_new,
     nci_ffcall_clone,
     nci_ffcall_invoke,
-    nci_ffcall_free
+    nci_ffcall_free,
+    nci_ffcall_new_callback
 };
 
 

Modified: branches/nci/src/nci_libffi.c
==============================================================================
--- branches/nci/src/nci_libffi.c       (original)
+++ branches/nci/src/nci_libffi.c       Mon Jan 16 08:28:44 2006
@@ -31,10 +31,11 @@ src/nci_libffi.c - NCI Implementation us
 static void nci_libffi_invoke (Interp * interpreter, PMC *function);
 
 static void
-nci_libffi_new (Interp *interpreter, PMC *pmc,
+nci_libffi_new (Interp *interpreter,
+                PMC *pmc,
                  STRING *signature, Parrot_csub_t func)
 {
-
+    
 }
 
 static void nci_libffi_clone (Interp * interpreter, PMC* pmc1, PMC* pmc2)
@@ -53,12 +54,23 @@ static void nci_libffi_invoke (Interp *i
 {
 }
 
+
+static void nci_libffi_new_callback (Interp* interpreter,
+                                     PMC* pmc,
+                                     PMC* sub,
+                                     STRING *cb_signature,
+                                     PMC* user_data)
+{
+}
+
+
 struct nci_vtable nci_libffi_vtable =
 {
     nci_libffi_new,
     nci_libffi_clone,
     nci_libffi_invoke,
-    nci_libffi_free
+    nci_libffi_free,
+    nci_libffi_new_callback
 };
 
 

Modified: branches/nci/tools/build/nci_builtin_c.pl
==============================================================================
--- branches/nci/tools/build/nci_builtin_c.pl   (original)
+++ branches/nci/tools/build/nci_builtin_c.pl   Mon Jan 16 08:28:44 2006
@@ -613,12 +613,24 @@ static void nci_builtin_free (Interp *in
 }
 
 
+static void nci_builtin_new_callback (Interp* interpreter,
+                                     PMC* pmc,
+                                     PMC* sub,
+                                     STRING *cb_signature,
+                                     PMC* user_data)
+{
+    /* This needs to be glued to Parrot_make_cb */
+
+}
+
+
 struct nci_vtable nci_builtin_vtable =
 {
     nci_builtin_new,
     nci_builtin_clone,
     nci_builtin_invoke,
-    nci_builtin_free
+    nci_builtin_free,
+    nci_builtin_new_callback
 };
 
 

Reply via email to