diff --git a/pcalc.y b/pcalc.y index 33274ae..4c05ad4 100644 --- a/pcalc.y +++ b/pcalc.y @@ -96,10 +96,10 @@ list: ; -junk: IBUILTIN str { (*($1->u.iptr))($2->u.str) ; } +junk: IBUILTIN str { (*($1->u.iptr.func_str))($2->u.str) ; } | IBUILTIN { } - | IBUILTIN VAR { (*($1->u.iptr))($2->u.val) ; } - | IBUILTIN expr { (*($1->u.iptr))($2) ; } + | IBUILTIN VAR { (*($1->u.iptr.func_dbl))($2->u.val) ; } + | IBUILTIN expr { (*($1->u.iptr.func_dbl))($2) ; } | STR { printf("%s", $1->name);} | STRVAR { printf("%s", $1->u.str);} ; diff --git a/symbol.c b/symbol.c index 6f367fc..335ca23 100644 --- a/symbol.c +++ b/symbol.c @@ -34,7 +34,7 @@ CONSTS consts[] = typedef struct { char *name ; - long double (*func)(); + long double (*func)(long double); } BUILTINS; @@ -80,7 +80,7 @@ BUILTINS builtins[] = typedef struct { char *name ; - int (*ifunc)() ; + IFUNC_UNION ifunc ; } IBUILTINS; @@ -88,21 +88,20 @@ IBUILTINS ibuiltins[] = { - {"date", ddate}, - {"print", print}, - {"echo", echo}, - {"_echo", echo_nl}, + {"date", {ddate}}, + {"print", {.func_dbl = print}}, + {"echo", {echo}}, + {"_echo", {echo_nl}}, - {"DATE", ddate}, - {"PRINT", print}, - {"ECHO", echo}, - {"_ECHO", echo_nl}, + {"DATE", {ddate}}, + {"PRINT", {.func_dbl = print}}, + {"ECHO", {echo}}, + {"_ECHO", {echo_nl}}, - {NULL, (void *) 0} + {NULL, (void *) 0} } ; - void init_sym(void) { diff --git a/symbol.h b/symbol.h index aa2382e..0158f65 100644 --- a/symbol.h +++ b/symbol.h @@ -3,6 +3,12 @@ /* -------- Macros: ------------------------------------------------------ */ +typedef union +{ + int (*func_str)(const char*); + int (*func_dbl)(long double); +} IFUNC_UNION; + typedef struct Symbol { /* symbol table entry */ char *name ; short type ; /* VAR, BLTIN, UNDEF */ @@ -13,8 +19,8 @@ typedef struct Symbol { /* symbol table entry */ int ival; /* if VAR */ long long lval; /* if VAR */ long double val; /* if VAR */ - long double (*ptr)(); /* if BUILTIN */ - int (*iptr)(); /* if IBUILTIN */ + long double (*ptr)(long double); /* if BUILTIN */ + IFUNC_UNION iptr; /* if IBUILTIN */ } u ; struct Symbol *next ; } Symbol ;