swissChili | b3ca4fb | 2021-04-20 10:33:00 -0700 | [diff] [blame] | 1 | #include "std.h" |
swissChili | f3e7f18 | 2021-04-20 13:57:22 -0700 | [diff] [blame^] | 2 | #include <stdlib.h> |
swissChili | b3ca4fb | 2021-04-20 10:33:00 -0700 | [diff] [blame] | 3 | |
| 4 | value_t l_plus (value_t a, value_t b) |
| 5 | { |
| 6 | if ( !integerp (a) || !integerp (b) ) |
| 7 | return nil; |
| 8 | |
| 9 | return (((a >> 2) + (b >> 2)) << 2) | INT_TAG; |
| 10 | } |
| 11 | |
| 12 | void add_function (struct environment *env, char *name, void *func, int nargs) |
| 13 | { |
| 14 | struct function *last, |
| 15 | *new = malloc (sizeof (struct function)); |
| 16 | |
| 17 | last = env->first; |
| 18 | new->prev = last; |
| 19 | new->name = name; |
| 20 | new->nargs = nargs; |
| 21 | new->code_ptr = func; |
| 22 | |
swissChili | f3e7f18 | 2021-04-20 13:57:22 -0700 | [diff] [blame^] | 23 | env->first = new; |
swissChili | b3ca4fb | 2021-04-20 10:33:00 -0700 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | void load_std (struct environment *env) |
| 27 | { |
| 28 | add_function (env, "+", l_plus, 2); |
| 29 | } |