diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-01-06 01:37:05 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-01-06 01:37:05 +0300 |
commit | 672512b0a2b3b4ae88f204293f4379c1fbb79850 (patch) | |
tree | c29ef6c7de3917e1057b74d08092f551139a7499 /src | |
parent | 1afd0cdc7820d9c3a9ae032ea40545d7d32bf9bf (diff) | |
download | csx-672512b0a2b3b4ae88f204293f4379c1fbb79850.tar csx-672512b0a2b3b4ae88f204293f4379c1fbb79850.tar.xz csx-672512b0a2b3b4ae88f204293f4379c1fbb79850.zip |
Added interpreter.
Diffstat (limited to 'src')
-rw-r--r-- | src/csx.c | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -190,6 +190,7 @@ static void *base_is_set(void *arg) static void *base_sethead(void *arg) { + arg = run_each(arg); pair_data *p = head(arg); p->head = head(tail(arg)); return null; @@ -197,6 +198,7 @@ static void *base_sethead(void *arg) static void *base_settail(void *arg) { + arg = run_each(arg); pair_data *p = head(arg); p->tail = head(tail(arg)); return null; @@ -421,6 +423,18 @@ static void *base_len(void *arg) return csx_int(len); } +static void *base_run(void *arg) +{ + arg = run_each(arg); + if (type(tail(arg)) == type_null) return csx_run(head(arg)); + void *saved = context; + context = head(tail(arg)); + void *res = csx_run(head(arg)); + void *rescontext = context; + context = saved; + return new_pair(res, rescontext); +} + static void *zip(void *params, void *values) { @@ -485,6 +499,21 @@ tailcall: } +static void *base_context(void *args) +{ + return context; +} + +static void new_context(); +static void *base_newcontext(void *args) +{ + void *saved = context; + new_context(); + void *res = context; + context = saved; + return res; +} + static void new_context() { context = new_pair(null, null); @@ -515,7 +544,9 @@ static void new_context() base_set(csx_list(csx_name("name"), csx_base(base_name), 0)); base_set(csx_list(csx_name("str"), csx_base(base_str), 0)); base_set(csx_list(csx_name("len"), csx_base(base_len), 0)); - base_set(csx_list(csx_name("run"), csx_base(csx_run), 0)); + base_set(csx_list(csx_name("run"), csx_base(base_run), 0)); + base_set(csx_list(csx_name("context"), csx_base(base_context), 0)); + base_set(csx_list(csx_name("newcontext"), csx_base(base_newcontext), 0)); } static void init() |