fix merging develop
This commit is contained in:
parent
58e1cf187d
commit
66f2f18a00
|
@ -4,8 +4,11 @@ open Expect
|
||||||
module DispatchT = Reducer_Dispatch_T
|
module DispatchT = Reducer_Dispatch_T
|
||||||
module Expression = Reducer_Expression
|
module Expression = Reducer_Expression
|
||||||
module ExpressionT = Reducer_Expression_T
|
module ExpressionT = Reducer_Expression_T
|
||||||
module TypeCompile = Reducer_Type_Compile
|
module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
|
||||||
|
module ProjectReducerFnT = ReducerProject_ReducerFn_T
|
||||||
module TypeChecker = Reducer_Type_TypeChecker
|
module TypeChecker = Reducer_Type_TypeChecker
|
||||||
|
module TypeCompile = Reducer_Type_Compile
|
||||||
|
|
||||||
open ReducerInterface_InternalExpressionValue
|
open ReducerInterface_InternalExpressionValue
|
||||||
|
|
||||||
type errorValue = Reducer_ErrorValue.errorValue
|
type errorValue = Reducer_ErrorValue.errorValue
|
||||||
|
@ -14,13 +17,14 @@ type errorValue = Reducer_ErrorValue.errorValue
|
||||||
// In dispatchChainPiece, we execute an return the result of execution if there is a type match.
|
// In dispatchChainPiece, we execute an return the result of execution if there is a type match.
|
||||||
// Otherwise we return None so that the call chain can continue.
|
// Otherwise we return None so that the call chain can continue.
|
||||||
// So we want to build a function like
|
// So we want to build a function like
|
||||||
// dispatchChainPiece = (call: functionCall, environment): option<result<internalExpressionValue, errorValue>>
|
// dispatchChainPiece = (call: functionCall, accessors): option<result<internalExpressionValue, errorValue>>
|
||||||
|
// Use accessors.environment to get the environment finally.
|
||||||
|
|
||||||
// Now lets make the dispatchChainPiece itself.
|
// Now lets make the dispatchChainPiece itself.
|
||||||
// Note that I am not passing the reducer to the dispatchChainPiece as an argument because it is in the context anyway.
|
// Note that I am not passing the reducer to the dispatchChainPiece as an argument because it is in the context anyway.
|
||||||
// Keep in mind that reducerFn is necessary for map/reduce so dispatchChainPiece should have a reducerFn in context.
|
// Keep in mind that reducerFn is necessary for map/reduce so dispatchChainPiece should have a reducerFn in context.
|
||||||
|
|
||||||
let makeMyDispatchChainPiece = (reducer: ExpressionT.reducerFn): DispatchT.dispatchChainPiece => {
|
let makeMyDispatchChainPiece = (reducer: ProjectReducerFnT.t): DispatchT.dispatchChainPiece => {
|
||||||
// Let's have a pure implementations
|
// Let's have a pure implementations
|
||||||
module Implementation = {
|
module Implementation = {
|
||||||
let stringConcat = (a: string, b: string): string => Js.String2.concat(a, b)
|
let stringConcat = (a: string, b: string): string => Js.String2.concat(a, b)
|
||||||
|
@ -45,15 +49,15 @@ let makeMyDispatchChainPiece = (reducer: ExpressionT.reducerFn): DispatchT.dispa
|
||||||
|
|
||||||
// Let's bridge the pure implementation to expression values
|
// Let's bridge the pure implementation to expression values
|
||||||
module Bridge = {
|
module Bridge = {
|
||||||
let stringConcat: DispatchT.genericIEvFunction = (args, _environment) => {
|
let stringConcat: DispatchT.genericIEvFunction = (args, _accessors: ProjectAccessorsT.t) => {
|
||||||
let (a, b) = extractStringString(args)
|
let (a, b) = extractStringString(args)
|
||||||
Implementation.stringConcat(a, b)->IEvString->Ok
|
Implementation.stringConcat(a, b)->IEvString->Ok
|
||||||
}
|
}
|
||||||
let arrayConcat: DispatchT.genericIEvFunction = (args, _environment) => {
|
let arrayConcat: DispatchT.genericIEvFunction = (args, _accessors: ProjectAccessorsT.t) => {
|
||||||
let (a, b) = extractArrayArray(args)
|
let (a, b) = extractArrayArray(args)
|
||||||
Implementation.arrayConcat(a, b)->IEvArray->Ok
|
Implementation.arrayConcat(a, b)->IEvArray->Ok
|
||||||
}
|
}
|
||||||
let plot: DispatchT.genericIEvFunction = (args, _environment) => {
|
let plot: DispatchT.genericIEvFunction = (args, _accessors: ProjectAccessorsT.t) => {
|
||||||
switch args {
|
switch args {
|
||||||
// Just assume that we are doing the business of extracting and converting the deep record
|
// Just assume that we are doing the business of extracting and converting the deep record
|
||||||
| [IEvRecord(_)] => Implementation.plot({"title": "This is a plot"})->IEvString->Ok
|
| [IEvRecord(_)] => Implementation.plot({"title": "This is a plot"})->IEvString->Ok
|
||||||
|
@ -98,12 +102,12 @@ let makeMyDispatchChainPiece = (reducer: ExpressionT.reducerFn): DispatchT.dispa
|
||||||
// Exactly the same as the one used in real life
|
// Exactly the same as the one used in real life
|
||||||
let _dispatch = (
|
let _dispatch = (
|
||||||
call: functionCall,
|
call: functionCall,
|
||||||
environment,
|
accessors: ProjectAccessorsT.t,
|
||||||
reducer: Reducer_Expression_T.reducerFn,
|
reducer: ProjectReducerFnT.t,
|
||||||
chain,
|
chain,
|
||||||
): result<internalExpressionValue, 'e> => {
|
): result<internalExpressionValue, 'e> => {
|
||||||
let dispatchChainPiece = makeMyDispatchChainPiece(reducer)
|
let dispatchChainPiece = makeMyDispatchChainPiece(reducer)
|
||||||
dispatchChainPiece(call, environment)->E.O2.defaultFn(() => chain(call, environment, reducer))
|
dispatchChainPiece(call, accessors)->E.O2.defaultFn(() => chain(call, accessors, reducer))
|
||||||
}
|
}
|
||||||
|
|
||||||
// What is important about this implementation?
|
// What is important about this implementation?
|
||||||
|
@ -112,12 +116,12 @@ let _dispatch = (
|
||||||
// B) Complicated recursive record types are not a problem.
|
// B) Complicated recursive record types are not a problem.
|
||||||
|
|
||||||
describe("Type Dispatch", () => {
|
describe("Type Dispatch", () => {
|
||||||
let reducerFn = Expression.reduceExpression
|
let reducerFn = Expression.reduceExpressionInProject
|
||||||
let dispatchChainPiece = makeMyDispatchChainPiece(reducerFn)
|
let dispatchChainPiece = makeMyDispatchChainPiece(reducerFn)
|
||||||
test("stringConcat", () => {
|
test("stringConcat", () => {
|
||||||
let call: functionCall = ("concat", [IEvString("hello"), IEvString("world")])
|
let call: functionCall = ("concat", [IEvString("hello"), IEvString("world")])
|
||||||
|
|
||||||
let result = dispatchChainPiece(call, defaultEnvironment)
|
let result = dispatchChainPiece(call, ProjectAccessorsT.identityAccessors)
|
||||||
expect(result)->toEqual(Some(Ok(IEvString("helloworld"))))
|
expect(result)->toEqual(Some(Ok(IEvString("helloworld"))))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
module TypeChecker = Reducer_Type_TypeChecker
|
module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
|
||||||
module T = Reducer_Dispatch_T
|
module T = Reducer_Dispatch_T
|
||||||
|
module TypeChecker = Reducer_Type_TypeChecker
|
||||||
open ReducerInterface_InternalExpressionValue
|
open ReducerInterface_InternalExpressionValue
|
||||||
|
|
||||||
type errorValue = Reducer_ErrorValue.errorValue
|
type errorValue = Reducer_ErrorValue.errorValue
|
||||||
|
|
||||||
let makeFromTypes = jumpTable => {
|
let makeFromTypes = jumpTable => {
|
||||||
let dispatchChainPiece: T.dispatchChainPiece = ((fnName, fnArgs): functionCall, environment) => {
|
let dispatchChainPiece: T.dispatchChainPiece = (
|
||||||
|
(fnName, fnArgs): functionCall,
|
||||||
|
accessors: ProjectAccessorsT.t,
|
||||||
|
) => {
|
||||||
let jumpTableEntry = jumpTable->Js.Array2.find(elem => {
|
let jumpTableEntry = jumpTable->Js.Array2.find(elem => {
|
||||||
let (candidName, candidType, _) = elem
|
let (candidName, candidType, _) = elem
|
||||||
candidName == fnName && TypeChecker.checkITypeArgumentsBool(candidType, fnArgs)
|
candidName == fnName && TypeChecker.checkITypeArgumentsBool(candidType, fnArgs)
|
||||||
})
|
})
|
||||||
switch jumpTableEntry {
|
switch jumpTableEntry {
|
||||||
| Some((_, _, bridgeFn)) => bridgeFn(fnArgs, environment)->Some
|
| Some((_, _, bridgeFn)) => bridgeFn(fnArgs, accessors)->Some
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
|
module InternalExpressionValue = ReducerInterface_InternalExpressionValue
|
||||||
module ExpressionT = Reducer_Expression_T
|
module ExpressionT = Reducer_Expression_T
|
||||||
|
module ProjectAccessorsT = ReducerProject_ProjectAccessors_T
|
||||||
|
module ProjectReducerFnT = ReducerProject_ReducerFn_T
|
||||||
|
|
||||||
// Each piece of the dispatch chain computes the result or returns None so that the chain can continue
|
// Each piece of the dispatch chain computes the result or returns None so that the chain can continue
|
||||||
type dispatchChainPiece = (
|
type dispatchChainPiece = (
|
||||||
InternalExpressionValue.functionCall,
|
InternalExpressionValue.functionCall,
|
||||||
InternalExpressionValue.environment,
|
ProjectAccessorsT.t,
|
||||||
) => option<result<InternalExpressionValue.t, Reducer_ErrorValue.errorValue>>
|
) => option<result<InternalExpressionValue.t, Reducer_ErrorValue.errorValue>>
|
||||||
|
|
||||||
type dispatchChainPieceWithReducer = (
|
type dispatchChainPieceWithReducer = (
|
||||||
InternalExpressionValue.functionCall,
|
InternalExpressionValue.functionCall,
|
||||||
InternalExpressionValue.environment,
|
ProjectAccessorsT.t,
|
||||||
ExpressionT.reducerFn,
|
ProjectReducerFnT.t,
|
||||||
) => option<result<InternalExpressionValue.t, Reducer_ErrorValue.errorValue>>
|
) => option<result<InternalExpressionValue.t, Reducer_ErrorValue.errorValue>>
|
||||||
|
|
||||||
// This is a switch statement case implementation: get the arguments and compute the result
|
// This is a switch statement case implementation: get the arguments and compute the result
|
||||||
type genericIEvFunction = (
|
type genericIEvFunction = (
|
||||||
array<InternalExpressionValue.t>,
|
array<InternalExpressionValue.t>,
|
||||||
InternalExpressionValue.environment,
|
ProjectAccessorsT.t,
|
||||||
) => result<InternalExpressionValue.t, Reducer_ErrorValue.errorValue>
|
) => result<InternalExpressionValue.t, Reducer_ErrorValue.errorValue>
|
||||||
|
|
|
@ -38,7 +38,7 @@ let fromTypeExpression = (typeExpressionSourceCode: string, reducerFn: ProjectRe
|
||||||
|
|
||||||
let fromTypeExpressionExn = (
|
let fromTypeExpressionExn = (
|
||||||
typeExpressionSourceCode: string,
|
typeExpressionSourceCode: string,
|
||||||
reducerFn: ExpressionT.reducerFn,
|
reducerFn: ProjectReducerFnT.t,
|
||||||
): T.t =>
|
): T.t =>
|
||||||
switch fromTypeExpression(typeExpressionSourceCode, reducerFn) {
|
switch fromTypeExpression(typeExpressionSourceCode, reducerFn) {
|
||||||
| Ok(value) => value
|
| Ok(value) => value
|
||||||
|
|
Loading…
Reference in New Issue
Block a user