progress with versioning

This commit is contained in:
Joeri Exelmans 2025-06-08 13:14:29 +02:00
parent e106ced1ec
commit d30f1312b6
2 changed files with 15 additions and 19 deletions

View file

@ -1,5 +1,5 @@
import { emptySet, add, length, forEach, union, has } from "../structures/set.js"; import { emptySet, add, length, forEach, has, remove } from "../structures/set.js";
import { getDepth, Slot, Value, Write } from "./value_slot.js"; import { getDepth, Slot } from "./value_slot.js";
import { compareSlot } from "./compare.js"; import { compareSlot } from "./compare.js";
import { makeTypeParser } from "../parser/type_parser.js"; import { makeTypeParser } from "../parser/type_parser.js";
import { newDynamic } from "../primitives/dynamic.js"; import { newDynamic } from "../primitives/dynamic.js";
@ -20,6 +20,10 @@ export const findLCA = slotA => slotB => {
} }
}; };
// returns
// {slotA} if slotA is younger
// {slotB} if slotB is younger
// {slotA, slotB} if they are concurrent (conflicting)
export const merge = slotA => slotB => { export const merge = slotA => slotB => {
const lca = findLCA(slotA)(slotB); const lca = findLCA(slotA)(slotB);
if (compareSlot(lca)(slotA) === 0) { if (compareSlot(lca)(slotA) === 0) {
@ -34,7 +38,7 @@ export const merge = slotA => slotB => {
}; };
export const mergeN = slots => { export const mergeN = slots => {
let toDelete = emptySetOfSlots; let result = slots;
forEach(slots)(slotA => { forEach(slots)(slotA => {
forEach(slots)(slotB => { forEach(slots)(slotB => {
// compare all non-identical pairs // compare all non-identical pairs
@ -44,26 +48,18 @@ export const mergeN = slots => {
// if in the pair, one is an ancestor of the other, // if in the pair, one is an ancestor of the other,
// only keep the other // only keep the other
if (has(m)(slotA)) { if (has(m)(slotA)) {
toDelete = add(toDelete)(slotB); result = remove(result)(slotB);
} }
} }
} }
}); });
}); });
let result = emptySetOfSlots;
forEach(slots)(slot => {
if (!has(toDelete)(slot)) {
result = add(result)(slot);
}
})
return result; return result;
}; };
const mkType = makeTypeParser({ const mkType = makeTypeParser({
extraPrimitives: [ extraPrimitives: [
["Value", Value], ["Slot" , Slot],
["Slot" , Slot ],
["Write", Write],
], ],
}); });

View file

@ -20,8 +20,8 @@ const [
[, {i: matchValue}], [, {i: matchValue}],
] = makeModuleEnum(Value)([ ] = makeModuleEnum(Value)([
{l: "literal" , r: Dynamic}, {l: "literal" , r: Dynamic},
{l: "read" , r: Write}, // a 'read' reads the result of a Write {l: "read" , r: Write}, // <- a 'read' reads the result of a Write (to a Slot)
{l: "transform", r: Transformation}, {l: "transform", r: Transformation}, // <- result of a function call
]); ]);
// Enum: Slot // Enum: Slot
@ -36,7 +36,7 @@ const [
{l: "write", r: Write}, {l: "write", r: Write},
]); ]);
// Struct: Transformation // Struct: Transformation (i.e., a function call)
const [ const [
// constructor // constructor
[, {i: newTransformation}], [, {i: newTransformation}],
@ -45,9 +45,9 @@ const [
// [, {i: getFn}], // [, {i: getFn}],
// [, {i: getOutput}], // [, {i: getOutput}],
] = makeModuleStruct(Transformation)([ ] = makeModuleStruct(Transformation)([
{l: "input" , r: Value }, {l: "input" , r: Value }, // <- the input is a value (e.g., could be the result of a Transformation itself)
{l: "fn" , r: Value }, {l: "fn" , r: Value }, // <- the function is also a value (e.g., could also be result of a transformation, e.g., when currying)
{l: "output", r: Dynamic}, {l: "output", r: Dynamic}, // <- the result
]); ]);
// Struct: Write // Struct: Write