wrote interpreter (independent of type inferencer)

This commit is contained in:
Joeri Exelmans 2025-05-26 15:34:50 +02:00
parent 2279c54229
commit 32bdc23ea7
6 changed files with 104 additions and 602 deletions

View file

@ -3,7 +3,7 @@ import { useContext } from "react";
import { CallContext } from "../../context/CallContext";
import { EnvContext } from "../../context/EnvContext";
import { GlobalContext } from "../../context/GlobalContext";
import { type Environment, type TypeInfoCall } from "../../eval/infer_type";
import { type StaticEnvironment, type TypeInfoCall } from "../../eval/infer_type";
import { getActions } from "../app/actions";
import { Type } from "../other/Type";
import "./CallBlock.css";
@ -22,7 +22,7 @@ export interface CallBlockProps<
typeInfo: TypeInfoCall;
}
function nestedFnProperties({state, setState, score, typeInfo}: CallBlockProps, env: Environment) {
function nestedFnProperties({state, setState, score, typeInfo}: CallBlockProps, env: StaticEnvironment) {
const setFn = (callback: SetStateFn) => {
setState(state => ({...state, fn: callback(state.fn)}));
};
@ -35,7 +35,7 @@ function nestedFnProperties({state, setState, score, typeInfo}: CallBlockProps,
return {state: state.fn, setState: setFn, onCancel: onFnCancel, score: scoreFn, typeInfo: typeInfo.fn};
}
function nestedInputProperties({state, setState, score, typeInfo}: CallBlockProps, env: Environment) {
function nestedInputProperties({state, setState, score, typeInfo}: CallBlockProps, env: StaticEnvironment) {
const setInput = (callback: SetStateFn) => {
setState(state => ({...state, input: callback(state.input)}));
};

View file

@ -5,7 +5,7 @@ import { trie } from "dope2";
import { CallContext } from "../../context/CallContext";
import { EnvContext } from "../../context/EnvContext";
import { GlobalContext } from "../../context/GlobalContext";
import { inferTypeInput, type Environment, type Type, type TypeInfoInput } from "../../eval/infer_type";
import { inferTypeInput, type StaticEnvironment, type Type, type TypeInfoInput } from "../../eval/infer_type";
import { getActions } from "../app/actions";
import { Input } from "../other/Input";
import { Type as TypeBlock } from "../other/Type";
@ -46,9 +46,11 @@ const attemptLiterals = [
const computeSuggestions = (
text: string,
env: Environment,
env: StaticEnvironment,
score: InputBlockProps['score'],
): PrioritizedSuggestionType[] => {
const startTime = performance.now();
const ls = [
...attemptLiterals
.filter(([_, test]) => test(text))
@ -69,9 +71,17 @@ const computeSuggestions = (
},
})),
];
const midTime = performance.now();
// return []; // <-- uncomment to disable suggestions (useful for debugging)
return ls.map((state) => [score(state), inferTypeInput(state, env).type, state] as PrioritizedSuggestionType)
const result = ls.map((state) => [score(state), inferTypeInput(state, env).type, state] as PrioritizedSuggestionType)
.sort(([a],[b]) => b-a);
const endTime = performance.now();
console.log(`computing suggestions took ${midTime-startTime} + ${endTime - midTime}`);
return result;
}
export function InputBlock({ state, setState, score, onCancel, typeInfo }: InputBlockProps) {