infer all types once at the root level, and pass the result down deeply
This commit is contained in:
parent
b2584a2495
commit
d000839878
6 changed files with 75 additions and 80 deletions
|
|
@ -1,14 +1,13 @@
|
|||
import { useContext } from "react";
|
||||
|
||||
import { EnvContext } from "../../context/EnvContext";
|
||||
import { ExprBlock, type ExprBlockState, type SetStateFn, type State2Props } from "./ExprBlock";
|
||||
import { GlobalContext } from "../../context/GlobalContext";
|
||||
|
||||
import { getActions } from "../app/actions";
|
||||
import "./CallBlock.css";
|
||||
import { CallContext } from "../../context/CallContext";
|
||||
import { inferTypeCall, type Environment } from "../../eval/infer_type";
|
||||
import { EnvContext } from "../../context/EnvContext";
|
||||
import { GlobalContext } from "../../context/GlobalContext";
|
||||
import { type Environment, type TypeInfoCall } from "../../eval/infer_type";
|
||||
import { getActions } from "../app/actions";
|
||||
import { Type } from "../other/Type";
|
||||
import "./CallBlock.css";
|
||||
import { ExprBlock, type ExprBlockState, type SetStateFn, type State2Props } from "./ExprBlock";
|
||||
|
||||
export interface CallBlockState {
|
||||
kind: "call";
|
||||
|
|
@ -19,9 +18,11 @@ export interface CallBlockState {
|
|||
export interface CallBlockProps<
|
||||
FnState=ExprBlockState,
|
||||
InputState=ExprBlockState,
|
||||
> extends State2Props<CallBlockState,ExprBlockState> {}
|
||||
> extends State2Props<CallBlockState,ExprBlockState> {
|
||||
typeInfo: TypeInfoCall;
|
||||
}
|
||||
|
||||
function nestedFnProperties({state, setState, score}: CallBlockProps, env: Environment) {
|
||||
function nestedFnProperties({state, setState, score, typeInfo}: CallBlockProps, env: Environment) {
|
||||
const setFn = (callback: SetStateFn) => {
|
||||
setState(state => ({...state, fn: callback(state.fn)}));
|
||||
};
|
||||
|
|
@ -31,10 +32,10 @@ function nestedFnProperties({state, setState, score}: CallBlockProps, env: Envir
|
|||
const scoreFn = (fnSuggestion: ExprBlockState) => {
|
||||
return score({ ...state, fn: fnSuggestion });
|
||||
};
|
||||
return {state: state.fn, setState: setFn, onCancel: onFnCancel, score: scoreFn};
|
||||
return {state: state.fn, setState: setFn, onCancel: onFnCancel, score: scoreFn, typeInfo: typeInfo.fn};
|
||||
}
|
||||
|
||||
function nestedInputProperties({state, setState, score}: CallBlockProps, env: Environment) {
|
||||
function nestedInputProperties({state, setState, score, typeInfo}: CallBlockProps, env: Environment) {
|
||||
const setInput = (callback: SetStateFn) => {
|
||||
setState(state => ({...state, input: callback(state.input)}));
|
||||
};
|
||||
|
|
@ -44,7 +45,7 @@ function nestedInputProperties({state, setState, score}: CallBlockProps, env: En
|
|||
const scoreInput = (inputSuggestion: ExprBlockState) => {
|
||||
return score({ ...state, input: inputSuggestion });
|
||||
};
|
||||
return {state: state.input, setState: setInput, onCancel: onInputCancel, score: scoreInput};
|
||||
return {state: state.input, setState: setInput, onCancel: onInputCancel, score: scoreInput, typeInfo: typeInfo.input};
|
||||
}
|
||||
|
||||
export function CallBlock(props: CallBlockProps) {
|
||||
|
|
@ -53,7 +54,6 @@ export function CallBlock(props: CallBlockProps) {
|
|||
const addParam = getActions(globalContext, props.setState).c;
|
||||
// const [resolved] = evalExprBlock(props.state, env);
|
||||
// return <span className={"functionBlock" + ((resolved.kind === "error") ? " unifyError" : "")}>
|
||||
const typeInfo = inferTypeCall(props.state, env);
|
||||
return <span className={"functionBlock"}>
|
||||
<CallContext value={{addParam}}>
|
||||
<FunctionHeader {...props} addParam={addParam} />
|
||||
|
|
@ -67,7 +67,7 @@ export function CallBlock(props: CallBlockProps) {
|
|||
{/* { (resolved.kind === "error") && resolved.e.toString()
|
||||
|| (resolved.kind === "value") && <Value dynamic={resolved} />
|
||||
|| "unknown" } */}
|
||||
:: <Type type={typeInfo.type} />
|
||||
:: <Type type={props.typeInfo.type} />
|
||||
</div>
|
||||
</div>
|
||||
</CallContext>
|
||||
|
|
@ -92,22 +92,21 @@ function FunctionHeader(props) {
|
|||
}
|
||||
}
|
||||
|
||||
function InputParams({ ...rest }) {
|
||||
function InputParams(props) {
|
||||
const env = useContext(EnvContext);
|
||||
const globalContext = useContext(GlobalContext);
|
||||
const typeInfo = inferTypeCall(rest.state, env);
|
||||
const inputEnv = typeInfo.fn.newEnv;
|
||||
const isOffending = typeInfo.err;
|
||||
const inputEnv = props.typeInfo.fn.newEnv;
|
||||
const isOffending = props.typeInfo.err;
|
||||
return <div className={"inputParam" + (isOffending ? " offending" : "")}>
|
||||
{rest.state.fn.kind === "call"
|
||||
{props.state.fn.kind === "call"
|
||||
&& globalContext?.syntacticSugar
|
||||
&& <InputParams
|
||||
{...nestedFnProperties(rest as CallBlockProps, env)}
|
||||
{...nestedFnProperties(props as CallBlockProps, env)}
|
||||
/>}
|
||||
{/* Our own input param */}
|
||||
<EnvContext value={inputEnv}>
|
||||
<ExprBlock
|
||||
{...nestedInputProperties(rest as CallBlockProps, env)}
|
||||
{...nestedInputProperties(props as CallBlockProps, env)}
|
||||
/>
|
||||
</EnvContext>
|
||||
</div>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue