allow methods to be builtins

This commit is contained in:
Bill Currie 2002-05-17 18:35:54 +00:00
parent 97170e97b5
commit b1d1159ae2
3 changed files with 44 additions and 16 deletions

View file

@ -41,12 +41,15 @@ typedef struct param_s {
const char *name;
} param_t;
struct expr_s;
param_t *new_param (const char *selector, type_t *type, const char *name);
param_t *_reverse_params (param_t *params, param_t *next);
param_t *reverse_params (param_t *params);
type_t *parse_params (type_t *type, param_t *params);
void build_scope (function_t *f, def_t *func, param_t *params);
function_t *new_function (void);
void build_builtin_function (def_t *def, struct expr_s *bi_val);
void build_function (function_t *f);
void finish_function (function_t *f);
void emit_function (function_t *f, expr_t *e);

View file

@ -135,6 +135,30 @@ new_function (void)
return f;
}
void
build_builtin_function (def_t *def, expr_t *bi_val)
{
function_t *f;
if (def->type->type != ev_func) {
error (bi_val, "%s is not a function", def->name);
return;
}
if (bi_val->type != ex_integer && bi_val->type != ex_float) {
error (bi_val, "invalid constant for = #");
return;
}
f = new_function ();
f->builtin = bi_val->type == ex_integer ? bi_val->e.integer_val
: (int)bi_val->e.float_val;
f->def = def;
build_function (f);
finish_function (f);
}
void
build_function (function_t *f)
{

View file

@ -372,22 +372,7 @@ var_initializer
}
| '=' '#' const
{
if (current_type->type != ev_func) {
error (0, "%s is not a function", current_def->name);
} else {
if ($3->type != ex_integer && $3->type != ex_float) {
error (0, "invalid constant for = #");
} else {
function_t *f;
f = new_function ();
f->builtin = $3->type == ex_integer
? $3->e.integer_val : (int)$3->e.float_val;
f->def = current_def;
build_function (f);
finish_function (f);
}
}
build_builtin_function (current_def, $3);
}
| '=' opt_state_expr begin_function statement_block end_function
{
@ -1093,6 +1078,14 @@ methoddef
}
finish_function ($6);
}
| '+' methoddecl '=' '#' const ';'
{
$2->instance = 0;
$2 = class_find_method (current_class, $2);
$2->def = method_def (current_class, $2);
build_builtin_function ($2->def, $5);
}
| '-' methoddecl
{
$2->instance = 1;
@ -1114,6 +1107,14 @@ methoddef
}
finish_function ($6);
}
| '-' methoddecl '=' '#' const ';'
{
$2->instance = 0;
$2 = class_find_method (current_class, $2);
$2->def = method_def (current_class, $2);
build_builtin_function ($2->def, $5);
}
;
methodprotolist