summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2009-12-16 17:05:50 +0100
committerJohannes Weiner <hannes@cmpxchg.org>2009-12-16 17:05:50 +0100
commitd7d20ffcf8399edb58f08ea1d24baac5692db7cb (patch)
tree7dae44eb39af691281586e29c9d7402617b14830
parent8ca5f5e2d3415f0e21724b211e1f9ee946571005 (diff)
object: add nil
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
-rw-r--r--include/sheep/object.h4
-rw-r--r--sheep/function.c2
-rw-r--r--sheep/object.c27
-rw-r--r--sheep/vm.c1
4 files changed, 33 insertions, 1 deletions
diff --git a/include/sheep/object.h b/include/sheep/object.h
index 667fcf6..87fd21b 100644
--- a/include/sheep/object.h
+++ b/include/sheep/object.h
@@ -31,4 +31,8 @@ static inline void sheep_set_data(sheep_t sheep, void *data)
int sheep_test(sheep_t);
int sheep_equal(sheep_t, sheep_t);
+extern struct sheep_object sheep_nil;
+
+void sheep_object_builtins(struct sheep_vm *);
+
#endif /* _SHEEP_OBJECT_H */
diff --git a/sheep/function.c b/sheep/function.c
index 0de48f7..1be9b8d 100644
--- a/sheep/function.c
+++ b/sheep/function.c
@@ -174,7 +174,7 @@ static sheep_t builtin_disassemble(struct sheep_vm *vm, unsigned int nr_args)
function->nr_parms, function->nr_locals, nr_foreigns);
sheep_code_disassemble(&function->code);
- return &sheep_true;
+ return &sheep_nil;
}
void sheep_function_builtins(struct sheep_vm *vm)
diff --git a/sheep/object.c b/sheep/object.c
index a59029c..6a48fc0 100644
--- a/sheep/object.c
+++ b/sheep/object.c
@@ -3,6 +3,7 @@
*
* Copyright (c) 2009 Johannes Weiner <hannes@cmpxchg.org>
*/
+#include <sheep/compile.h>
#include <sheep/vector.h>
#include <sheep/util.h>
#include <sheep/gc.h>
@@ -41,3 +42,29 @@ int sheep_equal(sheep_t a, sheep_t b)
return sheep_type(a)->equal(a, b);
return 0;
}
+
+static int test_nil(sheep_t sheep)
+{
+ return 0;
+}
+
+static void format_nil(sheep_t sheep, char **bufp, size_t *posp, int repr)
+{
+ sheep_addprintf(bufp, posp, "nil");
+}
+
+const struct sheep_type sheep_nil_type = {
+ .name = "nil",
+ .compile = sheep_compile_constant,
+ .test = test_nil,
+ .format = format_nil,
+};
+
+struct sheep_object sheep_nil = {
+ .type = &sheep_nil_type,
+};
+
+void sheep_object_builtins(struct sheep_vm *vm)
+{
+ sheep_vm_variable(vm, "nil", &sheep_nil);
+}
diff --git a/sheep/vm.c b/sheep/vm.c
index 2582129..001c97e 100644
--- a/sheep/vm.c
+++ b/sheep/vm.c
@@ -74,6 +74,7 @@ void sheep_vm_init(struct sheep_vm *vm, int ac, char **av)
{
memset(vm, 0, sizeof(*vm));
sheep_core_init(vm);
+ sheep_object_builtins(vm);
sheep_bool_builtins(vm);
sheep_number_builtins(vm);
sheep_string_builtins(vm);