lotta progress

This commit is contained in:
Joeri Exelmans 2025-03-23 13:25:47 +01:00
parent 29d20b2273
commit bc91d9bf39
27 changed files with 317 additions and 475 deletions

98
main.js
View file

@ -1,38 +1,28 @@
import {Function, ModuleMetaCircular, getIn, getOut} from "./metacircular.js";
import {ModuleTyped} from "./typed.js";
import {ModuleBool} from "./primitives/bool.js";
import { Double_to_Double_to_Double, ModuleDouble, mulDouble } from "./primitives/double.js";
import {Int_to_Int_to_Int, ModuleInt, mulInt} from "./primitives/int.js";
import { makeSquare } from "./lib/square.js";
import {makeIdFn} from "./lib/id.js";
import {DefaultMap, pretty} from "./util.js";
import { ModuleModule } from "./structures/list_types/module.js";
import { ModuleList } from "./structures/list.js";
import {Int, Bool, Double, Byte} from "./primitives/symbols.js";
import { makeListModule } from "./structures/list_common.js";
import { makeProductType } from "./structures/product.js";
import { makeSumType } from "./structures/sum.js";
import { sumType } from "./structures/sum.js";
import { prodType } from "./structures/product.js";
import { lsType } from "./structures/list_common.js";
import { select } from '@inquirer/prompts';
import { ModulePoint } from "./lib/point.js";
import { DefaultMap, pretty } from './util.js';
import { symbolFunction } from './structures/types.js';
import { ModuleStd } from './stdlib.js';
class Context {
constructor(mod) {
this.functionsFrom = new DefaultMap(() => []);
this.functionsTo = new DefaultMap(() => []);
this.types = new DefaultMap(() => []);
this.instances = new DefaultMap(() => []);
this.functionsFrom = new DefaultMap(() => []); // type to outgoing function
this.functionsTo = new DefaultMap(() => []); // type to incoming function
this.types = new DefaultMap(() => []); // instance to type
this.instances = new DefaultMap(() => []); // type to instance
for (const {i, t} of mod.l) {
this.types.getdefault(i, true).push(t);
this.instances.getdefault(t, true).push(i);
}
for (const fnType of this.instances.getdefault(Function)) {
for (const fn of this.instances.getdefault(fnType)) {
this.functionsFrom.getdefault(getIn(fnType), true).push(fn);
this.functionsTo.getdefault(getOut(fnType), true).push(fn);
for (const [i, types] of this.instances.m.entries()) {
for (const t of types) {
if (t.symbol === symbolFunction) {
// 'i' is a function
this.functionsFrom.getdefault(t.params[0], true).push(i);
this.functionsFrom.getdefault(t.params[1], true).push(i);
}
}
}
}
@ -68,62 +58,8 @@ class Context {
// }
}
const ListOfDouble = lsType(Double);
const ListOfDoubleModule = makeListModule(Double);
const ListOfListOfDouble = lsType(ListOfDouble);
const ListOfListOfDoubleModule = makeListModule(ListOfDouble);
const ListOfByte = lsType(Byte);
const ListOfByteModule = makeListModule(Byte);
const ModuleValues = {l:[
{i: 0n, t: Int},
{i: 42n, t: Int},
{i: false, t: Bool},
{i: 3.14159265359, t: Double},
{i: {l:[4.2, 7.6]} , t: ListOfDouble},
{i: {l:[{l:[4.2, 7.6]}, {l:[4.3]}]}, t: ListOfListOfDouble},
{i: new Uint8Array([1,2,3]), t: ListOfByte},
// i'm lazy
...ListOfDoubleModule.l,
...ListOfListOfDoubleModule.l,
...ListOfByteModule.l,
...makeProductType(Int, Bool).l,
...makeSumType(Int, Bool).l,
{i: {left: 42n, right: true}, t: prodType(Int, Bool)},
{i: {variant: "L", value: 100n}, t: sumType(Int, Bool)},
]};
import { select } from '@inquirer/prompts';
import { ModulePoint } from "./lib/point.js";
const ctx = new Context({l:[
// ...ModuleMetaCircular.l,
// ...ModuleTyped.l,
// // ...ModuleConformable,
// // ...ModuleConformanceCheckConforms,
// // ...ModuleNum,
// // ...ModuleEq,
// ...ModuleBool.l,
// ...ModuleInt.l,
// ...ModuleDouble.l,
// // ...ModuleSquare,
// // ...ModuleList,
// ...makeIdFn(Int).l,
// ...makeSquare({i: mulInt, t: Int_to_Int_to_Int}).l,
// ...makeSquare({i: mulDouble, t: Double_to_Double_to_Double}).l,
// ...ModuleList.l,
// ...ModuleValues.l,
// ...ModuleModule.l,
...ModuleStd.l,
...ModulePoint.l,
]});