add deep evaluation + remove environment React context (passed via typeInfo instead) + improve highlighting of statically unknown values
This commit is contained in:
parent
8576f7cb8d
commit
8385f08923
10 changed files with 223 additions and 79 deletions
|
|
@ -1,13 +1,13 @@
|
|||
import { useContext } from "react";
|
||||
|
||||
import { CallContext } from "../../context/CallContext";
|
||||
import { EnvContext } from "../../context/EnvContext";
|
||||
import { GlobalContext } from "../../context/GlobalContext";
|
||||
import { type StaticEnvironment, type TypeInfoCall } from "../../eval/infer_type";
|
||||
import { type TypeInfoCall } from "../../eval/infer_type";
|
||||
import { getActions } from "../app/actions";
|
||||
import { Type, TypeInfoBlock } from "../other/Type";
|
||||
import { TypeInfoBlock } from "../other/Type";
|
||||
import "./CallBlock.css";
|
||||
import { ExprBlock, type ExprBlockState, type SetStateFn, type State2Props } from "./ExprBlock";
|
||||
import type { DeepEvalResultCall } from "../../eval/deep_eval";
|
||||
|
||||
export interface CallBlockState {
|
||||
kind: "call";
|
||||
|
|
@ -20,9 +20,10 @@ export interface CallBlockProps<
|
|||
InputState=ExprBlockState,
|
||||
> extends State2Props<CallBlockState,ExprBlockState> {
|
||||
typeInfo: TypeInfoCall;
|
||||
evalResult: DeepEvalResultCall;
|
||||
}
|
||||
|
||||
function nestedFnProperties({state, setState, score, typeInfo}: CallBlockProps, env: StaticEnvironment) {
|
||||
function nestedFnProperties({state, setState, score, typeInfo, evalResult}: CallBlockProps) {
|
||||
const setFn = (callback: SetStateFn) => {
|
||||
setState(state => ({...state, fn: callback(state.fn)}));
|
||||
};
|
||||
|
|
@ -32,10 +33,10 @@ function nestedFnProperties({state, setState, score, typeInfo}: CallBlockProps,
|
|||
const scoreFn = (fnSuggestion: ExprBlockState) => {
|
||||
return score({ ...state, fn: fnSuggestion });
|
||||
};
|
||||
return {state: state.fn, setState: setFn, onCancel: onFnCancel, score: scoreFn, typeInfo: typeInfo.fn};
|
||||
return {state: state.fn, setState: setFn, onCancel: onFnCancel, score: scoreFn, typeInfo: typeInfo.fn, evalResult: evalResult.fn};
|
||||
}
|
||||
|
||||
function nestedInputProperties({state, setState, score, typeInfo}: CallBlockProps, env: StaticEnvironment) {
|
||||
function nestedInputProperties({state, setState, score, typeInfo, evalResult}: CallBlockProps) {
|
||||
const setInput = (callback: SetStateFn) => {
|
||||
setState(state => ({...state, input: callback(state.input)}));
|
||||
};
|
||||
|
|
@ -45,7 +46,7 @@ function nestedInputProperties({state, setState, score, typeInfo}: CallBlockProp
|
|||
const scoreInput = (inputSuggestion: ExprBlockState) => {
|
||||
return score({ ...state, input: inputSuggestion });
|
||||
};
|
||||
return {state: state.input, setState: setInput, onCancel: onInputCancel, score: scoreInput, typeInfo: typeInfo.input};
|
||||
return {state: state.input, setState: setInput, onCancel: onInputCancel, score: scoreInput, typeInfo: typeInfo.input, evalResult: evalResult.input};
|
||||
}
|
||||
|
||||
export function CallBlock(props: CallBlockProps) {
|
||||
|
|
@ -69,9 +70,8 @@ export function CallBlock(props: CallBlockProps) {
|
|||
}
|
||||
|
||||
function FunctionHeader(props) {
|
||||
const env = useContext(EnvContext);
|
||||
const globalContext = useContext(GlobalContext);
|
||||
const nestedProperties = nestedFnProperties(props, env);
|
||||
const nestedProperties = nestedFnProperties(props);
|
||||
if (props.state.fn.kind === "call" && globalContext?.syntacticSugar) {
|
||||
// if the function we're calling is itself the result of a function call,
|
||||
// then we are anonymous, and so we don't draw a function name
|
||||
|
|
@ -87,21 +87,17 @@ function FunctionHeader(props) {
|
|||
}
|
||||
|
||||
function InputParams(props) {
|
||||
const env = useContext(EnvContext);
|
||||
const globalContext = useContext(GlobalContext);
|
||||
const inputEnv = props.typeInfo.fn.newEnv;
|
||||
const isOffending = props.typeInfo.err;
|
||||
return <div className={"inputParam" + (isOffending ? " offending" : "")}>
|
||||
{props.state.fn.kind === "call"
|
||||
&& globalContext?.syntacticSugar
|
||||
&& <InputParams
|
||||
{...nestedFnProperties(props as CallBlockProps, env)}
|
||||
{...nestedFnProperties(props as CallBlockProps)}
|
||||
/>}
|
||||
{/* Our own input param */}
|
||||
<EnvContext value={inputEnv}>
|
||||
<ExprBlock
|
||||
{...nestedInputProperties(props as CallBlockProps, env)}
|
||||
/>
|
||||
</EnvContext>
|
||||
<ExprBlock
|
||||
{...nestedInputProperties(props as CallBlockProps)}
|
||||
/>
|
||||
</div>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue