blob: 7bed8dea3da73fc29a34102a2d76e0b4946fd19a [file] [log] [blame]
swissChilib3ca4fb2021-04-20 10:33:00 -07001#include "std.h"
swissChilif3e7f182021-04-20 13:57:22 -07002#include <stdlib.h>
swissChilib3ca4fb2021-04-20 10:33:00 -07003
4value_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
12void 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
swissChilif3e7f182021-04-20 13:57:22 -070023 env->first = new;
swissChilib3ca4fb2021-04-20 10:33:00 -070024}
25
26void load_std (struct environment *env)
27{
28 add_function (env, "+", l_plus, 2);
29}