1
0
mirror of https://github.com/janet-lang/janet synced 2025-11-18 08:15:13 +00:00

Initial struct prototype code.

Also add a number of cfunctions for manipulating structs
with prototypes.
This commit is contained in:
Calvin Rose
2021-05-28 21:37:13 -05:00
parent 7c757ef3bf
commit 4d983e54b5
11 changed files with 317 additions and 26 deletions

View File

@@ -104,6 +104,17 @@ static int traversal_next(Janet *x, Janet *y) {
janet_vm_traversal = t;
return 0;
}
/* Traverse prototype */
JanetStruct sproto = sself->proto;
JanetStruct oproto = sother->proto;
if (sproto && !oproto) return 3;
if (!sproto && oproto) return 1;
if (oproto && sproto) {
*x = janet_wrap_struct(sproto);
*y = janet_wrap_struct(oproto);
janet_vm_traversal = t - 1;
return 0;
}
}
t--;
}
@@ -276,6 +287,8 @@ int janet_equals(Janet x, Janet y) {
if (s1 == s2) break;
if (janet_struct_hash(s1) != janet_struct_hash(s2)) return 0;
if (janet_struct_length(s1) != janet_struct_length(s2)) return 0;
if (janet_struct_proto(s1) && !janet_struct_proto(s2)) return 0;
if (!janet_struct_proto(s1) && janet_struct_proto(s2)) return 0;
push_traversal_node(janet_struct_head(s1), janet_struct_head(s2), 0);
break;
}