[svn:parrot] r49276 - in trunk: compilers/imcc docs include/parrot src src/pmc
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Thu Sep 23 20:23:21 UTC 2010
Author: plobsing
Date: Thu Sep 23 20:23:19 2010
New Revision: 49276
URL: https://trac.parrot.org/parrot/changeset/49276
Log:
separate different types of PackFile_ConstTable_rlookup
Modified:
trunk/compilers/imcc/pbc.c
trunk/docs/embed.pod
trunk/include/parrot/packfile.h
trunk/src/packdump.c
trunk/src/packout.c
trunk/src/pmc/imageiofreeze.pmc
trunk/src/pmc/imageiosize.pmc
Modified: trunk/compilers/imcc/pbc.c
==============================================================================
--- trunk/compilers/imcc/pbc.c Thu Sep 23 12:39:55 2010 (r49275)
+++ trunk/compilers/imcc/pbc.c Thu Sep 23 20:23:19 2010 (r49276)
@@ -1049,9 +1049,8 @@
{
ASSERT_ARGS(add_const_str)
- PMC *s_pmc = key_new_string(interp, s);
PackFile_ConstTable *ct = interp->code->const_table;
- int i = PackFile_ConstTable_rlookup(interp, ct, s_pmc, PFC_STRING);
+ int i = PackFile_ConstTable_rlookup_str(interp, ct, s);
if (i >= 0)
return i;
Modified: trunk/docs/embed.pod
==============================================================================
--- trunk/docs/embed.pod Thu Sep 23 12:39:55 2010 (r49275)
+++ trunk/docs/embed.pod Thu Sep 23 20:23:19 2010 (r49276)
@@ -529,8 +529,6 @@
=item C<PackFile_destroy>
-=item C<PackFile_find_in_const>
-
=item C<PackFile_fixup_subs>
=item C<PackFile_new>
Modified: trunk/include/parrot/packfile.h
==============================================================================
--- trunk/include/parrot/packfile.h Thu Sep 23 12:39:55 2010 (r49275)
+++ trunk/include/parrot/packfile.h Thu Sep 23 20:23:19 2010 (r49276)
@@ -402,19 +402,16 @@
__attribute__nonnull__(2);
PARROT_EXPORT
-int PackFile_ConstTable_rlookup(PARROT_INTERP,
+int PackFile_ConstTable_rlookup_num(PARROT_INTERP,
ARGIN(const PackFile_ConstTable *ct),
- ARGIN(PMC *key),
- int type)
+ FLOATVAL n)
__attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(3);
+ __attribute__nonnull__(2);
PARROT_EXPORT
-int PackFile_find_in_const(PARROT_INTERP,
+int PackFile_ConstTable_rlookup_str(PARROT_INTERP,
ARGIN(const PackFile_ConstTable *ct),
- ARGIN(PMC *key),
- int type)
+ ARGIN(STRING *s))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
@@ -442,14 +439,15 @@
#define ASSERT_ARGS_PackFile_ConstTable_pack_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(seg))
-#define ASSERT_ARGS_PackFile_ConstTable_rlookup __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+#define ASSERT_ARGS_PackFile_ConstTable_rlookup_num \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(ct) \
- , PARROT_ASSERT_ARG(key))
-#define ASSERT_ARGS_PackFile_find_in_const __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ , PARROT_ASSERT_ARG(ct))
+#define ASSERT_ARGS_PackFile_ConstTable_rlookup_str \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(ct) \
- , PARROT_ASSERT_ARG(key))
+ , PARROT_ASSERT_ARG(s))
#define ASSERT_ARGS_PackFile_pack __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(self) \
Modified: trunk/src/packdump.c
==============================================================================
--- trunk/src/packdump.c Thu Sep 23 12:39:55 2010 (r49275)
+++ trunk/src/packdump.c Thu Sep 23 20:23:19 2010 (r49276)
@@ -244,27 +244,33 @@
case KEY_number_FLAG:
{
size_t ct_index;
+ FLOATVAL n;
+ GETATTR_Key_num_key(interp, key, n);
Parrot_io_printf(interp, " TYPE => NUMBER\n");
- ct_index = PackFile_find_in_const(interp, ct, key, PFC_NUMBER);
+ ct_index = PackFile_ConstTable_rlookup_num(interp, ct, n);
Parrot_io_printf(interp, " PFC_OFFSET => %ld\n", ct_index);
Parrot_io_printf(interp, " DATA => %ld\n",
ct->num.constants[ct_index]);
Parrot_io_printf(interp, " },\n");
}
break;
+
case KEY_string_FLAG:
{
size_t ct_index;
+ STRING *s;
+ GETATTR_Key_str_key(interp, key, s);
Parrot_io_printf(interp, " TYPE => STRING\n");
- ct_index = PackFile_find_in_const(interp, ct, key, PFC_STRING);
+ ct_index = PackFile_ConstTable_rlookup_str(interp, ct, s);
Parrot_io_printf(interp, " PFC_OFFSET => %ld\n", ct_index);
Parrot_io_printf(interp, " DATA => '%Ss'\n",
ct->str.constants[ct_index]);
Parrot_io_printf(interp, " },\n");
}
break;
+
case KEY_integer_FLAG | KEY_register_FLAG:
Parrot_io_printf(interp, " TYPE => I REGISTER\n");
Parrot_io_printf(interp, " DATA => %ld\n",
Modified: trunk/src/packout.c
==============================================================================
--- trunk/src/packout.c Thu Sep 23 12:39:55 2010 (r49275)
+++ trunk/src/packout.c Thu Sep 23 20:23:19 2010 (r49276)
@@ -262,11 +262,13 @@
/*
-=item C<int PackFile_find_in_const(PARROT_INTERP, const PackFile_ConstTable *ct,
-PMC *key, int type)>
+=item C<int PackFile_ConstTable_rlookup_num(PARROT_INTERP, const
+PackFile_ConstTable *ct, FLOATVAL n)>
-This is really ugly, we don't know where our C<PARROT_ARG_SC> key
-constant is in constant table, so we have to search for it.
+=item C<int PackFile_ConstTable_rlookup_str(PARROT_INTERP, const
+PackFile_ConstTable *ct, STRING *s)>
+
+Reverse lookup a constant in the constant table.
=cut
@@ -274,50 +276,31 @@
PARROT_EXPORT
int
-PackFile_find_in_const(PARROT_INTERP,
- ARGIN(const PackFile_ConstTable *ct), ARGIN(PMC *key), int type)
+PackFile_ConstTable_rlookup_num(PARROT_INTERP,
+ ARGIN(const PackFile_ConstTable *ct), FLOATVAL n)
{
- ASSERT_ARGS(PackFile_find_in_const)
- int i = PackFile_ConstTable_rlookup(interp, ct, key, type);
+ ASSERT_ARGS(PackFile_ConstTable_rlookup_num)
+ int i;
- if (i < 0) {
- Parrot_io_eprintf(NULL, "find_in_const: couldn't find const for key\n");
- Parrot_exit(interp, 1);
+ for (i = 0; i < ct->num.const_count; i++) {
+ if (ct->num.constants[i] == n)
+ return i;
}
- return i;
+ /* not found */
+ return -1;
}
-/*
-
-=item C<int PackFile_ConstTable_rlookup(PARROT_INTERP, const PackFile_ConstTable
-*ct, PMC *key, int type)>
-
-Reverse lookup a constant in the constant table.
-
-=cut
-
-*/
-
PARROT_EXPORT
int
-PackFile_ConstTable_rlookup(PARROT_INTERP,
- ARGIN(const PackFile_ConstTable *ct), ARGIN(PMC *key), int type)
+PackFile_ConstTable_rlookup_str(PARROT_INTERP,
+ ARGIN(const PackFile_ConstTable *ct), ARGIN(STRING *s))
{
- ASSERT_ARGS(PackFile_ConstTable_rlookup)
- int i, strings;
- FLOATVAL key_num;
- STRING *key_str;
- PMC *string_list;
-
- PARROT_ASSERT(type == PFC_STRING || type == PFC_NUMBER);
-
- GETATTR_Key_str_key(interp, key, key_str);
- GETATTR_Key_num_key(interp, key, key_num);
-
- if (type == PFC_STRING && ct->string_hash) {
- HashBucket *bucket = parrot_hash_get_bucket(interp, ct->string_hash,
- key_str);
+ ASSERT_ARGS(PackFile_ConstTable_rlookup_str)
+ int i;
+
+ if (ct->string_hash) {
+ HashBucket *bucket = parrot_hash_get_bucket(interp, ct->string_hash, s);
if (bucket) {
i = (int)PTR2INTVAL(bucket->value);
return i;
@@ -325,27 +308,12 @@
return -1;
}
- switch (type) {
- case PFC_STRING:
- for (i = 0; i < ct->str.const_count; i++) {
- STRING *sc = ct->str.constants[i];
- if (Parrot_str_equal(interp, key_str, sc)
- && key_str->encoding == sc->encoding) {
- return i;
- }
- }
- break;
-
- case PFC_NUMBER:
- for (i = 0; i < ct->num.const_count; i++) {
- if (ct->num.constants[i] == key_num)
- return i;
+ for (i = 0; i < ct->str.const_count; i++) {
+ STRING *sc = ct->str.constants[i];
+ if (Parrot_str_equal(interp, s, sc)
+ && s->encoding == sc->encoding) {
+ return i;
}
- break;
-
-
- default:
- PANIC(interp, "Universe imploded. Did you divide by zero?");
}
/* not found */
@@ -394,14 +362,25 @@
GETATTR_Key_int_key(interp, key, *cursor++);
break;
case KEY_number_FLAG:
- *cursor++ = PARROT_ARG_NC;
- /* Argh */
- *cursor++ = PackFile_find_in_const(interp, const_table, key, PFC_NUMBER);
+ {
+ FLOATVAL n;
+ GETATTR_Key_num_key(interp, key, n);
+ *cursor++ = PARROT_ARG_NC;
+ /* Argh */
+ *cursor++ = PackFile_ConstTable_rlookup_num(interp, const_table, n);
+ PARROT_ASSERT(cursor[-1] > 0);
+ }
break;
+
case KEY_string_FLAG:
- *cursor++ = PARROT_ARG_SC;
- /* Argh */
- *cursor++ = PackFile_find_in_const(interp, const_table, key, PFC_STRING);
+ {
+ STRING *s;
+ GETATTR_Key_str_key(interp, key, s);
+ *cursor++ = PARROT_ARG_SC;
+ /* Argh */
+ *cursor++ = PackFile_ConstTable_rlookup_str(interp, const_table, s);
+ PARROT_ASSERT(cursor[-1] > 0);
+ }
break;
case KEY_integer_FLAG | KEY_register_FLAG:
Modified: trunk/src/pmc/imageiofreeze.pmc
==============================================================================
--- trunk/src/pmc/imageiofreeze.pmc Thu Sep 23 12:39:55 2010 (r49275)
+++ trunk/src/pmc/imageiofreeze.pmc Thu Sep 23 20:23:19 2010 (r49276)
@@ -381,10 +381,9 @@
VTABLE void push_string(STRING *v) {
if (PObj_flag_TEST(private1, SELF)) {
/* store a reference to constant table entry of string */
- PMC * const v_pmc = key_new_string(interp, v);
PackFile_ConstTable * const table = PARROT_IMAGEIOFREEZE(SELF)->pf_ct;
const int idx =
- PackFile_ConstTable_rlookup(INTERP, table, v_pmc, PFC_STRING);
+ PackFile_ConstTable_rlookup_str(INTERP, table, v);
if (idx >= 0) {
STATICSELF.push_integer(idx);
Modified: trunk/src/pmc/imageiosize.pmc
==============================================================================
--- trunk/src/pmc/imageiosize.pmc Thu Sep 23 12:39:55 2010 (r49275)
+++ trunk/src/pmc/imageiosize.pmc Thu Sep 23 20:23:19 2010 (r49276)
@@ -204,7 +204,7 @@
/* store a reference to constant table entry of string */
PMC *v_pmc = key_new_string(interp, v);
PackFile_ConstTable *table = PARROT_IMAGEIOSIZE(SELF)->pf_ct;
- int idx = PackFile_ConstTable_rlookup(INTERP, table, v_pmc, PFC_STRING);
+ int idx = PackFile_ConstTable_rlookup_str(INTERP, table, v);
if (idx >= 0) {
STATICSELF.push_integer(idx);
More information about the parrot-commits
mailing list