Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ Thus, evaluators are responsible for providing functions to allow modules to rea
Each of the data types passed as identifier have functions to create an instance of that data type,
as well as read and write data to it (or call it, in the case of closures). See `conductor/types/IDataHandler`.

In the case of closures, the `closure_call` and `closure_call_unchecked` return `AsyncGenerator`s. In the case of CSE machines, yielding a closure call to a CSE closure would allow the module function to defer the execution until the closure's return value is executed.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The phrase "until the closure's return value is executed" is slightly confusing, as a return value itself is not executed. Consider rephrasing it to "until the closure's execution is completed and its return value is returned" or "until the closure is executed and its return value is obtained".


### Standard library

A standard library of functions must be made available to modules. See `conductor/stdlib` for sample implementations.
Expand Down
5 changes: 2 additions & 3 deletions src/conductor/stdlib/list/accumulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import { DataType, type IDataHandler, type TypedValue } from "../../types"
* @param resultType The (expected) type of the result.
* @returns A Promise resolving to the result of accumulating the Closure over the List.
*/
export async function accumulate<T extends Exclude<DataType, DataType.VOID>>(this: IDataHandler, op: TypedValue<DataType.CLOSURE, T>, initial: TypedValue<T>, sequence: TypedValue<DataType.LIST>, resultType: T): Promise<TypedValue<T>> {
export async function* accumulate<T extends Exclude<DataType, DataType.VOID>>(this: IDataHandler, op: TypedValue<DataType.CLOSURE, T>, initial: TypedValue<T>, sequence: TypedValue<DataType.LIST>, resultType: T): AsyncGenerator<void, TypedValue<T>, undefined> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The JSDoc @returns tag is outdated. It still states that the function returns a Promise, but the signature has been updated to return an AsyncGenerator. Please update the JSDoc to reflect this change.

const vec = await this.list_to_vec(sequence);
let result = initial;
for (let i = vec.length - 1; i >= 0; --i) {
result = await this.closure_call(op, [vec[i], result], resultType);
result = yield* this.closure_call(op, [vec[i], result], resultType);
}

return result;
}
2 changes: 1 addition & 1 deletion src/conductor/types/moduleInterface/ExternCallable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ type DataTypeMap<T extends readonly [...DataType[]]> = {
[Idx in keyof T]: TypedValue<T[Idx]>
};

export type ExternCallable<Arg extends readonly DataType[], Ret extends DataType> = (...args: DataTypeMap<Arg>) => TypedValue<Ret> | Promise<TypedValue<Ret>>;
export type ExternCallable<Arg extends readonly DataType[], Ret extends DataType> = (...args: DataTypeMap<Arg>) => AsyncGenerator<void, TypedValue<Ret>, undefined>;
6 changes: 3 additions & 3 deletions src/conductor/types/moduleInterface/IDataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ export interface IDataHandler {
* @param returnType The expected type of the returned value.
* @returns A promise to the returned typed value.
*/
closure_call<T extends DataType>(c: TypedValue<DataType.CLOSURE, T>, args: TypedValue<DataType>[], returnType: T): Promise<TypedValue<NoInfer<T>>>;
closure_call<T extends DataType>(c: TypedValue<DataType.CLOSURE, T>, args: TypedValue<DataType>[], returnType: T): AsyncGenerator<void, TypedValue<NoInfer<T>>, undefined>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The JSDoc @returns tag for closure_call is outdated. It still documents the return type as a Promise, but it now returns an AsyncGenerator. Please update the JSDoc to reflect this change.


/**
* Calls a Closure of known return type.
* @param c The Closure to be called.
* @param args An array of typed arguments to be passed to the Closure.
* @returns A promise to the returned typed value.
*/
closure_call_unchecked<T extends DataType>(c: TypedValue<DataType.CLOSURE, T>, args: TypedValue<DataType>[]): Promise<TypedValue<NoInfer<T>>>;
closure_call_unchecked<T extends DataType>(c: TypedValue<DataType.CLOSURE, T>, args: TypedValue<DataType>[]): AsyncGenerator<void, TypedValue<NoInfer<T>>, undefined>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The JSDoc @returns tag for closure_call_unchecked is outdated. It still documents the return type as a Promise, but it now returns an AsyncGenerator. Please update the JSDoc to reflect this change.


/**
* Asserts the arity of a Closure.
Expand Down Expand Up @@ -208,6 +208,6 @@ export interface IDataHandler {
list(...elements: TypedValue<DataType>[]): Promise<TypedValue<DataType.LIST>>;
is_list(xs: TypedValue<DataType.LIST>): Promise<boolean>;
list_to_vec(xs: TypedValue<DataType.LIST>): Promise<TypedValue<DataType>[]>;
accumulate<T extends Exclude<DataType, DataType.VOID>>(op: TypedValue<DataType.CLOSURE, T>, initial: TypedValue<T>, sequence: TypedValue<DataType.LIST>, resultType: T): Promise<TypedValue<T>>;
accumulate<T extends Exclude<DataType, DataType.VOID>>(op: TypedValue<DataType.CLOSURE, T>, initial: TypedValue<T>, sequence: TypedValue<DataType.LIST>, resultType: T): AsyncGenerator<void, TypedValue<T>, undefined>;
length(xs: TypedValue<DataType.LIST>): Promise<number>;
}