From 3682b7f9d01cc627a8651b2a579f71f0aab80487 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Sat, 30 May 2015 22:24:54 -0400 Subject: [PATCH] Starting to add support for vectors --- cyclone.h | 3 ++- runtime.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cyclone.h b/cyclone.h index 123f4f95..8662e558 100644 --- a/cyclone.h +++ b/cyclone.h @@ -173,7 +173,8 @@ typedef struct {tag_type tag; FILE *fp; int mode;} port_type; /* Vector type */ -// TODO +typedef struct {tag_type tag; int num_elt; object *elts;} vector_type; +typedef vector_type *vector; /* Define cons type. */ diff --git a/runtime.c b/runtime.c index b7ba836c..ce446d19 100644 --- a/runtime.c +++ b/runtime.c @@ -213,6 +213,17 @@ int equal(x, y) object x, y; return (type_of(y) == string_tag && strcmp(((string_type *) x)->str, ((string_type *) y)->str) == 0); + case vector_tag: + if (type_of(y) == vector_tag && + ((vector)x)->num_elt == ((vector)y)->num_elt) { + int i; + for (i = 0; i < ((vector)x)->num_elt; i++) { + if (equalp(((vector)x)->elts[i], ((vector)y)->elts[i]) == boolean_f) + return 0; + } + return 1; + } + return 0; default: return x == y; } @@ -302,6 +313,16 @@ object Cyc_display(x) object x; case string_tag: printf("%s", ((string_type *) x)->str); break; + case vector_tag: + printf("#("); + for (i = 0; i < ((vector) x)->num_elt; i++) { + if (i > 0) { + printf(" "); + } + Cyc_display(((vector)x)->elts[i]); + } + printf(")"); + break; case cons_tag: has_cycle = Cyc_has_cycle(x); printf("(");