mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Recursive arrays and dictionaries!
This commit is contained in:
@@ -271,6 +271,23 @@ int hashLiteral(Literal lit) {
|
||||
case LITERAL_STRING:
|
||||
return hashString(AS_STRING(lit), STRLEN(lit));
|
||||
|
||||
case LITERAL_ARRAY: {
|
||||
unsigned int res = 0;
|
||||
for (int i = 0; i < AS_DICTIONARY(lit)->count; i++) {
|
||||
res += hashLiteral(AS_ARRAY(lit)->literals[i]);
|
||||
}
|
||||
return hash(res);
|
||||
}
|
||||
|
||||
case LITERAL_DICTIONARY: {
|
||||
unsigned int res = 0;
|
||||
for (int i = 0; i < AS_DICTIONARY(lit)->count; i++) {
|
||||
res += hashLiteral(AS_DICTIONARY(lit)->entries[i].key);
|
||||
res += hashLiteral(AS_DICTIONARY(lit)->entries[i].value);
|
||||
}
|
||||
return hash(res);
|
||||
}
|
||||
|
||||
case LITERAL_IDENTIFIER:
|
||||
return hashString(AS_IDENTIFIER(lit), STRLEN_I(lit));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user