summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2010-02-15 21:49:01 +0100
committerJohannes Weiner <hannes@cmpxchg.org>2010-03-10 23:41:16 +0100
commit7ab64e7030e6d50a3f660cc6f1d1322f04e6fffd (patch)
tree048212d00a10e305dcd1046d0f40c5c514e602c1
parent14bdd99d233a73a2fad3b8f4b0538fee22c9f972 (diff)
clean up type implementations a bit
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
-rw-r--r--include/sheep/object_types.h4
-rw-r--r--sheep/alien.c8
-rw-r--r--sheep/bool.c8
-rw-r--r--sheep/function.c18
-rw-r--r--sheep/list.c130
-rw-r--r--sheep/module.c14
-rw-r--r--sheep/name.c12
-rw-r--r--sheep/number.c8
-rw-r--r--sheep/string.c52
9 files changed, 127 insertions, 127 deletions
diff --git a/include/sheep/object_types.h b/include/sheep/object_types.h
index 9b97898..ec01a2f 100644
--- a/include/sheep/object_types.h
+++ b/include/sheep/object_types.h
@@ -35,9 +35,9 @@ struct sheep_type {
int (*test)(sheep_t);
int (*equal)(sheep_t, sheep_t);
- const struct sheep_sequence *sequence;
-
void (*format)(sheep_t, char **, size_t *, int);
+
+ const struct sheep_sequence *sequence;
};
struct sheep_object {
diff --git a/sheep/alien.c b/sheep/alien.c
index 060cae1..661713d 100644
--- a/sheep/alien.c
+++ b/sheep/alien.c
@@ -10,12 +10,12 @@
#include <sheep/alien.h>
-static void free_alien(struct sheep_vm *vm, sheep_t sheep)
+static void alien_free(struct sheep_vm *vm, sheep_t sheep)
{
sheep_free(sheep_data(sheep));
}
-static void format_alien(sheep_t sheep, char **bufp, size_t *posp, int repr)
+static void alien_format(sheep_t sheep, char **bufp, size_t *posp, int repr)
{
struct sheep_alien *alien;
@@ -28,8 +28,8 @@ static void format_alien(sheep_t sheep, char **bufp, size_t *posp, int repr)
const struct sheep_type sheep_alien_type = {
.name = "alien",
- .free = free_alien,
- .format = format_alien,
+ .free = alien_free,
+ .format = alien_format,
};
sheep_t sheep_make_alien(struct sheep_vm *vm, sheep_alien_t function,
diff --git a/sheep/bool.c b/sheep/bool.c
index 453b102..24f33aa 100644
--- a/sheep/bool.c
+++ b/sheep/bool.c
@@ -12,12 +12,12 @@
#include <sheep/bool.h>
-static int test_bool(sheep_t sheep)
+static int bool_test(sheep_t sheep)
{
return sheep != &sheep_false;
}
-static void format_bool(sheep_t sheep, char **bufp, size_t *posp, int repr)
+static void bool_format(sheep_t sheep, char **bufp, size_t *posp, int repr)
{
if (sheep == &sheep_false)
sheep_addprintf(bufp, posp, "false");
@@ -28,8 +28,8 @@ static void format_bool(sheep_t sheep, char **bufp, size_t *posp, int repr)
const struct sheep_type sheep_bool_type = {
.name = "bool",
.compile = sheep_compile_constant,
- .test = test_bool,
- .format = format_bool,
+ .test = bool_test,
+ .format = bool_format,
};
struct sheep_object sheep_true = {
diff --git a/sheep/function.c b/sheep/function.c
index 2b36e2d..e485dc6 100644
--- a/sheep/function.c
+++ b/sheep/function.c
@@ -25,7 +25,7 @@ static void free_freevar(struct sheep_vector *foreign)
sheep_free(foreign);
}
-static void free_function(struct sheep_vm *vm, sheep_t sheep)
+static void function_free(struct sheep_vm *vm, sheep_t sheep)
{
struct sheep_function *function;
@@ -37,7 +37,7 @@ static void free_function(struct sheep_vm *vm, sheep_t sheep)
sheep_free(function);
}
-static void format_function(sheep_t sheep, char **bufp, size_t *posp, int repr)
+static void function_format(sheep_t sheep, char **bufp, size_t *posp, int repr)
{
struct sheep_function *function;
@@ -50,11 +50,11 @@ static void format_function(sheep_t sheep, char **bufp, size_t *posp, int repr)
const struct sheep_type sheep_function_type = {
.name = "function",
- .free = free_function,
- .format = format_function,
+ .free = function_free,
+ .format = function_format,
};
-static void mark_closure(sheep_t sheep)
+static void closure_mark(sheep_t sheep)
{
struct sheep_function *closure;
@@ -62,7 +62,7 @@ static void mark_closure(sheep_t sheep)
sheep_foreign_mark(closure->foreign);
}
-static void free_closure(struct sheep_vm *vm, sheep_t sheep)
+static void closure_free(struct sheep_vm *vm, sheep_t sheep)
{
struct sheep_function *closure;
@@ -74,9 +74,9 @@ static void free_closure(struct sheep_vm *vm, sheep_t sheep)
const struct sheep_type sheep_closure_type = {
.name = "function",
- .mark = mark_closure,
- .free = free_closure,
- .format = format_function,
+ .mark = closure_mark,
+ .free = closure_free,
+ .format = function_format,
};
sheep_t sheep_make_function(struct sheep_vm *vm, const char *name)
diff --git a/sheep/list.c b/sheep/list.c
index 0e9d211..3f398d9 100644
--- a/sheep/list.c
+++ b/sheep/list.c
@@ -16,6 +16,66 @@
#include <sheep/list.h>
+static void list_mark(sheep_t sheep)
+{
+ struct sheep_list *list;
+
+ list = sheep_list(sheep);
+ if (!list->head)
+ return;
+ sheep_mark(list->head);
+ /*
+ * Usually, list->head and list->tail are both NULL or both
+ * set. But to facilitate simpler, non-atomic construction
+ * sites, handle garbage collection cycles between setting the
+ * head and setting the tail.
+ */
+ if (list->tail)
+ sheep_mark(list->tail);
+}
+
+static void list_free(struct sheep_vm *vm, sheep_t sheep)
+{
+ sheep_free(sheep_list(sheep));
+}
+
+static int list_test(sheep_t sheep)
+{
+ return !!sheep_list(sheep)->head;
+}
+
+static int list_equal(sheep_t a, sheep_t b)
+{
+ struct sheep_list *la, *lb;
+
+ la = sheep_list(a);
+ lb = sheep_list(b);
+ while (la->head && lb->head) {
+ if (!sheep_equal(la->head, lb->head))
+ return 0;
+ la = sheep_list(la->tail);
+ lb = sheep_list(lb->tail);
+ }
+ return !(la->head || lb->head);
+}
+
+static void list_format(sheep_t sheep, char **bufp, size_t *posp, int repr)
+{
+ struct sheep_list *list;
+
+ list = sheep_list(sheep);
+ sheep_addprintf(bufp, posp, "(");
+ while (list->head) {
+ sheep = list->head;
+ __sheep_format(sheep, bufp, posp, 1);
+ list = sheep_list(list->tail);
+ if (!list->head)
+ break;
+ sheep_addprintf(bufp, posp, " ");
+ }
+ sheep_addprintf(bufp, posp, ")");
+}
+
static size_t list_length(sheep_t sheep)
{
struct sheep_list *list;
@@ -127,75 +187,15 @@ static const struct sheep_sequence list_sequence = {
.position = list_position,
};
-static void mark_list(sheep_t sheep)
-{
- struct sheep_list *list;
-
- list = sheep_list(sheep);
- if (!list->head)
- return;
- sheep_mark(list->head);
- /*
- * Usually, list->head and list->tail are both NULL or both
- * set. But to facilitate simpler, non-atomic construction
- * sites, handle garbage collection cycles between setting the
- * head and setting the tail.
- */
- if (list->tail)
- sheep_mark(list->tail);
-}
-
-static void free_list(struct sheep_vm *vm, sheep_t sheep)
-{
- sheep_free(sheep_list(sheep));
-}
-
-static int test_list(sheep_t sheep)
-{
- return !!sheep_list(sheep)->head;
-}
-
-static int equal_list(sheep_t a, sheep_t b)
-{
- struct sheep_list *la, *lb;
-
- la = sheep_list(a);
- lb = sheep_list(b);
- while (la->head && lb->head) {
- if (!sheep_equal(la->head, lb->head))
- return 0;
- la = sheep_list(la->tail);
- lb = sheep_list(lb->tail);
- }
- return !(la->head || lb->head);
-}
-
-static void format_list(sheep_t sheep, char **bufp, size_t *posp, int repr)
-{
- struct sheep_list *list;
-
- list = sheep_list(sheep);
- sheep_addprintf(bufp, posp, "(");
- while (list->head) {
- sheep = list->head;
- __sheep_format(sheep, bufp, posp, 1);
- list = sheep_list(list->tail);
- if (!list->head)
- break;
- sheep_addprintf(bufp, posp, " ");
- }
- sheep_addprintf(bufp, posp, ")");
-}
-
const struct sheep_type sheep_list_type = {
.name = "list",
- .mark = mark_list,
- .free = free_list,
+ .mark = list_mark,
+ .free = list_free,
.compile = sheep_compile_list,
- .test = test_list,
- .equal = equal_list,
+ .test = list_test,
+ .equal = list_equal,
+ .format = list_format,
.sequence = &list_sequence,
- .format = format_list,
};
sheep_t sheep_make_cons(struct sheep_vm *vm, sheep_t head, sheep_t tail)
diff --git a/sheep/module.c b/sheep/module.c
index 18405fb..579ce5e 100644
--- a/sheep/module.c
+++ b/sheep/module.c
@@ -19,7 +19,7 @@
#include <sheep/module.h>
-static void do_free_module(struct sheep_module *mod)
+static void free_module(struct sheep_module *mod)
{
sheep_free(mod->name);
sheep_map_drain(&mod->env);
@@ -28,12 +28,12 @@ static void do_free_module(struct sheep_module *mod)
sheep_free(mod);
}
-static void free_module(struct sheep_vm *vm, sheep_t sheep)
+static void module_free(struct sheep_vm *vm, sheep_t sheep)
{
- do_free_module(sheep_data(sheep));
+ free_module(sheep_data(sheep));
}
-static void format_module(sheep_t sheep, char **bufp, size_t *posp, int repr)
+static void module_format(sheep_t sheep, char **bufp, size_t *posp, int repr)
{
struct sheep_module *mod = sheep_data(sheep);
@@ -41,8 +41,8 @@ static void format_module(sheep_t sheep, char **bufp, size_t *posp, int repr)
}
const struct sheep_type sheep_module_type = {
- .free = free_module,
- .format = format_module,
+ .free = module_free,
+ .format = module_format,
};
enum {
@@ -177,7 +177,7 @@ sheep_t sheep_module_load(struct sheep_vm *vm, const char *name)
fprintf(stderr, "load: %s not found\n", name);
err:
- do_free_module(mod);
+ free_module(mod);
return NULL;
found:
return sheep_make_object(vm, &sheep_module_type, mod);
diff --git a/sheep/name.c b/sheep/name.c
index 8c0dbcb..e79c6f7 100644
--- a/sheep/name.c
+++ b/sheep/name.c
@@ -12,7 +12,7 @@
#include <sheep/name.h>
-static void free_name(struct sheep_vm *vm, sheep_t sheep)
+static void name_free(struct sheep_vm *vm, sheep_t sheep)
{
struct sheep_name *name;
@@ -22,7 +22,7 @@ static void free_name(struct sheep_vm *vm, sheep_t sheep)
sheep_free(name);
}
-static int equal_name(sheep_t a, sheep_t b)
+static int name_equal(sheep_t a, sheep_t b)
{
struct sheep_name *na, *nb;
unsigned int i;
@@ -39,7 +39,7 @@ static int equal_name(sheep_t a, sheep_t b)
return 1;
}
-static void format_name(sheep_t sheep, char **bufp, size_t *posp, int repr)
+static void name_format(sheep_t sheep, char **bufp, size_t *posp, int repr)
{
struct sheep_name *name;
unsigned int i;
@@ -52,10 +52,10 @@ static void format_name(sheep_t sheep, char **bufp, size_t *posp, int repr)
const struct sheep_type sheep_name_type = {
.name = "name",
- .free = free_name,
+ .free = name_free,
.compile = sheep_compile_name,
- .equal = equal_name,
- .format = format_name,
+ .equal = name_equal,
+ .format = name_format,
};
sheep_t sheep_make_name(struct sheep_vm *vm, const char *string)
diff --git a/sheep/number.c b/sheep/number.c
index 883ffb3..72ef74c 100644
--- a/sheep/number.c
+++ b/sheep/number.c
@@ -16,12 +16,12 @@
#include <sheep/number.h>
-static int test_number(sheep_t sheep)
+static int number_test(sheep_t sheep)
{
return !!sheep_fixnum(sheep);
}
-static void format_number(sheep_t sheep, char **bufp, size_t *posp, int repr)
+static void number_format(sheep_t sheep, char **bufp, size_t *posp, int repr)
{
sheep_addprintf(bufp, posp, "%ld", sheep_fixnum(sheep));
}
@@ -29,12 +29,12 @@ static void format_number(sheep_t sheep, char **bufp, size_t *posp, int repr)
const struct sheep_type sheep_number_type = {
.name = "number",
.compile = sheep_compile_constant,
- .test = test_number,
+ .test = number_test,
/*
* Fixnums are encoded in the reference pointer, equality is
* thus checked directly in sheep_equal().
*/
- .format = format_number,
+ .format = number_format,
};
sheep_t sheep_make_number(struct sheep_vm *vm, long number)
diff --git a/sheep/string.c b/sheep/string.c
index 1a1741b..adf521f 100644
--- a/sheep/string.c
+++ b/sheep/string.c
@@ -14,6 +14,28 @@
#include <sheep/string.h>
+static void string_free(struct sheep_vm *vm, sheep_t sheep)
+{
+ sheep_free(sheep_data(sheep));
+}
+
+static int string_test(sheep_t sheep)
+{
+ return strlen(sheep_rawstring(sheep)) > 0;
+}
+
+static int string_equal(sheep_t a, sheep_t b)
+{
+ return !strcmp(sheep_rawstring(a), sheep_rawstring(b));
+}
+
+static void string_format(sheep_t sheep, char **bufp, size_t *posp, int repr)
+{
+ const char *fmt = repr ? "\"%s\"" : "%s";
+
+ sheep_addprintf(bufp, posp, fmt, sheep_rawstring(sheep));
+}
+
static size_t string_length(sheep_t sheep)
{
return strlen(sheep_rawstring(sheep));
@@ -91,36 +113,14 @@ static const struct sheep_sequence string_sequence = {
.position = string_position,
};
-static void free_string(struct sheep_vm *vm, sheep_t sheep)
-{
- sheep_free(sheep_data(sheep));
-}
-
-static int test_string(sheep_t sheep)
-{
- return strlen(sheep_rawstring(sheep)) > 0;
-}
-
-static int equal_string(sheep_t a, sheep_t b)
-{
- return !strcmp(sheep_rawstring(a), sheep_rawstring(b));
-}
-
-static void format_string(sheep_t sheep, char **bufp, size_t *posp, int repr)
-{
- const char *fmt = repr ? "\"%s\"" : "%s";
-
- sheep_addprintf(bufp, posp, fmt, sheep_rawstring(sheep));
-}
-
const struct sheep_type sheep_string_type = {
.name = "string",
- .free = free_string,
+ .free = string_free,
.compile = sheep_compile_constant,
- .test = test_string,
- .equal = equal_string,
+ .test = string_test,
+ .equal = string_equal,
+ .format = string_format,
.sequence = &string_sequence,
- .format = format_string,
};
sheep_t __sheep_make_string(struct sheep_vm *vm, const char *str)