mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
Starting to add support for vectors
This commit is contained in:
parent
73442cd4b9
commit
3682b7f9d0
2 changed files with 23 additions and 1 deletions
|
@ -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. */
|
||||
|
||||
|
|
21
runtime.c
21
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("(");
|
||||
|
|
Loading…
Add table
Reference in a new issue