This commit is contained in:
Umur Ozkul 2022-08-18 15:32:26 +02:00
parent 868f9f428a
commit fdc7f06f08
27 changed files with 76 additions and 77 deletions

View File

@ -1,4 +1,4 @@
open ForTS_Types open ForTS_Types_
@module("ForTS_InternalValue_tag") @scope("InternalValueTag") @module("ForTS_InternalValue_tag") @scope("InternalValueTag")
external ivtVoid_: int = "IvtVoid" external ivtVoid_: int = "IvtVoid"

View File

@ -1,4 +1,4 @@
open ForTS_Types open ForTS_Types_
@genType @genType
let toString = (v: recordLike): string => let toString = (v: recordLike): string =>

View File

@ -1,3 +1,3 @@
open ForTS_Types open ForTS_Types_
@genType let toString = (_value: internalVoid): string => MyInterface_InternalValue_Void.toString @genType let toString = (_value: internalVoid): string => MyInterface_InternalValue_Void.toString

View File

@ -1,4 +1,4 @@
open ForTS_Types open ForTS_Types_
@genType @genType
let getResult = (_p: myProject): option<result_<internalValue, errorValue>> => let getResult = (_p: myProject): option<result_<internalValue, errorValue>> =>

View File

@ -0,0 +1,18 @@
open ForTS_Types_
@genType let isError = (r: result_<'a, 'e>): bool => Belt.Result.isError(r)
@genType let isOk = (r: result_<'a, 'e>): bool => Belt.Result.isOk(r)
@genType
let getError = (r: result_<'a, 'e>): option<'e> =>
switch r {
| Ok(_) => None
| Error(e) => Some(e)
}
@genType
let getValue = (r: result_<'a, 'e>): option<'a> =>
switch r {
| Ok(v) => Some(v)
| Error(_) => None
}

View File

@ -6,7 +6,7 @@
@genType.opaque type recordLike = MyInterface_InternalValue_RecordLike.t @genType.opaque type recordLike = MyInterface_InternalValue_RecordLike.t
@genType.opaque type internalVoid = int @genType.opaque type internalVoid = int
@genType.opaque type errorValue = My_ErrorValue.t @genType.opaque type errorValue = My_ErrorValue.t
@genType.opaque type result_<'a, 'e> = result<'a, 'e> // There has to be a type for each result permutation @genType.opaque type result_<'a, 'e> = result<'a, 'e>
@genType.opaque type myProject = {name: string} @genType.opaque type myProject = {name: string}
//There is no need to map option<> as it becomes nullable //There is no need to map option<> as it becomes nullable

View File

@ -1,4 +1,4 @@
open ForTS_Types open ForTS__Types
@genType let isError = (r: result_<'a, 'e>): bool => Belt.Result.isError(r) @genType let isError = (r: result_<'a, 'e>): bool => Belt.Result.isError(r)
@genType let isOk = (r: result_<'a, 'e>): bool => Belt.Result.isOk(r) @genType let isOk = (r: result_<'a, 'e>): bool => Belt.Result.isOk(r)

View File

@ -0,0 +1 @@
open ForTS__Types

View File

@ -0,0 +1 @@
open ForTS__Types

View File

@ -0,0 +1,19 @@
enum SquiggleValueTag {
SvtArray,
SvtArrayString,
SvtBool,
SvtCall,
SvtDate,
SvtDeclaration,
SvtDistribution
SvtLambda,
SvtModule,
SvtNumber,
SvtRecord,
SvtString,
SvtSymbol,
SvtTimeDuration,
SvtType,
SvtTypeIdentifier,
SvtVoid,
}

View File

@ -0,0 +1,20 @@
/*
The reason this is not ExpressionValue is that ExpressionValue is becoming a parametric type
to allow expressions for different domains.
So we rename it right away not cause a compatibility problem
*/
@genType.opaque type result_<'a, 'e> = result<'a, 'e>
@genType.opaque type squiggleValue
@genType.opaque type squiggleValue_Array
@genType.opaque type squiggleValue_ArrayString
@genType.opaque type squiggleValue_Date
@genType.opaque type squiggleValue_Declaration
@genType.opaque type squiggleValue_Distribution
@genType.opaque type squiggleValue_Lambda
@genType.opaque type squiggleValue_Record
@genType.opaque type squiggleValue_TimeDuration
@genType.opaque type squiggleValue_Type
@genType.opaque type squiggleValue_Void
@genType.opaque type reducer_errorValue

View File

@ -1,7 +1,7 @@
//FIXME: Move this under ForTS
@gentype.import("peggy") @genType.as("LocationRange") @gentype.import("peggy") @genType.as("LocationRange")
type location type location
@genType
type errorValue = type errorValue =
| REArityError(option<string>, int, int) | REArityError(option<string>, int, int)
| REArrayIndexNotFound(string, int) | REArrayIndexNotFound(string, int)
@ -23,7 +23,6 @@ type errorValue =
type t = errorValue type t = errorValue
@genType
let errorToString = err => let errorToString = err =>
switch err { switch err {
| REArityError(_oFnName, arity, usedArity) => | REArityError(_oFnName, arity, usedArity) =>

View File

@ -11,7 +11,6 @@ external castWithLocation: Js.Exn.t => withLocation = "%identity"
let syntaxErrorToLocation = (error: Js.Exn.t): Reducer_ErrorValue.location => let syntaxErrorToLocation = (error: Js.Exn.t): Reducer_ErrorValue.location =>
castWithLocation(error)["location"] castWithLocation(error)["location"]
@genType
let parse = (expr: string): result<node, errorValue> => let parse = (expr: string): result<node, errorValue> =>
try { try {
Ok(parse__(expr)) Ok(parse__(expr))

View File

@ -10,7 +10,6 @@ module ProjectItem = ReducerProject_ProjectItem
module T = ReducerProject_T module T = ReducerProject_T
module Topology = ReducerProject_Topology module Topology = ReducerProject_Topology
@genType.opaque
type reducerProject = T.t type reducerProject = T.t
type t = T.t type t = T.t
@ -232,34 +231,29 @@ To run a group of source codes and get results/bindings, the necessary methods a
A project has a public field tag with a constant value "reducerProject" A project has a public field tag with a constant value "reducerProject"
project = {tag: "reducerProject"} project = {tag: "reducerProject"}
*/ */
@genType
let createProject = (): reducerProject => Private.createProject()->T.Private.castFromInternalProject let createProject = (): reducerProject => Private.createProject()->T.Private.castFromInternalProject
/* /*
Answer all the source ids of all the sources in the project. Answer all the source ids of all the sources in the project.
*/ */
@genType
let getSourceIds = (project: reducerProject): array<string> => let getSourceIds = (project: reducerProject): array<string> =>
project->T.Private.castToInternalProject->Private.getSourceIds project->T.Private.castToInternalProject->Private.getSourceIds
/* /*
Sets the source for a given source Id. Sets the source for a given source Id.
*/ */
@genType
let setSource = (project: reducerProject, sourceId: string, value: string): unit => let setSource = (project: reducerProject, sourceId: string, value: string): unit =>
project->T.Private.castToInternalProject->Private.setSource(sourceId, value) project->T.Private.castToInternalProject->Private.setSource(sourceId, value)
/* /*
Gets the source for a given source id. Gets the source for a given source id.
*/ */
@genType
let getSource = (project: reducerProject, sourceId: string): option<string> => let getSource = (project: reducerProject, sourceId: string): option<string> =>
project->T.Private.castToInternalProject->Private.getSource(sourceId) project->T.Private.castToInternalProject->Private.getSource(sourceId)
/* /*
Touches the source for a given source id. This and dependent, sources are set to be re-evaluated. Touches the source for a given source id. This and dependent, sources are set to be re-evaluated.
*/ */
@genType
let touchSource = (project: reducerProject, sourceId: string): unit => let touchSource = (project: reducerProject, sourceId: string): unit =>
project->T.Private.castToInternalProject->Private.touchSource(sourceId) project->T.Private.castToInternalProject->Private.touchSource(sourceId)
@ -268,14 +262,12 @@ Cleans the compilation artifacts for a given source ID. The results stay untouch
Normally, you would never need the compilation artifacts again as the results with the same sources would never change. However, they are needed in case of any debugging reruns Normally, you would never need the compilation artifacts again as the results with the same sources would never change. However, they are needed in case of any debugging reruns
*/ */
@genType
let clean = (project: reducerProject, sourceId: string): unit => let clean = (project: reducerProject, sourceId: string): unit =>
project->T.Private.castToInternalProject->Private.clean(sourceId) project->T.Private.castToInternalProject->Private.clean(sourceId)
/* /*
Cleans all the compilation artifacts in all of the project Cleans all the compilation artifacts in all of the project
*/ */
@genType
let cleanAll = (project: reducerProject): unit => let cleanAll = (project: reducerProject): unit =>
project->T.Private.castToInternalProject->Private.cleanAll project->T.Private.castToInternalProject->Private.cleanAll
@ -283,21 +275,18 @@ let cleanAll = (project: reducerProject): unit =>
Cleans results. Compilation stays untouched to be able to re-run the source. Cleans results. Compilation stays untouched to be able to re-run the source.
You would not do this if you were not trying to debug the source code. You would not do this if you were not trying to debug the source code.
*/ */
@genType
let cleanResults = (project: reducerProject, sourceId: string): unit => let cleanResults = (project: reducerProject, sourceId: string): unit =>
project->T.Private.castToInternalProject->Private.cleanResults(sourceId) project->T.Private.castToInternalProject->Private.cleanResults(sourceId)
/* /*
Cleans all results. Compilations remains untouched to rerun the source. Cleans all results. Compilations remains untouched to rerun the source.
*/ */
@genType
let cleanAllResults = (project: reducerProject): unit => let cleanAllResults = (project: reducerProject): unit =>
project->T.Private.castToInternalProject->Private.cleanAllResults project->T.Private.castToInternalProject->Private.cleanAllResults
/* /*
To set the includes one first has to call "parseIncludes". The parsed includes or the parser error is returned. To set the includes one first has to call "parseIncludes". The parsed includes or the parser error is returned.
*/ */
@genType
let getIncludes = (project: reducerProject, sourceId: string): result< let getIncludes = (project: reducerProject, sourceId: string): result<
array<string>, array<string>,
Reducer_ErrorValue.errorValue, Reducer_ErrorValue.errorValue,
@ -306,7 +295,6 @@ let getIncludes = (project: reducerProject, sourceId: string): result<
/* /*
Answers the source codes after which this source code is continuing Answers the source codes after which this source code is continuing
*/ */
@genType
let getContinues = (project: reducerProject, sourceId: string): array<string> => let getContinues = (project: reducerProject, sourceId: string): array<string> =>
project->T.Private.castToInternalProject->Private.getContinues(sourceId) project->T.Private.castToInternalProject->Private.getContinues(sourceId)
@ -315,35 +303,30 @@ let getContinues = (project: reducerProject, sourceId: string): array<string> =>
It is used to define a continuation that is not visible in the source code. It is used to define a continuation that is not visible in the source code.
You can chain source codes on the web interface for example You can chain source codes on the web interface for example
*/ */
@genType
let setContinues = (project: reducerProject, sourceId: string, continues: array<string>): unit => let setContinues = (project: reducerProject, sourceId: string, continues: array<string>): unit =>
project->T.Private.castToInternalProject->Private.setContinues(sourceId, continues) project->T.Private.castToInternalProject->Private.setContinues(sourceId, continues)
/* /*
This source depends on the array of sources returned. This source depends on the array of sources returned.
*/ */
@genType
let getDependencies = (project: reducerProject, sourceId: string): array<string> => let getDependencies = (project: reducerProject, sourceId: string): array<string> =>
project->T.Private.castToInternalProject->Private.getDependencies(sourceId) project->T.Private.castToInternalProject->Private.getDependencies(sourceId)
/* /*
The sources returned are dependent on this The sources returned are dependent on this
*/ */
@genType
let getDependents = (project: reducerProject, sourceId: string): array<string> => let getDependents = (project: reducerProject, sourceId: string): array<string> =>
project->T.Private.castToInternalProject->Private.getDependents(sourceId) project->T.Private.castToInternalProject->Private.getDependents(sourceId)
/* /*
Get the run order for the sources in the project. Get the run order for the sources in the project.
*/ */
@genType
let getRunOrder = (project: reducerProject): array<string> => let getRunOrder = (project: reducerProject): array<string> =>
project->T.Private.castToInternalProject->Private.getRunOrder project->T.Private.castToInternalProject->Private.getRunOrder
/* /*
Get the run order to get the results of this specific source Get the run order to get the results of this specific source
*/ */
@genType
let getRunOrderFor = (project: reducerProject, sourceId: string) => let getRunOrderFor = (project: reducerProject, sourceId: string) =>
project->T.Private.castToInternalProject->Private.getRunOrderFor(sourceId) project->T.Private.castToInternalProject->Private.getRunOrderFor(sourceId)
@ -352,7 +335,6 @@ Parse includes so that you can load them before running.
Load includes by calling getIncludes which returns the includes that have been parsed. Load includes by calling getIncludes which returns the includes that have been parsed.
It is your responsibility to load the includes before running. It is your responsibility to load the includes before running.
*/ */
@genType
let parseIncludes = (project: reducerProject, sourceId: string): unit => let parseIncludes = (project: reducerProject, sourceId: string): unit =>
project->T.Private.castToInternalProject->Private.parseIncludes(sourceId) project->T.Private.castToInternalProject->Private.parseIncludes(sourceId)
@ -361,28 +343,24 @@ Parse the source code if it is not done already.
Use getRawParse to get the parse tree. Use getRawParse to get the parse tree.
You would need this function if you want to see the parse tree without running the source code. You would need this function if you want to see the parse tree without running the source code.
*/ */
@genType
let rawParse = (project: reducerProject, sourceId: string): unit => let rawParse = (project: reducerProject, sourceId: string): unit =>
project->T.Private.castToInternalProject->Private.rawParse(sourceId) project->T.Private.castToInternalProject->Private.rawParse(sourceId)
/* /*
Runs a specific source code if it is not done already. The code is parsed if it is not already done. It runs the dependencies if it is not already done. Runs a specific source code if it is not done already. The code is parsed if it is not already done. It runs the dependencies if it is not already done.
*/ */
@genType
let run = (project: reducerProject, sourceId: string): unit => let run = (project: reducerProject, sourceId: string): unit =>
project->T.Private.castToInternalProject->Private.run(sourceId) project->T.Private.castToInternalProject->Private.run(sourceId)
/* /*
Runs all of the sources in a project. Their results and bindings will be available Runs all of the sources in a project. Their results and bindings will be available
*/ */
@genType
let runAll = (project: reducerProject): unit => let runAll = (project: reducerProject): unit =>
project->T.Private.castToInternalProject->Private.runAll project->T.Private.castToInternalProject->Private.runAll
/* /*
Get the bindings after running this source file or the project Get the bindings after running this source file or the project
*/ */
@genType
let getExternalBindings = ( let getExternalBindings = (
project: reducerProject, project: reducerProject,
sourceId: string, sourceId: string,
@ -392,7 +370,6 @@ let getExternalBindings = (
/* /*
Get the result after running this source file or the project Get the result after running this source file or the project
*/ */
@genType
let getExternalResult = (project: reducerProject, sourceId: string): option< let getExternalResult = (project: reducerProject, sourceId: string): option<
result<ExternalExpressionValue.externalExpressionValue, Reducer_ErrorValue.errorValue>, result<ExternalExpressionValue.externalExpressionValue, Reducer_ErrorValue.errorValue>,
> => project->T.Private.castToInternalProject->Private.getExternalResult(sourceId) > => project->T.Private.castToInternalProject->Private.getExternalResult(sourceId)
@ -402,7 +379,6 @@ This is a convenience function to get the result of a single source without crea
However, without a project, you cannot handle include directives. However, without a project, you cannot handle include directives.
The source has to be include free The source has to be include free
*/ */
@genType
let evaluate = (sourceCode: string): ('r, 'b) => { let evaluate = (sourceCode: string): ('r, 'b) => {
let (result, continuation) = Private.evaluate(sourceCode) let (result, continuation) = Private.evaluate(sourceCode)
( (
@ -411,13 +387,11 @@ let evaluate = (sourceCode: string): ('r, 'b) => {
) )
} }
@genType
let setEnvironment = ( let setEnvironment = (
project: reducerProject, project: reducerProject,
environment: ExternalExpressionValue.environment, environment: ExternalExpressionValue.environment,
): unit => project->T.Private.castToInternalProject->Private.setEnvironment(environment) ): unit => project->T.Private.castToInternalProject->Private.setEnvironment(environment)
@genType
let foreignFunctionInterface = ( let foreignFunctionInterface = (
lambdaValue: ExternalExpressionValue.lambdaValue, lambdaValue: ExternalExpressionValue.lambdaValue,
argArray: array<ExternalExpressionValue.externalExpressionValue>, argArray: array<ExternalExpressionValue.externalExpressionValue>,

View File

@ -34,30 +34,6 @@ type resultString = result<string, distributionError>
@genType @genType
let makeSampleSetDist = SampleSetDist.make let makeSampleSetDist = SampleSetDist.make
// @genType
// let evaluate = Reducer.evaluate
// @genType
// let evaluateUsingOptions = Reducer.evaluateUsingOptions
@genType
let parse = Reducer_Peggy_Parse.parse
// @genType
// let evaluatePartialUsingExternalBindings = Reducer.evaluatePartialUsingExternalBindings
@genType
type externalBindings = Reducer.externalBindings
@genType
type expressionValue = ReducerInterface_ExternalExpressionValue.t
@genType
type recordEV = ReducerInterface_ExternalExpressionValue.record
@genType
type errorValue = Reducer_ErrorValue.errorValue
@genType @genType
let toPointSet = GenericDist.toPointSet let toPointSet = GenericDist.toPointSet
@ -70,30 +46,12 @@ type discreteShape = PointSetTypes.discreteShape
@genType @genType
type continuousShape = PointSetTypes.continuousShape type continuousShape = PointSetTypes.continuousShape
@genType
let errorValueToString = Reducer_ErrorValue.errorToString
@genType @genType
let distributionErrorToString = DistributionTypes.Error.toString let distributionErrorToString = DistributionTypes.Error.toString
@genType
type lambdaValue = ReducerInterface_ExternalExpressionValue.lambdaValue
@genType
type lambdaDeclaration = ReducerInterface_ExternalExpressionValue.lambdaDeclaration
@genType @genType
let defaultSamplingEnv = DistributionOperation.defaultEnv let defaultSamplingEnv = DistributionOperation.defaultEnv
@genType
type environment = ReducerInterface_ExternalExpressionValue.environment
@genType
let defaultEnvironment = ReducerInterface_ExternalExpressionValue.defaultEnvironment
// @genType
// let foreignFunctionInterface = Reducer.foreignFunctionInterface
@genType @genType
type declarationArg = Declaration.arg type declarationArg = Declaration.arg