diff options
author | Preston Pan <preston@nullring.xyz> | 2023-01-06 18:53:42 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2023-01-06 18:53:42 -0800 |
commit | 0771dd0e1a143c17920d65d5de8d010aa433ce1c (patch) | |
tree | 1e6ea87bf5b2673bf810db502050e55d66a95f97 /src/visitor.c | |
parent | f32cb9a129ebf1755ea300cf311f487c5b9f0f04 (diff) |
add comments
Diffstat (limited to 'src/visitor.c')
-rw-r--r-- | src/visitor.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/visitor.c b/src/visitor.c index ba29f3f..14ea404 100644 --- a/src/visitor.c +++ b/src/visitor.c @@ -397,6 +397,34 @@ ast_t *eval_list(visitor_t *v, ast_t *e) { ast_t *arg2 = eval_expr(v, args->cdr->car); ast_t *ret = init_ast_pair(arg1, arg2); return ret; + } else if (strcmp(function->string_value, "eq") == 0) { + if (cmp != 2) + eval_error(v, e); + + ast_t *arg1 = eval_expr(v, args->car); + ast_t *arg2 = eval_expr(v, args->cdr->car); + + if ((arg1->type == AST_STRING) && (arg2->type == AST_STRING)) { + return init_ast_bool(strcmp(arg1->string_value, arg2->string_value) == + 0); + } else + eval_error(v, e); + } else if (strcmp(function->string_value, "concat") == 0) { + if (cmp != 2) + eval_error(v, e); + + ast_t *arg1 = eval_expr(v, args->car); + ast_t *arg2 = eval_expr(v, args->cdr->car); + + if ((arg1->type == AST_STRING) && (arg2->type == AST_STRING)) { + int string_len1 = strlen(arg1->string_value); + int string_len2 = strlen(arg2->string_value); + char *ret = malloc((string_len1 + string_len2) * sizeof(char)); + strcat(ret, arg1->string_value); + strcat(ret, arg2->string_value); + return ret; + } else + eval_error(v, e); } } |