mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 04:25:06 +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 */
|
/* Vector type */
|
||||||
|
|
||||||
// TODO
|
typedef struct {tag_type tag; int num_elt; object *elts;} vector_type;
|
||||||
|
typedef vector_type *vector;
|
||||||
|
|
||||||
/* Define cons type. */
|
/* 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 &&
|
return (type_of(y) == string_tag &&
|
||||||
strcmp(((string_type *) x)->str,
|
strcmp(((string_type *) x)->str,
|
||||||
((string_type *) y)->str) == 0);
|
((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:
|
default:
|
||||||
return x == y;
|
return x == y;
|
||||||
}
|
}
|
||||||
|
@ -302,6 +313,16 @@ object Cyc_display(x) object x;
|
||||||
case string_tag:
|
case string_tag:
|
||||||
printf("%s", ((string_type *) x)->str);
|
printf("%s", ((string_type *) x)->str);
|
||||||
break;
|
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:
|
case cons_tag:
|
||||||
has_cycle = Cyc_has_cycle(x);
|
has_cycle = Cyc_has_cycle(x);
|
||||||
printf("(");
|
printf("(");
|
||||||
|
|
Loading…
Add table
Reference in a new issue