better auto-conversion of function parameters (ugh, this is getting messy

:( )
This commit is contained in:
Bill Currie 2004-02-04 04:33:08 +00:00
parent 237027d1ff
commit b2474a2b97
5 changed files with 41 additions and 21 deletions

View file

@ -48,7 +48,7 @@
self = [super initWithBounds:aRect]; self = [super initWithBounds:aRect];
rect = [[Rect alloc] initWithComponents:0 :0 :(integer)strlen (_title) * 8 :8]; rect = [[Rect alloc] initWithComponents:0 :0 :strlen (_title) * 8 :8];
title = [[Text alloc] initWithBounds:rect text:_title]; title = [[Text alloc] initWithBounds:rect text:_title];
rect.origin.x += rect.size.width + 8; rect.origin.x += rect.size.width + 8;

View file

@ -82,7 +82,7 @@ int method_compare (method_t *m1, method_t *m2);
keywordarg_t *new_keywordarg (const char *selector, struct expr_s *expr); keywordarg_t *new_keywordarg (const char *selector, struct expr_s *expr);
keywordarg_t *copy_keywordargs (const keywordarg_t *kwargs); keywordarg_t *copy_keywordargs (const keywordarg_t *kwargs);
struct expr_s *send_message (int super); struct expr_s *send_message (method_t *method, int super);
method_t *find_method (const char *sel_name); method_t *find_method (const char *sel_name);

View file

@ -149,6 +149,7 @@ convert_to_float (expr_t *e)
case ex_def: case ex_def:
case ex_expr: case ex_expr:
case ex_uexpr: case ex_uexpr:
case ex_temp:
return cast_expr (&type_float, e); return cast_expr (&type_float, e);
default: default:
internal_error (e); internal_error (e);
@ -169,7 +170,15 @@ do_op_float (int op, expr_t *e, expr_t *e1, expr_t *e2)
if (!valid_op (op, valid)) if (!valid_op (op, valid))
return error (e1, "invalid operand for float"); return error (e1, "invalid operand for float");
if (op == '=') { if (op == 'b') {
// bind is backwards to assign (why did I do that? :P)
if ((type = get_type (e2)) != &type_float) {
//FIXME optimize casting a constant
e->e.expr.e1 = e1 = cast_expr (type, e1);
} else if ((conv = convert_to_float (e1)) != e1) {
e->e.expr.e1 = e1 = conv;
}
} else if (op == '=' || op == PAS) {
if ((type = get_type (e1)) != &type_float) { if ((type = get_type (e1)) != &type_float) {
//FIXME optimize casting a constant //FIXME optimize casting a constant
e->e.expr.e2 = e2 = cast_expr (type, e2); e->e.expr.e2 = e2 = cast_expr (type, e2);
@ -636,6 +645,7 @@ convert_to_uinteger (expr_t *e)
case ex_def: case ex_def:
case ex_expr: case ex_expr:
case ex_uexpr: case ex_uexpr:
case ex_temp:
return cast_expr (&type_uinteger, e); return cast_expr (&type_uinteger, e);
default: default:
internal_error (e); internal_error (e);
@ -660,7 +670,14 @@ do_op_uinteger (int op, expr_t *e, expr_t *e1, expr_t *e2)
convert_short_uint (e1); convert_short_uint (e1);
if (e1->type == ex_integer) if (e1->type == ex_integer)
convert_int_uint (e1); convert_int_uint (e1);
if (op == '=') { if (op == 'b') {
// bind is backwards to assign (why did I do that? :P)
if ((type = get_type (e2)) != &type_uinteger) {
e->e.expr.e1 = e1 = cast_expr (type, e1);
} else if ((conv = convert_to_uinteger (e1)) != e1) {
e->e.expr.e1 = e1 = conv;
}
} else if (op == '=' || op == PAS) {
if ((type = get_type (e1)) != &type_uinteger) { if ((type = get_type (e1)) != &type_uinteger) {
e->e.expr.e2 = e2 = cast_expr (type, e2); e->e.expr.e2 = e2 = cast_expr (type, e2);
} else if ((conv = convert_to_uinteger (e2)) != e2) { } else if ((conv = convert_to_uinteger (e2)) != e2) {

View file

@ -1780,9 +1780,17 @@ function_expr (expr_t *e1, expr_t *e2)
int arg_expr_count = 0; int arg_expr_count = 0;
expr_t *call; expr_t *call;
expr_t *err = 0; expr_t *err = 0;
const char *func_name = "unknown";
if (e1->type == ex_error) if (e1->type == ex_error)
return e1; return e1;
if (e1->type == ex_def) {
func_name = e1->e.def->name;
} else if (e1->type == ex_uexpr && e1->e.expr.op == 'c') {
e = e1->e.expr.e1;
if (e->type == ex_def)
func_name = e->e.def->name;
}
for (e = e2; e; e = e->next) for (e = e2; e; e = e->next)
convert_name (e); convert_name (e);
for (e = e2; e; e = e->next) { for (e = e2; e; e = e->next) {
@ -1844,10 +1852,6 @@ function_expr (expr_t *e1, expr_t *e2)
type_t *t = get_type (e); type_t *t = get_type (e);
check_initialized (e); check_initialized (e);
if (ftype->parm_types[i] == &type_float && e->type == ex_integer) {
convert_int (e);
t = &type_float;
}
if (i < parm_count) { if (i < parm_count) {
if (e->type == ex_nil) if (e->type == ex_nil)
convert_nil (e, t = ftype->parm_types[i]); convert_nil (e, t = ftype->parm_types[i]);
@ -1859,8 +1863,9 @@ function_expr (expr_t *e1, expr_t *e2)
//print_type (ftype->parm_types[i]); puts (""); //print_type (ftype->parm_types[i]); puts ("");
//print_type (t); puts (""); //print_type (t); puts ("");
err = error (e, "type mismatch for parameter %d of %s", err = error (e, "type mismatch for parameter %d of %s",
i + 1, e1->e.def->name); i + 1, func_name);
} }
t = ftype->parm_types[i];
} else { } else {
if (e->type == ex_nil) if (e->type == ex_nil)
convert_nil (e, t = &type_vector); //XXX largest param size convert_nil (e, t = &type_vector); //XXX largest param size
@ -1877,7 +1882,7 @@ function_expr (expr_t *e1, expr_t *e2)
call = new_block_expr (); call = new_block_expr ();
call->e.block.is_call = 1; call->e.block.is_call = 1;
for (e = e2, i = 0; e; e = e->next, i++) { for (e = e2, i = 0; e; e = e->next, i++) {
if (has_function_call (e)) { if (has_function_call (e) || arg_types[i] != get_type (e)) {
*a = new_temp_def_expr (arg_types[i]); *a = new_temp_def_expr (arg_types[i]);
arg_exprs[arg_expr_count][0] = e; arg_exprs[arg_expr_count][0] = e;
arg_exprs[arg_expr_count][1] = *a; arg_exprs[arg_expr_count][1] = *a;
@ -2527,7 +2532,7 @@ super_expr (class_type_t *class_type)
binary_expr ('.', e, new_name_expr ("super_class"))); binary_expr ('.', e, new_name_expr ("super_class")));
append_expr (super_block, e); append_expr (super_block, e);
e = address_expr (super, 0, 0); e = address_expr (super, 0, type_id.aux_type);
super_block->e.block.result = e; super_block->e.block.result = e;
return super_block; return super_block;
} }
@ -2590,7 +2595,7 @@ message_expr (expr_t *receiver, keywordarg_t *message)
if ((err = method_check_params (method, args))) if ((err = method_check_params (method, args)))
return err; return err;
} }
call = function_expr (send_message (super), args); call = function_expr (send_message (method, super), args);
if (call->type == ex_error) if (call->type == ex_error)
return receiver; return receiver;

View file

@ -230,14 +230,16 @@ copy_keywordargs (const keywordarg_t *kwargs)
} }
expr_t * expr_t *
send_message (int super) send_message (method_t *method, int super)
{ {
expr_t *def;
if (super) if (super)
return new_def_expr (get_def (&type_supermsg, "obj_msgSend_super", def = new_def_expr (get_def (&type_supermsg, "obj_msgSend_super",
pr.scope, st_extern)); pr.scope, st_extern));
else else
return new_def_expr (get_def (&type_IMP, "obj_msgSend", pr.scope, def = new_def_expr (get_def (&type_IMP, "obj_msgSend", pr.scope,
st_extern)); st_extern));
return cast_expr (method->type, def);
} }
method_t * method_t *
@ -468,10 +470,6 @@ method_check_params (method_t *method, expr_t *args)
if (!t) if (!t)
return e; return e;
if (mtype->parm_types[i] == &type_float && e->type == ex_integer) {
convert_int (e);
t = &type_float;
}
if (i < parm_count) { if (i < parm_count) {
if (e->type != ex_nil) if (e->type != ex_nil)
if (!type_assignable (mtype->parm_types[i], t)) { if (!type_assignable (mtype->parm_types[i], t)) {