RENeedToRun->Error

This commit is contained in:
Umur Ozkul 2022-08-25 10:43:51 +02:00
parent b2fa0db627
commit 1dfc9fe820
9 changed files with 25 additions and 16 deletions

View File

@ -11,7 +11,7 @@ open Expect.Operators
let runFetchResult = (project, sourceId) => {
Project.run(project, sourceId)
Project.getResult(project, sourceId)->InternalExpressionValue.toStringOptionResult
Project.getResult(project, sourceId)->InternalExpressionValue.toStringResult
}
let runFetchBindings = (project, sourceId) => {

View File

@ -50,7 +50,7 @@ Case "Running a single source".
/* Let's display the result and bindings */
(
result->InternalExpressionValue.toStringOptionResult,
result->InternalExpressionValue.toStringResult,
bindings->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString,
)->expect == ("Ok(3)", "@{}")
/* You've got 3 with empty bindings. */
@ -64,7 +64,7 @@ Case "Running a single source".
let bindings = Project.getBindings(project, "main")
/* Now you have external bindings and external result. */
(
result->InternalExpressionValue.toStringOptionResult,
result->InternalExpressionValue.toStringResult,
bindings->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString,
)->expect == ("Ok(3)", "@{}")
})
@ -80,7 +80,7 @@ Case "Running a single source".
Project.runAll(project)
let result = Project.getResult(project, "main")
let _bindings = Project.getBindings(project, "main")
result->InternalExpressionValue.toStringOptionResult->expect == "Ok(3)"
result->InternalExpressionValue.toStringResult->expect == "Ok(3)"
})
test("shortcut", () => {

View File

@ -32,7 +32,7 @@ describe("ReducerProject Tutorial", () => {
let bindings3 = Project.getBindings(project, "source3")
(
result3->InternalExpressionValue.toStringOptionResult,
result3->InternalExpressionValue.toStringResult,
bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString,
)->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}")
})
@ -58,7 +58,7 @@ describe("ReducerProject Tutorial", () => {
let bindings3 = Project.getBindings(project, "source3")
(
result3->InternalExpressionValue.toStringOptionResult,
result3->InternalExpressionValue.toStringResult,
bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString,
)->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}")
})
@ -94,7 +94,7 @@ describe("ReducerProject Tutorial", () => {
let bindings3 = Project.getBindings(project, "source3")
(
result3->InternalExpressionValue.toStringOptionResult,
result3->InternalExpressionValue.toStringResult,
bindings3->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString,
)->expect == ("Ok(())", "@{x: 1,y: 2,z: 3}")
/*

View File

@ -146,7 +146,7 @@ Here we will finally proceed to a real life scenario. */
/* And see the result and bindings.. */
test("recursive includes", () => {
(
result->InternalExpressionValue.toStringOptionResult,
result->InternalExpressionValue.toStringResult,
bindings->InternalExpressionValue.IEvBindings->InternalExpressionValue.toString,
)->expect == ("Ok(6)", "@{doubleX: 2,x: 1,y: 2,z: 3}")
/* Everything as expected */

View File

@ -30,7 +30,7 @@ describe("ReducerProject Tutorial", () => {
/* We can now run the project */
Project.runAll(project)
let result = Project.getResult(project, "main")
result->InternalExpressionValue.toStringOptionResult->expect == "Ok(6)"
result->InternalExpressionValue.toStringResult->expect == "Ok(6)"
})
})

View File

@ -32,7 +32,7 @@ describe("ReducerProject Tutorial", () => {
test("userResults", () => {
let userResultsAsString = Belt.Array.map(userResults, aResult =>
aResult->InternalExpressionValue.toStringOptionResult
aResult->InternalExpressionValue.toStringResult
)
userResultsAsString->expect == ["Ok(2)", "Ok(4)", "Ok(6)", "Ok(8)", "Ok(10)"]
})

View File

@ -194,8 +194,9 @@ let getBindings = (project: reducerProject, sourceId: string): squiggleValue_Mod
Get the result after running this source file or the project
*/
@genType
let getResult = (project: reducerProject, sourceId: string): option<
result<squiggleValue, reducerErrorValue>,
let getResult = (project: reducerProject, sourceId: string): result<
squiggleValue,
reducerErrorValue,
> => project->T.Private.castToInternalProject->Private.getResult(sourceId)
/*

View File

@ -21,6 +21,7 @@ type errorValue =
| RESyntaxError(string, option<syntaxErrorLocation>)
| RETodo(string) // To do
| REUnitNotFound(string)
| RENeedToRun
type t = errorValue
@ -57,4 +58,5 @@ let errorToString = err =>
| RETodo(msg) => `TODO: ${msg}`
| REExpectedType(typeName, valueString) => `Expected type: ${typeName} but got: ${valueString}`
| REUnitNotFound(unitName) => `Unit not found: ${unitName}`
| RENeedToRun => "Need to run"
}

View File

@ -96,9 +96,15 @@ module Private = {
Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _)
}
let getResult = (project: t, sourceId: string): ProjectItem.T.resultType =>
let getResultOption = (project: t, sourceId: string): ProjectItem.T.resultType =>
project->getItem(sourceId)->ProjectItem.getResult
let getResult = (project: t, sourceId: string): ProjectItem.T.resultArgumentType =>
switch getResultOption(project, sourceId) {
| None => RENeedToRun->Error
| Some(result) => result
}
let setResult = (project: t, sourceId: string, value: ProjectItem.T.resultArgumentType): unit => {
let newItem = project->getItem(sourceId)->ProjectItem.setResult(value)
Belt.Map.String.set(project["items"], sourceId, newItem)->T.Private.setFieldItems(project, _)
@ -154,7 +160,7 @@ module Private = {
sourceId: string,
(rPrevResult: ProjectItem.T.resultArgumentType, continuation: ProjectItem.T.continuation),
): (ProjectItem.T.resultArgumentType, ProjectItem.T.continuation) => {
switch getResult(project, sourceId) {
switch getResultOption(project, sourceId) {
| Some(result) => (result, getContinuation(project, sourceId)) // already ran
| None =>
switch rPrevResult {
@ -165,7 +171,7 @@ module Private = {
| Ok(_prevResult) => {
doRunWithContinuation(project, sourceId, continuation)
(
getResult(project, sourceId)->Belt.Option.getWithDefault(rPrevResult),
getResultOption(project, sourceId)->Belt.Option.getWithDefault(rPrevResult),
getContinuation(project, sourceId),
)
}
@ -197,6 +203,6 @@ module Private = {
let these = project->getStdLib
let ofUser = Continuation.minus(those, these)
(getResult(project, "main")->Belt.Option.getWithDefault(IEvVoid->Ok), ofUser)
(getResultOption(project, "main")->Belt.Option.getWithDefault(IEvVoid->Ok), ofUser)
}
}