return STRINGS_SUBSTR_STR;
case STRINGS_STRTOK:
return STRINGS_STRTOK_STR;
+ case STRINGS_TOSTR:
+ return STRINGS_TOSTR_STR;
default:
return "NOT FOUND (STRING)";
}
+ case META_PREFIX:
+ switch(suffix) {
+ case META_UTOB:
+ return META_UTOB_STR;
+ case META_BTOU:
+ return META_BTOU_STR;
+ case META_PARSE:
+ return META_PARSE_STR;
+ case META_GETARGS:
+ return META_GETARGS_STR;
+ case META_GETENV:
+ return META_GETENV_STR;
+ case META_SETENV:
+ return META_SETENV_STR;
+ default: return "NOT FOUND (META)";
+ }
default:
return "NOT FOUND";
}
#include "../parser.h"
#include "meta.h"
+#include <stdlib.h>
+
Sexpr* m_utob(Sexpr* b, Sexpr* rest, Sexpr* env) {
if(META_UTOB_ARGS != u64_get_num_args(b)) {
return cons(b, rest);
sexpr_free(arg);
return cons(from_nil(), rest);
}
- return cons(from_quote(clone(env)), rest);
+ sexpr_free(b);
+ sexpr_free(arg);
+ Sexpr* outpart = cons(from_quote(clone(env)), rest);
+ return outpart;
}
Sexpr* m_setenv(Sexpr* b, Sexpr* rest, Sexpr* env) {
return cons(b, rest);
}
Sexpr* arg = eval(clone(car(b->value.b.args)), env);
- if(arg->type != CONS && cdr(arg)->type != NIL) {
+ if(unquote(arg)->type != CONS && cdr(unquote(arg))->type != NIL) {
ERR(META_SETENV_STR ": ", "not well-formed");
sexpr_free(b);
sexpr_free(arg);
return cons(from_nil(), rest);
}
+ Sexpr* newenvbody = clone(car(unquote(arg)));
+ sexpr_free(car(env));
+ env->value.c->car = newenvbody;
// todo
sexpr_free(b);
sexpr_free(arg);
Sexpr* eval(Sexpr* s, Sexpr* dict) {
/* char* out = sprint_sexpr_builtin(s);
- PRINT(out);
+ PRINTMV("evaling: ", out);
free(out); */
// okay.. important to note,
// this needs to free s
else { // non-nil
char* cdrstr = sprint_sexpr(curr_cell);
currsize += strlen(cdrstr) + 4; // dot, space, close, null-terminator
+ out = realloc(out, currsize);
strcat(out, ". ");
strcat(out, cdrstr);
strcat(out, ")");
else { // non-nil
char* cdrstr = sprint_sexpr_builtin(curr_cell);
currsize += strlen(cdrstr) + 4; // dot, space, close, null-terminator
+ out = realloc(out, currsize);
strcat(out, ". ");
strcat(out, cdrstr);
strcat(out, ")");
run_eval_test("(tostr (cons 43 \"test\"))");
+ run_eval_test("(utob 512)");
+ run_eval_test("(btou +)");
+ run_eval_test("(parse \"(cons 4 5)\")");
+ run_eval_test("(getargs 54)");
+ run_eval_test("(getargs +)");
+ run_eval_test("(getargs (+ 5))");
+
+ run_eval_test("(getenv t)");
+ run_eval_test("(setenv (cons (cons nil nil) nil))");
+
}
void many_asserts() {
}
void isolating_problem() {
+ run_eval_test("(getenv t)");
//run_eval_test("(if t (cons 1 2) (cons 2 1))");
//run_eval_test("((cons 4 5) (cons 2 3))");
- run_eval_test("((quote asdf) 45)");
+ //run_eval_test("((quote asdf) 45)");
//run_eval_test("((cons 4 5) 5)");
//Sexpr* env = init_dict();
//env = load_env(env);