branching and very basic merging of slots

This commit is contained in:
Joeri Exelmans 2025-04-17 09:19:41 +02:00
parent 614e6c0fdb
commit 3978f7f835
32 changed files with 684 additions and 420 deletions

View file

@ -6,8 +6,8 @@ import { isFunction, prettyT } from '../structures/types.js';
import { ModuleStd } from '../stdlib.js';
import { Double, GenericType, Int, SymbolT, Type } from "../primitives/types.js";
import { eqType } from '../primitives/type.js';
import { Any } from '../typed.js';
import { assign, assignFn, makeGeneric, onlyOccurring } from '../generics/generics.js';
import { Any } from "../primitives/types.js";
import { assignFn, makeGeneric, onlyOccurring } from '../generics/generics.js';
// import {emitKeypressEvents} from 'node:readline';
@ -48,6 +48,15 @@ class Context {
this.types.getdefault(i, true).add(t);
this.types.getdefault(i, true).add(Any);
if (t.typeVars) {
// console.log("generic:", prettyT(t));
this.types.getdefault(t, true).add(GenericType);
}
else {
// console.log("non-generic:", prettyT(t));
this.types.getdefault(t, true).add(Type);
}
this.instances.getdefault(t, true).add(i);
this.instances.getdefault(Any, true).add(i);
}
@ -318,7 +327,7 @@ async function callFunction(fn, fnT) {
}
else {
inType = fnT.params[0];
choices = [...ctx.instances.getdefault(inType)].flatMap(i => toChoices([i, ctx.types.getdefault(i)]));
choices = [...ctx.instances.getdefault(inType)].flatMap(i => toChoices([i, [inType]]));
}
const choice = await select({
@ -337,7 +346,7 @@ async function callFunction(fn, fnT) {
i = await createInstance(inType);
t = inType;
if (i === undefined) {
return;
return callFunction(fn, fnT);
}
}
else {
@ -345,7 +354,8 @@ async function callFunction(fn, fnT) {
t = choice.t;
}
const genT = t.typeVars ? t : makeGeneric(() => t);
const assignedFnType = assignFn(fnT, genT);
const genFnT = fnT.typeVars ? fnT : makeGeneric(() => fnT);
const assignedFnType = assignFn(genFnT, genT);
await apply(i, fn, assignedFnType);
return callFunction(fn, fnT);
}
@ -417,11 +427,10 @@ async function transform(i, t) {
async function apply(i, fn, fnT) {
const result = fn(i);
// console.log(fn, '(', i, ')', '=', result);
let resultType;
// console.log(fnT);
if (fnT.typeVars) {
resultType = onlyOccurring(fnT.type.params[1], fnT.typeVars);
const res = onlyOccurring(fnT.type.params[1], fnT.typeVars);
resultType = res.typeVars.size > 0 ? res : res.type;
}
else {
resultType = fnT.params[1];