#include <inttypes.h>
#include <stdlib.h>
-#include <stdio.h>
Sexpr* c_i(Sexpr* b, Sexpr* rest, Sexpr* env) {
if(COMB_I_ARGS != u64_get_num_args(b)) {
return cons(x, rest);
}
+Sexpr* c_b(Sexpr* b, Sexpr* rest, Sexpr* env) {
+ if(COMB_B_ARGS != u64_get_num_args(b)) {
+ return cons(b, rest);
+ }
+ Sexpr* args = b->value.b.args;
+ Sexpr* x = clone(car(cdr(cdr(args))));
+ Sexpr* y = clone(car(cdr(args)));
+ Sexpr* z = clone(car(args));
+ sexpr_free(b);
+
+ Sexpr* ret = cons(x, cons(cons(y, cons(z, from_nil())), rest));
+ return ret;
+}
+
+Sexpr* c_c(Sexpr* b, Sexpr* rest, Sexpr* env) {
+ if(COMB_C_ARGS != u64_get_num_args(b)) {
+ return cons(b, rest);
+ }
+ Sexpr* args = b->value.b.args;
+ Sexpr* x = clone(car(cdr(cdr(args))));
+ Sexpr* y = clone(car(cdr(args)));
+ Sexpr* z = clone(car(args));
+ sexpr_free(b);
+
+ Sexpr* ret = cons(x, cons(z, cons(y, rest)));
+ return ret;
+}
+
+Sexpr* c_w(Sexpr* b, Sexpr* rest, Sexpr* env) {
+ if(COMB_W_ARGS != u64_get_num_args(b)) {
+ return cons(b, rest);
+ }
+ Sexpr* args = b->value.b.args;
+ Sexpr* x = clone(car(cdr(args)));
+ Sexpr* y = clone(car(args));
+ Sexpr* y2 = clone(y);
+ sexpr_free(b);
+ Sexpr* ret = cons(x, cons(y, cons(y2, rest)));
+ return ret;
+}
+
Sexpr* x_comb_dispatch(Sexpr* b, Sexpr* rest, Sexpr* env) {
uint64_t code = b->value.b.opcode & 0xff;
return c_s(b, rest, env);
case COMB_K:
return c_k(b, rest, env);
+ case COMB_B:
+ return c_b(b, rest, env);
+ case COMB_C:
+ return c_c(b, rest, env);
+ case COMB_W:
+ return c_w(b, rest, env);
default:
return from_nil();
}
append_to_dict(env, k, v);
sexpr_free(v);
sexpr_free(k);
-
+
+ k = from_sym("B");
+ v = from_opcode((COMB_PREFIX << 8) | COMB_B);
+ append_to_dict(env, k, v);
+ sexpr_free(v);
+ sexpr_free(k);
+
+ k = from_sym("C");
+ v = from_opcode((COMB_PREFIX << 8) | COMB_C);
+ append_to_dict(env, k, v);
+ sexpr_free(v);
+ sexpr_free(k);
+
+ k = from_sym("W");
+ v = from_opcode((COMB_PREFIX << 8) | COMB_W);
+ append_to_dict(env, k, v);
+ sexpr_free(v);
+ sexpr_free(k);
+
return env;
}