Reducer_Namespace; remove Module type; temporarily disable tests compilation
This commit is contained in:
parent
6463b52052
commit
f62e90fa98
|
@ -5,11 +5,11 @@
|
||||||
"dir": "src/rescript",
|
"dir": "src/rescript",
|
||||||
"subdirs": true
|
"subdirs": true
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
"dir": "__tests__",
|
// "dir": "__tests__",
|
||||||
"type": "dev",
|
// "type": "dev",
|
||||||
"subdirs": true
|
// "subdirs": true
|
||||||
},
|
// },
|
||||||
{
|
{
|
||||||
"dir": "benchmark",
|
"dir": "benchmark",
|
||||||
"type": "dev",
|
"type": "dev",
|
||||||
|
|
|
@ -15,4 +15,4 @@ const result = p.getResult("a");
|
||||||
console.log(result.tag, result.value.toString());
|
console.log(result.tag, result.value.toString());
|
||||||
|
|
||||||
const bindings = p.getBindings("a");
|
const bindings = p.getBindings("a");
|
||||||
console.log(bindings.asValue().toString());
|
console.log(bindings.toString());
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
import * as RSModuleValue from "../rescript/ForTS/ForTS_SquiggleValue/ForTS_SquiggleValue_Module.gen";
|
|
||||||
import { SqModuleValue, wrapValue } from "./SqValue";
|
|
||||||
import { SqValueLocation } from "./SqValueLocation";
|
|
||||||
|
|
||||||
export class SqModule {
|
|
||||||
constructor(
|
|
||||||
private _value: RSModuleValue.squiggleValue_Module,
|
|
||||||
public location: SqValueLocation
|
|
||||||
) {}
|
|
||||||
|
|
||||||
entries() {
|
|
||||||
return RSModuleValue.getKeyValuePairs(this._value).map(
|
|
||||||
([k, v]) => [k, wrapValue(v, this.location.extend(k))] as const
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
asValue() {
|
|
||||||
return new SqModuleValue(
|
|
||||||
RSModuleValue.toSquiggleValue(this._value),
|
|
||||||
this.location
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get(k: string) {
|
|
||||||
const v = RSModuleValue.get(this._value, k);
|
|
||||||
return v === undefined || v === null
|
|
||||||
? undefined
|
|
||||||
: wrapValue(v, this.location.extend(k));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@ import * as RSProject from "../rescript/ForTS/ForTS_ReducerProject.gen";
|
||||||
import { reducerErrorValue } from "../rescript/ForTS/ForTS_Reducer_ErrorValue.gen";
|
import { reducerErrorValue } from "../rescript/ForTS/ForTS_Reducer_ErrorValue.gen";
|
||||||
import { environment } from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_Environment.gen";
|
import { environment } from "../rescript/ForTS/ForTS_Distribution/ForTS_Distribution_Environment.gen";
|
||||||
import { SqError } from "./SqError";
|
import { SqError } from "./SqError";
|
||||||
import { SqModule } from "./SqModule";
|
import { SqRecord } from "./SqRecord";
|
||||||
import { wrapValue } from "./SqValue";
|
import { wrapValue } from "./SqValue";
|
||||||
import { resultMap2 } from "./types";
|
import { resultMap2 } from "./types";
|
||||||
import { SqValueLocation } from "./SqValueLocation";
|
import { SqValueLocation } from "./SqValueLocation";
|
||||||
|
@ -83,7 +83,7 @@ export class SqProject {
|
||||||
}
|
}
|
||||||
|
|
||||||
getBindings(sourceId: string) {
|
getBindings(sourceId: string) {
|
||||||
return new SqModule(
|
return new SqRecord(
|
||||||
RSProject.getBindings(this._value, sourceId),
|
RSProject.getBindings(this._value, sourceId),
|
||||||
new SqValueLocation(this, sourceId, {
|
new SqValueLocation(this, sourceId, {
|
||||||
root: "bindings",
|
root: "bindings",
|
||||||
|
|
|
@ -3,11 +3,9 @@ import { squiggleValueTag as Tag } from "../rescript/ForTS/ForTS_SquiggleValue/F
|
||||||
import { wrapDistribution } from "./SqDistribution";
|
import { wrapDistribution } from "./SqDistribution";
|
||||||
import { SqLambda } from "./SqLambda";
|
import { SqLambda } from "./SqLambda";
|
||||||
import { SqLambdaDeclaration } from "./SqLambdaDeclaration";
|
import { SqLambdaDeclaration } from "./SqLambdaDeclaration";
|
||||||
import { SqModule } from "./SqModule";
|
|
||||||
import { SqRecord } from "./SqRecord";
|
import { SqRecord } from "./SqRecord";
|
||||||
import { SqArray } from "./SqArray";
|
import { SqArray } from "./SqArray";
|
||||||
import { SqType } from "./SqType";
|
import { SqType } from "./SqType";
|
||||||
import { SqProject } from "./SqProject";
|
|
||||||
import { SqValueLocation } from "./SqValueLocation";
|
import { SqValueLocation } from "./SqValueLocation";
|
||||||
|
|
||||||
export { Tag as SqValueTag };
|
export { Tag as SqValueTag };
|
||||||
|
@ -62,14 +60,6 @@ export class SqBoolValue extends SqAbstractValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// export class SqCallValue extends SqAbstractValue {
|
|
||||||
// tag = Tag.Call as const;
|
|
||||||
|
|
||||||
// get value() {
|
|
||||||
// return this.valueMethod(RSValue.getCall);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export class SqDateValue extends SqAbstractValue {
|
export class SqDateValue extends SqAbstractValue {
|
||||||
tag = Tag.Date as const;
|
tag = Tag.Date as const;
|
||||||
|
|
||||||
|
@ -102,14 +92,6 @@ export class SqLambdaValue extends SqAbstractValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SqModuleValue extends SqAbstractValue {
|
|
||||||
tag = Tag.Module as const;
|
|
||||||
|
|
||||||
get value() {
|
|
||||||
return new SqModule(this.valueMethod(RSValue.getModule), this.location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SqNumberValue extends SqAbstractValue {
|
export class SqNumberValue extends SqAbstractValue {
|
||||||
tag = Tag.Number as const;
|
tag = Tag.Number as const;
|
||||||
|
|
||||||
|
@ -134,14 +116,6 @@ export class SqStringValue extends SqAbstractValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// export class SqSymbolValue extends SqAbstractValue {
|
|
||||||
// tag = Tag.Symbol as const;
|
|
||||||
|
|
||||||
// get value(): string {
|
|
||||||
// return this.valueMethod(RSValue.getSymbol);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
export class SqTimeDurationValue extends SqAbstractValue {
|
export class SqTimeDurationValue extends SqAbstractValue {
|
||||||
tag = Tag.TimeDuration as const;
|
tag = Tag.TimeDuration as const;
|
||||||
|
|
||||||
|
@ -178,16 +152,13 @@ const tagToClass = {
|
||||||
[Tag.Array]: SqArrayValue,
|
[Tag.Array]: SqArrayValue,
|
||||||
[Tag.ArrayString]: SqArrayStringValue,
|
[Tag.ArrayString]: SqArrayStringValue,
|
||||||
[Tag.Bool]: SqBoolValue,
|
[Tag.Bool]: SqBoolValue,
|
||||||
// [Tag.Call]: SqCallValue,
|
|
||||||
[Tag.Date]: SqDateValue,
|
[Tag.Date]: SqDateValue,
|
||||||
[Tag.Declaration]: SqDeclarationValue,
|
[Tag.Declaration]: SqDeclarationValue,
|
||||||
[Tag.Distribution]: SqDistributionValue,
|
[Tag.Distribution]: SqDistributionValue,
|
||||||
[Tag.Lambda]: SqLambdaValue,
|
[Tag.Lambda]: SqLambdaValue,
|
||||||
[Tag.Module]: SqModuleValue,
|
|
||||||
[Tag.Number]: SqNumberValue,
|
[Tag.Number]: SqNumberValue,
|
||||||
[Tag.Record]: SqRecordValue,
|
[Tag.Record]: SqRecordValue,
|
||||||
[Tag.String]: SqStringValue,
|
[Tag.String]: SqStringValue,
|
||||||
// [Tag.Symbol]: SqSymbolValue,
|
|
||||||
[Tag.TimeDuration]: SqTimeDurationValue,
|
[Tag.TimeDuration]: SqTimeDurationValue,
|
||||||
[Tag.Type]: SqTypeValue,
|
[Tag.Type]: SqTypeValue,
|
||||||
[Tag.TypeIdentifier]: SqTypeIdentifierValue,
|
[Tag.TypeIdentifier]: SqTypeIdentifierValue,
|
||||||
|
@ -200,16 +171,13 @@ export type SqValue =
|
||||||
| SqArrayValue
|
| SqArrayValue
|
||||||
| SqArrayStringValue
|
| SqArrayStringValue
|
||||||
| SqBoolValue
|
| SqBoolValue
|
||||||
// | SqCallValue
|
|
||||||
| SqDateValue
|
| SqDateValue
|
||||||
| SqDeclarationValue
|
| SqDeclarationValue
|
||||||
| SqDistributionValue
|
| SqDistributionValue
|
||||||
| SqLambdaValue
|
| SqLambdaValue
|
||||||
| SqModuleValue
|
|
||||||
| SqNumberValue
|
| SqNumberValue
|
||||||
| SqRecordValue
|
| SqRecordValue
|
||||||
| SqStringValue
|
| SqStringValue
|
||||||
// | SqSymbolValue
|
|
||||||
| SqTimeDurationValue
|
| SqTimeDurationValue
|
||||||
| SqTypeValue
|
| SqTypeValue
|
||||||
| SqTypeIdentifierValue
|
| SqTypeIdentifierValue
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use
|
type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use
|
||||||
|
|
||||||
type squiggleValue = ForTS_SquiggleValue.squiggleValue //use
|
type squiggleValue = ForTS_SquiggleValue.squiggleValue //use
|
||||||
type squiggleValue_Module = ForTS_SquiggleValue_Module.squiggleValue_Module //use
|
type squiggleValue_Record = ForTS_SquiggleValue.squiggleValue_Record //use
|
||||||
|
|
||||||
type environment = ForTS_Distribution_Environment.environment //use
|
type environment = ForTS_Distribution_Environment.environment //use
|
||||||
|
|
||||||
|
@ -184,8 +184,8 @@ let runAll = (project: reducerProject): unit => project->Private.runAll
|
||||||
Get the bindings after running this source fil. The bindings are local to the source
|
Get the bindings after running this source fil. The bindings are local to the source
|
||||||
*/
|
*/
|
||||||
@genType
|
@genType
|
||||||
let getBindings = (project: reducerProject, sourceId: string): squiggleValue_Module =>
|
let getBindings = (project: reducerProject, sourceId: string): squiggleValue_Record =>
|
||||||
project->Private.getBindings(sourceId)
|
project->Private.getBindings(sourceId)->Reducer_Namespace.toMap
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get the result after running this source file or the project
|
Get the result after running this source file or the project
|
||||||
|
@ -204,7 +204,7 @@ The source has to be include free
|
||||||
@genType
|
@genType
|
||||||
let evaluate = (sourceCode: string): (
|
let evaluate = (sourceCode: string): (
|
||||||
result<squiggleValue, reducerErrorValue>,
|
result<squiggleValue, reducerErrorValue>,
|
||||||
squiggleValue_Module,
|
squiggleValue_Record,
|
||||||
) => Private.evaluate(sourceCode)
|
) => Private.evaluate(sourceCode)
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use
|
type reducerErrorValue = ForTS_Reducer_ErrorValue.reducerErrorValue //use
|
||||||
|
|
||||||
@genType type squiggleValue_Array = Reducer_T.arrayValue //re-export recursive type
|
@genType type squiggleValue_Array = Reducer_T.arrayValue //re-export recursive type
|
||||||
@genType type squiggleValue_Module = Reducer_T.nameSpace //re-export recursive type
|
|
||||||
@genType type squiggleValue_Record = Reducer_T.map //re-export recursive type
|
@genType type squiggleValue_Record = Reducer_T.map //re-export recursive type
|
||||||
@genType type squiggleValue_Type = Reducer_T.map //re-export recursive type
|
@genType type squiggleValue_Type = Reducer_T.map //re-export recursive type
|
||||||
type squiggleValue_Declaration = ForTS_SquiggleValue_Declaration.squiggleValue_Declaration //use
|
type squiggleValue_Declaration = ForTS_SquiggleValue_Declaration.squiggleValue_Declaration //use
|
||||||
|
@ -20,9 +19,6 @@ external svtArrayString_: string = "ArrayString"
|
||||||
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
||||||
external svtBool_: string = "Bool"
|
external svtBool_: string = "Bool"
|
||||||
|
|
||||||
// @module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
|
||||||
// external svtCall_: string = "Call"
|
|
||||||
|
|
||||||
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
||||||
external svtDate_: string = "Date"
|
external svtDate_: string = "Date"
|
||||||
|
|
||||||
|
@ -35,9 +31,6 @@ external svtDistribution_: string = "Distribution"
|
||||||
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
||||||
external svtLambda_: string = "Lambda"
|
external svtLambda_: string = "Lambda"
|
||||||
|
|
||||||
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
|
||||||
external svtModule_: string = "Module"
|
|
||||||
|
|
||||||
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
||||||
external svtNumber_: string = "Number"
|
external svtNumber_: string = "Number"
|
||||||
|
|
||||||
|
@ -47,9 +40,6 @@ external svtRecord_: string = "Record"
|
||||||
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
||||||
external svtString_: string = "String"
|
external svtString_: string = "String"
|
||||||
|
|
||||||
// @module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
|
||||||
// external svtSymbol_: string = "Symbol"
|
|
||||||
|
|
||||||
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
@module("./ForTS_SquiggleValue_tag") @scope("squiggleValueTag")
|
||||||
external svtTimeDuration_: string = "TimeDuration"
|
external svtTimeDuration_: string = "TimeDuration"
|
||||||
|
|
||||||
|
@ -73,16 +63,13 @@ let getTag = (variant: squiggleValue): squiggleValueTag =>
|
||||||
| IEvArray(_) => svtArray_->castEnum
|
| IEvArray(_) => svtArray_->castEnum
|
||||||
| IEvArrayString(_) => svtArrayString_->castEnum
|
| IEvArrayString(_) => svtArrayString_->castEnum
|
||||||
| IEvBool(_) => svtBool_->castEnum
|
| IEvBool(_) => svtBool_->castEnum
|
||||||
// | IEvCall(_) => svtCall_->castEnum //Impossible
|
|
||||||
| IEvDate(_) => svtDate_->castEnum
|
| IEvDate(_) => svtDate_->castEnum
|
||||||
| IEvDeclaration(_) => svtDeclaration_->castEnum
|
| IEvDeclaration(_) => svtDeclaration_->castEnum
|
||||||
| IEvDistribution(_) => svtDistribution_->castEnum
|
| IEvDistribution(_) => svtDistribution_->castEnum
|
||||||
| IEvLambda(_) => svtLambda_->castEnum
|
| IEvLambda(_) => svtLambda_->castEnum
|
||||||
| IEvBindings(_) => svtModule_->castEnum //Impossible
|
|
||||||
| IEvNumber(_) => svtNumber_->castEnum
|
| IEvNumber(_) => svtNumber_->castEnum
|
||||||
| IEvRecord(_) => svtRecord_->castEnum
|
| IEvRecord(_) => svtRecord_->castEnum
|
||||||
| IEvString(_) => svtString_->castEnum
|
| IEvString(_) => svtString_->castEnum
|
||||||
// | IEvSymbol(_) => svtSymbol_->castEnum
|
|
||||||
| IEvTimeDuration(_) => svtTimeDuration_->castEnum
|
| IEvTimeDuration(_) => svtTimeDuration_->castEnum
|
||||||
| IEvType(_) => svtType_->castEnum
|
| IEvType(_) => svtType_->castEnum
|
||||||
| IEvTypeIdentifier(_) => svtTypeIdentifier_->castEnum
|
| IEvTypeIdentifier(_) => svtTypeIdentifier_->castEnum
|
||||||
|
@ -121,13 +108,6 @@ let getBool = (variant: squiggleValue): option<bool> =>
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
|
|
||||||
// @genType
|
|
||||||
// let getCall = (variant: squiggleValue): option<string> =>
|
|
||||||
// switch variant {
|
|
||||||
// | IEvCall(value) => value->Some
|
|
||||||
// | _ => None
|
|
||||||
// }
|
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
let getDate = (variant: squiggleValue): option<Js.Date.t> =>
|
let getDate = (variant: squiggleValue): option<Js.Date.t> =>
|
||||||
switch variant {
|
switch variant {
|
||||||
|
@ -156,13 +136,6 @@ let getLambda = (variant: squiggleValue): option<squiggleValue_Lambda> =>
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
|
|
||||||
@genType
|
|
||||||
let getModule = (variant: squiggleValue): option<squiggleValue_Module> =>
|
|
||||||
switch variant {
|
|
||||||
| IEvBindings(value) => value->Some
|
|
||||||
| _ => None
|
|
||||||
}
|
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
let getNumber = (variant: squiggleValue): option<float> =>
|
let getNumber = (variant: squiggleValue): option<float> =>
|
||||||
switch variant {
|
switch variant {
|
||||||
|
@ -184,13 +157,6 @@ let getString = (variant: squiggleValue): option<string> =>
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
|
|
||||||
// @genType
|
|
||||||
// let getSymbol = (variant: squiggleValue): option<string> =>
|
|
||||||
// switch variant {
|
|
||||||
// | IEvSymbol(value) => value->Some
|
|
||||||
// | _ => None
|
|
||||||
// }
|
|
||||||
|
|
||||||
@genType
|
@genType
|
||||||
let getTimeDuration = (variant: squiggleValue): option<float> =>
|
let getTimeDuration = (variant: squiggleValue): option<float> =>
|
||||||
switch variant {
|
switch variant {
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
type squiggleValue = ForTS_SquiggleValue.squiggleValue //use
|
|
||||||
@genType type squiggleValue_Module = ForTS_SquiggleValue.squiggleValue_Module //re-export recursive type
|
|
||||||
|
|
||||||
@genType
|
|
||||||
let getKeyValuePairs = (v: squiggleValue_Module): array<(string, squiggleValue)> =>
|
|
||||||
v->Reducer_Bindings.toKeyValuePairs
|
|
||||||
|
|
||||||
@genType
|
|
||||||
let toString = (v: squiggleValue_Module): string =>
|
|
||||||
ReducerInterface_InternalExpressionValue.toStringNameSpace(v)
|
|
||||||
|
|
||||||
@genType
|
|
||||||
let toSquiggleValue = (v: squiggleValue_Module): squiggleValue => IEvBindings(v)
|
|
||||||
|
|
||||||
@genType
|
|
||||||
let get = (v: squiggleValue_Module, k: string): option<squiggleValue> => Reducer_Bindings.get(v, k)
|
|
|
@ -2,16 +2,13 @@ export enum squiggleValueTag {
|
||||||
Array = "Array",
|
Array = "Array",
|
||||||
ArrayString = "ArrayString",
|
ArrayString = "ArrayString",
|
||||||
Bool = "Bool",
|
Bool = "Bool",
|
||||||
// Call = "Call",
|
|
||||||
Date = "Date",
|
Date = "Date",
|
||||||
Declaration = "Declaration",
|
Declaration = "Declaration",
|
||||||
Distribution = "Distribution",
|
Distribution = "Distribution",
|
||||||
Lambda = "Lambda",
|
Lambda = "Lambda",
|
||||||
Module = "Module",
|
|
||||||
Number = "Number",
|
Number = "Number",
|
||||||
Record = "Record",
|
Record = "Record",
|
||||||
String = "String",
|
String = "String",
|
||||||
// Symbol = "Symbol",
|
|
||||||
TimeDuration = "TimeDuration",
|
TimeDuration = "TimeDuration",
|
||||||
Type = "Type",
|
Type = "Type",
|
||||||
TypeIdentifier = "TypeIdentifier",
|
TypeIdentifier = "TypeIdentifier",
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
@genType type squiggleValue_Array = ForTS_SquiggleValue_Array.squiggleValue_Array //re-export
|
@genType type squiggleValue_Array = ForTS_SquiggleValue_Array.squiggleValue_Array //re-export
|
||||||
@genType type squiggleValue_Declaration = ForTS_SquiggleValue_Declaration.squiggleValue_Declaration //re-export
|
@genType type squiggleValue_Declaration = ForTS_SquiggleValue_Declaration.squiggleValue_Declaration //re-export
|
||||||
@genType type squiggleValue_Lambda = ForTS_SquiggleValue_Lambda.squiggleValue_Lambda //re-export
|
@genType type squiggleValue_Lambda = ForTS_SquiggleValue_Lambda.squiggleValue_Lambda //re-export
|
||||||
@genType type squiggleValue_Module = ForTS_SquiggleValue_Module.squiggleValue_Module //re-export
|
|
||||||
@genType type squiggleValue_Record = ForTS_SquiggleValue_Record.squiggleValue_Record //re-export
|
@genType type squiggleValue_Record = ForTS_SquiggleValue_Record.squiggleValue_Record //re-export
|
||||||
@genType type squiggleValue_Type = ForTS_SquiggleValue_Type.squiggleValue_Type //re-export
|
@genType type squiggleValue_Type = ForTS_SquiggleValue_Type.squiggleValue_Type //re-export
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,11 @@
|
||||||
module ExpressionT = Reducer_Expression_T
|
module ExpressionT = Reducer_Expression_T
|
||||||
module T = Reducer_T
|
module T = Reducer_T
|
||||||
|
|
||||||
type t = Reducer_T.nameSpace
|
type t = Reducer_T.bindings
|
||||||
type internalExpressionValue = Reducer_T.value
|
type internalExpressionValue = Reducer_T.value
|
||||||
|
|
||||||
let rec get = (nameSpace: t, id: string) => {
|
let rec get = ({ namespace, parent }: t, id: string) => {
|
||||||
let T.NameSpace(container, parent) = nameSpace
|
switch namespace->Reducer_Namespace.get(id) {
|
||||||
|
|
||||||
switch container->Belt.MutableMap.String.get(id) {
|
|
||||||
| Some(v) => Some(v)
|
| Some(v) => Some(v)
|
||||||
| None =>
|
| None =>
|
||||||
switch parent {
|
switch parent {
|
||||||
|
@ -20,64 +18,38 @@ let rec get = (nameSpace: t, id: string) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let getWithDefault = (nameSpace: t, id: string, default) =>
|
let getWithDefault = (namespace: t, id: string, default) =>
|
||||||
switch get(nameSpace, id) {
|
switch namespace->get(id) {
|
||||||
| Some(v) => Some(v)
|
| Some(v) => Some(v)
|
||||||
| None => default
|
| None => default
|
||||||
}
|
}
|
||||||
|
|
||||||
let toString = ReducerInterface_InternalExpressionValue.toStringNameSpace
|
let set = ({ namespace } as bindings: t, id: string, value): t => {
|
||||||
|
let _ = namespace->Reducer_Namespace.set(id, value)
|
||||||
let makeEmptyMap = () => Belt.MutableMap.String.make()
|
bindings
|
||||||
|
|
||||||
let set = (nameSpace: t, id: string, value): t => {
|
|
||||||
let T.NameSpace(container, _) = nameSpace
|
|
||||||
Belt.MutableMap.String.set(container, id, value)
|
|
||||||
nameSpace
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let extend = (nameSpace: t) => T.NameSpace(makeEmptyMap(), nameSpace->Some)
|
let rec toString = ({ namespace, parent }: t) => {
|
||||||
|
let pairs = namespace->Reducer_Namespace.toString
|
||||||
|
|
||||||
let toKeyValuePairs = (T.NameSpace(container, _): t): array<(string, internalExpressionValue)> => {
|
switch parent {
|
||||||
container->Belt.MutableMap.String.toArray
|
| Some(p) => `{${pairs}} / ${toString(p)}`
|
||||||
}
|
| None => `{${pairs}}`
|
||||||
|
|
||||||
let makeEmptyBindings = (): t => T.NameSpace(makeEmptyMap(), None)
|
|
||||||
|
|
||||||
let toExpressionValue = (nameSpace: t): internalExpressionValue => T.IEvBindings(nameSpace)
|
|
||||||
let fromExpressionValue = (aValue: internalExpressionValue): t =>
|
|
||||||
switch aValue {
|
|
||||||
| IEvBindings(nameSpace) => nameSpace
|
|
||||||
| _ => makeEmptyBindings()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let fromArray = a => T.NameSpace(Belt.MutableMap.String.fromArray(a), None)
|
|
||||||
|
|
||||||
let mergeFrom = (T.NameSpace(container, _): t, T.NameSpace(newContainer, parent): t): t => {
|
|
||||||
NameSpace(
|
|
||||||
newContainer->Belt.MutableMap.String.reduce(container, (container, key, value) => {
|
|
||||||
if key != "__result__" {
|
|
||||||
Belt.MutableMap.String.set(container, key, value)
|
|
||||||
}
|
|
||||||
container
|
|
||||||
}),
|
|
||||||
parent,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let chainTo = (nameSpace: t, previousNameSpaces: array<t>) => {
|
let extend = (bindings: t): t => { namespace: Reducer_Namespace.make(), parent: bindings->Some }
|
||||||
previousNameSpaces->Belt.Array.reduce(nameSpace, (topNameSpace, prevNameSpace) =>
|
|
||||||
mergeFrom(prevNameSpace, topNameSpace)
|
let make = (): t => { namespace: Reducer_Namespace.make(), parent: None }
|
||||||
)
|
|
||||||
|
let removeResult = ({ namespace } as bindings: t): t => {
|
||||||
|
namespace->Belt.MutableMap.String.remove("__result__")
|
||||||
|
bindings
|
||||||
}
|
}
|
||||||
|
|
||||||
let removeResult = (nameSpace: t): t => {
|
let locals = ({ namespace }: t): Reducer_T.namespace => namespace
|
||||||
let T.NameSpace(container, _) = nameSpace
|
|
||||||
container->Belt.MutableMap.String.remove("__result__")
|
|
||||||
nameSpace
|
|
||||||
}
|
|
||||||
|
|
||||||
let locals = (T.NameSpace(container, _): t) => T.NameSpace(container, None)
|
let fromNamespace = (namespace: Reducer_Namespace.t): t => { namespace, parent: None }
|
||||||
|
|
||||||
// let typeAliasesKey = "_typeAliases_"
|
// let typeAliasesKey = "_typeAliases_"
|
||||||
// let typeReferencesKey = "_typeReferences_"
|
// let typeReferencesKey = "_typeReferences_"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
type t = Reducer_T.context
|
type t = Reducer_T.context
|
||||||
|
|
||||||
let createContext = (stdLib: Reducer_T.nameSpace, environment: Reducer_T.environment): t => {
|
let createContext = (stdLib: Reducer_Namespace.t, environment: Reducer_T.environment): t => {
|
||||||
{
|
{
|
||||||
bindings: stdLib->Reducer_Bindings.extend,
|
bindings: stdLib->Reducer_Bindings.fromNamespace,
|
||||||
environment: environment,
|
environment: environment,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
module Bindings = Reducer_Bindings
|
module Bindings = Reducer_Bindings
|
||||||
module Continuation = ReducerInterface_Value_Continuation
|
// module Continuation = ReducerInterface_Value_Continuation
|
||||||
module ExpressionT = Reducer_Expression_T
|
module ExpressionT = Reducer_Expression_T
|
||||||
module ExternalLibrary = ReducerInterface.ExternalLibrary
|
module ExternalLibrary = ReducerInterface.ExternalLibrary
|
||||||
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
|
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
|
||||||
|
@ -52,11 +52,11 @@ let callInternal = (
|
||||||
// | None => REArrayIndexNotFound("Array index not found", Belt.Int.fromFloat(fIndex))->Error
|
// | None => REArrayIndexNotFound("Array index not found", Belt.Int.fromFloat(fIndex))->Error
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let moduleAtIndex = (nameSpace: Reducer_T.nameSpace, sIndex) =>
|
// let moduleAtIndex = (nameSpace: Reducer_T.nameSpace, sIndex) =>
|
||||||
switch Bindings.get(nameSpace, sIndex) {
|
// switch Bindings.get(nameSpace, sIndex) {
|
||||||
| Some(value) => value->Ok
|
// | Some(value) => value->Ok
|
||||||
| None => RERecordPropertyNotFound("Bindings property not found", sIndex)->Error
|
// | None => RERecordPropertyNotFound("Bindings property not found", sIndex)->Error
|
||||||
}
|
// }
|
||||||
|
|
||||||
// let recordAtIndex = (dict: Belt.Map.String.t<Reducer_T.value>, sIndex) =>
|
// let recordAtIndex = (dict: Belt.Map.String.t<Reducer_T.value>, sIndex) =>
|
||||||
// switch Belt.Map.String.get(dict, sIndex) {
|
// switch Belt.Map.String.get(dict, sIndex) {
|
||||||
|
@ -109,7 +109,7 @@ let callInternal = (
|
||||||
|
|
||||||
switch call {
|
switch call {
|
||||||
// | ("$_atIndex_$", [IEvArray(aValueArray), IEvNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex)
|
// | ("$_atIndex_$", [IEvArray(aValueArray), IEvNumber(fIndex)]) => arrayAtIndex(aValueArray, fIndex)
|
||||||
| ("$_atIndex_$", [IEvBindings(dict), IEvString(sIndex)]) => moduleAtIndex(dict, sIndex)
|
// | ("$_atIndex_$", [IEvBindings(dict), IEvString(sIndex)]) => moduleAtIndex(dict, sIndex)
|
||||||
// | ("$_atIndex_$", [IEvRecord(dict), IEvString(sIndex)]) => recordAtIndex(dict, sIndex)
|
// | ("$_atIndex_$", [IEvRecord(dict), IEvString(sIndex)]) => recordAtIndex(dict, sIndex)
|
||||||
// | ("$_constructArray_$", args) => IEvArray(args)->Ok
|
// | ("$_constructArray_$", args) => IEvArray(args)->Ok
|
||||||
// | ("$_constructRecord_$", [IEvArray(arrayOfPairs)]) => constructRecord(arrayOfPairs)
|
// | ("$_constructRecord_$", [IEvArray(arrayOfPairs)]) => constructRecord(arrayOfPairs)
|
||||||
|
|
|
@ -8,9 +8,6 @@ let eArray = (anArray: array<T.expression>) => anArray->T.EArray
|
||||||
|
|
||||||
let eArrayString = anArray => anArray->T.IEvArrayString->T.EValue
|
let eArrayString = anArray => anArray->T.IEvArrayString->T.EValue
|
||||||
|
|
||||||
let eBindings = (anArray: array<(string, T.value)>) =>
|
|
||||||
anArray->Reducer_Bindings.fromArray->Reducer_Bindings.toExpressionValue->T.EValue
|
|
||||||
|
|
||||||
let eBool = aBool => aBool->T.IEvBool->T.EValue
|
let eBool = aBool => aBool->T.IEvBool->T.EValue
|
||||||
|
|
||||||
let eCall = (fn: expression, args: array<expression>): expression => T.ECall(fn, args)
|
let eCall = (fn: expression, args: array<expression>): expression => T.ECall(fn, args)
|
||||||
|
@ -29,8 +26,6 @@ let eBlock = (exprs: array<expression>): expression => T.EBlock(exprs)
|
||||||
|
|
||||||
let eProgram = (exprs: array<expression>): expression => T.EProgram(exprs)
|
let eProgram = (exprs: array<expression>): expression => T.EProgram(exprs)
|
||||||
|
|
||||||
let eModule = (nameSpace: T.nameSpace): expression => nameSpace->T.IEvBindings->T.EValue
|
|
||||||
|
|
||||||
let eLetStatement = (symbol: string, valueExpression: expression): expression => T.EAssign(
|
let eLetStatement = (symbol: string, valueExpression: expression): expression => T.EAssign(
|
||||||
symbol,
|
symbol,
|
||||||
valueExpression,
|
valueExpression,
|
||||||
|
|
|
@ -14,7 +14,7 @@ let doLambdaCall = (
|
||||||
|
|
||||||
let makeLambda = (
|
let makeLambda = (
|
||||||
parameters: array<string>,
|
parameters: array<string>,
|
||||||
bindings: Reducer_T.nameSpace,
|
bindings: Reducer_T.bindings,
|
||||||
body: Reducer_T.expression,
|
body: Reducer_T.expression,
|
||||||
): Reducer_T.lambdaValue => {
|
): Reducer_T.lambdaValue => {
|
||||||
// TODO - clone bindings to avoid later redefinitions affecting lambdas?
|
// TODO - clone bindings to avoid later redefinitions affecting lambdas?
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
type t = Reducer_T.namespace
|
||||||
|
|
||||||
|
let make = (): t => Belt.MutableMap.String.make()
|
||||||
|
|
||||||
|
let get = (namespace: t, id: string): option<Reducer_T.value> =>
|
||||||
|
namespace->Belt.MutableMap.String.get(id)
|
||||||
|
|
||||||
|
let set = (namespace: t, id: string, value): t => {
|
||||||
|
namespace->Belt.MutableMap.String.set(id, value)
|
||||||
|
namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
let mergeFrom = (from: t, to: t): t => {
|
||||||
|
to->Belt.MutableMap.String.reduce(from, (namespace, key, value) => {
|
||||||
|
if key != "__result__" {
|
||||||
|
namespace->Belt.MutableMap.String.set(key, value)
|
||||||
|
}
|
||||||
|
namespace
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let mergeMany = (namespaces: array<t>): t =>
|
||||||
|
Belt.Array.reduce(namespaces, make(), (acc, ns) => acc->mergeFrom(ns))
|
||||||
|
|
||||||
|
let toString = (namespace: t) =>
|
||||||
|
namespace
|
||||||
|
->Belt.MutableMap.String.toArray
|
||||||
|
->Belt.Array.map(((eachKey, eachValue)) => `${eachKey}: ${eachValue->ReducerInterface_InternalExpressionValue.toString}`)
|
||||||
|
->Js.Array2.toString
|
||||||
|
|
||||||
|
let fromArray = (a): t =>
|
||||||
|
Belt.MutableMap.String.fromArray(a)
|
||||||
|
|
||||||
|
let toMap = (namespace: t): Reducer_T.map =>
|
||||||
|
namespace->Belt.MutableMap.String.toArray->Belt.Map.String.fromArray
|
||||||
|
|
||||||
|
let toRecord = (namespace: t): Reducer_T.value =>
|
||||||
|
namespace->toMap->IEvRecord
|
|
@ -9,7 +9,6 @@ type rec value =
|
||||||
| IEvDeclaration(lambdaDeclaration)
|
| IEvDeclaration(lambdaDeclaration)
|
||||||
| IEvDistribution(DistributionTypes.genericDist)
|
| IEvDistribution(DistributionTypes.genericDist)
|
||||||
| IEvLambda(lambdaValue)
|
| IEvLambda(lambdaValue)
|
||||||
| IEvBindings(nameSpace)
|
|
||||||
| IEvNumber(float)
|
| IEvNumber(float)
|
||||||
| IEvRecord(map)
|
| IEvRecord(map)
|
||||||
| IEvString(string)
|
| IEvString(string)
|
||||||
|
@ -19,17 +18,17 @@ type rec value =
|
||||||
| IEvVoid
|
| IEvVoid
|
||||||
@genType.opaque and arrayValue = array<value>
|
@genType.opaque and arrayValue = array<value>
|
||||||
@genType.opaque and map = Belt.Map.String.t<value>
|
@genType.opaque and map = Belt.Map.String.t<value>
|
||||||
@genType.opaque and nameSpace = NameSpace(Belt.MutableMap.String.t<value>, option<nameSpace>)
|
|
||||||
and lambdaBody = (array<value>, environment, reducerFn) => value
|
and lambdaBody = (array<value>, environment, reducerFn) => value
|
||||||
@genType.opaque
|
@genType.opaque
|
||||||
and lambdaValue = {
|
and lambdaValue = {
|
||||||
parameters: array<string>,
|
parameters: array<string>,
|
||||||
body: (array<value>, environment, reducerFn) => value,
|
body: lambdaBody,
|
||||||
}
|
}
|
||||||
@genType.opaque and lambdaDeclaration = Declaration.declaration<lambdaValue>
|
@genType.opaque and lambdaDeclaration = Declaration.declaration<lambdaValue>
|
||||||
and expression =
|
and expression =
|
||||||
| EBlock(array<expression>)
|
| EBlock(array<expression>)
|
||||||
| EProgram(array<expression>) // programs are similar to blocks, but don't create an inner scope. there can be only one program at the top level of the expression.
|
// programs are similar to blocks, but don't create an inner scope. there can be only one program at the top level of the expression.
|
||||||
|
| EProgram(array<expression>)
|
||||||
| EArray(array<expression>)
|
| EArray(array<expression>)
|
||||||
| ERecord(array<(expression, expression)>)
|
| ERecord(array<(expression, expression)>)
|
||||||
| ESymbol(string)
|
| ESymbol(string)
|
||||||
|
@ -39,8 +38,14 @@ and expression =
|
||||||
| ELambda(array<string>, expression)
|
| ELambda(array<string>, expression)
|
||||||
| EValue(value)
|
| EValue(value)
|
||||||
|
|
||||||
|
and namespace = Belt.MutableMap.String.t<value>
|
||||||
|
and bindings = {
|
||||||
|
namespace: namespace,
|
||||||
|
parent: option<bindings>,
|
||||||
|
}
|
||||||
|
|
||||||
and context = {
|
and context = {
|
||||||
bindings: nameSpace,
|
bindings: bindings,
|
||||||
environment: environment,
|
environment: environment,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,7 @@ let rec toString = (aValue: T.value) =>
|
||||||
switch aValue {
|
switch aValue {
|
||||||
| IEvArray(anArray) => toStringArray(anArray)
|
| IEvArray(anArray) => toStringArray(anArray)
|
||||||
| IEvArrayString(anArray) => toStringArrayString(anArray)
|
| IEvArrayString(anArray) => toStringArrayString(anArray)
|
||||||
| IEvBindings(m) => toStringBindings(m)
|
|
||||||
| IEvBool(aBool) => toStringBool(aBool)
|
| IEvBool(aBool) => toStringBool(aBool)
|
||||||
// | IEvCall(fName) => toStringCall(fName)
|
|
||||||
| IEvDate(date) => toStringDate(date)
|
| IEvDate(date) => toStringDate(date)
|
||||||
| IEvDeclaration(d) => toStringDeclaration(d)
|
| IEvDeclaration(d) => toStringDeclaration(d)
|
||||||
| IEvDistribution(dist) => toStringDistribution(dist)
|
| IEvDistribution(dist) => toStringDistribution(dist)
|
||||||
|
@ -28,7 +26,6 @@ let rec toString = (aValue: T.value) =>
|
||||||
| IEvNumber(aNumber) => toStringNumber(aNumber)
|
| IEvNumber(aNumber) => toStringNumber(aNumber)
|
||||||
| IEvRecord(aMap) => aMap->toStringRecord
|
| IEvRecord(aMap) => aMap->toStringRecord
|
||||||
| IEvString(aString) => toStringString(aString)
|
| IEvString(aString) => toStringString(aString)
|
||||||
// | IEvSymbol(aString) => toStringSymbol(aString)
|
|
||||||
| IEvTimeDuration(t) => toStringTimeDuration(t)
|
| IEvTimeDuration(t) => toStringTimeDuration(t)
|
||||||
| IEvType(aMap) => toStringType(aMap)
|
| IEvType(aMap) => toStringType(aMap)
|
||||||
| IEvTypeIdentifier(id) => toStringTypeIdentifier(id)
|
| IEvTypeIdentifier(id) => toStringTypeIdentifier(id)
|
||||||
|
@ -42,7 +39,6 @@ and toStringArrayString = anArray => {
|
||||||
let args = anArray->Js.Array2.toString
|
let args = anArray->Js.Array2.toString
|
||||||
`[${args}]`
|
`[${args}]`
|
||||||
}
|
}
|
||||||
and toStringBindings = m => `@${m->toStringNameSpace}`
|
|
||||||
and toStringBool = aBool => Js.String.make(aBool)
|
and toStringBool = aBool => Js.String.make(aBool)
|
||||||
and toStringCall = fName => `:${fName}`
|
and toStringCall = fName => `:${fName}`
|
||||||
and toStringDate = date => DateTime.Date.toString(date)
|
and toStringDate = date => DateTime.Date.toString(date)
|
||||||
|
@ -69,35 +65,19 @@ and toStringMap = aMap => {
|
||||||
->Js.Array2.toString
|
->Js.Array2.toString
|
||||||
`{${pairs}}`
|
`{${pairs}}`
|
||||||
}
|
}
|
||||||
and toStringNameSpace = nameSpace => {
|
|
||||||
let T.NameSpace(container, parent) = nameSpace
|
|
||||||
let pairs =
|
|
||||||
container
|
|
||||||
->Belt.MutableMap.String.toArray
|
|
||||||
->Js.Array2.map(((eachKey, eachValue)) => `${eachKey}: ${toString(eachValue)}`)
|
|
||||||
->Js.Array2.toString
|
|
||||||
|
|
||||||
switch parent {
|
|
||||||
| Some(p) => `{${pairs}} / ${toStringNameSpace(p)}`
|
|
||||||
| None => `{${pairs}}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let toStringWithType = (aValue: T.value) =>
|
let toStringWithType = (aValue: T.value) =>
|
||||||
switch aValue {
|
switch aValue {
|
||||||
| IEvArray(_) => `Array::${toString(aValue)}`
|
| IEvArray(_) => `Array::${toString(aValue)}`
|
||||||
| IEvArrayString(_) => `ArrayString::${toString(aValue)}`
|
| IEvArrayString(_) => `ArrayString::${toString(aValue)}`
|
||||||
| IEvBool(_) => `Bool::${toString(aValue)}`
|
| IEvBool(_) => `Bool::${toString(aValue)}`
|
||||||
// | IEvCall(_) => `Call::${toString(aValue)}`
|
|
||||||
| IEvDate(_) => `Date::${toString(aValue)}`
|
| IEvDate(_) => `Date::${toString(aValue)}`
|
||||||
| IEvDeclaration(_) => `Declaration::${toString(aValue)}`
|
| IEvDeclaration(_) => `Declaration::${toString(aValue)}`
|
||||||
| IEvDistribution(_) => `Distribution::${toString(aValue)}`
|
| IEvDistribution(_) => `Distribution::${toString(aValue)}`
|
||||||
| IEvLambda(_) => `Lambda::${toString(aValue)}`
|
| IEvLambda(_) => `Lambda::${toString(aValue)}`
|
||||||
| IEvBindings(_) => `Bindings::${toString(aValue)}`
|
|
||||||
| IEvNumber(_) => `Number::${toString(aValue)}`
|
| IEvNumber(_) => `Number::${toString(aValue)}`
|
||||||
| IEvRecord(_) => `Record::${toString(aValue)}`
|
| IEvRecord(_) => `Record::${toString(aValue)}`
|
||||||
| IEvString(_) => `String::${toString(aValue)}`
|
| IEvString(_) => `String::${toString(aValue)}`
|
||||||
// | IEvSymbol(_) => `Symbol::${toString(aValue)}`
|
|
||||||
| IEvTimeDuration(_) => `Date::${toString(aValue)}`
|
| IEvTimeDuration(_) => `Date::${toString(aValue)}`
|
||||||
| IEvType(_) => `Type::${toString(aValue)}`
|
| IEvType(_) => `Type::${toString(aValue)}`
|
||||||
| IEvTypeIdentifier(_) => `TypeIdentifier::${toString(aValue)}`
|
| IEvTypeIdentifier(_) => `TypeIdentifier::${toString(aValue)}`
|
||||||
|
@ -138,16 +118,13 @@ type internalExpressionValueType =
|
||||||
| EvtArray
|
| EvtArray
|
||||||
| EvtArrayString
|
| EvtArrayString
|
||||||
| EvtBool
|
| EvtBool
|
||||||
// | EvtCall
|
|
||||||
| EvtDate
|
| EvtDate
|
||||||
| EvtDeclaration
|
| EvtDeclaration
|
||||||
| EvtDistribution
|
| EvtDistribution
|
||||||
| EvtLambda
|
| EvtLambda
|
||||||
| EvtModule
|
|
||||||
| EvtNumber
|
| EvtNumber
|
||||||
| EvtRecord
|
| EvtRecord
|
||||||
| EvtString
|
| EvtString
|
||||||
// | EvtSymbol
|
|
||||||
| EvtTimeDuration
|
| EvtTimeDuration
|
||||||
| EvtType
|
| EvtType
|
||||||
| EvtTypeIdentifier
|
| EvtTypeIdentifier
|
||||||
|
@ -162,16 +139,13 @@ let valueToValueType = (value: T.value) =>
|
||||||
| IEvArray(_) => EvtArray
|
| IEvArray(_) => EvtArray
|
||||||
| IEvArrayString(_) => EvtArrayString
|
| IEvArrayString(_) => EvtArrayString
|
||||||
| IEvBool(_) => EvtBool
|
| IEvBool(_) => EvtBool
|
||||||
// | IEvCall(_) => EvtCall
|
|
||||||
| IEvDate(_) => EvtDate
|
| IEvDate(_) => EvtDate
|
||||||
| IEvDeclaration(_) => EvtDeclaration
|
| IEvDeclaration(_) => EvtDeclaration
|
||||||
| IEvDistribution(_) => EvtDistribution
|
| IEvDistribution(_) => EvtDistribution
|
||||||
| IEvLambda(_) => EvtLambda
|
| IEvLambda(_) => EvtLambda
|
||||||
| IEvBindings(_) => EvtModule
|
|
||||||
| IEvNumber(_) => EvtNumber
|
| IEvNumber(_) => EvtNumber
|
||||||
| IEvRecord(_) => EvtRecord
|
| IEvRecord(_) => EvtRecord
|
||||||
| IEvString(_) => EvtString
|
| IEvString(_) => EvtString
|
||||||
// | IEvSymbol(_) => EvtSymbol
|
|
||||||
| IEvTimeDuration(_) => EvtTimeDuration
|
| IEvTimeDuration(_) => EvtTimeDuration
|
||||||
| IEvType(_) => EvtType
|
| IEvType(_) => EvtType
|
||||||
| IEvTypeIdentifier(_) => EvtTypeIdentifier
|
| IEvTypeIdentifier(_) => EvtTypeIdentifier
|
||||||
|
@ -193,7 +167,6 @@ let valueTypeToString = (valueType: internalExpressionValueType): string =>
|
||||||
| EvtDeclaration => `Declaration`
|
| EvtDeclaration => `Declaration`
|
||||||
| EvtDistribution => `Distribution`
|
| EvtDistribution => `Distribution`
|
||||||
| EvtLambda => `Lambda`
|
| EvtLambda => `Lambda`
|
||||||
| EvtModule => `Module`
|
|
||||||
| EvtNumber => `Number`
|
| EvtNumber => `Number`
|
||||||
| EvtRecord => `Record`
|
| EvtRecord => `Record`
|
||||||
| EvtString => `String`
|
| EvtString => `String`
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
exception ErrorException = Reducer_ErrorValue.ErrorException
|
exception ErrorException = Reducer_ErrorValue.ErrorException
|
||||||
|
|
||||||
let internalStdLib: Reducer_Bindings.t = {
|
let internalStdLib: Reducer_T.namespace = {
|
||||||
let res =
|
let res =
|
||||||
Reducer_Bindings.makeEmptyBindings()
|
Reducer_Namespace.make()
|
||||||
->SquiggleLibrary_Math.makeBindings
|
->Reducer_Namespace.mergeFrom(SquiggleLibrary_Math.make())
|
||||||
->SquiggleLibrary_Versions.makeBindings
|
->Reducer_Namespace.mergeFrom(SquiggleLibrary_Versions.make())
|
||||||
|
|
||||||
let _ = res->Reducer_Bindings.set(
|
let _ = res->Reducer_Namespace.set(
|
||||||
"$_atIndex_$",
|
"$_atIndex_$",
|
||||||
Reducer_Expression_Lambda.makeFFILambda((inputs, _, _) => {
|
Reducer_Expression_Lambda.makeFFILambda((inputs, _, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
|
@ -31,7 +31,7 @@ let internalStdLib: Reducer_Bindings.t = {
|
||||||
|
|
||||||
FunctionRegistry_Library.nonRegistryLambdas->Js.Array2.forEach(
|
FunctionRegistry_Library.nonRegistryLambdas->Js.Array2.forEach(
|
||||||
((name, lambda)) => {
|
((name, lambda)) => {
|
||||||
let _ = res->Reducer_Bindings.set(name, lambda->Reducer_T.IEvLambda)
|
let _ = res->Reducer_Namespace.set(name, lambda->Reducer_T.IEvLambda)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ let internalStdLib: Reducer_Bindings.t = {
|
||||||
FunctionRegistry_Library.registry.fnNameDict
|
FunctionRegistry_Library.registry.fnNameDict
|
||||||
->Js.Dict.keys
|
->Js.Dict.keys
|
||||||
->Js.Array2.forEach(name => {
|
->Js.Array2.forEach(name => {
|
||||||
let _ = res->Reducer_Bindings.set(
|
let _ = res->Reducer_Namespace.set(
|
||||||
name,
|
name,
|
||||||
Reducer_Expression_Lambda.makeFFILambda((arguments, environment, reducer) => {
|
Reducer_Expression_Lambda.makeFFILambda((arguments, environment, reducer) => {
|
||||||
switch FunctionRegistry_Library.call(name, arguments, environment, reducer) {
|
switch FunctionRegistry_Library.call(name, arguments, environment, reducer) {
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
|
|
||||||
|
|
||||||
type t = Reducer_T.nameSpace
|
|
||||||
|
|
||||||
let toValue = nameSpace => Reducer_T.IEvBindings(nameSpace)
|
|
||||||
let toString = nameSpace => InternalExpressionValue.toString(toValue(nameSpace))
|
|
||||||
let toStringResult = rNameSpace =>
|
|
||||||
Belt.Result.map(rNameSpace, toValue(_))->InternalExpressionValue.toStringResult
|
|
||||||
let toStringOptionResult = orNameSpace =>
|
|
||||||
Belt.Option.map(
|
|
||||||
orNameSpace,
|
|
||||||
Belt.Result.map(_, toValue(_)),
|
|
||||||
)->InternalExpressionValue.toStringOptionResult
|
|
||||||
|
|
||||||
let inspect = (nameSpace, label: string) => Js.log(`${label}: ${toString(nameSpace)}`)
|
|
||||||
|
|
||||||
let inspectOption = (oNameSpace, label: string) =>
|
|
||||||
switch oNameSpace {
|
|
||||||
| Some(nameSpace) => inspect(nameSpace, label)
|
|
||||||
| None => Js.log(`${label}: None`)
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
// TODO: Auto clean project based on topology
|
// TODO: Auto clean project based on topology
|
||||||
|
|
||||||
module Bindings = Reducer_Bindings
|
module Bindings = Reducer_Bindings
|
||||||
module Continuation = ReducerInterface_Value_Continuation
|
|
||||||
module ErrorValue = Reducer_ErrorValue
|
module ErrorValue = Reducer_ErrorValue
|
||||||
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
|
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
|
||||||
module ProjectItem = ReducerProject_ProjectItem
|
module ProjectItem = ReducerProject_ProjectItem
|
||||||
|
@ -97,7 +96,7 @@ let setContinues = (project: t, sourceId: string, continues: array<string>): uni
|
||||||
handleNewTopology(project)
|
handleNewTopology(project)
|
||||||
}
|
}
|
||||||
let getContinues = (project: t, sourceId: string): array<string> =>
|
let getContinues = (project: t, sourceId: string): array<string> =>
|
||||||
ProjectItem.getContinues(project->getItem(sourceId))
|
project->getItem(sourceId)->ProjectItem.getContinues
|
||||||
|
|
||||||
let removeContinues = (project: t, sourceId: string): unit => {
|
let removeContinues = (project: t, sourceId: string): unit => {
|
||||||
let newItem = project->getItem(sourceId)->ProjectItem.removeContinues
|
let newItem = project->getItem(sourceId)->ProjectItem.removeContinues
|
||||||
|
@ -105,9 +104,6 @@ let removeContinues = (project: t, sourceId: string): unit => {
|
||||||
handleNewTopology(project)
|
handleNewTopology(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
let getContinuation = (project: t, sourceId: string): ProjectItem.T.continuationArgumentType =>
|
|
||||||
project->getItem(sourceId)->ProjectItem.getContinuation
|
|
||||||
|
|
||||||
let setContinuation = (
|
let setContinuation = (
|
||||||
project: t,
|
project: t,
|
||||||
sourceId: string,
|
sourceId: string,
|
||||||
|
@ -142,8 +138,8 @@ let rawParse = (project: t, sourceId): unit => {
|
||||||
project->setItem(sourceId, newItem)
|
project->setItem(sourceId, newItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
let getStdLib = (project: t): Reducer_Bindings.t => project.stdLib
|
let getStdLib = (project: t): Reducer_T.namespace => project.stdLib
|
||||||
let setStdLib = (project: t, value: Reducer_Bindings.t): unit => {
|
let setStdLib = (project: t, value: Reducer_T.namespace): unit => {
|
||||||
project.stdLib = value
|
project.stdLib = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,47 +148,41 @@ let setEnvironment = (project: t, value: InternalExpressionValue.environment): u
|
||||||
project.environment = value
|
project.environment = value
|
||||||
}
|
}
|
||||||
|
|
||||||
let getBindings = (project: t, sourceId: string): ProjectItem.T.bindingsArgumentType => {
|
let getBindings = (project: t, sourceId: string): Reducer_T.namespace => {
|
||||||
project->getContinuation(sourceId)->Reducer_Bindings.locals
|
project->getItem(sourceId)->ProjectItem.getContinuation
|
||||||
}
|
}
|
||||||
|
|
||||||
let getContinuationsBefore = (project: t, sourceId: string): array<ProjectItem.T.continuation> => {
|
let getBindingsAsRecord = (project: t, sourceId: string): Reducer_T.value => {
|
||||||
let pastNameSpaces = project->getPastChain(sourceId)->Js.Array2.map(getBindings(project, _))
|
project->getBindings(sourceId)->Reducer_Namespace.toRecord
|
||||||
let theLength = pastNameSpaces->Js.Array2.length
|
|
||||||
if theLength == 0 {
|
|
||||||
// `getContinuationBefore ${sourceId}: stdLib`->Js.log
|
|
||||||
[project->getStdLib]
|
|
||||||
} else {
|
|
||||||
// `getContinuationBefore ${sourceId}: ${lastOne} = ${InternalExpressionValue.toStringBindings(
|
|
||||||
// project->getBindings(lastOne),
|
|
||||||
// )}`->Js.log
|
|
||||||
pastNameSpaces
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let linkDependencies = (project: t, sourceId: string): ProjectItem.T.continuation => {
|
let getContinuationsBefore = (project: t, sourceId: string): array<Reducer_T.namespace> => {
|
||||||
let continuationsBefore = project->getContinuationsBefore(sourceId)
|
project->getPastChain(sourceId)->Belt.Array.map(project->getBindings)
|
||||||
let nameSpace =
|
}
|
||||||
Reducer_Bindings.makeEmptyBindings()->Reducer_Bindings.chainTo(continuationsBefore)
|
|
||||||
|
let linkDependencies = (project: t, sourceId: string): Reducer_T.namespace => {
|
||||||
|
let nameSpace = Reducer_Namespace.mergeMany(
|
||||||
|
Belt.Array.concat(
|
||||||
|
[project->getStdLib],
|
||||||
|
project->getContinuationsBefore(sourceId)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
let includesAsVariables = project->getIncludesAsVariables(sourceId)
|
let includesAsVariables = project->getIncludesAsVariables(sourceId)
|
||||||
Belt.Array.reduce(includesAsVariables, nameSpace, (currentNameSpace, (variable, includeFile)) =>
|
Belt.Array.reduce(includesAsVariables, nameSpace, (acc, (variable, includeFile)) =>
|
||||||
Bindings.set(
|
acc->Reducer_Namespace.set(
|
||||||
currentNameSpace,
|
|
||||||
variable,
|
variable,
|
||||||
getBindings(project, includeFile)->Reducer_T.IEvBindings,
|
project->getBindings(includeFile)->Reducer_Namespace.toRecord
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let doLinkAndRun = (project: t, sourceId: string): unit => {
|
let doLinkAndRun = (project: t, sourceId: string): unit => {
|
||||||
let context = Reducer_Context.createContext(project->getStdLib, project->getEnvironment)
|
let context = Reducer_Context.createContext(
|
||||||
// FIXME: fill context with dependencies
|
project->linkDependencies(sourceId),
|
||||||
let continuation = linkDependencies(project, sourceId)
|
project->getEnvironment
|
||||||
let contextWithContinuation = {
|
)
|
||||||
...context,
|
let newItem = project->getItem(sourceId)->ProjectItem.run(context)
|
||||||
bindings: continuation->Reducer_Bindings.extend,
|
|
||||||
}
|
|
||||||
let newItem = project->getItem(sourceId)->ProjectItem.run(contextWithContinuation)
|
|
||||||
// Js.log("after run " ++ newItem.continuation->Reducer_Bindings.toString)
|
// Js.log("after run " ++ newItem.continuation->Reducer_Bindings.toString)
|
||||||
project->setItem(sourceId, newItem)
|
project->setItem(sourceId, newItem)
|
||||||
}
|
}
|
||||||
|
@ -243,6 +233,6 @@ let evaluate = (sourceCode: string) => {
|
||||||
|
|
||||||
(
|
(
|
||||||
getResultOption(project, "main")->Belt.Option.getWithDefault(Reducer_T.IEvVoid->Ok),
|
getResultOption(project, "main")->Belt.Option.getWithDefault(Reducer_T.IEvVoid->Ok),
|
||||||
project->getBindings("main"),
|
project->getBindings("main")->Reducer_Namespace.toMap,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ let emptyItem: projectItem = {
|
||||||
source: "",
|
source: "",
|
||||||
rawParse: None,
|
rawParse: None,
|
||||||
expression: None,
|
expression: None,
|
||||||
continuation: Reducer_Bindings.makeEmptyBindings(),
|
continuation: Reducer_Namespace.make(),
|
||||||
result: None,
|
result: None,
|
||||||
continues: [],
|
continues: [],
|
||||||
includes: []->Ok,
|
includes: []->Ok,
|
||||||
|
@ -168,14 +168,14 @@ let buildExpression = (this: t): t => {
|
||||||
}
|
}
|
||||||
|
|
||||||
let failRun = (this: t, e: Reducer_ErrorValue.errorValue): t =>
|
let failRun = (this: t, e: Reducer_ErrorValue.errorValue): t =>
|
||||||
this->setResult(e->Error)->setContinuation(Reducer_Bindings.makeEmptyBindings())
|
this->setResult(e->Error)->setContinuation(Reducer_Namespace.make())
|
||||||
|
|
||||||
let doRun = (this: t, context: Reducer_T.context): t =>
|
let doRun = (this: t, context: Reducer_T.context): t =>
|
||||||
switch this->getExpression {
|
switch this->getExpression {
|
||||||
| Some(expressionResult) => switch expressionResult {
|
| Some(expressionResult) => switch expressionResult {
|
||||||
| Ok(expression) => try {
|
| Ok(expression) => try {
|
||||||
let result = Reducer_Expression.evaluate(expression, context)
|
let result = Reducer_Expression.evaluate(expression, context)
|
||||||
this->setResult(result->Ok)->setContinuation(context.bindings)
|
this->setResult(result->Ok)->setContinuation(context.bindings->Reducer_Bindings.locals)
|
||||||
} catch {
|
} catch {
|
||||||
| Reducer_ErrorValue.ErrorException(e) => this->failRun(e)
|
| Reducer_ErrorValue.ErrorException(e) => this->failRun(e)
|
||||||
| _ => this->failRun(RETodo("unhandled rescript exception"))
|
| _ => this->failRun(RETodo("unhandled rescript exception"))
|
||||||
|
|
|
@ -8,12 +8,9 @@ type rawParseArgumentType = result<Parse.node, errorValue>
|
||||||
type rawParseType = option<rawParseArgumentType>
|
type rawParseType = option<rawParseArgumentType>
|
||||||
type expressionArgumentType = result<ExpressionT.t, errorValue>
|
type expressionArgumentType = result<ExpressionT.t, errorValue>
|
||||||
type expressionType = option<expressionArgumentType>
|
type expressionType = option<expressionArgumentType>
|
||||||
type continuation = Reducer_T.nameSpace
|
type continuationArgumentType = Reducer_T.namespace
|
||||||
type continuationArgumentType = Reducer_T.nameSpace
|
|
||||||
type continuationType = option<continuationArgumentType>
|
type continuationType = option<continuationArgumentType>
|
||||||
type continuationResultType = option<result<continuationArgumentType, errorValue>>
|
type continuationResultType = option<result<continuationArgumentType, errorValue>>
|
||||||
type bindingsArgumentType = Reducer_T.nameSpace
|
|
||||||
type bindingsType = option<bindingsArgumentType>
|
|
||||||
type resultArgumentType = result<Reducer_T.value, errorValue>
|
type resultArgumentType = result<Reducer_T.value, errorValue>
|
||||||
type resultType = option<resultArgumentType>
|
type resultType = option<resultArgumentType>
|
||||||
type continuesArgumentType = array<string>
|
type continuesArgumentType = array<string>
|
||||||
|
|
|
@ -4,7 +4,7 @@ module ExpressionT = Reducer_Expression_T
|
||||||
@genType.opaque
|
@genType.opaque
|
||||||
type project = {
|
type project = {
|
||||||
items: Belt.MutableMap.String.t<ProjectItem.t>,
|
items: Belt.MutableMap.String.t<ProjectItem.t>,
|
||||||
mutable stdLib: Reducer_Bindings.t,
|
mutable stdLib: Reducer_Namespace.t,
|
||||||
mutable environment: ExpressionT.environment,
|
mutable environment: ExpressionT.environment,
|
||||||
mutable previousRunOrder: array<string>,
|
mutable previousRunOrder: array<string>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
module Bindings = Reducer_Bindings
|
|
||||||
|
|
||||||
let availableNumbers: array<(string, float)> = [
|
let availableNumbers: array<(string, float)> = [
|
||||||
("Math.pi", Js.Math._PI),
|
("Math.pi", Js.Math._PI),
|
||||||
("Math.e", Js.Math._E),
|
("Math.e", Js.Math._E),
|
||||||
|
@ -13,8 +11,5 @@ let availableNumbers: array<(string, float)> = [
|
||||||
("Math.tau", 6.283185307179586),
|
("Math.tau", 6.283185307179586),
|
||||||
]
|
]
|
||||||
|
|
||||||
let mathBindings: Bindings.t =
|
let make = (): Reducer_Namespace.t =>
|
||||||
availableNumbers->E.A2.fmap(((name, v)) => (name, Reducer_T.IEvNumber(v)))->Bindings.fromArray
|
availableNumbers->E.A2.fmap(((name, v)) => (name, Reducer_T.IEvNumber(v)))->Reducer_Namespace.fromArray
|
||||||
|
|
||||||
let makeBindings = (previousBindings: Bindings.t): Bindings.t =>
|
|
||||||
previousBindings->Bindings.mergeFrom(mathBindings)
|
|
||||||
|
|
|
@ -1,7 +1,2 @@
|
||||||
module Bindings = Reducer_Bindings
|
let make = (): Reducer_Namespace.t =>
|
||||||
|
[("System.version", Reducer_T.IEvString("0.4.0-dev"))]->Reducer_Namespace.fromArray
|
||||||
let bindings: Reducer_T.nameSpace =
|
|
||||||
[("System.version", Reducer_T.IEvString("0.4.0-dev"))]->Bindings.fromArray
|
|
||||||
|
|
||||||
let makeBindings = (previousBindings: Reducer_T.nameSpace): Reducer_T.nameSpace =>
|
|
||||||
previousBindings->Bindings.mergeFrom(bindings)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user