Added the opaque data type

This commit is contained in:
2022-10-03 21:02:13 +01:00
parent 016ab9c5fe
commit ca24c4f211
5 changed files with 212 additions and 4 deletions

View File

@@ -136,13 +136,18 @@ void freeLiteralDictionary(LiteralDictionary* dictionary) {
void setLiteralDictionary(LiteralDictionary* dictionary, Literal key, Literal value) {
if (IS_NULL(key)) {
fprintf(stderr, ERROR "Dictionaries can't have null keys (get)\n" RESET);
fprintf(stderr, ERROR "Dictionaries can't have null keys (set)\n" RESET);
return;
}
//BUGFIX: Can't hash a function
if (IS_FUNCTION(key) || IS_FUNCTION_NATIVE(key)) {
fprintf(stderr, ERROR "Dictionaries can't have function keys (get)\n" RESET);
fprintf(stderr, ERROR "Dictionaries can't have function keys (set)\n" RESET);
return;
}
if (IS_OPAQUE(key)) {
fprintf(stderr, ERROR "Dictionaries can't have opaque keys (set)\n" RESET);
return;
}
@@ -156,13 +161,18 @@ void setLiteralDictionary(LiteralDictionary* dictionary, Literal key, Literal va
Literal getLiteralDictionary(LiteralDictionary* dictionary, Literal key) {
if (IS_NULL(key)) {
fprintf(stderr, ERROR "Dictionaries can't have null keys (set)\n" RESET);
fprintf(stderr, ERROR "Dictionaries can't have null keys (get)\n" RESET);
return TO_NULL_LITERAL;
}
//BUGFIX: Can't hash a function
if (IS_FUNCTION(key) || IS_FUNCTION_NATIVE(key)) {
fprintf(stderr, ERROR "Dictionaries can't have function keys (set)\n" RESET);
fprintf(stderr, ERROR "Dictionaries can't have function keys (get)\n" RESET);
return TO_NULL_LITERAL;
}
if (IS_OPAQUE(key)) {
fprintf(stderr, ERROR "Dictionaries can't have opaque keys (get)\n" RESET);
return TO_NULL_LITERAL;
}
@@ -188,6 +198,11 @@ void removeLiteralDictionary(LiteralDictionary* dictionary, Literal key) {
return;
}
if (IS_OPAQUE(key)) {
fprintf(stderr, ERROR "Dictionaries can't have opaque keys (remove)\n" RESET);
return;
}
_entry* entry = getEntryArray(dictionary->entries, dictionary->capacity, key, hashLiteral(key), true);
if (entry != NULL) {