(def C3 (C* (B C2)))
(def Cn (Z (B (S (C (eq 0) C)) (B (B (B C)) (B D (C B (C - 1)))))))
+
+(def C?n (Z (B (S (C (eq 0) C)) (B (S (R B (B C))) (C B (C - 1))))))
\ No newline at end of file
+(def printthen (D (D evalarg (K I) print)))
+
(def range (abstract-rec (eq 0) (C cons) (C - 1) nil))
(def x-times-n (C (C (D abstract-rec (eq 0) (D B K cons)) (C - 1)) nil))
if(func->type != BUILTIN) {
return dispatch_others(func, rest, env);
}
+ // should i find a nice way to move these next few lines to its own function in sexpr.c?
Sexpr* ret = malloc(sizeof(Sexpr));
ret->type = BUILTIN;
ret->value.b.opcode = func->value.b.opcode;
ret->value.b.args = cons(clone(car(rest)), clone(func->value.b.args));
+ ret->refcount = 1;
Sexpr* cdrrest = clone(cdr(rest));
sexpr_free(rest);
return dispatch(ret, cdrrest, env);
Sexpr* ret = malloc(sizeof(Sexpr));
ret->type = NIL;
ret->value.n = NULL;
+ ret->refcount = 1;
return ret;
}
Sexpr* ret = malloc(sizeof(Sexpr));
ret->type = T;
ret->value.t = NULL;
+ ret->refcount = 1;
return ret;
}
Sexpr* ret = malloc(sizeof(Sexpr));
ret->type = SYM;
ret->value.s = strdup(s);
+ ret->refcount = 1;
return ret;
}
Sexpr* ret = malloc(sizeof(Sexpr));
ret->type = STR;
ret->value.str = strdup(s);
+ ret->refcount = 1;
return ret;
}
Sexpr* ret = malloc(sizeof(Sexpr));
ret->type = UINT;
ret->value.u = u;
+ ret->refcount = 1;
return ret;
}
ret->type = BUILTIN;
ret->value.b.opcode = u;
ret->value.b.args = from_nil();
+ ret->refcount = 1;
return ret;
}
Sexpr* ret = malloc(sizeof(Sexpr));
ret->type = QUOTE;
ret->value.q = s;
+ ret->refcount = 1;
return ret;
}
Sexpr* ret = malloc(sizeof(Sexpr));
ret->type = PTR;
ret->value.p = p;
+ ret->refcount = 1;
return ret;
}
c->cdr = cdr;
s->type = CONS;
s->value.c = c;
+ s->refcount = 1;
return s;
}
}
void sexpr_free(Sexpr* s) {
+ if(s->refcount > 1) {
+ s->refcount--;
+ return;
+ }
if(s->type == CONS) {
sexpr_free(car(s));
sexpr_free(cdr(s));
}
Sexpr* clone(Sexpr* s) {
+ s->refcount++;
+ return s;
+ /*
Sexpr* ret;
switch(s->type) {
case UINT:
break;
}
return ret;
+ */
}
typedef struct Sexpr {
Sexpr_Type type;
+ size_t refcount;
union {
K_UINT_TYPE u;
char* str;