deal with eval errors
This commit is contained in:
parent
32bdc23ea7
commit
4a4cee6ee9
5 changed files with 31 additions and 3 deletions
|
|
@ -8,6 +8,8 @@ import { biggerExample, emptySet, factorial, higherOrder, higherOrder2Params, in
|
||||||
|
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import { evalExpr } from '../../eval/eval';
|
import { evalExpr } from '../../eval/eval';
|
||||||
|
import { Value } from '../other/Value';
|
||||||
|
import { Type } from '../other/Type';
|
||||||
|
|
||||||
|
|
||||||
const examples: [string, ExprBlockState][] = [
|
const examples: [string, ExprBlockState][] = [
|
||||||
|
|
@ -182,7 +184,13 @@ export function App() {
|
||||||
}}
|
}}
|
||||||
typeInfo={typeInfo}
|
typeInfo={typeInfo}
|
||||||
/>
|
/>
|
||||||
={evalExpr(currentState, extendedEnv)}
|
=
|
||||||
|
<Value dynamic={{
|
||||||
|
i: evalExpr(currentState, extendedEnv),
|
||||||
|
t: typeInfo.type,
|
||||||
|
}}/>
|
||||||
|
::
|
||||||
|
<Type type={typeInfo.type}/>
|
||||||
</GlobalContext>
|
</GlobalContext>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
import { getHumanReadableName, getSymbol, symbolDict, symbolDictIterator, symbolFunction, symbolList, symbolProduct, symbolSet, symbolSetIterator, symbolSum } from "dope2";
|
import { getHumanReadableName, getSymbol, symbolDict, symbolDictIterator, symbolFunction, symbolList, symbolProduct, symbolSet, symbolSetIterator, symbolSum } from "dope2";
|
||||||
|
|
||||||
import "./Type.css";
|
import "./Type.css";
|
||||||
|
import { ValueUnknown } from "./Value";
|
||||||
|
|
||||||
export function Type({type}) {
|
export function Type({type}) {
|
||||||
|
if (type === undefined) {
|
||||||
|
// Types are just values, and sometimes, when using a Type as a Value, the Type is unknown (e.g., because of an eval error when computing the type)
|
||||||
|
return <ValueUnknown/>;
|
||||||
|
}
|
||||||
const symbol = getSymbol(type);
|
const symbol = getSymbol(type);
|
||||||
switch (symbol) {
|
switch (symbol) {
|
||||||
case symbolFunction:
|
case symbolFunction:
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,8 @@
|
||||||
margin-right: 2px;
|
margin-right: 2px;
|
||||||
padding-left: 2px;
|
padding-left: 2px;
|
||||||
padding-right: 2px;
|
padding-right: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.valueUnknown {
|
||||||
|
color: darkgrey;
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import {getType, getInst, getSymbol, Double, Int, symbolFunction, symbolProduct, symbolSum, symbolDict, symbolSet, symbolList, eqType, match, getLeft, getRight, dict, Bool, set, Unit, symbolType, symbolUUID, getHumanReadableName, Ordering} from "dope2";
|
import {getType, getInst, getSymbol, Double, Int, symbolFunction, symbolProduct, symbolSum, symbolDict, symbolSet, symbolList, eqType, match, getLeft, getRight, dict, Bool, set, Unit, symbolType, symbolUUID, getHumanReadableName, Ordering, isTypeVar} from "dope2";
|
||||||
|
|
||||||
import "./Value.css";
|
import "./Value.css";
|
||||||
import { Type } from "./Type";
|
import { Type } from "./Type";
|
||||||
|
|
@ -6,6 +6,11 @@ import { Type } from "./Type";
|
||||||
export function Value({dynamic}) {
|
export function Value({dynamic}) {
|
||||||
const type = getType(dynamic);
|
const type = getType(dynamic);
|
||||||
const inst = getInst(dynamic);
|
const inst = getInst(dynamic);
|
||||||
|
if (inst === undefined) {
|
||||||
|
// Sometimes we only know the type of a value, not the value itself.
|
||||||
|
// For instance, if there is an evaluation error somewhere.
|
||||||
|
return <ValueUnknown/>;
|
||||||
|
}
|
||||||
if (eqType(type)(Double)) {
|
if (eqType(type)(Double)) {
|
||||||
return <ValueDouble val={inst}/>;
|
return <ValueDouble val={inst}/>;
|
||||||
}
|
}
|
||||||
|
|
@ -87,4 +92,7 @@ function ValueUUID({val}) {
|
||||||
}
|
}
|
||||||
function ValueOrdering({val}) {
|
function ValueOrdering({val}) {
|
||||||
return <span className="valueOrdering">{{[-1]: "LessThan", [0]: "Equal", [1]: "GreaterThan" }[val]}</span>
|
return <span className="valueOrdering">{{[-1]: "LessThan", [0]: "Equal", [1]: "GreaterThan" }[val]}</span>
|
||||||
|
}
|
||||||
|
export function ValueUnknown() {
|
||||||
|
return <span className="valueUnknown">unknown</span>
|
||||||
}
|
}
|
||||||
|
|
@ -49,7 +49,10 @@ export function evalCall(s: CallBlockState, env: DynamicEnvironment): EvalResult
|
||||||
const fn = evalExpr(s.fn, env);
|
const fn = evalExpr(s.fn, env);
|
||||||
const input = evalExpr(s.input, env);
|
const input = evalExpr(s.input, env);
|
||||||
if (fn !== undefined && input !== undefined) {
|
if (fn !== undefined && input !== undefined) {
|
||||||
return fn(input);
|
try {
|
||||||
|
return fn(input);
|
||||||
|
}
|
||||||
|
catch {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue