Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active February 25, 2019 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pervognsen/f3783c756c1dfd600b104dcb1df8204d to your computer and use it in GitHub Desktop.
Save pervognsen/f3783c756c1dfd600b104dcb1df8204d to your computer and use it in GitHub Desktop.
func normalize_func(type: Type*): Type* {
key: char[];
num_params := alen(type.tfunc.params);
for (i := 0; i < num_params; i++) {
param := normalize(type.tfunc.params[i]);
acatn(key, (:char*)param, sizeof(param));
}
ret := normalize(type.tfunc.ret);
acatn(key, (:char*)ret, sizeof(ret));
normalized := agetn(normalized_funcs, key, alen(key));
if (!normalized) {
params: TypeFuncParam[];
for (i := 0; i < num_params; i++) {
apush(params, {type = normalize(type.tfunc.params[i])});
}
normalized = new Type{kind = TYPE_FUNC, tfunc = {params = params, ret = ret}};
aputn(normalized_funcs, key, alen(key), normalized);
}
return normalized;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment