if(CORE_CAR_ARGS != u64_get_num_args(b))
return cons(b, rest);
Sexpr* args = b->value.b.args;
- // huh okay, can i ditch the eval now that i'm doing the 'rest' thing?
- return cons(car(eval(car(args), env)), rest);
+ Sexpr* arg = unquote(eval(car(args), env));
+ return cons(from_quote(car(arg)), rest);
}
Sexpr* c_cdr(Sexpr* b, Sexpr* rest, Sexpr* env) {
if(CORE_CDR_ARGS != u64_get_num_args(b))
return cons(b, rest);
Sexpr* args = b->value.b.args;
- // see above
- return cons(cdr(eval(car(args), env)), rest);
+ Sexpr* arg = unquote(eval(car(args), env));
+ return cons(from_quote(cdr(arg)), rest);
}
Sexpr* c_if(Sexpr* b, Sexpr* rest, Sexpr* env) {
if(CORE_IF_ARGS != u64_get_num_args(b))
Sexpr* falsy = car(args);
Sexpr* truthy = car(cdr(args));
Sexpr* cond = car(cdr(cdr(args)));
- if(eval(cond, env)->type != NIL)
+ if(unquote(eval(cond, env))->type != NIL)
return cons(truthy, rest);
else
return cons(falsy, rest);
return cons(b, rest);
Sexpr* args = b->value.b.args;
// yeah eval is kinda necessary for this one I'd say
- Sexpr* lh = eval(car(args), env);
- Sexpr* rh = eval(car(cdr(args)), env);
+ Sexpr* lh = unquote(eval(car(args), env));
+ Sexpr* rh = unquote(eval(car(cdr(args)), env));
+
if(equal(lh, rh)->type == T)
return cons(from_t(), rest);
return cons(from_nil(), rest);
return cons(b, rest);
Sexpr* args = b->value.b.args;
// I guess I would need the eval to check if eventually is nil
- if(eval(car(args), env)->type == NIL)
+ if(unquote(eval(car(args), env))->type == NIL)
return cons(from_t(), rest);
return cons(from_nil(), rest);
}
return s;
}
+
+// wait uh oh, do I do the quote-unquote thing here or in builtins/core?
Sexpr* car(Sexpr* s) {
+ if(s->type == QUOTE)
+ return from_quote(s->value.q->value.c->car);
return s->value.c->car;
}
Sexpr* cdr(Sexpr* s) {
+ if(s->type == QUOTE)
+ return from_quote(s->value.q->value.c->cdr);
return s->value.c->cdr;
}
+Sexpr* unquote(Sexpr* s) {
+ if(s->type ==QUOTE)
+ return s->value.q;
+ return s;
+
+}
+
Sexpr* equal(Sexpr* a, Sexpr* b) {
// need to change later with proper builtins and so forth
if(a->type != b->type)
return out;
}
else if(s->type == BUILTIN) {
- nbytes = snprintf(NULL, 0, "%" PRIu64 "", s->value.u) + 2;
+ nbytes = snprintf(NULL, 0, "%" PRIu64 "", s->value.b.opcode) + 2;
out = malloc(nbytes*sizeof(char));
out[0] = '_';
- snprintf(out + 1, nbytes, "%" PRIu64 "", s->value.u);
+ snprintf(out + 1, nbytes, "%" PRIu64 "", s->value.b.opcode);
return out;
}
else if(s->type == QUOTE) {