aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2021-01-02 19:39:59 +0300
committerAleksey Veresov <aleksey@veresov.pro>2021-01-02 19:39:59 +0300
commitcff0c84f6b14f37497ff22c54948380af64e8106 (patch)
tree2acf23d98b0f9681d5f42346230538aa684a527b
parent0c32a26c9a43b2d45968b9ac59b8916c1d4092d1 (diff)
downloadcsx-cff0c84f6b14f37497ff22c54948380af64e8106.tar
csx-cff0c84f6b14f37497ff22c54948380af64e8106.tar.xz
csx-cff0c84f6b14f37497ff22c54948380af64e8106.zip
It's alive.
-rw-r--r--Makefile4
-rw-r--r--examples/fib.c2
-rw-r--r--include/csx.h2
-rw-r--r--src/csx.c24
4 files changed, 11 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index 05c8746..f2fe69a 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ MAN = man
# Library itself:
LIB = libcsx.a
# Modules:
-EXTERNAL = $(foreach x,$(notdir $(wildcard $(INCLUDE)/csx/*.h)),$(x:.h=))
+EXTERNAL = $(foreach x,$(notdir $(wildcard $(INCLUDE)/*.h)),$(x:.h=))
INTERNAL = $(foreach x,$(notdir $(wildcard $(SRCDIR)/*.h)),$(x:.h=))
# Default target is library:
@@ -53,7 +53,7 @@ EXAMPLES = $(foreach x,$(XSRC:.c=),$(BUILD)/$(x))
# Dependency file:
DEPS = deps.mk
-SRCINC = -I$(INCLUDE)/csx
+SRCINC = -I$(INCLUDE)
XINC = -I$(INCLUDE)
SRCBUILD = $(BUILD)/$(SRCDIR)
XBLD = $(BUILD)/$(EXADIR)
diff --git a/examples/fib.c b/examples/fib.c
index 0c94673..fc03fbb 100644
--- a/examples/fib.c
+++ b/examples/fib.c
@@ -21,7 +21,7 @@ void process()
char *fib = csx_name("fib");
char *num = csx_name("num");
csx_eval(l(define, fib, l(fn, l(num, 0),
- l(csx_if, l(inc, num, n(2), 0), n(1),
+ l(csx_if, l(inc, num, n(3), 0), n(1),
l(sum,
l(fib, l(diff, num, n(1), 0), 0),
l(fib, l(diff, num, n(2), 0), 0),
diff --git a/include/csx.h b/include/csx.h
index 90d18c2..836ee6a 100644
--- a/include/csx.h
+++ b/include/csx.h
@@ -10,7 +10,7 @@ int *csx_num(int num);
void *csx_eval(void *expression);
-typedef void *(csx_base_data)(void *arg);
+typedef void *(*csx_base_data)(void *arg);
void *csx_base(csx_base_data base);
char *csx_name(const char *name);
diff --git a/src/csx.c b/src/csx.c
index abf94aa..7225792 100644
--- a/src/csx.c
+++ b/src/csx.c
@@ -24,7 +24,7 @@ typedef struct pair_data {
/* typedef char name_data; */
-typedef csx_base_data base_data;
+/* typedef csx_base_data base_data; */
/* typedef int num_data; */
@@ -70,9 +70,9 @@ static char *new_name(const char *name)
return res;
}
-static base_data *new_base(base_data base)
+static csx_base_data *new_base(csx_base_data base)
{
- base_data *res = new(type_base, sizeof(base_data));
+ csx_base_data *res = new(type_base, sizeof(csx_base_data));
*res = base;
return res;
}
@@ -133,7 +133,7 @@ static void *base_define(void *arg)
{
pair_data *res;
void *name = head(arg);
- void *value = head(tail(arg));
+ void *value = csx_eval(head(tail(arg)));
if (type(context) == type_null) {
void *nameval = new_pair(name, value);
context = new_pair(new_pair(nameval, null), null);
@@ -171,24 +171,12 @@ static void *base_is_name(void *arg)
return type(head(arg)) == type_name ? one : null;
}
-static void *base_is_base(void *arg)
-{
- arg = eval_each(arg);
- return type(head(arg)) == type_base ? one : null;
-}
-
static void *base_is_num(void *arg)
{
arg = eval_each(arg);
return type(head(arg)) == type_num ? one : null;
}
-static void *base_is_fn(void *arg)
-{
- arg = eval_each(arg);
- return type(head(arg)) == type_fn ? one : null;
-}
-
static void *base_sum(void *arg)
{
arg = eval_each(arg);
@@ -436,7 +424,7 @@ tailcall:
void *ops = tail(arg);
applycall:
if (type(fn) == type_base) {
- base_data *base = fn;
+ csx_base_data *base = (void *)fn;
if (*base == base_eval) {
ops = eval_each(ops);
arg = head(ops);
@@ -510,6 +498,8 @@ static void new_context()
base_define(csx_list(new_name("define"), new_base(base_define), 0));
base_define(csx_list(new_name("fn"), new_base(base_fn), 0));
base_define(csx_list(new_name("if"), new_base(base_if), 0));
+ base_define(csx_list(new_name("and"), new_base(base_and), 0));
+ base_define(csx_list(new_name("or"), new_base(base_or), 0));
}