Skip to content

Commit

Permalink
use positive values for PARROT_DATA_TYPE
Browse files Browse the repository at this point in the history
Negative values were used to support multi-dispatch. This code smell has been
moved closer to the source and will eventually be eliminated.
  • Loading branch information
plobsing committed Apr 23, 2011
1 parent 6c38adc commit 74b5665
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
10 changes: 5 additions & 5 deletions include/parrot/datatypes.h
Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down
30 changes: 15 additions & 15 deletions src/multidispatch.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/pmc.c
Expand Up @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/pmc/callcontext.pmc
Expand Up @@ -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:
Expand Down

0 comments on commit 74b5665

Please sign in to comment.