more progress

This commit is contained in:
Joeri Exelmans 2025-05-12 11:11:18 +02:00
parent 2b0d8bc2c6
commit ebae0afc81
7 changed files with 94 additions and 21 deletions

View file

@ -1,4 +1,4 @@
import {getType, getInst, getSymbol, Double, Int, symbolFunction, symbolProduct, symbolSum, symbolDict, symbolSet, symbolList, eqType, match, getLeft, getRight} from "dope2";
import {getType, getInst, getSymbol, Double, Int, symbolFunction, symbolProduct, symbolSum, symbolDict, symbolSet, symbolList, eqType, match, getLeft, getRight, dict} from "dope2";
import "./Value.css";
@ -11,6 +11,7 @@ export function Value({dynamic}) {
if (eqType(type)(Int)) {
return <ValueInt val={inst}/>;
}
const symbol = getSymbol(type);
switch (symbol) {
case symbolFunction:
@ -20,10 +21,13 @@ export function Value({dynamic}) {
// return <BinaryType type={type} cssClass="productType" infix="&#10799;" prefix="" suffix=""/>;
case symbolSum:
return <ValueSum val={inst} leftType={type.params[0](type)} rightType={type.params[1](type)}/>;
case symbolProduct:
return <ValueProduct val={inst} leftType={type.params[0](type)} rightType={type.params[1](type)}/>;
case symbolProduct:
return <ValueProduct val={inst} leftType={type.params[0](type)} rightType={type.params[1](type)}/>;
// case symbolDict:
case symbolDict:
return <ValueDict val={inst} keyType={type.params[0](type)} valueType={type.params[1](type)}/>;
// return <BinaryType type={type} cssClass="dictType" infix="&rArr;" prefix="{" suffix="}"/>;
// case symbolSet:
// return <UnaryType type={type} cssClass="setType" prefix="{" suffix="}" />;
@ -36,10 +40,10 @@ export function Value({dynamic}) {
}
function ValueDouble({val}) {
return <span className="value">{val.toString()}</span>;
return <span className="valuePrimitive">{val.toString()}</span>;
}
function ValueInt({val}) {
return <span className="value">{val.toString()}</span>;
return <span className="valuePrimitive">{val.toString()}</span>;
}
function ValueFunction() {
return <>&#119891;&#119899;&nbsp;</>;
@ -52,9 +56,29 @@ function List({val, elemType}) {
}
function ValueSum({val, leftType, rightType}) {
return match(val)
(l => <>L <Value dynamic={{i:l, t:leftType}}/></>)
(r => <>R <Value dynamic={{i:r, t:rightType}}/></>);
(l => <span className="sumType">L <Value dynamic={{i:l, t:leftType}}/></span>)
(r => <span className="sumType">R <Value dynamic={{i:r, t:rightType}}/></span>);
}
function ValueProduct({val, leftType, rightType}) {
return <>(<Value dynamic={{i:getLeft(val), t:leftType}}/>,&nbsp;<Value dynamic={{i:getRight(val), t:rightType}} />)</>;
return <span className="productType">(<Value dynamic={{i:getLeft(val), t:leftType}}/>,&nbsp;<Value dynamic={{i:getRight(val), t:rightType}} />)</span>;
}
function ValueDict({val, keyType, valueType}) {
let i=0;
return <span className="dictType">{'{'}<>{
dict.fold
(acc => key => value => {
console.log({acc, key, value});
return acc.concat([<>
<Value key={i++} dynamic={{i: key, t: keyType}}/>
&rArr;
<Value key={i++} dynamic={{i: value, t: valueType}}/>
</>]);
})
([])
(val)
.map(result => {
console.log(result);
return result;
})
}</>{'}'}</span>;
}