Add TYPE_PROCEDURE
This commit is contained in:
parent
a222a8bbca
commit
d732c955ce
5 changed files with 46 additions and 6 deletions
22
object.c
22
object.c
|
@ -16,6 +16,21 @@ static struct Object *new(const enum Type type)
|
|||
return object;
|
||||
}
|
||||
|
||||
struct Object *Object_new_procedure(
|
||||
const char *const name,
|
||||
struct Object *(*const func)(struct Object *args)
|
||||
) {
|
||||
struct Object *const object = new(TYPE_PROCEDURE);
|
||||
object->procedure.name = NULL;
|
||||
if (name && name[0]) {
|
||||
object->procedure.name = malloc(strlen(name) + 1);
|
||||
assert(object->procedure.name);
|
||||
strcpy(object->procedure.name, name);
|
||||
}
|
||||
object->procedure.func = func;
|
||||
return object;
|
||||
}
|
||||
|
||||
struct Object *Object_new_pair(struct Object *const a, struct Object *const b)
|
||||
{
|
||||
struct Object *const object = new(TYPE_PAIR);
|
||||
|
@ -104,6 +119,13 @@ void Object_print(struct Object *const self, const unsigned indent)
|
|||
printf("%s:", Type_to_str(self->type));
|
||||
|
||||
switch (self->type) {
|
||||
case TYPE_PROCEDURE:
|
||||
if (self->procedure.name) {
|
||||
printf("#<procedure:%s>\n", self->procedure.name);
|
||||
} else {
|
||||
printf("#<procedure>\n");
|
||||
}
|
||||
break;
|
||||
case TYPE_PAIR:
|
||||
printf("\n");
|
||||
Object_print(self->pair.a, indent + 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue