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")
external ivtVoid_: int = "IvtVoid"

View File

@ -1,4 +1,4 @@
open ForTS_Types
open ForTS_Types_
@genType
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

View File

@ -1,4 +1,4 @@
open ForTS_Types
open ForTS_Types_
@genType
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 internalVoid = int
@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}
//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 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")
type location
@genType
type errorValue =
| REArityError(option<string>, int, int)
| REArrayIndexNotFound(string, int)
@ -23,7 +23,6 @@ type errorValue =
type t = errorValue
@genType
let errorToString = err =>
switch err {
| 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 =>
castWithLocation(error)["location"]
@genType
let parse = (expr: string): result<node, errorValue> =>
try {
Ok(parse__(expr))

View File

@ -10,7 +10,6 @@ module ProjectItem = ReducerProject_ProjectItem
module T = ReducerProject_T
module Topology = ReducerProject_Topology
@genType.opaque
type reducerProject = 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"
project = {tag: "reducerProject"}
*/
@genType
let createProject = (): reducerProject => Private.createProject()->T.Private.castFromInternalProject
/*
Answer all the source ids of all the sources in the project.
*/
@genType
let getSourceIds = (project: reducerProject): array<string> =>
project->T.Private.castToInternalProject->Private.getSourceIds
/*
Sets the source for a given source Id.
*/
@genType
let setSource = (project: reducerProject, sourceId: string, value: string): unit =>
project->T.Private.castToInternalProject->Private.setSource(sourceId, value)
/*
Gets the source for a given source id.
*/
@genType
let getSource = (project: reducerProject, sourceId: string): option<string> =>
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.
*/
@genType
let touchSource = (project: reducerProject, sourceId: string): unit =>
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
*/
@genType
let clean = (project: reducerProject, sourceId: string): unit =>
project->T.Private.castToInternalProject->Private.clean(sourceId)
/*
Cleans all the compilation artifacts in all of the project
*/
@genType
let cleanAll = (project: reducerProject): unit =>
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.
You would not do this if you were not trying to debug the source code.
*/
@genType
let cleanResults = (project: reducerProject, sourceId: string): unit =>
project->T.Private.castToInternalProject->Private.cleanResults(sourceId)
/*
Cleans all results. Compilations remains untouched to rerun the source.
*/
@genType
let cleanAllResults = (project: reducerProject): unit =>
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.
*/
@genType
let getIncludes = (project: reducerProject, sourceId: string): result<
array<string>,
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
*/
@genType
let getContinues = (project: reducerProject, sourceId: string): array<string> =>
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.
You can chain source codes on the web interface for example
*/
@genType
let setContinues = (project: reducerProject, sourceId: string, continues: array<string>): unit =>
project->T.Private.castToInternalProject->Private.setContinues(sourceId, continues)
/*
This source depends on the array of sources returned.
*/
@genType
let getDependencies = (project: reducerProject, sourceId: string): array<string> =>
project->T.Private.castToInternalProject->Private.getDependencies(sourceId)
/*
The sources returned are dependent on this
*/
@genType
let getDependents = (project: reducerProject, sourceId: string): array<string> =>
project->T.Private.castToInternalProject->Private.getDependents(sourceId)
/*
Get the run order for the sources in the project.
*/
@genType
let getRunOrder = (project: reducerProject): array<string> =>
project->T.Private.castToInternalProject->Private.getRunOrder
/*
Get the run order to get the results of this specific source
*/
@genType
let getRunOrderFor = (project: reducerProject, sourceId: string) =>
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.
It is your responsibility to load the includes before running.
*/
@genType
let parseIncludes = (project: reducerProject, sourceId: string): unit =>
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.
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 =>
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.
*/
@genType
let run = (project: reducerProject, sourceId: string): unit =>
project->T.Private.castToInternalProject->Private.run(sourceId)
/*
Runs all of the sources in a project. Their results and bindings will be available
*/
@genType
let runAll = (project: reducerProject): unit =>
project->T.Private.castToInternalProject->Private.runAll
/*
Get the bindings after running this source file or the project
*/
@genType
let getExternalBindings = (
project: reducerProject,
sourceId: string,
@ -392,7 +370,6 @@ let getExternalBindings = (
/*
Get the result after running this source file or the project
*/
@genType
let getExternalResult = (project: reducerProject, sourceId: string): option<
result<ExternalExpressionValue.externalExpressionValue, Reducer_ErrorValue.errorValue>,
> => 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.
The source has to be include free
*/
@genType
let evaluate = (sourceCode: string): ('r, 'b) => {
let (result, continuation) = Private.evaluate(sourceCode)
(
@ -411,13 +387,11 @@ let evaluate = (sourceCode: string): ('r, 'b) => {
)
}
@genType
let setEnvironment = (
project: reducerProject,
environment: ExternalExpressionValue.environment,
): unit => project->T.Private.castToInternalProject->Private.setEnvironment(environment)
@genType
let foreignFunctionInterface = (
lambdaValue: ExternalExpressionValue.lambdaValue,
argArray: array<ExternalExpressionValue.externalExpressionValue>,

View File

@ -34,30 +34,6 @@ type resultString = result<string, distributionError>
@genType
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
let toPointSet = GenericDist.toPointSet
@ -70,30 +46,12 @@ type discreteShape = PointSetTypes.discreteShape
@genType
type continuousShape = PointSetTypes.continuousShape
@genType
let errorValueToString = Reducer_ErrorValue.errorToString
@genType
let distributionErrorToString = DistributionTypes.Error.toString
@genType
type lambdaValue = ReducerInterface_ExternalExpressionValue.lambdaValue
@genType
type lambdaDeclaration = ReducerInterface_ExternalExpressionValue.lambdaDeclaration
@genType
let defaultSamplingEnv = DistributionOperation.defaultEnv
@genType
type environment = ReducerInterface_ExternalExpressionValue.environment
@genType
let defaultEnvironment = ReducerInterface_ExternalExpressionValue.defaultEnvironment
// @genType
// let foreignFunctionInterface = Reducer.foreignFunctionInterface
@genType
type declarationArg = Declaration.arg