[svn:parrot] r49731 - in branches/gsoc_nci: config/gen/libffi src/pmc

plobsing at svn.parrot.org plobsing at svn.parrot.org
Sat Oct 30 06:18:16 UTC 2010


Author: plobsing
Date: Sat Oct 30 06:18:15 2010
New Revision: 49731
URL: https://trac.parrot.org/parrot/changeset/49731

Log:
remove old libffi signature parser

Modified:
   branches/gsoc_nci/config/gen/libffi/nci-ffi.pmc.in
   branches/gsoc_nci/src/pmc/nci.pmc

Modified: branches/gsoc_nci/config/gen/libffi/nci-ffi.pmc.in
==============================================================================
--- branches/gsoc_nci/config/gen/libffi/nci-ffi.pmc.in	Sat Oct 30 06:11:23 2010	(r49730)
+++ branches/gsoc_nci/config/gen/libffi/nci-ffi.pmc.in	Sat Oct 30 06:18:15 2010	(r49731)
@@ -34,21 +34,11 @@
 static ffi_type * nci_to_ffi_type(PARROT_INTERP, nci_sig_elem_t nci_t)
         __attribute__nonnull__(1);
 
-static INTVAL parse_prefix(INTVAL c);
-static INTVAL parse_sig(PARROT_INTERP,
-    STRING *sig,
-    size_t sig_length,
-    Parrot_NCI_attributes *nci_info)
-        __attribute__nonnull__(1);
-
 #define ASSERT_ARGS_build_libffi_func __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(nci))
 #define ASSERT_ARGS_nci_to_ffi_type __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_parse_prefix __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_parse_sig __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(interp))
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
@@ -68,68 +58,6 @@
 #  error "unhandled NUMVAL_SIZE value"
 #endif
 
-static
-size_t
-parse_return(PARROT_INTERP, STRING* sig, size_t sig_length,
-             Parrot_NCI_attributes * nci_info, ffi_type **return_type);
-
-static
-size_t
-parse_args(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-           Parrot_NCI_attributes *nci_info, ffi_type ***arg_types);
-
-static
-size_t
-parse_identifier(PARROT_INTERP,
-                 STRING* sig, size_t start, size_t end,
-                 ffi_type** sig_obj,
-                 char* pmc_type, size_t *pmc_count,
-                 char* translation, size_t *translation_length);
-
-static
-size_t
-parse_structure(PARROT_INTERP, STRING* sig, size_t start, size_t end,
-                ffi_type** sig_obj, char* pmc_type);
-
-static
-size_t
-structure_length(PARROT_INTERP, STRING* sig, size_t start, size_t end);
-
-static
-size_t
-count_args(PARROT_INTERP, STRING* sig, size_t start, size_t end);
-
-static
-size_t
-find_matching(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-              INTVAL start_character, INTVAL end_character);
-
-#define IS_DIGIT(x)               (((x) == '0') || ((x) == '1') || ((x) == '2') || ((x) == '3') \
-                                || ((x) == '4') || ((x) == '5') || ((x) == '6') || ((x) == '7') \
-                                || ((x) == '8') || ((x) == '9'))
-
-#define IS_PREFIX(x)              (((x) == '*') || ((x) == 'u'))
-
-#define IS_OLD_TYPE(x)            (((x) == 'P') || ((x) == 'J') || ((x) == 'N') || ((x) == 'S') \
-                                || ((x) == 'O') || ((x) == '@') || ((x) == 'B') || ((x) == 'p') \
-                                || ((x) == '2') || ((x) == '3') || ((x) == '4') || ((x) == 'U') \
-                                || ((x) == 'V') || ((x) == 'I'))
-
-#define IS_TYPE(x)                (((x) == 'i') || ((x) == 'v') || ((x) == 'l') || ((x) == 't') \
-                                || ((x) == 'c') || ((x) == 'b') || ((x) == 'f') || ((x) == 'd') \
-                                || ((x) == 's') || IS_OLD_TYPE(x))
-
-#define IS_POSTFIX(x)             ((x) == '{') /*  || IS_DIGIT(x)) */
-#define IS_INFIX(x)               ((x) == '|')
-#define IS_START_CIRCUMFIX(x)     ((x) == '(')
-#define IS_END_CIRCUMFIX(x)       ((x) == ')')
-#define IS_NOT_END_CIRCUMFIX(x)   ((x) != ')')
-
-#define PREFIX_POINTER  (1<<0)
-#define PREFIX_SIGNED   (   0)
-#define PREFIX_UNSIGNED (1<<1)
-#define PREFIX_NATIVE   (1<<2)
-
 typedef struct pmc_holder_t {
     PMC* p;
     union {
@@ -138,97 +66,6 @@
     };
 } pmc_holder_t;
 
-/*
-
-=item C<static INTVAL parse_sig(PARROT_INTERP, STRING *sig, size_t sig_length,
-Parrot_NCI_attributes *nci_info)>
-
-Parse a full signature. All signatures should contain a return type and a list of
-arguments. "vv" Would be the shortest "void fn(void)" signature you can legally make.
-
-See C<parse_return> and C<parse_args> to see how the signature is broken down.
-
-=cut
-
-*/
-
-static INTVAL
-parse_sig(PARROT_INTERP, STRING *sig, size_t sig_length, Parrot_NCI_attributes *nci_info) {
-    ffi_cif cif;
-    ffi_type *return_type;
-    ffi_type **arg_types;
-
-    if (sig_length) {
-        size_t i = parse_return(interp, sig, sig_length, nci_info, &return_type);
-        if (i < sig_length)
-            parse_args(interp, sig, i, sig_length, nci_info, &arg_types);
-        else {
-            arg_types       = mem_internal_allocate_n_zeroed_typed(1, ffi_type*);
-            arg_types[0]    = &ffi_type_void;
-            nci_info->pcc_params_signature = string_make(interp, "", 1, NULL, 0);
-            nci_info->arg_translation = NULL;
-            nci_info->arity = 0;
-        }
-    }
-    else {
-        arg_types       = mem_internal_allocate_n_zeroed_typed(1, ffi_type*);
-        arg_types[0]    = &ffi_type_void;
-        return_type     = &ffi_type_void;
-        nci_info->pcc_params_signature = string_make(interp, "", 1, NULL, 0);
-        nci_info->arg_translation = NULL;
-        nci_info->arity = 0;
-    }
-
-    if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI,
-                     nci_info->arity, return_type, arg_types) == FFI_OK) {
-        nci_info->cif = (void*)mem_internal_allocate_typed(ffi_cif);
-        memcpy(nci_info->cif, &cif, sizeof (ffi_cif));
-        nci_info->arg_types = arg_types;
-
-        return 1;
-    }
-
-    if (arg_types) {
-        mem_sys_free(arg_types);
-    }
-
-    /* TODO: Throw Error here. */
-    printf("Bad signature\n");
-
-    return 0;
-}
-
-/*
-
-=item C<static size_t parse_return(PARROT_INTERP, STRING *sig, size_t sig_length,
-                                   Parrot_NCI_attributes* nci_info, ffi_type **return_type)>
-
-Parses the return type. This assumes the first identifier is the return type.
-
-See C<parse_identifier> to see how a single identifer is parsed.
-
-=cut
-
-*/
-
-static size_t
-parse_return(PARROT_INTERP, STRING *sig, size_t sig_length,
-             Parrot_NCI_attributes* nci_info, ffi_type **return_type) {
-    char *t = mem_allocate_n_zeroed_typed(2, char);
-    size_t j = 0, k = 0;
-    /* Should be 1 character plus a NULL" */
-    char * result_sig = mem_allocate_n_zeroed_typed(2, char);
-    size_t result_length = parse_identifier(interp,
-                                            sig, 0, sig_length,
-                                            return_type,
-                                            result_sig, &j,
-                                            t, &k);
-
-    nci_info->pcc_return_signature = string_make(interp, result_sig, 2, NULL, 0);
-    nci_info->return_translation = (void*)t;
-    mem_sys_free(result_sig);
-    return result_length;
-}
 
 /*
 
@@ -307,449 +144,6 @@
     }
 }
 
-/*
-
-=item C<static size_t parse_args(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-                          Parrot_NCI_attributes *nci_info, ffi_type ***arg_types)>
-
-Parses the signatures arguments. It takes an offset to know where to start looking.
-This should fill out a list of C<ffi_type*> args.
-
-See C<parse_identifier> to see how a single identifer is parsed.
-
-=cut
-
-*/
-
-static size_t
-parse_args(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-           Parrot_NCI_attributes *nci_info, ffi_type ***arg_types) {
-    size_t i = start;
-    size_t arg_count = 0;
-    size_t argc = count_args(interp, sig, start, sig_length);
-    char* parrot_types = mem_allocate_n_zeroed_typed(argc + 1, char);
-    size_t parrot_types_length = 0;
-    char* translation_types = mem_allocate_n_zeroed_typed(argc + 1, char);
-    size_t translation_length = 0;
-
-    *arg_types = mem_internal_allocate_n_zeroed_typed(argc + 1, ffi_type*);
-
-    while (i < sig_length) {
-        ffi_type *ident;
-        i = parse_identifier(interp,
-                             sig, i, sig_length,
-                             &ident,
-                             parrot_types, &parrot_types_length,
-                             translation_types, &translation_length);
-        (*arg_types)[arg_count] = ident;
-        arg_count++;
-    }
-
-    nci_info->pcc_params_signature = string_make(interp, parrot_types,
-                                                 strlen(parrot_types), NULL, 0);
-    nci_info->arg_translation = translation_types;
-    nci_info->arity = arg_count;
-
-    mem_sys_free(parrot_types);
-
-    return i;
-}
-
-/*
-
-=item C<static size_t parse_identifier(PARROT_INTERP, STRING *sig, size_t start,
-                                       size_t sig_length, ffi_type **type_obj,
-                                       char **type, size_t *pmc_count,
-                                       char **translation, size_t *translation_count)>
-
-Parse an identifier and build its representation used for PCC and any translations
-that are needed.
-
-An example of a transation is "t", it will take a STRING* and convert it to a
-char* for the function call.
-
-=cut
-
-*/
-
-static size_t
-parse_identifier(PARROT_INTERP,
-                 STRING *sig, size_t start, size_t sig_length,
-                 ffi_type **type_obj,
-                 char *type, size_t *pmc_count,
-                 char *translation, size_t *translation_count) {
-    size_t i = start;
-    INTVAL done = 0;
-
-    while (!done && i < sig_length) {
-        INTVAL c = Parrot_str_indexed(interp, sig, i);
-        int prefix = 0;
-        while (IS_PREFIX(c)) {
-            prefix |= parse_prefix(c);
-            i++;
-
-            if (i < sig_length)
-                c = Parrot_str_indexed(interp, sig, i);
-            else
-                return i;
-        }
-
-        if (IS_START_CIRCUMFIX(c)) {
-            i = parse_structure(interp, sig, i + 1, sig_length, type_obj, type);
-            i++;
-
-            if (i < sig_length)
-                c = Parrot_str_indexed(interp, sig, i);
-            else
-                return i;
-        }
-        else if (IS_TYPE(c)) {
-            if (prefix & PREFIX_POINTER) {
-                *type_obj = &ffi_type_pointer;
-                continue;
-            }
-            translation[(*translation_count)++] = ' ';
-            switch (c) {
-              case (INTVAL)' ':
-              case (INTVAL)'0':    /* null ptr or such - doesn't consume a reg */
-                break;
-              case (INTVAL)'c':
-                translation[(*translation_count) - 1] = 'c';
-                type[(*pmc_count)++] = 'I';
-                if (prefix & PREFIX_UNSIGNED) {
-                  *type_obj = &ffi_type_uchar;
-                }
-                else {
-                  *type_obj = &ffi_type_schar;
-                }
-                break;
-              case (INTVAL)'B':
-                translation[(*translation_count) - 1] = 'B';
-                type[(*pmc_count)++] = 'S';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'b':
-                translation[(*translation_count) - 1] = 'b';
-                type[(*pmc_count)++] = 'S';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'s':
-                translation[(*translation_count) - 1] = 's';
-                type[(*pmc_count)++] = 'I';
-                if (prefix & PREFIX_UNSIGNED) {
-                  *type_obj = &ffi_type_ushort;
-                }
-                else {
-                  *type_obj = &ffi_type_sshort;
-                }
-                break;
-              case (INTVAL)'I':   /* INTVAL */
-              case (INTVAL)'i':
-                translation[(*translation_count) - 1] = 'i';
-                type[(*pmc_count)++] = 'I';
-                if (prefix & PREFIX_UNSIGNED) {
-                  *type_obj = &ffi_type_uint;
-                }
-                else {
-                  *type_obj = &ffi_type_sint;
-                }
-                break;
-              case (INTVAL)'l':
-                translation[(*translation_count) - 1] = 'l';
-                type[(*pmc_count)++] = 'I';
-                if (prefix & PREFIX_UNSIGNED) {
-                  *type_obj = &ffi_type_ulong;
-                }
-                else {
-                  *type_obj = &ffi_type_slong;
-                }
-                break;
-              case (INTVAL)'q':
-                translation[(*translation_count) - 1] = 'q';
-                type[(*pmc_count)++] = 'I';
-                if (prefix & PREFIX_UNSIGNED) {
-                  *type_obj = &ffi_type_uint64;
-                }
-                else {
-                  *type_obj = &ffi_type_sint64;
-                }
-                break;
-              case (INTVAL)'J':   /* interpreter */
-                translation[(*translation_count) - 1] = 'J';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'p':   /* push pmc->data */
-                translation[(*translation_count) - 1] = 'p';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'2':
-                translation[(*translation_count) - 1] = '2';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'3':
-                translation[(*translation_count) - 1] = '3';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'4':
-                translation[(*translation_count) - 1] = '4';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break; 
-              case (INTVAL)'P':   /* push PMC * */
-                translation[(*translation_count) - 1] = 'P';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'V':   /* push PMC * */
-                translation[(*translation_count) - 1] = 'V';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'S':
-                type[(*pmc_count)++] = 'S';
-                *type_obj = &ffi_type_pointer;
-              case (INTVAL)'t':
-                translation[(*translation_count) - 1] = 't';
-                type[(*pmc_count)++] = 'S';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'v':
-                type[(*pmc_count)++] = 'v';
-                *type_obj = &ffi_type_void;
-                break;
-#if (DOUBLE_SIZE == 4) /* FLOATVAL is a float */
-              case (INTVAL)'N':
-#endif
-              case (INTVAL)'f':
-                translation[(*translation_count) - 1] = 'f';
-                type[(*pmc_count)++] = 'N';
-                *type_obj = &ffi_type_float;
-                break;
-#if (DOUBLE_SIZE == 8) /* FLOATVAL is a double */
-              case (INTVAL)'N':
-#endif
-              case (INTVAL)'d':
-                translation[(*translation_count) - 1] = 'd';
-                type[(*pmc_count)++] = 'N';
-                *type_obj = &ffi_type_double;
-                break;
-#if (DOUBLE_SIZE > 8) /* FLOATVAL is a long double */
-              case (INTVAL)'N':
-#endif
-              case (INTVAL)'D':
-                translation[(*translation_count) - 1] = 'D';
-                type[(*pmc_count)++] = 'N';
-                *type_obj = &ffi_type_longdouble;
-                break;
-              case (INTVAL)'O':   /* push PMC * invocant */
-                *type_obj = &ffi_type_pointer;
-                type[(*pmc_count)++] = 'P';
-                type[(*pmc_count)++] = 'i';
-                break;
-              case (INTVAL)'@':   /* push PMC * slurpy */
-                *type_obj = &ffi_type_pointer;
-                type[(*pmc_count)++] = 'P';
-                type[(*pmc_count)++] = 's';
-                break;
-              default:
-                Parrot_ex_throw_from_c_args(interp, NULL,
-                            EXCEPTION_JIT_ERROR,
-                            "Unknown param Signature %c\n", (char)c);
-                break;
-            }
-            i++;
-
-            if (i < sig_length)
-                c = Parrot_str_indexed(interp, sig, i);
-            else
-                return i;
-        }
-        else {
-            Parrot_ex_throw_from_c_args(interp, NULL,
-                            EXCEPTION_JIT_ERROR,
-                            "Unknown param Signature %c\n", (char)c);
-        }
-
-        /*
-         * Parse postfix ops
-         * TODO: Parse postfix ops, currently I skip them.
-         */
-        while (IS_POSTFIX(c)) {
-            i++;
-            if (i < sig_length)
-                c = Parrot_str_indexed(interp, sig, i);
-            else
-                return i;
-        }
-
-        if ((i < sig_length) && (c == (INTVAL)'|')) {
-            /* Its a union, parse it special. */
-        }
-        else {
-            done = 1;
-        }
-    }
-
-    return i;
-}
-
-/*
-
-=item C<static INTVAL parse_prefix(INTVAL c)>
-
-Parse a prefix character.
-
-=cut
-
-*/
-
-static INTVAL
-parse_prefix(INTVAL c) {
-    switch (c) {
-      case '*':
-        return PREFIX_POINTER;
-        break;
-      case 'u':
-        return PREFIX_UNSIGNED;
-        break;
-      default:
-        return 0;
-        break;
-    }
-
-    return 0;
-}
-
-/*
-
-=item C<static size_t parse_structure(PARROT_INTERP, STRING* sig, size_t start,
-                                      size_t sig_length, ffi_type **type_obj, char* pmc_type)>
-
-Parses a stucture.
-TODO: This should auto inflate to an UnmanagedStruct or a ManagedStruct in the future.
-
-=cut
-
-*/
-
-static size_t
-parse_structure(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-                ffi_type **type_obj, char* pmc_type) {
-    size_t i = start;
-    size_t struct_len = structure_length(interp, sig, start, sig_length);
-    size_t element_counter = 0;
-    INTVAL c;
-
-    *type_obj = (ffi_type*)mem_internal_allocate_typed(ffi_type*);
-    (*type_obj)->elements = mem_internal_allocate_n_zeroed_typed(struct_len + 1, ffi_type*);
-
-    (*type_obj)->size = (*type_obj)->alignment = 0;
-    (*type_obj)->type = FFI_TYPE_STRUCT;
-
-    c = Parrot_str_indexed(interp, sig, i);
-    while (i < sig_length && IS_NOT_END_CIRCUMFIX(c)) {
-        i = parse_identifier(interp, sig, i, sig_length,
-                             &(*type_obj)->elements[element_counter],
-                             NULL, 0, NULL, 0);
-        element_counter++;
-        c = Parrot_str_indexed(interp, sig, i);
-    }
-
-    (*type_obj)->elements[struct_len] = NULL;
-
-    return i;
-}
-
-/*
-
-=item C<static size_t structure_length(PARROT_INTERP, STRING* sig,
-                                       size_t start, size_t sig_length)>
-
-Calculates the number of items in a stucture for size purposes.
-
-=cut
-
-*/
-
-static size_t
-structure_length(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length) {
-    size_t len = 0;
-    size_t i = start;
-    INTVAL depth = 0;
-    INTVAL c = Parrot_str_indexed(interp, sig, i);
-    while (i < sig_length && depth != -1) {
-        if (IS_START_CIRCUMFIX(c)) depth++;
-        else if (IS_END_CIRCUMFIX(c)) depth--;
-        else if (depth == 0 && (IS_TYPE(c))) len++;
-        i++;
-        c = Parrot_str_indexed(interp, sig, i);
-    }
-
-    return len;
-}
-
-/*
-
-=item C<static size_t find_matching(PARROT_INTERP, STRING* sig, size_t start,
-                            size_t sig_length, INTVAL start_character, INTVAL end_character)>
-
-Find matching symbols, used for finding the start and stop of a stucture, it is
-also recursive to handle structures inside of structures.
-
-=cut
-
-*/
-
-static size_t
-find_matching(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-              INTVAL start_character, INTVAL end_character) {
-    size_t i = start;
-    INTVAL c = Parrot_str_indexed(interp, sig, i);
-    while (i < sig_length && c != end_character) {
-        if (c == start_character)
-            i = find_matching(interp, sig, i, sig_length, start_character, end_character);
-        i++;
-        c = Parrot_str_indexed(interp, sig, i);
-    }
-
-    return i;
-}
-
-/*
-
-=item C<size_t count_args(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length)>
-
-Counts the number of arguments from a given starting point. It only counts
-identiers, not prefix, infix or postfix modifiers. Structures are considered as
-1 item in most cases.
-
-=cut
-
-*/
-
-static size_t
-count_args(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length) {
-    size_t length = 0;
-    size_t i = start;
-
-    while (i < sig_length) {
-        const INTVAL c = Parrot_str_indexed(interp, sig, i);
-        if (IS_START_CIRCUMFIX(c)) {
-            i = find_matching(interp, sig, i + 1, sig_length, '(', ')');
-            length++;
-        }
-        else if (IS_TYPE(c)) {
-            length++;
-        }
-        i++;
-    }
-
-    return length;
-}
-
 static void
 build_libffi_func(PARROT_INTERP, ARGMOD(Parrot_NCI_attributes *nci))
 {

Modified: branches/gsoc_nci/src/pmc/nci.pmc
==============================================================================
--- branches/gsoc_nci/src/pmc/nci.pmc	Sat Oct 30 06:11:23 2010	(r49730)
+++ branches/gsoc_nci/src/pmc/nci.pmc	Sat Oct 30 06:18:15 2010	(r49731)
@@ -34,21 +34,11 @@
 static ffi_type * nci_to_ffi_type(PARROT_INTERP, nci_sig_elem_t nci_t)
         __attribute__nonnull__(1);
 
-static INTVAL parse_prefix(INTVAL c);
-static INTVAL parse_sig(PARROT_INTERP,
-    STRING *sig,
-    size_t sig_length,
-    Parrot_NCI_attributes *nci_info)
-        __attribute__nonnull__(1);
-
 #define ASSERT_ARGS_build_libffi_func __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(nci))
 #define ASSERT_ARGS_nci_to_ffi_type __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_parse_prefix __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
-#define ASSERT_ARGS_parse_sig __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(interp))
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
@@ -68,68 +58,6 @@
 #  error "unhandled NUMVAL_SIZE value"
 #endif
 
-static
-size_t
-parse_return(PARROT_INTERP, STRING* sig, size_t sig_length,
-             Parrot_NCI_attributes * nci_info, ffi_type **return_type);
-
-static
-size_t
-parse_args(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-           Parrot_NCI_attributes *nci_info, ffi_type ***arg_types);
-
-static
-size_t
-parse_identifier(PARROT_INTERP,
-                 STRING* sig, size_t start, size_t end,
-                 ffi_type** sig_obj,
-                 char* pmc_type, size_t *pmc_count,
-                 char* translation, size_t *translation_length);
-
-static
-size_t
-parse_structure(PARROT_INTERP, STRING* sig, size_t start, size_t end,
-                ffi_type** sig_obj, char* pmc_type);
-
-static
-size_t
-structure_length(PARROT_INTERP, STRING* sig, size_t start, size_t end);
-
-static
-size_t
-count_args(PARROT_INTERP, STRING* sig, size_t start, size_t end);
-
-static
-size_t
-find_matching(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-              INTVAL start_character, INTVAL end_character);
-
-#define IS_DIGIT(x)               (((x) == '0') || ((x) == '1') || ((x) == '2') || ((x) == '3') \
-                                || ((x) == '4') || ((x) == '5') || ((x) == '6') || ((x) == '7') \
-                                || ((x) == '8') || ((x) == '9'))
-
-#define IS_PREFIX(x)              (((x) == '*') || ((x) == 'u'))
-
-#define IS_OLD_TYPE(x)            (((x) == 'P') || ((x) == 'J') || ((x) == 'N') || ((x) == 'S') \
-                                || ((x) == 'O') || ((x) == '@') || ((x) == 'B') || ((x) == 'p') \
-                                || ((x) == '2') || ((x) == '3') || ((x) == '4') || ((x) == 'U') \
-                                || ((x) == 'V') || ((x) == 'I'))
-
-#define IS_TYPE(x)                (((x) == 'i') || ((x) == 'v') || ((x) == 'l') || ((x) == 't') \
-                                || ((x) == 'c') || ((x) == 'b') || ((x) == 'f') || ((x) == 'd') \
-                                || ((x) == 's') || IS_OLD_TYPE(x))
-
-#define IS_POSTFIX(x)             ((x) == '{') /*  || IS_DIGIT(x)) */
-#define IS_INFIX(x)               ((x) == '|')
-#define IS_START_CIRCUMFIX(x)     ((x) == '(')
-#define IS_END_CIRCUMFIX(x)       ((x) == ')')
-#define IS_NOT_END_CIRCUMFIX(x)   ((x) != ')')
-
-#define PREFIX_POINTER  (1<<0)
-#define PREFIX_SIGNED   (   0)
-#define PREFIX_UNSIGNED (1<<1)
-#define PREFIX_NATIVE   (1<<2)
-
 typedef struct pmc_holder_t {
     PMC* p;
     union {
@@ -138,97 +66,6 @@
     };
 } pmc_holder_t;
 
-/*
-
-=item C<static INTVAL parse_sig(PARROT_INTERP, STRING *sig, size_t sig_length,
-Parrot_NCI_attributes *nci_info)>
-
-Parse a full signature. All signatures should contain a return type and a list of
-arguments. "vv" Would be the shortest "void fn(void)" signature you can legally make.
-
-See C<parse_return> and C<parse_args> to see how the signature is broken down.
-
-=cut
-
-*/
-
-static INTVAL
-parse_sig(PARROT_INTERP, STRING *sig, size_t sig_length, Parrot_NCI_attributes *nci_info) {
-    ffi_cif cif;
-    ffi_type *return_type;
-    ffi_type **arg_types;
-
-    if (sig_length) {
-        size_t i = parse_return(interp, sig, sig_length, nci_info, &return_type);
-        if (i < sig_length)
-            parse_args(interp, sig, i, sig_length, nci_info, &arg_types);
-        else {
-            arg_types       = mem_internal_allocate_n_zeroed_typed(1, ffi_type*);
-            arg_types[0]    = &ffi_type_void;
-            nci_info->pcc_params_signature = string_make(interp, "", 1, NULL, 0);
-            nci_info->arg_translation = NULL;
-            nci_info->arity = 0;
-        }
-    }
-    else {
-        arg_types       = mem_internal_allocate_n_zeroed_typed(1, ffi_type*);
-        arg_types[0]    = &ffi_type_void;
-        return_type     = &ffi_type_void;
-        nci_info->pcc_params_signature = string_make(interp, "", 1, NULL, 0);
-        nci_info->arg_translation = NULL;
-        nci_info->arity = 0;
-    }
-
-    if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI,
-                     nci_info->arity, return_type, arg_types) == FFI_OK) {
-        nci_info->cif = (void*)mem_internal_allocate_typed(ffi_cif);
-        memcpy(nci_info->cif, &cif, sizeof (ffi_cif));
-        nci_info->arg_types = arg_types;
-
-        return 1;
-    }
-
-    if (arg_types) {
-        mem_sys_free(arg_types);
-    }
-
-    /* TODO: Throw Error here. */
-    printf("Bad signature\n");
-
-    return 0;
-}
-
-/*
-
-=item C<static size_t parse_return(PARROT_INTERP, STRING *sig, size_t sig_length,
-                                   Parrot_NCI_attributes* nci_info, ffi_type **return_type)>
-
-Parses the return type. This assumes the first identifier is the return type.
-
-See C<parse_identifier> to see how a single identifer is parsed.
-
-=cut
-
-*/
-
-static size_t
-parse_return(PARROT_INTERP, STRING *sig, size_t sig_length,
-             Parrot_NCI_attributes* nci_info, ffi_type **return_type) {
-    char *t = mem_allocate_n_zeroed_typed(2, char);
-    size_t j = 0, k = 0;
-    /* Should be 1 character plus a NULL" */
-    char * result_sig = mem_allocate_n_zeroed_typed(2, char);
-    size_t result_length = parse_identifier(interp,
-                                            sig, 0, sig_length,
-                                            return_type,
-                                            result_sig, &j,
-                                            t, &k);
-
-    nci_info->pcc_return_signature = string_make(interp, result_sig, 2, NULL, 0);
-    nci_info->return_translation = (void*)t;
-    mem_sys_free(result_sig);
-    return result_length;
-}
 
 /*
 
@@ -307,449 +144,6 @@
     }
 }
 
-/*
-
-=item C<static size_t parse_args(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-                          Parrot_NCI_attributes *nci_info, ffi_type ***arg_types)>
-
-Parses the signatures arguments. It takes an offset to know where to start looking.
-This should fill out a list of C<ffi_type*> args.
-
-See C<parse_identifier> to see how a single identifer is parsed.
-
-=cut
-
-*/
-
-static size_t
-parse_args(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-           Parrot_NCI_attributes *nci_info, ffi_type ***arg_types) {
-    size_t i = start;
-    size_t arg_count = 0;
-    size_t argc = count_args(interp, sig, start, sig_length);
-    char* parrot_types = mem_allocate_n_zeroed_typed(argc + 1, char);
-    size_t parrot_types_length = 0;
-    char* translation_types = mem_allocate_n_zeroed_typed(argc + 1, char);
-    size_t translation_length = 0;
-
-    *arg_types = mem_internal_allocate_n_zeroed_typed(argc + 1, ffi_type*);
-
-    while (i < sig_length) {
-        ffi_type *ident;
-        i = parse_identifier(interp,
-                             sig, i, sig_length,
-                             &ident,
-                             parrot_types, &parrot_types_length,
-                             translation_types, &translation_length);
-        (*arg_types)[arg_count] = ident;
-        arg_count++;
-    }
-
-    nci_info->pcc_params_signature = string_make(interp, parrot_types,
-                                                 strlen(parrot_types), NULL, 0);
-    nci_info->arg_translation = translation_types;
-    nci_info->arity = arg_count;
-
-    mem_sys_free(parrot_types);
-
-    return i;
-}
-
-/*
-
-=item C<static size_t parse_identifier(PARROT_INTERP, STRING *sig, size_t start,
-                                       size_t sig_length, ffi_type **type_obj,
-                                       char **type, size_t *pmc_count,
-                                       char **translation, size_t *translation_count)>
-
-Parse an identifier and build its representation used for PCC and any translations
-that are needed.
-
-An example of a transation is "t", it will take a STRING* and convert it to a
-char* for the function call.
-
-=cut
-
-*/
-
-static size_t
-parse_identifier(PARROT_INTERP,
-                 STRING *sig, size_t start, size_t sig_length,
-                 ffi_type **type_obj,
-                 char *type, size_t *pmc_count,
-                 char *translation, size_t *translation_count) {
-    size_t i = start;
-    INTVAL done = 0;
-
-    while (!done && i < sig_length) {
-        INTVAL c = Parrot_str_indexed(interp, sig, i);
-        int prefix = 0;
-        while (IS_PREFIX(c)) {
-            prefix |= parse_prefix(c);
-            i++;
-
-            if (i < sig_length)
-                c = Parrot_str_indexed(interp, sig, i);
-            else
-                return i;
-        }
-
-        if (IS_START_CIRCUMFIX(c)) {
-            i = parse_structure(interp, sig, i + 1, sig_length, type_obj, type);
-            i++;
-
-            if (i < sig_length)
-                c = Parrot_str_indexed(interp, sig, i);
-            else
-                return i;
-        }
-        else if (IS_TYPE(c)) {
-            if (prefix & PREFIX_POINTER) {
-                *type_obj = &ffi_type_pointer;
-                continue;
-            }
-            translation[(*translation_count)++] = ' ';
-            switch (c) {
-              case (INTVAL)' ':
-              case (INTVAL)'0':    /* null ptr or such - doesn't consume a reg */
-                break;
-              case (INTVAL)'c':
-                translation[(*translation_count) - 1] = 'c';
-                type[(*pmc_count)++] = 'I';
-                if (prefix & PREFIX_UNSIGNED) {
-                  *type_obj = &ffi_type_uchar;
-                }
-                else {
-                  *type_obj = &ffi_type_schar;
-                }
-                break;
-              case (INTVAL)'B':
-                translation[(*translation_count) - 1] = 'B';
-                type[(*pmc_count)++] = 'S';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'b':
-                translation[(*translation_count) - 1] = 'b';
-                type[(*pmc_count)++] = 'S';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'s':
-                translation[(*translation_count) - 1] = 's';
-                type[(*pmc_count)++] = 'I';
-                if (prefix & PREFIX_UNSIGNED) {
-                  *type_obj = &ffi_type_ushort;
-                }
-                else {
-                  *type_obj = &ffi_type_sshort;
-                }
-                break;
-              case (INTVAL)'I':   /* INTVAL */
-              case (INTVAL)'i':
-                translation[(*translation_count) - 1] = 'i';
-                type[(*pmc_count)++] = 'I';
-                if (prefix & PREFIX_UNSIGNED) {
-                  *type_obj = &ffi_type_uint;
-                }
-                else {
-                  *type_obj = &ffi_type_sint;
-                }
-                break;
-              case (INTVAL)'l':
-                translation[(*translation_count) - 1] = 'l';
-                type[(*pmc_count)++] = 'I';
-                if (prefix & PREFIX_UNSIGNED) {
-                  *type_obj = &ffi_type_ulong;
-                }
-                else {
-                  *type_obj = &ffi_type_slong;
-                }
-                break;
-              case (INTVAL)'q':
-                translation[(*translation_count) - 1] = 'q';
-                type[(*pmc_count)++] = 'I';
-                if (prefix & PREFIX_UNSIGNED) {
-                  *type_obj = &ffi_type_uint64;
-                }
-                else {
-                  *type_obj = &ffi_type_sint64;
-                }
-                break;
-              case (INTVAL)'J':   /* interpreter */
-                translation[(*translation_count) - 1] = 'J';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'p':   /* push pmc->data */
-                translation[(*translation_count) - 1] = 'p';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'2':
-                translation[(*translation_count) - 1] = '2';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'3':
-                translation[(*translation_count) - 1] = '3';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'4':
-                translation[(*translation_count) - 1] = '4';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break; 
-              case (INTVAL)'P':   /* push PMC * */
-                translation[(*translation_count) - 1] = 'P';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'V':   /* push PMC * */
-                translation[(*translation_count) - 1] = 'V';
-                type[(*pmc_count)++] = 'P';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'S':
-                type[(*pmc_count)++] = 'S';
-                *type_obj = &ffi_type_pointer;
-              case (INTVAL)'t':
-                translation[(*translation_count) - 1] = 't';
-                type[(*pmc_count)++] = 'S';
-                *type_obj = &ffi_type_pointer;
-                break;
-              case (INTVAL)'v':
-                type[(*pmc_count)++] = 'v';
-                *type_obj = &ffi_type_void;
-                break;
-#if (DOUBLE_SIZE == 4) /* FLOATVAL is a float */
-              case (INTVAL)'N':
-#endif
-              case (INTVAL)'f':
-                translation[(*translation_count) - 1] = 'f';
-                type[(*pmc_count)++] = 'N';
-                *type_obj = &ffi_type_float;
-                break;
-#if (DOUBLE_SIZE == 8) /* FLOATVAL is a double */
-              case (INTVAL)'N':
-#endif
-              case (INTVAL)'d':
-                translation[(*translation_count) - 1] = 'd';
-                type[(*pmc_count)++] = 'N';
-                *type_obj = &ffi_type_double;
-                break;
-#if (DOUBLE_SIZE > 8) /* FLOATVAL is a long double */
-              case (INTVAL)'N':
-#endif
-              case (INTVAL)'D':
-                translation[(*translation_count) - 1] = 'D';
-                type[(*pmc_count)++] = 'N';
-                *type_obj = &ffi_type_longdouble;
-                break;
-              case (INTVAL)'O':   /* push PMC * invocant */
-                *type_obj = &ffi_type_pointer;
-                type[(*pmc_count)++] = 'P';
-                type[(*pmc_count)++] = 'i';
-                break;
-              case (INTVAL)'@':   /* push PMC * slurpy */
-                *type_obj = &ffi_type_pointer;
-                type[(*pmc_count)++] = 'P';
-                type[(*pmc_count)++] = 's';
-                break;
-              default:
-                Parrot_ex_throw_from_c_args(interp, NULL,
-                            EXCEPTION_JIT_ERROR,
-                            "Unknown param Signature %c\n", (char)c);
-                break;
-            }
-            i++;
-
-            if (i < sig_length)
-                c = Parrot_str_indexed(interp, sig, i);
-            else
-                return i;
-        }
-        else {
-            Parrot_ex_throw_from_c_args(interp, NULL,
-                            EXCEPTION_JIT_ERROR,
-                            "Unknown param Signature %c\n", (char)c);
-        }
-
-        /*
-         * Parse postfix ops
-         * TODO: Parse postfix ops, currently I skip them.
-         */
-        while (IS_POSTFIX(c)) {
-            i++;
-            if (i < sig_length)
-                c = Parrot_str_indexed(interp, sig, i);
-            else
-                return i;
-        }
-
-        if ((i < sig_length) && (c == (INTVAL)'|')) {
-            /* Its a union, parse it special. */
-        }
-        else {
-            done = 1;
-        }
-    }
-
-    return i;
-}
-
-/*
-
-=item C<static INTVAL parse_prefix(INTVAL c)>
-
-Parse a prefix character.
-
-=cut
-
-*/
-
-static INTVAL
-parse_prefix(INTVAL c) {
-    switch (c) {
-      case '*':
-        return PREFIX_POINTER;
-        break;
-      case 'u':
-        return PREFIX_UNSIGNED;
-        break;
-      default:
-        return 0;
-        break;
-    }
-
-    return 0;
-}
-
-/*
-
-=item C<static size_t parse_structure(PARROT_INTERP, STRING* sig, size_t start,
-                                      size_t sig_length, ffi_type **type_obj, char* pmc_type)>
-
-Parses a stucture.
-TODO: This should auto inflate to an UnmanagedStruct or a ManagedStruct in the future.
-
-=cut
-
-*/
-
-static size_t
-parse_structure(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-                ffi_type **type_obj, char* pmc_type) {
-    size_t i = start;
-    size_t struct_len = structure_length(interp, sig, start, sig_length);
-    size_t element_counter = 0;
-    INTVAL c;
-
-    *type_obj = (ffi_type*)mem_internal_allocate_typed(ffi_type*);
-    (*type_obj)->elements = mem_internal_allocate_n_zeroed_typed(struct_len + 1, ffi_type*);
-
-    (*type_obj)->size = (*type_obj)->alignment = 0;
-    (*type_obj)->type = FFI_TYPE_STRUCT;
-
-    c = Parrot_str_indexed(interp, sig, i);
-    while (i < sig_length && IS_NOT_END_CIRCUMFIX(c)) {
-        i = parse_identifier(interp, sig, i, sig_length,
-                             &(*type_obj)->elements[element_counter],
-                             NULL, 0, NULL, 0);
-        element_counter++;
-        c = Parrot_str_indexed(interp, sig, i);
-    }
-
-    (*type_obj)->elements[struct_len] = NULL;
-
-    return i;
-}
-
-/*
-
-=item C<static size_t structure_length(PARROT_INTERP, STRING* sig,
-                                       size_t start, size_t sig_length)>
-
-Calculates the number of items in a stucture for size purposes.
-
-=cut
-
-*/
-
-static size_t
-structure_length(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length) {
-    size_t len = 0;
-    size_t i = start;
-    INTVAL depth = 0;
-    INTVAL c = Parrot_str_indexed(interp, sig, i);
-    while (i < sig_length && depth != -1) {
-        if (IS_START_CIRCUMFIX(c)) depth++;
-        else if (IS_END_CIRCUMFIX(c)) depth--;
-        else if (depth == 0 && (IS_TYPE(c))) len++;
-        i++;
-        c = Parrot_str_indexed(interp, sig, i);
-    }
-
-    return len;
-}
-
-/*
-
-=item C<static size_t find_matching(PARROT_INTERP, STRING* sig, size_t start,
-                            size_t sig_length, INTVAL start_character, INTVAL end_character)>
-
-Find matching symbols, used for finding the start and stop of a stucture, it is
-also recursive to handle structures inside of structures.
-
-=cut
-
-*/
-
-static size_t
-find_matching(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length,
-              INTVAL start_character, INTVAL end_character) {
-    size_t i = start;
-    INTVAL c = Parrot_str_indexed(interp, sig, i);
-    while (i < sig_length && c != end_character) {
-        if (c == start_character)
-            i = find_matching(interp, sig, i, sig_length, start_character, end_character);
-        i++;
-        c = Parrot_str_indexed(interp, sig, i);
-    }
-
-    return i;
-}
-
-/*
-
-=item C<size_t count_args(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length)>
-
-Counts the number of arguments from a given starting point. It only counts
-identiers, not prefix, infix or postfix modifiers. Structures are considered as
-1 item in most cases.
-
-=cut
-
-*/
-
-static size_t
-count_args(PARROT_INTERP, STRING* sig, size_t start, size_t sig_length) {
-    size_t length = 0;
-    size_t i = start;
-
-    while (i < sig_length) {
-        const INTVAL c = Parrot_str_indexed(interp, sig, i);
-        if (IS_START_CIRCUMFIX(c)) {
-            i = find_matching(interp, sig, i + 1, sig_length, '(', ')');
-            length++;
-        }
-        else if (IS_TYPE(c)) {
-            length++;
-        }
-        i++;
-    }
-
-    return length;
-}
-
 static void
 build_libffi_func(PARROT_INTERP, ARGMOD(Parrot_NCI_attributes *nci))
 {


More information about the parrot-commits mailing list