Author: nickg
Date: Wed Jan 11 14:00:13 2006
New Revision: 11103
Modified:
branches/nci/MANIFEST
branches/nci/config/gen/makefiles/root.in
branches/nci/include/parrot/nci.h
branches/nci/src/nci_ffcall.c
branches/nci/tools/build/nci_builtin_c.pl
Log:
NCI #7. Factor out common nci code into new file.
This code was static originally, but will be useful in all NCI
implementations.
Also removed C++ comments which had crept in.
Modified: branches/nci/MANIFEST
==============================================================================
--- branches/nci/MANIFEST (original)
+++ branches/nci/MANIFEST Wed Jan 11 14:00:13 2006
@@ -1777,6 +1777,7 @@ src/memory.c
src/method_util.c []
src/misc.c []
src/mmd.c []
+src/nci.c []
src/nci_builtin_sigs.txt [devel]doc
src/nci_ffcall.c []
src/nci_test.c []
Modified: branches/nci/config/gen/makefiles/root.in
==============================================================================
--- branches/nci/config/gen/makefiles/root.in (original)
+++ branches/nci/config/gen/makefiles/root.in Wed Jan 11 14:00:13 2006
@@ -418,6 +418,7 @@ INTERP_O_FILES = \
$(SRC_DIR)/spf_vtable$(O) \
$(SRC_DIR)/datatypes$(O) \
$(SRC_DIR)/fingerprint$(O) \
+ $(SRC_DIR)/nci$(O) \
$(SRC_DIR)/nci_builtin$(O) \
$(SRC_DIR)/nci_ffcall$(O) \
$(SRC_DIR)/cpu_dep$(O) \
@@ -1069,6 +1070,8 @@ $(SRC_DIR)/dataypes$(O) : $(GENERAL_H_FI
$(SRC_DIR)/exit$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/exit.c
+$(SRC_DIR)/nci$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/nci.c
+
$(SRC_DIR)/nci_builtin$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/nci_builtin.c
$(SRC_DIR)/nci_ffcall$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/nci_ffcall.c \
Modified: branches/nci/include/parrot/nci.h
==============================================================================
--- branches/nci/include/parrot/nci.h (original)
+++ branches/nci/include/parrot/nci.h Wed Jan 11 14:00:13 2006
@@ -25,17 +25,39 @@ typedef void (*nci_free_method_t)(Interp
struct nci_vtable {
- // Used to initialise a new NCI PMC
+ /* Used to initialise a new NCI PMC */
nci_new_method_t nci_new;
- // Used to clone an NCI PMC
+ /* Used to clone an NCI PMC */
nci_clone_method_t nci_clone;
- // Used to invoke the NCI call
+ /* Used to invoke the NCI call */
nci_invoke_method_t nci_invoke;
- // Cleans up the NCI data structures
+ /* Cleans up the NCI data structures */
nci_free_method_t nci_free;
};
+INTVAL Parrot_get_nci_I(Interp *interpreter, struct call_state *st, int n);
+FLOATVAL Parrot_get_nci_N(Interp *interpreter, struct call_state *st, int n);
+STRING* Parrot_get_nci_S(Interp *interpreter, struct call_state *st, int n);
+PMC* Parrot_get_nci_P(Interp *interpreter, struct call_state *st, int n);
+
+void Parrot_set_nci_I(Interp *interpreter, struct call_state *st, INTVAL val);
+void Parrot_set_nci_N(Interp *interpreter, struct call_state *st, FLOATVAL
val);
+void Parrot_set_nci_S(Interp *interpreter, struct call_state *st, STRING *val);
+void Parrot_set_nci_P(Interp *interpreter, struct call_state *st, PMC* val);
+
+char *Parrot_convert_signature (const char *signature);
+
+#define GET_NCI_I(n) Parrot_get_nci_I(interpreter, &st, n)
+#define GET_NCI_S(n) Parrot_get_nci_S(interpreter, &st, n)
+#define GET_NCI_N(n) Parrot_get_nci_N(interpreter, &st, n)
+#define GET_NCI_P(n) Parrot_get_nci_P(interpreter, &st, n)
+
+#define SET_NCI_I(v) Parrot_set_nci_I(interpreter, &st, v)
+#define SET_NCI_S(v) Parrot_set_nci_S(interpreter, &st, v)
+#define SET_NCI_N(v) Parrot_set_nci_N(interpreter, &st, v)
+#define SET_NCI_P(v) Parrot_set_nci_P(interpreter, &st, v)
+
#endif /* PARROT_NCI_H_GUARD */
/*
Modified: branches/nci/src/nci_ffcall.c
==============================================================================
--- branches/nci/src/nci_ffcall.c (original)
+++ branches/nci/src/nci_ffcall.c Wed Jan 11 14:00:13 2006
@@ -75,150 +75,10 @@ typedef struct NCIArgs
} NCIArgs;
-/* Convenience routines for fetching values */
-
-static INTVAL
-get_nci_I(Interp *interpreter, struct call_state *st, int n)
-{
- assert(n < st->src.n);
- Parrot_fetch_arg_nci(interpreter, st);
-
- return UVal_int(st->val);
-}
-
-static FLOATVAL
-get_nci_N(Interp *interpreter, struct call_state *st, int n)
-{
- assert(n < st->src.n);
- Parrot_fetch_arg_nci(interpreter, st);
-
- return UVal_num(st->val);
-}
-
-static STRING*
-get_nci_S(Interp *interpreter, struct call_state *st, int n)
-{
- assert(n < st->src.n);
- Parrot_fetch_arg_nci(interpreter, st);
-
- return UVal_str(st->val);
-}
-
-static PMC*
-get_nci_P(Interp *interpreter, struct call_state *st, int n)
-{
- /*
- * exessive args are passed as NULL
- * used by e.g. MMD infix like __add
- */
- if (n < st->src.n)
- Parrot_fetch_arg_nci(interpreter, st);
- else
- UVal_pmc(st->val) = NULL;
-
- return UVal_pmc(st->val);
-}
-
-#define GET_NCI_I(n) get_nci_I(interpreter, &st, n)
-#define GET_NCI_S(n) get_nci_S(interpreter, &st, n)
-#define GET_NCI_N(n) get_nci_N(interpreter, &st, n)
-#define GET_NCI_P(n) get_nci_P(interpreter, &st, n)
-
-
-/* Convenience routines for setting values */
-
-static void
-set_nci_I(Interp *interpreter, struct call_state *st, INTVAL val)
-{
- Parrot_init_ret_nci(interpreter, st, "I");
- UVal_int(st->val) = val;
- Parrot_convert_arg(interpreter, st);
- Parrot_store_arg(interpreter, st);
-}
-
-static void
-set_nci_N(Interp *interpreter, struct call_state *st, FLOATVAL val)
-{
- Parrot_init_ret_nci(interpreter, st, "N");
- UVal_num(st->val) = val;
- Parrot_convert_arg(interpreter, st);
- Parrot_store_arg(interpreter, st);
-}
-
-static void
-set_nci_S(Interp *interpreter, struct call_state *st, STRING *val)
-{
- Parrot_init_ret_nci(interpreter, st, "S");
- UVal_str(st->val) = val;
- Parrot_convert_arg(interpreter, st);
- Parrot_store_arg(interpreter, st);
-}
-
-static void
-set_nci_P(Interp *interpreter, struct call_state *st, PMC* val)
-{
- Parrot_init_ret_nci(interpreter, st, "P");
- UVal_pmc(st->val) = val;
- Parrot_convert_arg(interpreter, st);
- Parrot_store_arg(interpreter, st);
-}
-
-
-/* Convert NCI signatures to parrot ones */
-
-static char *convert_signature (const char *signature)
-{
- int i, length = strlen (signature);
-
- char *signature_parrot = (char *) malloc (length);
-
- for (i = 0 ; i < length+1 ; i++)
- {
- char map = '\0';
-
- switch (signature[i])
- {
- case 'p': map = 'P'; break;
- case 'i': map = 'I'; break;
- case '3': map = 'P'; break;
- case '2': map = 'P'; break;
- case '4': map = 'P'; break;
- case 'l': map = 'I'; break;
- case 'c': map = 'I'; break;
- case 's': map = 'I'; break;
- case 'f': map = 'N'; break;
- case 'd': map = 'N'; break;
- case 'b': map = 'S'; break;
- case 't': map = 'S'; break;
- case 'P': map = 'P'; break;
- case '0': map = 'P'; break;
- case 'S': map = 'S'; break;
- case 'I': map = 'I'; break;
- case 'N': map = 'N'; break;
- case 'B': map = 'S'; break;
- case 'v': map = 'v'; break;
- case 'J': map = ' '; break;
-
- }
-
- signature_parrot[i] = map;
- }
-
-
-#if 0
- printf ("Map '%s' to '%s'\n",
- signature,
- signature_parrot);
-#endif
-
- return signature_parrot;
-}
-
-
/* =========== Main NCI call code =========== */
-extern void nci_ffcall_invoke (Interp * interpreter, PMC *function);
+static void nci_ffcall_invoke (Interp * interpreter, PMC *function);
static void
nci_ffcall_new (Interp *interpreter, PMC *pmc,
@@ -228,7 +88,7 @@ nci_ffcall_new (Interp *interpreter, PMC
nci_args->func = func;
nci_args->signature = string_to_cstring (interpreter, signature);
- nci_args->signature_parrot = convert_signature (nci_args->signature);
+ nci_args->signature_parrot= Parrot_convert_signature (nci_args->signature);
PMC_data(pmc) = nci_args;
@@ -275,7 +135,7 @@ static void nci_ffcall_invoke (Interp *i
NCIArgs* nci_args = (NCIArgs *) PMC_data(pmc);
signature = nci_args->signature;
- pointer = nci_args->func;
+ pointer = (__VA_function) nci_args->func;
/* Set up return type for function */
switch (signature[0])
@@ -435,10 +295,10 @@ static void nci_ffcall_invoke (Interp *i
}
- // Make the actual call to C function
+ /* Make the actual call to C function */
av_call (alist);
- // Reinitialise interating arguments
+ /* Reinitialise interating arguments */
Parrot_init_arg_nci(interpreter, &st, nci_args->signature_parrot+1);
/* Write backs to variables and cleanup */
@@ -470,7 +330,7 @@ static void nci_ffcall_invoke (Interp *i
break;
default:
- // This is required to synchronise the arguments
+ /* This is required to synchronise the arguments */
temp = GET_NCI_P (i);
break;
}
@@ -485,31 +345,31 @@ static void nci_ffcall_invoke (Interp *i
case 'P':
temp = pmc_new(interpreter, enum_class_UnManagedStruct);
PMC_data (temp) = nci_args->result._pointer;
- set_nci_P (interpreter, &st, temp);
+ SET_NCI_P (temp);
break;
case 'c':
- set_nci_I(interpreter, &st, nci_args->result._char);
+ SET_NCI_I(nci_args->result._char);
break;
case 's':
- set_nci_I(interpreter, &st, nci_args->result._short);
+ SET_NCI_I(nci_args->result._short);
break;
case 'i':
- set_nci_I(interpreter, &st, nci_args->result._int);
+ SET_NCI_I(nci_args->result._int);
break;
case 'l':
- set_nci_I(interpreter, &st, nci_args->result._long);
+ SET_NCI_I(nci_args->result._long);
break;
case 'f':
- set_nci_N(interpreter, &st, nci_args->result._float);
+ SET_NCI_N(nci_args->result._float);
break;
case 'd':
- set_nci_N(interpreter, &st, nci_args->result._double);
+ SET_NCI_N(nci_args->result._double);
break;
case 't':
@@ -517,7 +377,7 @@ static void nci_ffcall_invoke (Interp *i
STRING *string =
string_from_cstring(interpreter,
nci_args->result._string, 0);
- set_nci_S (interpreter, &st, string);
+ SET_NCI_S (string);
}
break;
}
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 Wed Jan 11 14:00:13 2006
@@ -112,24 +112,24 @@ my %ret_type_decl =
);
my %ret_assign =
- ( p => "PMC_data(final_destination) = return_data;\n
set_nci_P(interpreter, &st, final_destination);",
- i => "set_nci_I(interpreter, &st, return_data);",
- I => "set_nci_I(interpreter, &st, return_data);",
- l => "set_nci_I(interpreter, &st, return_data);",
- s => "set_nci_I(interpreter, &st, return_data);",
- c => "set_nci_I(interpreter, &st, return_data);",
- 4 => "set_nci_I(interpreter, &st, *return_data);",
- 3 => "set_nci_I(interpreter, &st, *return_data);",
- 2 => "set_nci_I(interpreter, &st, *return_data);",
- f => "set_nci_N(interpreter, &st, return_data);",
- d => "set_nci_N(interpreter, &st, return_data);",
- N => "set_nci_N(interpreter, &st, return_data);",
- P => "set_nci_P(interpreter, &st, return_data);",
- S => "set_nci_S(interpreter, &st, return_data);",
+ ( p => "PMC_data(final_destination) = return_data;\n
Parrot_set_nci_P(interpreter, &st, final_destination);",
+ i => "Parrot_set_nci_I(interpreter, &st, return_data);",
+ I => "Parrot_set_nci_I(interpreter, &st, return_data);",
+ l => "Parrot_set_nci_I(interpreter, &st, return_data);",
+ s => "Parrot_set_nci_I(interpreter, &st, return_data);",
+ c => "Parrot_set_nci_I(interpreter, &st, return_data);",
+ 4 => "Parrot_set_nci_I(interpreter, &st, *return_data);",
+ 3 => "Parrot_set_nci_I(interpreter, &st, *return_data);",
+ 2 => "Parrot_set_nci_I(interpreter, &st, *return_data);",
+ f => "Parrot_set_nci_N(interpreter, &st, return_data);",
+ d => "Parrot_set_nci_N(interpreter, &st, return_data);",
+ N => "Parrot_set_nci_N(interpreter, &st, return_data);",
+ P => "Parrot_set_nci_P(interpreter, &st, return_data);",
+ S => "Parrot_set_nci_S(interpreter, &st, return_data);",
v => "",
- t => "final_destination = string_from_cstring(interpreter, return_data,
0);\n set_nci_S(interpreter, &st, final_destination);",
-# b => "PObj_bufstart(final_destination) = return_data;\n
set_nci_S(interpreter, &st, final_destination);",
-# B => "PObj_bufstart(final_destination) = *return_data;\n
set_nci_S(interpreter, &st, final_destination);",
+ t => "final_destination = string_from_cstring(interpreter, return_data,
0);\n Parrot_set_nci_S(interpreter, &st, final_destination);",
+# b => "PObj_bufstart(final_destination) = return_data;\n
Parrot_set_nci_S(interpreter, &st, final_destination);",
+# B => "PObj_bufstart(final_destination) = *return_data;\n
Parrot_set_nci_S(interpreter, &st, final_destination);",
);
my %func_call_assign =
@@ -259,95 +259,6 @@ sub print_head {
/*# define CAN_BUILD_CALL_FRAMES*/
#endif
-/*
- * helper funcs - get argument n
- */
-static INTVAL
-get_nci_I(Interp *interpreter, struct call_state *st, int n)
-{
- assert(n < st->src.n);
- Parrot_fetch_arg_nci(interpreter, st);
-
- return UVal_int(st->val);
-}
-
-static FLOATVAL
-get_nci_N(Interp *interpreter, struct call_state *st, int n)
-{
- assert(n < st->src.n);
- Parrot_fetch_arg_nci(interpreter, st);
-
- return UVal_num(st->val);
-}
-
-static STRING*
-get_nci_S(Interp *interpreter, struct call_state *st, int n)
-{
- assert(n < st->src.n);
- Parrot_fetch_arg_nci(interpreter, st);
-
- return UVal_str(st->val);
-}
-
-static PMC*
-get_nci_P(Interp *interpreter, struct call_state *st, int n)
-{
- /*
- * exessive args are passed as NULL
- * used by e.g. MMD infix like __add
- */
- if (n < st->src.n)
- Parrot_fetch_arg_nci(interpreter, st);
- else
- UVal_pmc(st->val) = NULL;
-
- return UVal_pmc(st->val);
-}
-
-#define GET_NCI_I(n) get_nci_I(interpreter, &st, n)
-#define GET_NCI_S(n) get_nci_S(interpreter, &st, n)
-#define GET_NCI_N(n) get_nci_N(interpreter, &st, n)
-#define GET_NCI_P(n) get_nci_P(interpreter, &st, n)
-
-/*
- * set return value
- */
-static void
-set_nci_I(Interp *interpreter, struct call_state *st, INTVAL val)
-{
- Parrot_init_ret_nci(interpreter, st, "I");
- UVal_int(st->val) = val;
- Parrot_convert_arg(interpreter, st);
- Parrot_store_arg(interpreter, st);
-}
-
-static void
-set_nci_N(Interp *interpreter, struct call_state *st, FLOATVAL val)
-{
- Parrot_init_ret_nci(interpreter, st, "N");
- UVal_num(st->val) = val;
- Parrot_convert_arg(interpreter, st);
- Parrot_store_arg(interpreter, st);
-}
-
-static void
-set_nci_S(Interp *interpreter, struct call_state *st, STRING *val)
-{
- Parrot_init_ret_nci(interpreter, st, "S");
- UVal_str(st->val) = val;
- Parrot_convert_arg(interpreter, st);
- Parrot_store_arg(interpreter, st);
-}
-
-static void
-set_nci_P(Interp *interpreter, struct call_state *st, PMC* val)
-{
- Parrot_init_ret_nci(interpreter, st, "P");
- UVal_pmc(st->val) = val;
- Parrot_convert_arg(interpreter, st);
- Parrot_store_arg(interpreter, st);
-}
-
/* All our static functions that call in various ways. Yes, terribly
hackish, but that is just fine */