sexpr_free(b);
return ret;
}
-Sexpr* c_if(Sexpr* b, Sexpr* rest, Sexpr* env) {
- if(CORE_IF_ARGS != u64_get_num_args(b))
- return cons(b, rest);
- Sexpr* args = b->value.b.args;
-
- Sexpr* cond = eval(clone(car(cdr(cdr(args)))), env);
- if(unquote(cond)->type != NIL) {
- Sexpr* truthy = clone(car(cdr(args)));
- sexpr_free(cond);
- sexpr_free(b);
- return cons(truthy, rest);
- }
- else {
- Sexpr* falsy = clone(car(args));
- sexpr_free(cond);
- sexpr_free(b);
- return cons(falsy, rest);
- }
-}
Sexpr* c_eq(Sexpr* b, Sexpr* rest, Sexpr* env) {
if(CORE_EQ_ARGS != u64_get_num_args(b))
return cons(b, rest);
return c_car(b, rest, env);
case CORE_CDR:
return c_cdr(b, rest, env);
- case CORE_IF:
- return c_if(b, rest, env);
case CORE_EQ:
return c_eq(b, rest, env);
case CORE_NOT:
load_builtin(CORE_CONS_STR, (CORE_PREFIX << 8) | CORE_CONS, env);
load_builtin(CORE_CAR_STR, (CORE_PREFIX << 8) | CORE_CAR, env);
load_builtin(CORE_CDR_STR, (CORE_PREFIX << 8) | CORE_CDR, env);
- load_builtin(CORE_IF_STR, (CORE_PREFIX << 8) | CORE_IF, env);
load_builtin(CORE_EQ_STR, (CORE_PREFIX << 8) | CORE_EQ, env);
load_builtin(CORE_NOT_STR, (CORE_PREFIX << 8) | CORE_NOT, env);
load_builtin(CORE_ATOM_STR, (CORE_PREFIX << 8) | CORE_ATOM, env);
#define CORE_CDR 0x03
#define CORE_CDR_ARGS 1
#define CORE_CDR_STR "cdr"
-#define CORE_IF 0x04
-#define CORE_IF_ARGS 3
-#define CORE_IF_STR "if"
-#define CORE_EQ 0x05
+#define CORE_EQ 0x04
#define CORE_EQ_ARGS 2
#define CORE_EQ_STR "eq"
-#define CORE_NOT 0x06
+#define CORE_NOT 0x05
#define CORE_NOT_ARGS 1
#define CORE_NOT_STR "not"
-#define CORE_ATOM 0x07
+#define CORE_ATOM 0x06
#define CORE_ATOM_ARGS 1
#define CORE_ATOM_STR "atom"
-#define CORE_REST 0x08
+#define CORE_REST 0x07
#define CORE_REST_ARGS 2
#define CORE_REST_STR "rest"
-#define CORE_UNQUOTE 0x09
+#define CORE_UNQUOTE 0x08
#define CORE_UNQUOTE_ARGS 1
#define CORE_UNQUOTE_STR "unquote"
-#define CORE_APPLYN 0x0a
+#define CORE_APPLYN 0x09
#define CORE_APPLYN_ARGS 3
#define CORE_APPLYN_STR "applyn"