Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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 src/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
runtime: createEmptyRuntime(),
numberOfOuterEnvironments: 1,
prelude: null,
pendingStreamFnStack: [],
streamLineage: new Map<string, string[]>(),
debugger: createEmptyDebugger(),
nativeStorage: createNativeStorage(),
executionMethod: 'auto',
Expand Down Expand Up @@ -363,7 +365,7 @@
'call_cc(f)',
context.variant === Variant.EXPLICIT_CONTROL
? call_with_current_continuation
: (f: any) => {

Check warning on line 368 in src/createContext.ts

View workflow job for this annotation

GitHub Actions / build

'f' is defined but never used. Allowed unused args must match /^_/u
throw new Error('call_cc is only available in Explicit-Control variant');
},
);
Expand Down
29 changes: 29 additions & 0 deletions src/cse-machine/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ export function* generateCSEMachineStateStream(
context.runtime.changepointSteps.push(steps + 1);
}

const evalResult = context.runtime.stash?.peek();
const mostRecentControlHeight =
context.pendingStreamFnStack[context.pendingStreamFnStack.length - 1]?.[1];

if (
Array.isArray(evalResult) &&
evalResult.length === 2 &&
mostRecentControlHeight !== undefined &&
context.runtime.control?.size() === mostRecentControlHeight - 1
) {
const mostRecentNullaryFnId = context.pendingStreamFnStack.pop()?.[0];
if (mostRecentNullaryFnId !== undefined) {
if (!context.streamLineage.get(mostRecentNullaryFnId)) {
context.streamLineage.set(mostRecentNullaryFnId, []);
}
context.streamLineage.get(mostRecentNullaryFnId)?.push((evalResult as any).id);
}
}

control.pop();
if (isNode(command)) {
context.runtime.nodes.shift();
Expand Down Expand Up @@ -834,6 +853,16 @@ const cmdEvaluators: CommandEvaluators = {
context.runtime.environments.unshift(func.environment);
}

// Streams Visualisation:
// If CALL0, push the nullary fn to pendingStreamFnStack
// (to map which nullary fn produces which pairs; for nested nullary fn)
if (func.node.params.length === 0) {
context.pendingStreamFnStack.push([
func.id,
context.runtime.control !== null ? context.runtime.control.size() : 0,
]);
}

// Handle special case if function is simple
if (isSimpleFunction(func.node)) {
// Closures convert ArrowExpressionStatements to BlockStatements
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export interface Context<T = any> {
changepointSteps: number[];
};

// STREAM VISUALISATION
streamLineage: Map<string, string[]>;

pendingStreamFnStack: [string, number][];

numberOfOuterEnvironments: number;

prelude: string | null;
Expand Down
Loading