mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-26 05:42:07 +00:00
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
|
#include "dictionaryClass.h"
|
||
|
#include <string.h>
|
||
|
#include "garbageCollector.h"
|
||
|
|
||
|
u8 dictOneStrOneAll[] = { StringClass, VARARGCOUNT };
|
||
|
|
||
|
Dict_t* getEntry(Vector_t *v, char* name) {
|
||
|
vecForEach(Dict_t*, dict, v) {
|
||
|
if (!strcmp(name, dict->name)) {
|
||
|
return dict;
|
||
|
}
|
||
|
}
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
ClassFunction(dictSet) {
|
||
|
addPendingReference(args[1]);
|
||
|
char* arg = CpyStr(args[0]->string.value);
|
||
|
Dict_t* possibleEntry = getEntry(&caller->dictionary.vector, arg);
|
||
|
if (possibleEntry == NULL) {
|
||
|
Dict_t a = { .name = arg, .var = args[1] };
|
||
|
vecAdd(&caller->dictionary.vector, a);
|
||
|
}
|
||
|
else {
|
||
|
possibleEntry->var = args[1];
|
||
|
free(arg);
|
||
|
}
|
||
|
return &emptyClass;
|
||
|
}
|
||
|
|
||
|
ClassFunctionTableEntry_t dictFunctions[] = {
|
||
|
{"set", dictSet, 2, dictOneStrOneAll},
|
||
|
};
|
||
|
|
||
|
Variable_t getDictMember(Variable_t* var, char* memberName) {
|
||
|
if (!strcmp(memberName, "set"))
|
||
|
return getGenericFunctionMember(var, memberName, dictFunctions, ARRAY_SIZE(dictFunctions));
|
||
|
|
||
|
vecForEach(Dict_t*, dict, (&var->dictionary.vector)) {
|
||
|
if (!strcmp(dict->name, memberName)) {
|
||
|
Variable_t a = { 0 };
|
||
|
a.variableType = ReferenceType;
|
||
|
a.referenceType = dict->var;
|
||
|
addPendingReference(dict->var);
|
||
|
return a;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return (Variable_t) { 0 };
|
||
|
}
|