[svn:parrot] r48892 - in branches/oplib_handling_cleanup: include/parrot src src/runcore

plobsing at svn.parrot.org plobsing at svn.parrot.org
Thu Sep 9 21:50:59 UTC 2010


Author: plobsing
Date: Thu Sep  9 21:50:59 2010
New Revision: 48892
URL: https://trac.parrot.org/parrot/changeset/48892

Log:
add interp.op_hash to map op names to op info
will replace hacking core_ops to accomplish the same

Modified:
   branches/oplib_handling_cleanup/include/parrot/hash.h
   branches/oplib_handling_cleanup/include/parrot/interpreter.h
   branches/oplib_handling_cleanup/include/parrot/runcore_api.h
   branches/oplib_handling_cleanup/src/global_setup.c
   branches/oplib_handling_cleanup/src/hash.c
   branches/oplib_handling_cleanup/src/runcore/main.c

Modified: branches/oplib_handling_cleanup/include/parrot/hash.h
==============================================================================
--- branches/oplib_handling_cleanup/include/parrot/hash.h	Thu Sep  9 21:37:38 2010	(r48891)
+++ branches/oplib_handling_cleanup/include/parrot/hash.h	Thu Sep  9 21:50:59 2010	(r48892)
@@ -234,6 +234,14 @@
         __attribute__nonnull__(1);
 
 PARROT_WARN_UNUSED_RESULT
+PARROT_PURE_FUNCTION
+int hash_compare_cstring(SHIM_INTERP,
+    ARGIN(const char *a),
+    ARGIN(const char *b))
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3);
+
+PARROT_WARN_UNUSED_RESULT
 PARROT_CONST_FUNCTION
 int hash_compare_int(SHIM_INTERP,
     ARGIN_NULLOK(const void *a),
@@ -364,6 +372,11 @@
         __attribute__nonnull__(2);
 
 PARROT_WARN_UNUSED_RESULT
+PARROT_PURE_FUNCTION
+size_t key_hash_cstring(SHIM_INTERP, ARGIN(const void *value), size_t seed)
+        __attribute__nonnull__(2);
+
+PARROT_WARN_UNUSED_RESULT
 PARROT_CONST_FUNCTION
 size_t key_hash_int(SHIM_INTERP,
     ARGIN_NULLOK(const void *value),
@@ -485,6 +498,9 @@
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_parrot_new_pointer_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_hash_compare_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(a) \
+    , PARROT_ASSERT_ARG(b))
 #define ASSERT_ARGS_hash_compare_int __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_hash_compare_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
@@ -544,6 +560,8 @@
 #define ASSERT_ARGS_hash_value_to_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(hash))
+#define ASSERT_ARGS_key_hash_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(value))
 #define ASSERT_ARGS_key_hash_int __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_key_hash_PMC __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \

Modified: branches/oplib_handling_cleanup/include/parrot/interpreter.h
==============================================================================
--- branches/oplib_handling_cleanup/include/parrot/interpreter.h	Thu Sep  9 21:37:38 2010	(r48891)
+++ branches/oplib_handling_cleanup/include/parrot/interpreter.h	Thu Sep  9 21:50:59 2010	(r48892)
@@ -216,6 +216,8 @@
     struct PackFile          *initial_pf;     /* first created PF  */
 
     struct _imc_info_t *imc_info;             /* imcc data */
+    Hash               *op_hash;              /* mapping from op names to op_info_t */
+
 
     const char *output_file;                  /* where to write output */
 

Modified: branches/oplib_handling_cleanup/include/parrot/runcore_api.h
==============================================================================
--- branches/oplib_handling_cleanup/include/parrot/runcore_api.h	Thu Sep  9 21:37:38 2010	(r48891)
+++ branches/oplib_handling_cleanup/include/parrot/runcore_api.h	Thu Sep  9 21:50:59 2010	(r48892)
@@ -78,6 +78,10 @@
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
 
+void parrot_hash_oplib(PARROT_INTERP, ARGIN(op_lib_t *lib))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
 void Parrot_runcore_destroy(PARROT_INTERP)
         __attribute__nonnull__(1);
 
@@ -103,6 +107,9 @@
 #define ASSERT_ARGS_Parrot_runcore_switch __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(name))
+#define ASSERT_ARGS_parrot_hash_oplib __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(lib))
 #define ASSERT_ARGS_Parrot_runcore_destroy __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_Parrot_runcore_init __attribute__unused__ int _ASSERT_ARGS_CHECK = (\

Modified: branches/oplib_handling_cleanup/src/global_setup.c
==============================================================================
--- branches/oplib_handling_cleanup/src/global_setup.c	Thu Sep  9 21:37:38 2010	(r48891)
+++ branches/oplib_handling_cleanup/src/global_setup.c	Thu Sep  9 21:50:59 2010	(r48892)
@@ -23,6 +23,7 @@
 
 #define INSIDE_GLOBAL_SETUP
 #include "parrot/parrot.h"
+#include "parrot/oplib/core_ops.h"
 #include "global_setup.str"
 
 /* These functions are defined in the auto-generated file core_pmcs.c */
@@ -217,6 +218,19 @@
 
     create_initial_context(interp);
 
+    /* initialize the ops hash */
+    if (interp->parent_interpreter) {
+        interp->op_hash = interp->parent_interpreter->op_hash;
+    }
+    else {
+        op_lib_t  *core_ops = PARROT_CORE_OPLIB_INIT(interp, 1);
+        interp->op_hash     = parrot_create_hash_sized(interp, enum_type_ptr, Hash_key_type_cstring,
+                                                        (hash_comp_fn)hash_compare_cstring,
+                                                        (hash_hash_key_fn)key_hash_cstring,
+                                                        core_ops->op_count);
+        parrot_hash_oplib(interp, core_ops);
+    }
+
     /* create the namespace root stash */
     interp->root_namespace = Parrot_pmc_new(interp, enum_class_NameSpace);
     Parrot_init_HLL(interp);

Modified: branches/oplib_handling_cleanup/src/hash.c
==============================================================================
--- branches/oplib_handling_cleanup/src/hash.c	Thu Sep  9 21:37:38 2010	(r48891)
+++ branches/oplib_handling_cleanup/src/hash.c	Thu Sep  9 21:50:59 2010	(r48892)
@@ -54,21 +54,6 @@
         __attribute__nonnull__(2);
 
 PARROT_WARN_UNUSED_RESULT
-PARROT_PURE_FUNCTION
-static int hash_compare_cstring(SHIM_INTERP,
-    ARGIN(const char *a),
-    ARGIN(const char *b))
-        __attribute__nonnull__(2)
-        __attribute__nonnull__(3);
-
-PARROT_WARN_UNUSED_RESULT
-PARROT_PURE_FUNCTION
-static size_t key_hash_cstring(SHIM_INTERP,
-    ARGIN(const void *value),
-    size_t seed)
-        __attribute__nonnull__(2);
-
-PARROT_WARN_UNUSED_RESULT
 PARROT_CONST_FUNCTION
 static size_t key_hash_pointer(SHIM_INTERP,
     ARGIN(const void *value),
@@ -97,11 +82,6 @@
 #define ASSERT_ARGS_get_string_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(value))
-#define ASSERT_ARGS_hash_compare_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(a) \
-    , PARROT_ASSERT_ARG(b))
-#define ASSERT_ARGS_key_hash_cstring __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
-       PARROT_ASSERT_ARG(value))
 #define ASSERT_ARGS_key_hash_pointer __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(value))
 #define ASSERT_ARGS_parrot_mark_hash_both __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -238,8 +218,7 @@
 
 /*
 
-=item C<static size_t key_hash_cstring(PARROT_INTERP, const void *value, size_t
-seed)>
+=item C<size_t key_hash_cstring(PARROT_INTERP, const void *value, size_t seed)>
 
 Creates and returns a hash value from a string.
 
@@ -254,7 +233,7 @@
 
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
-static size_t
+size_t
 key_hash_cstring(SHIM_INTERP, ARGIN(const void *value), size_t seed)
 {
     ASSERT_ARGS(key_hash_cstring)
@@ -272,8 +251,7 @@
 
 /*
 
-=item C<static int hash_compare_cstring(PARROT_INTERP, const char *a, const char
-*b)>
+=item C<int hash_compare_cstring(PARROT_INTERP, const char *a, const char *b)>
 
 Compares two C strings for equality, returning -1, 0, and 1 if the first string
 is less than, equal to, or greater than the second, respectively.
@@ -284,7 +262,7 @@
 
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
-static int
+int
 hash_compare_cstring(SHIM_INTERP, ARGIN(const char *a), ARGIN(const char *b))
 {
     ASSERT_ARGS(hash_compare_cstring)

Modified: branches/oplib_handling_cleanup/src/runcore/main.c
==============================================================================
--- branches/oplib_handling_cleanup/src/runcore/main.c	Thu Sep  9 21:37:38 2010	(r48891)
+++ branches/oplib_handling_cleanup/src/runcore/main.c	Thu Sep  9 21:50:59 2010	(r48892)
@@ -390,6 +390,30 @@
 }
 
 
+/*
+
+=item C<void parrot_hash_oplib(PARROT_INTERP, op_lib_t *lib)>
+
+Add the ops in C<lib> to the global name => op_info hash.
+
+=cut
+
+*/
+
+void
+parrot_hash_oplib(PARROT_INTERP, ARGIN(op_lib_t *lib))
+{
+    ASSERT_ARGS(parrot_hash_oplib)
+    int i;
+    for (i = 0; i < lib->op_count; i++) {
+        op_info_t *op = &lib->op_info_table[i];
+        parrot_hash_put(interp, interp->op_hash, (void *)op->full_name, (void *)op);
+        if (!parrot_hash_exists(interp, interp->op_hash, (void *)op->name))
+            parrot_hash_put(interp, interp->op_hash, (void *)op->name, (void *)op);
+    }
+}
+
+
 
 
 /*


More information about the parrot-commits mailing list