From 74b5665fb93d76b2dc9f55b7f6d83e837e5ce9ab Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Sat, 23 Apr 2011 01:36:20 -0400 Subject: [PATCH] use positive values for PARROT_DATA_TYPE Negative values were used to support multi-dispatch. This code smell has been moved closer to the source and will eventually be eliminated. --- include/parrot/datatypes.h | 10 +++++----- src/multidispatch.c | 30 +++++++++++++++--------------- src/pmc.c | 2 +- src/pmc/callcontext.pmc | 8 ++++---- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/parrot/datatypes.h b/include/parrot/datatypes.h index d1b471ed3c..7bca6897e3 100644 --- a/include/parrot/datatypes.h +++ b/include/parrot/datatypes.h @@ -17,13 +17,13 @@ /* &gen_from_enum(datatypes.pasm) subst(s/enum_type_(\w+)/uc("DATATYPE_$1")/e) */ typedef enum { - enum_type_undef, /* illegal */ - enum_first_type = -100, + enum_type_undef = 0, /* illegal */ + enum_first_type = 1, - enum_type_INTVAL = -100, /* parrot types */ + enum_type_INTVAL = 1, /* parrot types */ enum_type_FLOATVAL, enum_type_STRING, - enum_type_PMC, /* actual PMCs have positive class numbers */ + enum_type_PMC, enum_type_char, /* native integer types */ enum_type_short, @@ -62,8 +62,8 @@ typedef enum { enum_type_func_ptr, /* a function pointer */ enum_type_sized, - enum_last_type /* + one */ + enum_last_type /* + one */ } PARROT_DATA_TYPE; /* &end_gen */ diff --git a/src/multidispatch.c b/src/multidispatch.c index 95f75df942..7b31739b9a 100644 --- a/src/multidispatch.c +++ b/src/multidispatch.c @@ -401,13 +401,13 @@ mmd_build_type_tuple_from_type_list(PARROT_INTERP, ARGIN(PMC *type_list)) INTVAL type; if (STRING_equal(interp, type_name, CONST_STRING(interp, "DEFAULT"))) - type = enum_type_PMC; + type = -enum_type_PMC; else if (STRING_equal(interp, type_name, CONST_STRING(interp, "STRING"))) - type = enum_type_STRING; + type = -enum_type_STRING; else if (STRING_equal(interp, type_name, CONST_STRING(interp, "INTVAL"))) - type = enum_type_INTVAL; + type = -enum_type_INTVAL; else if (STRING_equal(interp, type_name, CONST_STRING(interp, "FLOATVAL"))) - type = enum_type_FLOATVAL; + type = -enum_type_FLOATVAL; else type = Parrot_pmc_get_type_str(interp, type_name); @@ -654,25 +654,25 @@ mmd_distance(PARROT_INTERP, ARGIN(PMC *pmc), ARGIN(PMC *arg_tuple)) * weighing other things. A direct autobox should be cheaper than an * autobox plus type conversion or implicit type acceptance. */ switch (type_call) { - case enum_type_INTVAL: + case -enum_type_INTVAL: if (type_sig == enum_class_Integer) { dist++; continue; } - if (type_sig == enum_type_PMC || + if (type_sig == -enum_type_PMC || (type_sig >= enum_class_default && type_sig < enum_class_core_max)) { ++dist; type_call = enum_class_Integer; } break; - case enum_type_FLOATVAL: + case -enum_type_FLOATVAL: if (type_sig == enum_class_Float) { dist++; continue; } - if (type_sig == enum_type_PMC || + if (type_sig == -enum_type_PMC || (type_sig >= enum_class_default && type_sig < enum_class_core_max)) { ++dist; type_call = enum_class_Float; } break; - case enum_type_STRING: + case -enum_type_STRING: if (type_sig == enum_class_String) { dist++; continue; } - if (type_sig == enum_type_PMC || + if (type_sig == -enum_type_PMC || (type_sig >= enum_class_default && type_sig < enum_class_core_max)) { ++dist; type_call = enum_class_String; @@ -686,12 +686,12 @@ mmd_distance(PARROT_INTERP, ARGIN(PMC *pmc), ARGIN(PMC *arg_tuple)) * different native types are very different, except a PMC * which matches any PMC */ - if (type_call <= 0 && type_sig == enum_type_PMC) { + if (type_call <= 0 && type_sig == -enum_type_PMC) { ++dist; continue; } - if ((type_sig <= 0 && type_sig != enum_type_PMC) || type_call <= 0) { + if ((type_sig <= 0 && type_sig != -enum_type_PMC) || type_call <= 0) { dist = MMD_BIG_DISTANCE; break; } @@ -718,7 +718,7 @@ mmd_distance(PARROT_INTERP, ARGIN(PMC *pmc), ARGIN(PMC *arg_tuple)) * if the type wasn't in MRO check, if any PMC matches * in that case use the distance + 1 (of an any PMC parent) */ - if (j == m && type_sig != enum_type_PMC) { + if (j == m && type_sig != -enum_type_PMC) { dist = MMD_BIG_DISTANCE; break; } @@ -729,12 +729,12 @@ mmd_distance(PARROT_INTERP, ARGIN(PMC *pmc), ARGIN(PMC *arg_tuple)) { STRING *s1, *s2; if (type_sig < 0) - s1 = Parrot_dt_get_datatype_name(interp, type_sig); + s1 = Parrot_dt_get_datatype_name(interp, -type_sig); else s1 = interp->vtables[type_sig]->whoami; if (type_call < 0) - s2 = Parrot_dt_get_datatype_name(interp, type_call); + s2 = Parrot_dt_get_datatype_name(interp, -type_call); else s2 = interp->vtables[type_call]->whoami; diff --git a/src/pmc.c b/src/pmc.c index b2f0215f88..1dbe9aae72 100644 --- a/src/pmc.c +++ b/src/pmc.c @@ -786,7 +786,7 @@ Parrot_pmc_get_type_str(PARROT_INTERP, ARGIN_NULLOK(STRING *name)) return VTABLE_get_integer(interp, item); } else - return Parrot_dt_get_datatype_enum(interp, name); + return -Parrot_dt_get_datatype_enum(interp, name); } } diff --git a/src/pmc/callcontext.pmc b/src/pmc/callcontext.pmc index 8d4f9ec4eb..e5dd17b447 100644 --- a/src/pmc/callcontext.pmc +++ b/src/pmc/callcontext.pmc @@ -824,12 +824,12 @@ CallContext. INTVAL type; switch (c[i].type) { - case INTCELL: type = enum_type_INTVAL; break; - case FLOATCELL: type = enum_type_FLOATVAL; break; - case STRINGCELL: type = enum_type_STRING; break; + case INTCELL: type = -enum_type_INTVAL; break; + case FLOATCELL: type = -enum_type_FLOATVAL; break; + case STRINGCELL: type = -enum_type_STRING; break; case PMCCELL: type = PMC_IS_NULL(c[i].u.p) - ? (INTVAL) enum_type_PMC + ? (INTVAL)-enum_type_PMC : VTABLE_type(INTERP, c[i].u.p); break; default: