diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-01-04 01:25:44 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-01-04 01:25:44 +0300 |
commit | 0b4de175110bdf6ffaeb0ba3b86053fd2fec78be (patch) | |
tree | ac9b054f1ea89c5bc0772afa06b7092f81e1fbbe /src | |
parent | 76ad99e0aa3fc5dd079dcf1b2f232c2a5f390372 (diff) | |
download | csx-0b4de175110bdf6ffaeb0ba3b86053fd2fec78be.tar csx-0b4de175110bdf6ffaeb0ba3b86053fd2fec78be.tar.xz csx-0b4de175110bdf6ffaeb0ba3b86053fd2fec78be.zip |
.
Diffstat (limited to 'src')
-rw-r--r-- | src/csx.c | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -3,6 +3,7 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h> +#include <stdio.h> static void init(); @@ -146,7 +147,7 @@ static void *base_set(void *arg) { pair_data *res; void *name = head(arg); - void *value = head(tail(arg)); + void *value = csx_run(head(tail(arg))); if (type(context) == type_null) { void *nameval = new_pair(name, value); context = new_pair(new_pair(nameval, null), null); @@ -202,7 +203,7 @@ static void *base_tail(void *arg) static void *base_quote(void *arg) { - return arg; + return head(arg); } static void *base_same(void *arg) @@ -293,6 +294,12 @@ static void *base_inv(void *arg) return csx_int(0); } +static void *base_div(void *arg) +{ + arg = run_each(arg); + return csx_int(*(int *)head(arg) / *(int *)head(tail(arg))); +} + static void *base_mod(void *arg) { arg = run_each(arg); @@ -330,6 +337,21 @@ static void *base_dec(void *arg) } +static void *base_out(void *arg) +{ + arg = run_each(arg); + int res = putchar(*(int *)head(arg)); + return res != EOF ? one : null; +} + +static void *base_in(void *arg) +{ + arg = run_each(arg); + int res = getchar(); + return res != EOF ? csx_int(res) : null; +} + + static void *zip(void *params, void *values) { void *res = null; @@ -398,9 +420,12 @@ static void new_context() base_set(csx_list(csx_name("*"), csx_base(base_prod), 0)); base_set(csx_list(csx_name("neg"), csx_base(base_neg), 0)); base_set(csx_list(csx_name("inv"), csx_base(base_inv), 0)); + base_set(csx_list(csx_name("div"), csx_base(base_div), 0)); base_set(csx_list(csx_name("mod"), csx_base(base_mod), 0)); base_set(csx_list(csx_name("<"), csx_base(base_inc), 0)); base_set(csx_list(csx_name(">"), csx_base(base_dec), 0)); + base_set(csx_list(csx_name("out"), csx_base(base_out), 0)); + base_set(csx_list(csx_name("in"), csx_base(base_in), 0)); base_set(csx_list(csx_name("run"), csx_base(csx_run), 0)); } |