remove IEvArrayString, implement __result__, cleanups
This commit is contained in:
parent
065a7aeec0
commit
43635bd39b
|
@ -152,12 +152,6 @@ export const ExpressionViewer: React.FC<Props> = ({ value, width }) => {
|
|||
// {() => value.value}
|
||||
// </VariableBox>
|
||||
// );
|
||||
case SqValueTag.ArrayString:
|
||||
return (
|
||||
<VariableBox value={value} heading="Array String">
|
||||
{() => value.value.map((r) => `"${r}"`).join(", ")}
|
||||
</VariableBox>
|
||||
);
|
||||
case SqValueTag.Date:
|
||||
return (
|
||||
<VariableBox value={value} heading="Date">
|
||||
|
@ -242,24 +236,24 @@ export const ExpressionViewer: React.FC<Props> = ({ value, width }) => {
|
|||
</VariableBox>
|
||||
);
|
||||
}
|
||||
case SqValueTag.Module: {
|
||||
return (
|
||||
<VariableList value={value} heading="Module">
|
||||
{(_) =>
|
||||
value.value
|
||||
.entries()
|
||||
.filter(([key, _]) => !key.match(/^(__result__)$/))
|
||||
.map(([key, r]) => (
|
||||
<ExpressionViewer
|
||||
key={key}
|
||||
value={r}
|
||||
width={width !== undefined ? width - 20 : width}
|
||||
/>
|
||||
))
|
||||
}
|
||||
</VariableList>
|
||||
);
|
||||
}
|
||||
// case SqValueTag.Module: {
|
||||
// return (
|
||||
// <VariableList value={value} heading="Module">
|
||||
// {(_) =>
|
||||
// value.value
|
||||
// .entries()
|
||||
// .filter(([key, _]) => !key.match(/^(__result__)$/))
|
||||
// .map(([key, r]) => (
|
||||
// <ExpressionViewer
|
||||
// key={key}
|
||||
// value={r}
|
||||
// width={width !== undefined ? width - 20 : width}
|
||||
// />
|
||||
// ))
|
||||
// }
|
||||
// </VariableList>
|
||||
// );
|
||||
// }
|
||||
case SqValueTag.Record:
|
||||
const plot = makePlot(value.value);
|
||||
if (plot) {
|
||||
|
|
|
@ -4,7 +4,7 @@ open Reducer_TestHelpers
|
|||
describe("Parse ternary operator", () => {
|
||||
testParseToBe(
|
||||
"true ? 'YES' : 'NO'",
|
||||
"Ok({(:$$_ternary_$$ true 'YES' 'NO')})",
|
||||
"Ok(true ? ('YES') : ('NO'))",
|
||||
)
|
||||
})
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ describe("eval", () => {
|
|||
testEvalToBe("(1+2)*3", "Ok(9)")
|
||||
testEvalToBe("2>1", "Ok(true)")
|
||||
testEvalToBe("concat('a ', 'b')", "Ok('a b')")
|
||||
testEvalToBe("concat([3,4], [5,6,7])", "Ok([3,4,5,6,7])")
|
||||
testEvalToBe("log(10)", "Ok(2.302585092994046)")
|
||||
testEvalToBe("cos(10)", "Ok(-0.8390715290764524)")
|
||||
// TODO more built ins
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as RSRecord from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Record.gen";
|
||||
import { wrapValue } from "./SqValue";
|
||||
import { SqRecordValue, wrapValue } from "./SqValue";
|
||||
import { SqValueLocation } from "./SqValueLocation";
|
||||
|
||||
type T = RSRecord.squiggleValue_Record;
|
||||
|
@ -16,4 +16,11 @@ export class SqRecord {
|
|||
toString() {
|
||||
return RSRecord.toString(this._value);
|
||||
}
|
||||
|
||||
asValue() {
|
||||
return new SqRecordValue(
|
||||
RSRecord.toSquiggleValue(this._value),
|
||||
this.location
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,14 +44,6 @@ export class SqArrayValue extends SqAbstractValue {
|
|||
}
|
||||
}
|
||||
|
||||
export class SqArrayStringValue extends SqAbstractValue {
|
||||
tag = Tag.ArrayString as const;
|
||||
|
||||
get value() {
|
||||
return this.valueMethod(RSValue.getArrayString);
|
||||
}
|
||||
}
|
||||
|
||||
export class SqBoolValue extends SqAbstractValue {
|
||||
tag = Tag.Bool as const;
|
||||
|
||||
|
@ -150,7 +142,6 @@ export class SqVoidValue extends SqAbstractValue {
|
|||
|
||||
const tagToClass = {
|
||||
[Tag.Array]: SqArrayValue,
|
||||
[Tag.ArrayString]: SqArrayStringValue,
|
||||
[Tag.Bool]: SqBoolValue,
|
||||
[Tag.Date]: SqDateValue,
|
||||
[Tag.Declaration]: SqDeclarationValue,
|
||||
|
@ -169,7 +160,6 @@ const tagToClass = {
|
|||
// type SqValue = typeof tagToClass[keyof typeof tagToClass];
|
||||
export type SqValue =
|
||||
| SqArrayValue
|
||||
| SqArrayStringValue
|
||||
| SqBoolValue
|
||||
| SqDateValue
|
||||
| SqDeclarationValue
|
||||
|
|
|
@ -13,9 +13,6 @@ type squiggleValue_Lambda = ForTS_SquiggleValue_Lambda.squiggleValue_Lambda //us
|
|||
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
||||
external svtArray_: string = "Array"
|
||||
|
||||
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
||||
external svtArrayString_: string = "ArrayString"
|
||||
|
||||
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
||||
external svtBool_: string = "Bool"
|
||||
|
||||
|
@ -61,7 +58,6 @@ external castEnum: string => squiggleValueTag = "%identity"
|
|||
let getTag = (variant: squiggleValue): squiggleValueTag =>
|
||||
switch variant {
|
||||
| IEvArray(_) => svtArray_->castEnum
|
||||
| IEvArrayString(_) => svtArrayString_->castEnum
|
||||
| IEvBool(_) => svtBool_->castEnum
|
||||
| IEvDate(_) => svtDate_->castEnum
|
||||
| IEvDeclaration(_) => svtDeclaration_->castEnum
|
||||
|
@ -94,13 +90,6 @@ let getArray = (variant: squiggleValue): option<squiggleValue_Array> =>
|
|||
| _ => None
|
||||
}
|
||||
|
||||
@genType
|
||||
let getArrayString = (variant: squiggleValue): option<array<string>> =>
|
||||
switch variant {
|
||||
| IEvArrayString(value) => value->Some
|
||||
| _ => None
|
||||
}
|
||||
|
||||
@genType
|
||||
let getBool = (variant: squiggleValue): option<bool> =>
|
||||
switch variant {
|
||||
|
|
|
@ -7,3 +7,6 @@ let getKeyValuePairs = (value: squiggleValue_Record): array<(string, squiggleVal
|
|||
|
||||
@genType
|
||||
let toString = (v: squiggleValue_Record) => ReducerInterface_InternalExpressionValue.toStringMap(v)
|
||||
|
||||
@genType
|
||||
let toSquiggleValue = (v: squiggleValue_Record): squiggleValue => IEvRecord(v)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
export enum squiggleValueTag {
|
||||
Array = "Array",
|
||||
ArrayString = "ArrayString",
|
||||
Bool = "Bool",
|
||||
Date = "Date",
|
||||
Declaration = "Declaration",
|
||||
|
|
|
@ -93,4 +93,57 @@ let library = [
|
|||
}
|
||||
}
|
||||
),
|
||||
makeFn(
|
||||
"concat",
|
||||
[FRTypeString, FRTypeString],
|
||||
inputs => {
|
||||
switch inputs {
|
||||
| [IEvString(a), IEvString(b)] => {
|
||||
let answer = Js.String2.concat(a, b)
|
||||
answer->Reducer_T.IEvString->Ok
|
||||
}
|
||||
| _ => Error(impossibleError)
|
||||
}
|
||||
}
|
||||
),
|
||||
makeFn(
|
||||
"concat",
|
||||
[FRTypeArray(FRTypeAny), FRTypeArray(FRTypeAny)],
|
||||
inputs => {
|
||||
switch inputs {
|
||||
| [IEvArray(originalA), IEvArray(b)] => {
|
||||
let a = originalA->Js.Array2.copy
|
||||
let _ = Js.Array2.pushMany(a, b)
|
||||
a->Reducer_T.IEvArray->Ok
|
||||
}
|
||||
| _ => Error(impossibleError)
|
||||
}
|
||||
}
|
||||
),
|
||||
makeFn(
|
||||
"inspect",
|
||||
[FRTypeAny],
|
||||
inputs => {
|
||||
switch inputs {
|
||||
| [value] => {
|
||||
Js.log(value->ReducerInterface_InternalExpressionValue.toString)
|
||||
value->Ok
|
||||
}
|
||||
| _ => Error(impossibleError)
|
||||
}
|
||||
}
|
||||
),
|
||||
makeFn(
|
||||
"inspect",
|
||||
[FRTypeAny, FRTypeString],
|
||||
inputs => {
|
||||
switch inputs {
|
||||
| [value, IEvString(label)] => {
|
||||
Js.log(`${label}: ${value->ReducerInterface_InternalExpressionValue.toString}`)
|
||||
value->Ok
|
||||
}
|
||||
| _ => Error(impossibleError)
|
||||
}
|
||||
}
|
||||
),
|
||||
]
|
||||
|
|
|
@ -34,15 +34,15 @@ let callInternal = (
|
|||
| call => call->IEV.toStringFunctionCall->MathJs.Eval.eval
|
||||
}
|
||||
|
||||
let doAddArray = (originalA, b) => {
|
||||
let a = originalA->Js.Array2.copy
|
||||
let _ = Js.Array2.pushMany(a, b)
|
||||
a->Reducer_T.IEvArray->Ok
|
||||
}
|
||||
let doAddString = (a, b) => {
|
||||
let answer = Js.String2.concat(a, b)
|
||||
answer->Reducer_T.IEvString->Ok
|
||||
}
|
||||
// let doAddArray = (originalA, b) => {
|
||||
// let a = originalA->Js.Array2.copy
|
||||
// let _ = Js.Array2.pushMany(a, b)
|
||||
// a->Reducer_T.IEvArray->Ok
|
||||
// }
|
||||
// let doAddString = (a, b) => {
|
||||
// let answer = Js.String2.concat(a, b)
|
||||
// answer->Reducer_T.IEvString->Ok
|
||||
// }
|
||||
|
||||
let inspect = (value: Reducer_T.value) => {
|
||||
Js.log(value->IEV.toString)
|
||||
|
@ -107,10 +107,10 @@ let callInternal = (
|
|||
// | ("$_typeTuple_$", [IEvArray(elems)]) => TypeBuilder.typeTuple(elems)
|
||||
// | ("$_typeArray_$", [elem]) => TypeBuilder.typeArray(elem)
|
||||
// | ("$_typeRecord_$", [IEvRecord(propertyMap)]) => TypeBuilder.typeRecord(propertyMap)
|
||||
| ("concat", [IEvArray(aValueArray), IEvArray(bValueArray)]) =>
|
||||
doAddArray(aValueArray, bValueArray)
|
||||
| ("concat", [IEvString(aValueString), IEvString(bValueString)]) =>
|
||||
doAddString(aValueString, bValueString)
|
||||
// | ("concat", [IEvArray(aValueArray), IEvArray(bValueArray)]) =>
|
||||
// doAddArray(aValueArray, bValueArray)
|
||||
// | ("concat", [IEvString(aValueString), IEvString(bValueString)]) =>
|
||||
// doAddString(aValueString, bValueString)
|
||||
| ("inspect", [value, IEvString(label)]) => inspectLabel(value, label)
|
||||
| ("inspect", [value]) => inspect(value)
|
||||
| (_, [IEvBool(_)])
|
||||
|
|
|
@ -6,8 +6,6 @@ type expression = Reducer_T.expression
|
|||
|
||||
let eArray = (anArray: array<T.expression>) => anArray->T.EArray
|
||||
|
||||
let eArrayString = anArray => anArray->T.IEvArrayString->T.EValue
|
||||
|
||||
let eBool = aBool => aBool->T.IEvBool->T.EValue
|
||||
|
||||
let eCall = (fn: expression, args: array<expression>): expression => T.ECall(fn, args)
|
||||
|
|
|
@ -11,11 +11,7 @@ let set = (namespace: t, id: string, value): t => {
|
|||
|
||||
let mergeFrom = (from: t, to: t): t => {
|
||||
to->Belt.Map.String.reduce(from, (namespace, key, value) => {
|
||||
if key != "__result__" {
|
||||
namespace->set(key, value)
|
||||
} else {
|
||||
namespace
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ type environment = GenericDist.env
|
|||
@genType.opaque
|
||||
type rec value =
|
||||
| IEvArray(arrayValue)
|
||||
| IEvArrayString(array<string>)
|
||||
| IEvBool(bool)
|
||||
| IEvDate(Js.Date.t)
|
||||
| IEvDeclaration(lambdaDeclaration)
|
||||
|
|
|
@ -17,7 +17,6 @@ type functionCall = (string, array<t>)
|
|||
let rec toString = (aValue: T.value) =>
|
||||
switch aValue {
|
||||
| IEvArray(anArray) => toStringArray(anArray)
|
||||
| IEvArrayString(anArray) => toStringArrayString(anArray)
|
||||
| IEvBool(aBool) => toStringBool(aBool)
|
||||
| IEvDate(date) => toStringDate(date)
|
||||
| IEvDeclaration(d) => toStringDeclaration(d)
|
||||
|
@ -35,10 +34,6 @@ and toStringArray = anArray => {
|
|||
let args = anArray->Js.Array2.map(each => toString(each))->Js.Array2.toString
|
||||
`[${args}]`
|
||||
}
|
||||
and toStringArrayString = anArray => {
|
||||
let args = anArray->Js.Array2.toString
|
||||
`[${args}]`
|
||||
}
|
||||
and toStringBool = aBool => Js.String.make(aBool)
|
||||
and toStringCall = fName => `:${fName}`
|
||||
and toStringDate = date => DateTime.Date.toString(date)
|
||||
|
@ -69,7 +64,6 @@ and toStringMap = aMap => {
|
|||
let toStringWithType = (aValue: T.value) =>
|
||||
switch aValue {
|
||||
| IEvArray(_) => `Array::${toString(aValue)}`
|
||||
| IEvArrayString(_) => `ArrayString::${toString(aValue)}`
|
||||
| IEvBool(_) => `Bool::${toString(aValue)}`
|
||||
| IEvDate(_) => `Date::${toString(aValue)}`
|
||||
| IEvDeclaration(_) => `Declaration::${toString(aValue)}`
|
||||
|
@ -116,7 +110,6 @@ let toStringResultRecord = x =>
|
|||
|
||||
type internalExpressionValueType =
|
||||
| EvtArray
|
||||
| EvtArrayString
|
||||
| EvtBool
|
||||
| EvtDate
|
||||
| EvtDeclaration
|
||||
|
@ -137,7 +130,6 @@ type functionDefinitionSignature =
|
|||
let valueToValueType = (value: T.value) =>
|
||||
switch value {
|
||||
| IEvArray(_) => EvtArray
|
||||
| IEvArrayString(_) => EvtArrayString
|
||||
| IEvBool(_) => EvtBool
|
||||
| IEvDate(_) => EvtDate
|
||||
| IEvDeclaration(_) => EvtDeclaration
|
||||
|
@ -160,7 +152,6 @@ let functionCallToCallSignature = (functionCall: functionCall): functionCallSign
|
|||
let valueTypeToString = (valueType: internalExpressionValueType): string =>
|
||||
switch valueType {
|
||||
| EvtArray => `Array`
|
||||
| EvtArrayString => `ArrayString`
|
||||
| EvtBool => `Bool`
|
||||
// | EvtCall => `Call`
|
||||
| EvtDate => `Date`
|
||||
|
|
|
@ -22,7 +22,7 @@ let internalStdLib: Reducer_T.namespace = {
|
|||
}
|
||||
| [IEvRecord(dict), IEvString(sIndex)] => switch Belt.Map.String.get(dict, sIndex) {
|
||||
| Some(value) => value
|
||||
| None => RERecordPropertyNotFound("Record index not found", sIndex)->ErrorException->raise
|
||||
| None => RERecordPropertyNotFound("Record property not found", sIndex)->ErrorException->raise
|
||||
}
|
||||
| _ => REOther("Trying to access key on wrong value")->ErrorException->raise
|
||||
}
|
||||
|
|
|
@ -161,15 +161,25 @@ let getContinuationsBefore = (project: t, sourceId: string): array<Reducer_T.nam
|
|||
}
|
||||
|
||||
let linkDependencies = (project: t, sourceId: string): Reducer_T.namespace => {
|
||||
let nameSpace = Reducer_Namespace.mergeMany(
|
||||
Belt.Array.concat(
|
||||
let pastChain = project->getPastChain(sourceId)
|
||||
let namespace = Reducer_Namespace.mergeMany(
|
||||
Belt.Array.concatMany([
|
||||
[project->getStdLib],
|
||||
project->getContinuationsBefore(sourceId)
|
||||
)
|
||||
pastChain->Belt.Array.map(project->getBindings),
|
||||
pastChain->Belt.Array.map(
|
||||
id => Reducer_Namespace.fromArray([
|
||||
("__result__",
|
||||
switch project->getResult(id) {
|
||||
| Ok(result) => result
|
||||
| Error(error) => error->Reducer_ErrorValue.ErrorException->raise
|
||||
})
|
||||
])
|
||||
),
|
||||
])
|
||||
)
|
||||
|
||||
let includesAsVariables = project->getIncludesAsVariables(sourceId)
|
||||
Belt.Array.reduce(includesAsVariables, nameSpace, (acc, (variable, includeFile)) =>
|
||||
Belt.Array.reduce(includesAsVariables, namespace, (acc, (variable, includeFile)) =>
|
||||
acc->Reducer_Namespace.set(
|
||||
variable,
|
||||
project->getBindings(includeFile)->Reducer_Namespace.toRecord
|
||||
|
|
Loading…
Reference in New Issue
Block a user