refactor a bit
This commit is contained in:
parent
4fee37944d
commit
230916ceb1
12 changed files with 342 additions and 398 deletions
24
src/eval.ts
24
src/eval.ts
|
|
@ -4,6 +4,7 @@ import type { ExprBlockState } from "./ExprBlock";
|
|||
import type { InputValueType } from "./InputBlock";
|
||||
|
||||
const IS_DEV = (import.meta.env.MODE === "development");
|
||||
const VERBOSE = false;
|
||||
|
||||
export interface Environment {
|
||||
names: any;
|
||||
|
|
@ -43,12 +44,6 @@ export interface Unknown {
|
|||
// the value of every block is either known (Dynamic), an error, or unknown
|
||||
export type ResolvedType = Dynamic | DeepError | Unknown;
|
||||
|
||||
// export const evalEditorBlock = (s: ExprBlockState, env: Environment): [ResolvedType,Environment] => {
|
||||
// const [resolved] = proxyEditorBlock(s, env);
|
||||
// const [t, newEnv] = recomputeTypeVarsForEnv(resolved.t, env);
|
||||
// return [{...resolved, t }, newEnv];
|
||||
// };
|
||||
|
||||
class NotFoundError extends Error {}
|
||||
|
||||
export const evalEditorBlock = (s: ExprBlockState, env: Environment): [ResolvedType,Environment] => {
|
||||
|
|
@ -74,10 +69,10 @@ export function evalInputBlock(text: string, value: InputValueType, env: Environ
|
|||
const found = trie.get(env.names)(text);
|
||||
if (found) {
|
||||
if (found.kind === "unknown") {
|
||||
console.log('returning', text, 'as-is');
|
||||
// console.log('returning', text, 'as-is');
|
||||
return [found, env]; // don't rewrite lambda parameters
|
||||
}
|
||||
console.log('rewriting', text);
|
||||
// console.log('rewriting', text);
|
||||
return recomputeTypeVarsForEnv(text, found, env);
|
||||
}
|
||||
}
|
||||
|
|
@ -171,7 +166,7 @@ function evalCallBlock3(fnResolved: ResolvedType, inputResolved: ResolvedType, e
|
|||
const [abstractOutputType, env2] = makeTypeVar(env, "<out>");
|
||||
const matchFnType = fnType(_ => inputResolved.t)(_ => abstractOutputType);
|
||||
|
||||
if (IS_DEV) {
|
||||
if (VERBOSE) {
|
||||
console.log('========= evalCallBlock3 =========')
|
||||
console.log('env :', env);
|
||||
console.log('fnKind :', fnResolved.kind);
|
||||
|
|
@ -197,7 +192,7 @@ function evalCallBlock3(fnResolved: ResolvedType, inputResolved: ResolvedType, e
|
|||
// we don't want to 'bubble up' our outType substitution, because it's just a temporary variable
|
||||
const unificationWithoutOutType = new Map([...unification].filter(([symbol]) => symbol !== abstractOutputType.symbol));
|
||||
|
||||
if (IS_DEV) {
|
||||
if (VERBOSE) {
|
||||
console.log('unification :', prettyU(unification));
|
||||
console.log('unificationInvR :', prettyRU(unificationR));
|
||||
console.log('unifiedFnType :', prettyT(unifiedFnType));
|
||||
|
|
@ -212,7 +207,7 @@ function evalCallBlock3(fnResolved: ResolvedType, inputResolved: ResolvedType, e
|
|||
|
||||
// const grandUnification = unificationWithoutOutType;
|
||||
|
||||
if (IS_DEV) {
|
||||
if (VERBOSE) {
|
||||
console.log('grandUnification :', prettyU(grandUnification));
|
||||
console.log('==================================')
|
||||
}
|
||||
|
|
@ -278,8 +273,6 @@ function evalCallBlock3(fnResolved: ResolvedType, inputResolved: ResolvedType, e
|
|||
}
|
||||
throw e;
|
||||
}
|
||||
// }
|
||||
// throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -296,7 +289,7 @@ const prettyRU = (rUni: Map<string, Type>) => {
|
|||
export function evalLambdaBlock(paramName: string, expr: ExprBlockState, env: Environment): [ResolvedType,Environment] {
|
||||
const [paramType, staticInnerEnv] = makeTypeVar(env, paramName);
|
||||
|
||||
if (IS_DEV) {
|
||||
if (VERBOSE) {
|
||||
console.log('====== begin evalLambdaBlock ======')
|
||||
console.log('paramName :', paramName);
|
||||
console.log('paramType :', prettyT(paramType));
|
||||
|
|
@ -345,7 +338,7 @@ export function evalLambdaBlock(paramName: string, expr: ExprBlockState, env: En
|
|||
|
||||
// const [lambdaResolvedNormalized, resultEnv] = recomputeTypeVarsForEnv(paramName, lambdaResolved, env);
|
||||
|
||||
if (IS_DEV) {
|
||||
if (VERBOSE) {
|
||||
console.log('======= end evalLambdaBlock =======')
|
||||
console.log('paramType :', prettyT(paramType));
|
||||
console.log('exprType :', prettyT(exprResolved.t));
|
||||
|
|
@ -353,7 +346,6 @@ export function evalLambdaBlock(paramName: string, expr: ExprBlockState, env: En
|
|||
console.log('exprUnificationR :', prettyRU(reduced));
|
||||
console.log('lambdaType :', prettyT(lambdaT));
|
||||
console.log('lambdaTypeSubsituted:', prettyT(lambdaTSubstituted));
|
||||
// console.log('normalizedT :', prettyT(lambdaResolvedNormalized.t));
|
||||
console.log('===================================')
|
||||
}
|
||||
return [lambdaResolved, env];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue