diff --git a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res index 9244c515..3a990326 100644 --- a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res +++ b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject.res @@ -10,8 +10,8 @@ module ProjectItem = ReducerProject_ProjectItem module T = ReducerProject_T module Topology = ReducerProject_Topology -@genType.opaque type project = T.t +@genType.opaque type t = T.t module Private = { @@ -27,6 +27,7 @@ module Private = { let createProject = () => { let this: t = { + "tag": "reducerProject", "items": Belt.Map.String.empty, "stdLib": ReducerInterface_StdLib.internalStdLib, "environment": InternalExpressionValue.defaultEnvironment, @@ -226,30 +227,38 @@ To run a group of source codes and get results/bindings, the necessary methods a - run or runAll - getExternalBindings - getExternalResult + +A project has a public field tag with a constant value "reducerProject" +project = {tag: "reducerProject"} */ +@genType let createProject = (): t => Private.createProject()->T.Private.castFromInternalProject /* Answer all the source ids of all the sources in the project. */ +@genType let getSourceIds = (this: t): array => this->T.Private.castToInternalProject->Private.getSourceIds /* Sets the source for a given source Id. */ +@genType let setSource = (this: t, sourceId: string, value: string): unit => this->T.Private.castToInternalProject->Private.setSource(sourceId, value) /* Gets the source for a given source id. */ +@genType let getSource = (this: t, sourceId: string): option => this->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 = (this: t, sourceId: string): unit => this->T.Private.castToInternalProject->Private.touchSource(sourceId) @@ -258,36 +267,44 @@ 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 = (this: t, sourceId: string): unit => this->T.Private.castToInternalProject->Private.clean(sourceId) /* Cleans all the compilation artifacts in all of the project */ +@genType let cleanAll = (this: t): unit => this->T.Private.castToInternalProject->Private.cleanAll /* 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 = (this: t, sourceId: string): unit => this->T.Private.castToInternalProject->Private.cleanResults(sourceId) /* Cleans all results. Compilations remains untouched to rerun the source. */ +@genType let cleanAllResults = (this: t): unit => this->T.Private.castToInternalProject->Private.cleanAllResults /* To set the includes one first has to call "parseIncludes". The parsed includes or the parser error is returned. */ -let getIncludes = (this: t, sourceId: string): ProjectItem.T.includesType => - this->T.Private.castToInternalProject->Private.getIncludes(sourceId) +@genType +let getIncludes = (this: t, sourceId: string): result< + array, + Reducer_ErrorValue.errorValue, +> => this->T.Private.castToInternalProject->Private.getIncludes(sourceId) /* Answers the source codes after which this source code is continuing */ +@genType let getContinues = (this: t, sourceId: string): array => this->T.Private.castToInternalProject->Private.getContinues(sourceId) @@ -296,35 +313,35 @@ let getContinues = (this: t, sourceId: string): array => 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 = (this: t, sourceId: string, continues: array): unit => this->T.Private.castToInternalProject->Private.setContinues(sourceId, continues) -/* -Break the continuation chain. This source will become a standalone source. -*/ -let removeContinues = (this: t, sourceId: string): unit => - this->T.Private.castToInternalProject->Private.removeContinues(sourceId) - /* This source depends on the array of sources returned. */ +@genType let getDependencies = (this: t, sourceId: string): array => this->T.Private.castToInternalProject->Private.getDependencies(sourceId) /* The sources returned are dependent on this */ +@genType let getDependents = (this: t, sourceId: string): array => this->T.Private.castToInternalProject->Private.getDependents(sourceId) /* Get the run order for the sources in the project. */ -let getRunOrder = (this: t) => this->T.Private.castToInternalProject->Private.getRunOrder +@genType +let getRunOrder = (this: t): array => + this->T.Private.castToInternalProject->Private.getRunOrder /* Get the run order to get the results of this specific source */ +@genType let getRunOrderFor = (this: t, sourceId: string) => this->T.Private.castToInternalProject->Private.getRunOrderFor(sourceId) @@ -333,6 +350,7 @@ 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 = (this: t, sourceId: string): unit => this->T.Private.castToInternalProject->Private.parseIncludes(sourceId) @@ -341,29 +359,34 @@ 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 = (this: t, sourceId: string): unit => this->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 = (this: t, sourceId: string): unit => this->T.Private.castToInternalProject->Private.run(sourceId) /* Runs all of the sources in a project. Their results and bindings will be available */ +@genType let runAll = (this: t): unit => this->T.Private.castToInternalProject->Private.runAll /* Get the bindings after running this source file or the project */ +@genType let getExternalBindings = (this: t, sourceId: string): ExternalExpressionValue.record => this->T.Private.castToInternalProject->Private.getExternalBindings(sourceId) /* Get the result after running this source file or the project */ +@genType let getExternalResult = (this: t, sourceId: string): option< result, > => this->T.Private.castToInternalProject->Private.getExternalResult(sourceId) @@ -373,6 +396,7 @@ 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) ( @@ -381,6 +405,7 @@ let evaluate = (sourceCode: string): ('r, 'b) => { ) } +@genType let foreignFunctionInterface = ( lambdaValue: ExternalExpressionValue.lambdaValue, argArray: array, diff --git a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res index 9e14c70c..c7bf968a 100644 --- a/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res +++ b/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_T.res @@ -2,11 +2,12 @@ module ProjectItem = ReducerProject_ProjectItem module ExpressionT = Reducer_Expression_T module ProjectAccessorsT = ReducerProject_ProjectAccessors_T -type project = Object +type project = {"tag": string} type t = project module Private = { type internalProject = { + "tag": string, "items": Belt.Map.String.t, "stdLib": Reducer_Bindings.t, "environment": ExpressionT.environment,