demolish external value

This commit is contained in:
Umur Ozkul 2022-08-19 21:12:04 +02:00
parent f573c326d2
commit d7ed875566
12 changed files with 5 additions and 205 deletions

View File

@ -1,6 +1,5 @@
// Reducer_Helpers // Reducer_Helpers
module ErrorValue = Reducer_ErrorValue module ErrorValue = Reducer_ErrorValue
module ExternalExpressionValue = ReducerInterface.ExternalExpressionValue
module InternalExpressionValue = ReducerInterface.InternalExpressionValue module InternalExpressionValue = ReducerInterface.InternalExpressionValue
module Bindings = Reducer_Bindings module Bindings = Reducer_Bindings

View File

@ -1,5 +1,5 @@
module MathJs = Reducer_MathJs module MathJs = Reducer_MathJs
module ErrorValue = Reducer.ErrorValue module ErrorValue = Reducer_ErrorValue
open Jest open Jest
open ExpectJs open ExpectJs

View File

@ -1,11 +1,11 @@
open ReducerInterface.ExternalExpressionValue open ReducerInterface.InternalExpressionValue
open Jest open Jest
open Expect open Expect
describe("ExpressionValue", () => { describe("ExpressionValue", () => {
test("argsToString", () => expect([EvNumber(1.), EvString("a")]->argsToString)->toBe("1,'a'")) test("argsToString", () => expect([IEvNumber(1.), IEvString("a")]->argsToString)->toBe("1,'a'"))
test("toStringFunctionCall", () => test("toStringFunctionCall", () =>
expect(("fn", [EvNumber(1.), EvString("a")])->toStringFunctionCall)->toBe("fn(1,'a')") expect(("fn", [IEvNumber(1.), IEvString("a")])->toStringFunctionCall)->toBe("fn(1,'a')")
) )
}) })

View File

@ -1,17 +0,0 @@
module ErrorValue = Reducer_ErrorValue
module Expression = Reducer_Expression
module ExternalExpressionValue = ReducerInterface_ExternalExpressionValue
type environment = ReducerInterface_InternalExpressionValue.environment
type errorValue = Reducer_ErrorValue.errorValue
type expressionValue = ExternalExpressionValue.t
type externalBindings = ReducerInterface_ExternalExpressionValue.externalBindings
type lambdaValue = ExternalExpressionValue.lambdaValue
/*
Use Reducer_Project instead
*/
let defaultEnvironment = ExternalExpressionValue.defaultEnvironment
// let defaultExternalBindings = ReducerInterface_StdLib.externalStdLib

View File

@ -1,45 +0,0 @@
module ErrorValue = Reducer_ErrorValue
module Expression = Reducer_Expression
@genType0
type environment = ReducerInterface_ExternalExpressionValue.environment
@genType
type errorValue = Reducer_ErrorValue.errorValue
@genType
type expressionValue = ReducerInterface_ExternalExpressionValue.t
@genType
type externalBindings = ReducerInterface_ExternalExpressionValue.externalBindings
@genType
type lambdaValue = ReducerInterface_ExternalExpressionValue.lambdaValue
// @genType
// let evaluateUsingOptions: (
// ~environment: option<QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.environment>,
// ~externalBindings: option<
// QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.externalBindings,
// >,
// string,
// ) => result<expressionValue, errorValue>
// @genType
// let evaluatePartialUsingExternalBindings: (
// string,
// QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.externalBindings,
// QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.environment,
// ) => result<externalBindings, errorValue>
// @genType
// let evaluate: string => result<expressionValue, errorValue>
// let parse: string => result<Expression.t, errorValue>
// @genType
// let foreignFunctionInterface: (
// QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.lambdaValue,
// array<QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.t>,
// QuriSquiggleLang.ReducerInterface_ExternalExpressionValue.environment,
// ) => result<expressionValue, errorValue>
@genType
let defaultEnvironment: environment
// @genType
// let defaultExternalBindings: externalBindings

View File

@ -2,7 +2,6 @@ module Bindings = Reducer_Bindings
module BindingsReplacer = Reducer_Expression_BindingsReplacer module BindingsReplacer = Reducer_Expression_BindingsReplacer
module BuiltIn = Reducer_Dispatch_BuiltIn module BuiltIn = Reducer_Dispatch_BuiltIn
module ExpressionBuilder = Reducer_Expression_ExpressionBuilder module ExpressionBuilder = Reducer_Expression_ExpressionBuilder
module ExternalExpressionValue = ReducerInterface_ExternalExpressionValue
module Extra = Reducer_Extra module Extra = Reducer_Extra
module InternalExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
module Lambda = Reducer_Expression_Lambda module Lambda = Reducer_Expression_Lambda
@ -13,7 +12,6 @@ module Result = Belt.Result
module T = Reducer_Expression_T module T = Reducer_Expression_T
type errorValue = Reducer_ErrorValue.errorValue type errorValue = Reducer_ErrorValue.errorValue
type externalExpressionValue = ReducerInterface_ExternalExpressionValue.t
type t = T.t type t = T.t
/* /*

View File

@ -7,7 +7,6 @@ module Bindings = Reducer_Bindings
type errorValue = Reducer_ErrorValue.errorValue type errorValue = Reducer_ErrorValue.errorValue
type expression = ExpressionT.expression type expression = ExpressionT.expression
type internalExpressionValue = InternalExpressionValue.t type internalExpressionValue = InternalExpressionValue.t
type externalBindings = ReducerInterface_ExternalExpressionValue.externalBindings
let isMacroName = (fName: string): bool => fName->Js.String2.startsWith("$$") let isMacroName = (fName: string): bool => fName->Js.String2.startsWith("$$")

View File

@ -1,4 +1,3 @@
module ExternalExpressionValue = ReducerInterface_ExternalExpressionValue
module ExternalLibrary = ReducerInterface_ExternalLibrary module ExternalLibrary = ReducerInterface_ExternalLibrary
module InternalExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
module StdLib = ReducerInterface_StdLib module StdLib = ReducerInterface_StdLib

View File

@ -1,111 +0,0 @@
/*
Irreducible values. Reducer does not know about those. Only used for external calls
This is a configuration to to make external calls of those types
*/
module Extra_Array = Reducer_Extra_Array
module ErrorValue = Reducer_ErrorValue
@genType.opaque
type internalCode = Object
@genType.opaque
type hiddenNameSpace = Object
@genType
type rec externalExpressionValue =
| EvArray(array<externalExpressionValue>)
| EvArrayString(array<string>)
| EvBool(bool)
| EvCall(string) // External function call
| EvDate(Js.Date.t)
| EvDeclaration(lambdaDeclaration)
| EvDistribution(DistributionTypes.genericDist)
| EvLambda(lambdaValue)
| EvModule(record)
| EvNumber(float)
| EvRecord(record)
| EvString(string)
| EvSymbol(string)
| EvTimeDuration(float)
| EvType(record)
| EvTypeIdentifier(string)
| EvVoid
and record = Js.Dict.t<externalExpressionValue>
and lambdaValue = {
parameters: array<string>,
context: hiddenNameSpace,
body: internalCode,
}
and lambdaDeclaration = Declaration.declaration<lambdaValue>
@genType
type externalBindings = record
@genType
type t = externalExpressionValue
type functionCall = (string, array<externalExpressionValue>)
let rec toString = aValue =>
switch aValue {
| EvArray(anArray) => {
let args = anArray->Js.Array2.map(each => toString(each))->Js.Array2.toString
`[${args}]`
}
| EvArrayString(anArray) => {
let args = anArray->Js.Array2.toString
`[${args}]`
}
| EvBool(aBool) => Js.String.make(aBool)
| EvCall(fName) => `:${fName}`
| EvDate(date) => DateTime.Date.toString(date)
| EvDeclaration(d) => Declaration.toString(d, r => toString(EvLambda(r)))
| EvDistribution(dist) => GenericDist.toString(dist)
| EvLambda(lambdaValue) => `lambda(${Js.Array2.toString(lambdaValue.parameters)}=>internal code)`
| EvModule(m) => `@${m->toStringRecord}`
| EvNumber(aNumber) => Js.String.make(aNumber)
| EvRecord(aRecord) => aRecord->toStringRecord
| EvString(aString) => `'${aString}'`
| EvSymbol(aString) => `:${aString}`
| EvTimeDuration(t) => DateTime.Duration.toString(t)
| EvType(t) => `type${t->toStringRecord}`
| EvTypeIdentifier(id) => `#${id}`
| EvVoid => `()`
}
and toStringRecord = aRecord => {
let pairs =
aRecord
->Js.Dict.entries
->Js.Array2.map(((eachKey, eachValue)) => `${eachKey}: ${toString(eachValue)}`)
->Js.Array2.toString
`{${pairs}}`
}
let argsToString = (args: array<externalExpressionValue>): string => {
args->Js.Array2.map(arg => arg->toString)->Js.Array2.toString
}
let toStringFunctionCall = ((fn, args)): string => `${fn}(${argsToString(args)})`
let toStringResult = x =>
switch x {
| Ok(a) => `Ok(${toString(a)})`
| Error(m) => `Error(${ErrorValue.errorToString(m)})`
}
let toStringOptionResult = x =>
switch x {
| Some(a) => toStringResult(a)
| None => `None`
}
let toStringOption = x =>
switch x {
| Some(a) => toString(a)
| None => `None`
}
@genType
type environment = GenericDist.env
@genType
let defaultEnvironment: environment = DistributionOperation.defaultEnv

View File

@ -1,4 +1,4 @@
let dispatch: ( let dispatch: (
ReducerInterface_InternalExpressionValue.functionCall, ReducerInterface_InternalExpressionValue.functionCall,
ReducerInterface_ExternalExpressionValue.environment, ReducerInterface_InternalExpressionValue.environment,
) => option<result<ReducerInterface_InternalExpressionValue.t, Reducer_ErrorValue.errorValue>> ) => option<result<ReducerInterface_InternalExpressionValue.t, Reducer_ErrorValue.errorValue>>

View File

@ -172,27 +172,6 @@ let valueToValueType = value =>
| IEvVoid => EvtVoid | IEvVoid => EvtVoid
} }
let externalValueToValueType = (value: ReducerInterface_ExternalExpressionValue.t) =>
switch value {
| EvArray(_) => EvtArray
| EvArrayString(_) => EvtArrayString
| EvBool(_) => EvtBool
| EvCall(_) => EvtCall
| EvDate(_) => EvtDate
| EvDeclaration(_) => EvtDeclaration
| EvDistribution(_) => EvtDistribution
| EvLambda(_) => EvtLambda
| EvModule(_) => EvtModule
| EvNumber(_) => EvtNumber
| EvRecord(_) => EvtRecord
| EvString(_) => EvtString
| EvSymbol(_) => EvtSymbol
| EvTimeDuration(_) => EvtTimeDuration
| EvType(_) => EvtType
| EvTypeIdentifier(_) => EvtTypeIdentifier
| EvVoid => EvtVoid
}
let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => { let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => {
let (fn, args) = functionCall let (fn, args) = functionCall
CallSignature(fn, args->Js.Array2.map(valueToValueType)) CallSignature(fn, args->Js.Array2.map(valueToValueType))

View File

@ -1,7 +1,6 @@
module Parse = Reducer_Peggy_Parse module Parse = Reducer_Peggy_Parse
module ExpressionT = Reducer_Expression_T module ExpressionT = Reducer_Expression_T
module InternalExpressionValue = ReducerInterface_InternalExpressionValue module InternalExpressionValue = ReducerInterface_InternalExpressionValue
module ExternalExpressionValue = ReducerInterface_ExternalExpressionValue
open Reducer_ErrorValue open Reducer_ErrorValue
type sourceArgumentType = string type sourceArgumentType = string