From: Elijah Cohen Date: Fri, 22 Nov 2024 22:52:28 +0000 (-0600) Subject: bug fixins, mostly. nothing major X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=e3810045c3012afb15d243289f59024229dcaf2e;p=klapaucius bug fixins, mostly. nothing major --- diff --git a/demos.kl b/demos.kl index 941e2a7..b724c21 100644 --- a/demos.kl +++ b/demos.kl @@ -14,11 +14,11 @@ (def U (L O)) (def F (E T T E T)) -(def and (B W (B C) I)) -(def or (S I I)) -(def not (B C (C I) nil t)) -(def xor (C (C Phi not) I)) -(def zerop (B C (C I) (t nil) t)) +(def church-and (B W (B C) I)) +(def church-or (S I I)) +(def church-not (B C (C I) nil t)) +(def church-xor (C (C Phi not) I)) +(def church-zerop (B C (C I) (t nil) t)) (def fac (Z (D S (C (eq 0) 1) (D S * (C B (C - 1)))))) diff --git a/src/builtins.c b/src/builtins.c index fe91838..8f580ae 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -215,6 +215,23 @@ char* lookup_builtin(Sexpr* b) { default: return "NOT FOUND (IO)"; } + case STRINGS_PREFIX: + switch(suffix) { + case STRINGS_STRLEN: + return STRINGS_STRLEN_STR; + case STRINGS_STRCAT: + return STRINGS_STRCAT_STR; + case STRINGS_STRAT: + return STRINGS_STRAT_STR; + case STRINGS_STREXPAND: + return STRINGS_STREXPAND_STR; + case STRINGS_SUBSTR: + return STRINGS_SUBSTR_STR; + case STRINGS_STRTOK: + return STRINGS_STRTOK_STR; + default: + return "NOT FOUND (STRING)"; + } default: return "NOT FOUND"; } diff --git a/src/builtins/io.c b/src/builtins/io.c index 8da2589..ef3f83d 100644 --- a/src/builtins/io.c +++ b/src/builtins/io.c @@ -14,7 +14,7 @@ Sexpr* io_print(Sexpr* b, Sexpr* rest, Sexpr* env) { if(IO_PRINT_ARGS != u64_get_num_args(b)) { return cons(b, rest); } - Sexpr* arg = clone(car(b->value.b.args)); + Sexpr* arg = eval(clone(car(b->value.b.args)), env); sexpr_free(b); char* out = sprint_sexpr(arg); sexpr_free(arg); diff --git a/src/builtins/strings.c b/src/builtins/strings.c index a99e546..09a1d04 100644 --- a/src/builtins/strings.c +++ b/src/builtins/strings.c @@ -15,7 +15,7 @@ Sexpr* s_strlen(Sexpr* b, Sexpr* rest, Sexpr* env) { if(STRINGS_STRLEN_ARGS != u64_get_num_args(b)) { return cons(b, rest); } - Sexpr* arg = car(b->value.b.args); + Sexpr* arg = eval(clone(car(b->value.b.args)), env); #ifdef TYPECHECK if(unquote(arg)->type != STR) { ERR("strlen: ", "argument not string"); @@ -23,7 +23,7 @@ Sexpr* s_strlen(Sexpr* b, Sexpr* rest, Sexpr* env) { return cons(from_nil(), rest); } #endif // typecheck - size_t sl = strlen(arg->value.str); + size_t sl = strlen(unquote(arg)->value.str); sexpr_free(b); return cons (from_uint(sl), rest); } @@ -36,7 +36,7 @@ Sexpr* s_strcat(Sexpr* b, Sexpr* rest, Sexpr* env) { Sexpr* snd = eval(clone(car(args)), env); Sexpr* fst = eval(clone(car(cdr(args))), env); #ifdef TYPECHECK - if(snd->type != STR || fst->type != STR) { + if(unquote(snd)->type != STR || unquote(fst)->type != STR) { ERR("strcat: ", "arguments not string"); sexpr_free(snd); sexpr_free(fst); @@ -44,8 +44,8 @@ Sexpr* s_strcat(Sexpr* b, Sexpr* rest, Sexpr* env) { return cons(from_nil(), rest); } #endif // typecheck - char* fs = fst->value.str; - char* ss = snd->value.str; + char* fs = unquote(fst)->value.str; + char* ss = unquote(snd)->value.str; char* out = malloc(sizeof(char)*(strlen(fs)+strlen(ss))); strcpy(out, fs); strcat(out, ss); @@ -66,7 +66,7 @@ Sexpr* s_strat(Sexpr* b, Sexpr* rest, Sexpr* env) { Sexpr* index = eval(clone(car(cdr(args))), env); Sexpr* str = eval(clone(car(args)), env); #ifdef TYPECHECK - if(str->type != STR || index->type != UINT) { + if(unquote(str)->type != STR || unquote(index)->type != UINT) { ERR("strat: ", "arguments not string"); sexpr_free(index); sexpr_free(str); @@ -74,8 +74,8 @@ Sexpr* s_strat(Sexpr* b, Sexpr* rest, Sexpr* env) { return cons(from_nil(), rest); } #endif // typecheck - size_t len = strlen(str->value.str); - size_t idx = index->value.u; + size_t len = strlen(unquote(str)->value.str); + size_t idx = unquote(index)->value.u; if(len < idx) { WARN("", "index out of bounds"); return cons(from_nil(), rest); @@ -95,14 +95,14 @@ Sexpr* s_strexpand(Sexpr* b, Sexpr* rest, Sexpr* env) { Sexpr* args = b->value.b.args; Sexpr* arg = eval(clone(car(args)), env); #ifdef TYPECHECK - if(arg->type != STR) { + if(unquote(arg)->type != STR) { ERR("strexpand: ", "argument not string"); sexpr_free(arg); sexpr_free(b); return cons(from_nil(), rest); } #endif // typecheck - size_t len = strlen(arg->value.str); + size_t len = strlen(unquote(arg)->value.str); Sexpr* toret = from_nil(); char arr[] = {'\0', '\0'}; while(len > 0) { @@ -123,7 +123,7 @@ Sexpr* s_substr(Sexpr* b, Sexpr* rest, Sexpr* env) { Sexpr* subex = eval(clone(car(cdr(args))), env); Sexpr* strex = eval(clone(car(args)), env); #ifdef TYPECHECK - if(subex->type != STR || strex->type != STR) { + if(unquote(subex)->type != STR || unquote(strex)->type != STR) { ERR("substr: ", "arguments not strings"); sexpr_free(subex); sexpr_free(strex); @@ -132,8 +132,8 @@ Sexpr* s_substr(Sexpr* b, Sexpr* rest, Sexpr* env) { } #endif Sexpr* result = from_nil(); - char* sub = subex->value.str; - char* str = strex->value.str; + char* sub = unquote(subex)->value.str; + char* str = unquote(strex)->value.str; char* currstr = str; char* res; size_t idx; @@ -160,7 +160,7 @@ Sexpr* s_strtok(Sexpr* b, Sexpr* rest, Sexpr* env) { Sexpr* delimex = eval(clone(car(cdr(args))), env); Sexpr* strex = eval(clone(car(args)), env); #ifdef TYPECHECK - if(delimex->type != STR || strex->type != STR) { + if(unquote(delimex)->type != STR || unquote(strex)->type != STR) { ERR("strtok: ", "arguments not strings"); sexpr_free(delimex); sexpr_free(strex); @@ -169,8 +169,8 @@ Sexpr* s_strtok(Sexpr* b, Sexpr* rest, Sexpr* env) { } #endif Sexpr* result = from_nil(); - char* delim = delimex->value.str; - char* str = strex->value.str; + char* delim = unquote(delimex)->value.str; + char* str = unquote(strex)->value.str; char* out = strtok(str, delim); while(out != NULL) { result = cons(from_string(out), result);