parser for types + start moving all types to separate modules

This commit is contained in:
Joeri Exelmans 2025-05-06 23:41:12 +02:00
parent 8eec5b9239
commit 1d826ea8d4
11 changed files with 277 additions and 88 deletions

View file

@ -96,7 +96,7 @@ export const mergeTwoWay = (m1, m2) => {
// fType, aType: generic types to unify
// fStack, aStack: internal use.
const __unify = (typeVars, fType, aType, fStack=[], aStack=[]) => {
console.log("__unify", {typeVars, fType, aType, fStack, aStack});
// console.log("__unify", {typeVars, fType, aType, fStack, aStack});
if (typeVars.has(fType)) {
// simplest case: formalType is a type paramater
// => substitute with actualType
@ -182,12 +182,13 @@ const __unify = (typeVars, fType, aType, fStack=[], aStack=[]) => {
export const unify = (fGenericType, aGenericType) => {
let allTypeVars;
[allTypeVars, fGenericType, aGenericType] = safeUnionTypeVars(fGenericType, aGenericType);
const {genericType} = __unify(allTypeVars, fGenericType.type, aGenericType.type);
const {genericType, substitutions} = __unify(allTypeVars, fGenericType.type, aGenericType.type);
// console.log('unification complete! substitutions:', substitutions);
return recomputeTypeVars(genericType);
};
export const substitute = (type, substitutions, stack=[]) => {
console.log('substitute...', {type, substitutions, stack});
// console.log('substitute...', {type, substitutions, stack});
return substitutions.get(type)
|| {
symbol: type.symbol,