commit a253fe487b61b0f734d8e4d38fcbbcbe2afd7f76
parent a29d9e01a68ebf4bfa8dd66452358cb3610ee46d
Author: sin <sin@2f30.org>
Date: Fri, 16 May 2014 11:46:41 +0100
Add null predicate
Diffstat:
1 file changed, 22 insertions(+), 0 deletions(-)
diff --git a/parser.c b/parser.c
@@ -75,6 +75,7 @@ static struct object *evalset(struct object *);
/* primitive procedures */
static struct object *evalboolean(struct object *);
static struct object *evaldiff(struct object *);
+static struct object *evalnull(struct object *);
static struct object *evalplus(struct object *);
struct {
@@ -96,6 +97,7 @@ struct {
} procs[] = {
{ .name = "boolean", .fn = evalboolean },
{ .name = "diff", .fn = evaldiff },
+ { .name = "null", .fn = evalnull },
{ .name = "plus", .fn = evalplus },
};
@@ -465,6 +467,26 @@ evaldiff(struct object *o)
}
static struct object *
+evalnull(struct object *o)
+{
+ struct object *arg;
+
+ if (o->type != OPair)
+ return NULL;
+ if (car(o)->type != OIdentifier ||
+ strcmp(car(o)->d.i.s, "null") != 0)
+ return NULL;
+ arg = eval(cadr(o));
+ if (arg->type == OError)
+ return arg;
+ if (caddr(o))
+ return error("multiple arguments");
+ if (arg->type == OEmptylist)
+ return boolean(true);
+ return boolean(false);
+}
+
+static struct object *
doplus(struct object *o, struct object *n)
{
struct object *otmp;