self-host fonts; proper error bubbling
This commit is contained in:
parent
68104a8102
commit
46baad7cf4
8 changed files with 63 additions and 34 deletions
37
src/eval.ts
37
src/eval.ts
|
|
@ -1,4 +1,4 @@
|
|||
import { assignFnSubstitutions, dict, Double, fnType, getSymbol, growEnv, Int, makeGeneric, NotAFunctionError, prettyT, set, substitute, symbolFunction, trie, TYPE_VARS, UnifyError } from "dope2";
|
||||
import { assignFnSubstitutions, dict, Double, fnType, getSymbol, growEnv, Int, NotAFunctionError, prettyT, substitute, symbolFunction, trie, TYPE_VARS, UnifyError } from "dope2";
|
||||
|
||||
import type { EditorState } from "./Editor";
|
||||
import type { InputValueType, SuggestionType } from "./InputBlock";
|
||||
|
|
@ -68,13 +68,16 @@ export function evalInputBlock(text: string, value: InputValueType, env): Resolv
|
|||
...found,
|
||||
substitutions: new Map(),
|
||||
};
|
||||
} else {
|
||||
return entirelyUnknown(env);
|
||||
}
|
||||
}
|
||||
else { // kind === "text" -> unresolved
|
||||
return entirelyUnknown(env);
|
||||
}
|
||||
// kind === "text" -> unresolved
|
||||
return {
|
||||
kind: "error",
|
||||
t: getUnusedTypeVar(env),
|
||||
e: new Error(`'${text}' not found`),
|
||||
depth: 0,
|
||||
substitutions: new Map(),
|
||||
};
|
||||
}
|
||||
|
||||
const mergeMaps = (...maps: Map<Type,Type>[]) => {
|
||||
|
|
@ -166,7 +169,8 @@ export function evalCallBlock(fn: EditorState, input: EditorState, env): Resolve
|
|||
|
||||
export function evalLetInBlock(value: EditorState, name: string, inner: EditorState, env): ResolvedType {
|
||||
const valueResolved = evalEditorBlock(value, env);
|
||||
const innerEnv = makeInnerEnv(env, name, valueResolved)
|
||||
// console.log('eval', name, '...', valueResolved.kind, valueResolved.e);
|
||||
const innerEnv = makeInnerEnv(env, name, valueResolved);
|
||||
return evalEditorBlock(inner, innerEnv);
|
||||
}
|
||||
|
||||
|
|
@ -181,14 +185,29 @@ export function getUnusedTypeVar(env) {
|
|||
export function evalLambdaBlock(paramName: string, expr: EditorState, env): ResolvedType {
|
||||
const paramType = getUnusedTypeVar(env);
|
||||
// static env: we only know the name and the type
|
||||
const staticInnerEnv = makeInnerEnv(env, paramName, {
|
||||
const staticInnerEnv = growEnv(env)(paramName)({
|
||||
kind: "unknown", // parameter value is not statically known
|
||||
t: paramType,
|
||||
substitutions: new Map(),
|
||||
});
|
||||
})
|
||||
// const staticInnerEnv = makeInnerEnv(env, paramName, {
|
||||
// kind: "unknown", // parameter value is not statically known
|
||||
// t: paramType,
|
||||
// substitutions: new Map(),
|
||||
// });
|
||||
const exprResolved = evalEditorBlock(expr, staticInnerEnv);
|
||||
const lambdaT = fnType(_ => paramType)(_ => exprResolved.t);
|
||||
const lambdaTSubstituted = substitute(lambdaT, exprResolved.substitutions, []);
|
||||
// console.log('inner kind', exprResolved.kind, paramName);
|
||||
if (exprResolved.kind === "error") {
|
||||
return {
|
||||
kind: "error",
|
||||
t: lambdaTSubstituted,
|
||||
depth: 0,
|
||||
e: exprResolved.e,
|
||||
substitutions: staticInnerEnv.substitutions,
|
||||
}
|
||||
}
|
||||
const paramTypeSubstituted = lambdaTSubstituted.params[0](lambdaTSubstituted);
|
||||
const fn = (x: any) => {
|
||||
const innerEnv = makeInnerEnv(env, paramName, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue